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

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

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};

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.

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

This article has been dead for over six months. Start a new discussion instead.