954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

rotate a TBitmap using scanlines?!

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

Attachments 13804_flip_reverse_rotate_a_bitmap.ZIP (298.66KB)
OnIIcE
Light Poster
34 posts since Dec 2007
Reputation Points: 9
Solved Threads: 1
 

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.

Attachments frrl.zip (2.02KB)
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

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:

FUNCTION FlipReverseScanLine(CONST Flip, Reverse:  BOOLEAN;
                               CONST Bitmap:  TBitmap):  TBitmap;
  VAR
    i     :  INTEGER;
    j     :  INTEGER;
    RowIn :  pRGBArray;
    RowOut:  pRGBArray;
  BEGIN
    IF   Bitmap.PixelFormat <> pf24bit
    THEN RAISE EBitmapError.Create('Can Flip/Reverse only 24-bit bitmap');

    RESULT := TBitmap.Create;
    RESULT.Width       := Bitmap.Width;
    RESULT.Height      := Bitmap.Height;
    RESULT.PixelFormat := Bitmap.PixelFormat;

    FOR j := 0 TO Bitmap.Height-1 DO
    BEGIN
      RowIn := Bitmap.Scanline[j];
      IF   Flip
      THEN RowOut := RESULT.Scanline[Bitmap.Height - 1 - j]
      ELSE RowOut := RESULT.Scanline[j];

      // Optimization technique:  Use two FOR loops so IF is outside of inner loop
      IF   Reverse
      THEN BEGIN
        FOR i := 0 TO Bitmap.Width-1 DO
          RowOut[i] := RowIn[Bitmap.Width-1-i]
      END
      ELSE BEGIN
        FOR i := 0 TO Bitmap.Width-1 DO
          RowOut[i] := RowIn[i]
      END

    END
  END {FlipReverseScanLine};
OnIIcE
Light Poster
34 posts since Dec 2007
Reputation Points: 9
Solved Threads: 1
 

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.

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

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

for(int j=0; j < (ImgHeight-1);j++)
	{
	rowIn = (S_PixelColours*)OrigImg->ScanLine[j];
        rowOut = (S_PixelColours*)result->ScanLine[j];
	for(int i=0; i<(ImgWidth-1);i++)
	{
        rowOut[i] = rowIn[ImgWidth-1-j];
	}

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 =)

OnIIcE
Light Poster
34 posts since Dec 2007
Reputation Points: 9
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You