rotate a TBitmap using scanlines?!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 23
Reputation: OnIIcE is an unknown quantity at this point 
Solved Threads: 0
OnIIcE OnIIcE is offline Offline
Newbie Poster

rotate a TBitmap using scanlines?!

 
0
  #1
Feb 15th, 2008
hello!

im trying to rotate a tbitmap image using scanlines, and cant figure out how to do it!
ive go it working moving pixel by pixel but i want to be able to speed it up using scanlines.
im using borland 6 C++, and doin some reasearch they (borland) gave away this sample of code of their website that does exactly it, but its in pascal and ive had trouble trying to convert the language =(
ive included the file you get from the site which does it, if anyone can help translate!

thanks alot =)

Edit:
oh and if your sceptical of the file, you can download it direct or see it etc here
http://codecentral.borland.com/Item/13804
Last edited by OnIIcE; Feb 15th, 2008 at 5:45 pm.
Attached Files
File Type: zip 13804_flip_reverse_rotate_a_bitmap.ZIP (298.7 KB, 16 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: rotate a TBitmap using scanlines?!

 
0
  #2
Feb 15th, 2008
This should get you started.

Please note that I've never used Borland C++ Builder, I don't have it, and I have not tested this code.

I only translated the EBitmapError class and the RotateScanline90 function set.

Hope this helps.
Attached Files
File Type: zip frrl.zip (2.0 KB, 26 views)
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 23
Reputation: OnIIcE is an unknown quantity at this point 
Solved Threads: 0
OnIIcE OnIIcE is offline Offline
Newbie Poster

Re: rotate a TBitmap using scanlines?!

 
0
  #3
Feb 16th, 2008
hi thanks alot! it worked wounders! i just had to change a couple of things to make it work in borland! =D
thanks very muchly =)

would it be easy to translate the reverse function (using scan lines)?
if its to much trouble thats find since you help me lots! i spent hours thursday and friday night trying to do that!!

i think its just this function:

  1. FUNCTION FlipReverseScanLine(CONST Flip, Reverse: BOOLEAN;
  2. CONST Bitmap: TBitmap): TBitmap;
  3. VAR
  4. i : INTEGER;
  5. j : INTEGER;
  6. RowIn : pRGBArray;
  7. RowOut: pRGBArray;
  8. BEGIN
  9. IF Bitmap.PixelFormat <> pf24bit
  10. THEN RAISE EBitmapError.Create('Can Flip/Reverse only 24-bit bitmap');
  11.  
  12. RESULT := TBitmap.Create;
  13. RESULT.Width := Bitmap.Width;
  14. RESULT.Height := Bitmap.Height;
  15. RESULT.PixelFormat := Bitmap.PixelFormat;
  16.  
  17. FOR j := 0 TO Bitmap.Height-1 DO
  18. BEGIN
  19. RowIn := Bitmap.Scanline[j];
  20. IF Flip
  21. THEN RowOut := RESULT.Scanline[Bitmap.Height - 1 - j]
  22. ELSE RowOut := RESULT.Scanline[j];
  23.  
  24. // Optimization technique: Use two FOR loops so IF is outside of inner loop
  25. IF Reverse
  26. THEN BEGIN
  27. FOR i := 0 TO Bitmap.Width-1 DO
  28. RowOut[i] := RowIn[Bitmap.Width-1-i]
  29. END
  30. ELSE BEGIN
  31. FOR i := 0 TO Bitmap.Width-1 DO
  32. RowOut[i] := RowIn[i]
  33. END
  34.  
  35. END
  36. END {FlipReverseScanLine};
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: rotate a TBitmap using scanlines?!

 
0
  #4
Feb 16th, 2008
With what I've given you already you should be able to do it yourself. I know it is tough at first but the functions are all so similar that you can do it.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 23
Reputation: OnIIcE is an unknown quantity at this point 
Solved Threads: 0
OnIIcE OnIIcE is offline Offline
Newbie Poster

Re: rotate a TBitmap using scanlines?!

 
0
  #5
Feb 16th, 2008
true, it was lazy of me to ask! but ive tried now, and i keep getting a error when the code runs saying that the scanline is out of range!

this what ive got to reverse/mirror the image

  1. for(int j=0; j < (ImgHeight-1);j++)
  2. {
  3. rowIn = (S_PixelColours*)OrigImg->ScanLine[j];
  4. rowOut = (S_PixelColours*)result->ScanLine[j];
  5. for(int i=0; i<(ImgWidth-1);i++)
  6. {
  7. rowOut[i] = rowIn[ImgWidth-1-j];
  8. }
edit:
ive amended my code slightly, and now i dont have a error, it just messes the picture up lots!

edit2:

ahhh ive realised my mistake! i was minusing j instead of i !!!!
thanks alot again =)
Last edited by OnIIcE; Feb 16th, 2008 at 3:58 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC