Recent

Author Topic: Trouble in mirroring a bitmap  (Read 4670 times)

CSGM

  • Newbie
  • Posts: 3
Trouble in mirroring a bitmap
« on: December 28, 2010, 07:15:37 pm »
Hi everyone, I'm a new user of Lazarus and FPC, and I'm have some trouble when I try to mirror a bitmap along the y axe.

I'm working in window7, professional edition.

I have the same code in Delphi and it works fine. But the similar code (below) in Lazarus doesnt work.

I thank a lot for any help or tip.

I have implemented the following code in Lazarus:

also follow the original bitmap and output using the sent code.

Thanks

csgm

{-----------------------------------------------------------------}

type
    TRGBArray = array[0..3] of TRGBTriple;
    pRGBArray = ^TRGBArray;

procedure MirrorVertical(Bitmap: TBitmap);
var i, j, w: Integer;
    In: pRGBArray;
    Out: pRGBArray;
begin
     w := bitmap.width * sizeof(TRGBTriple);
     GetMem(In, w);

     auxLBMP:=bitmap.CreateIntfImage;

     for j := 0 to Bitmap.Height - 1
     do begin
             move(auxLBMP.GetDataLineStart(j)^, In^, w);
             Out := auxLBMP.GetDataLineStart(j);
             for i := 0 to Bitmap.Width - 1
             do Out := In[Bitmap.Width - 1 - i];
        end;

     bitmap.LoadFromIntfImage(auxLBMP);
     auxLBMP.Free;
     FreeMem(In);
end;
{-----------------------------------------------------------------}

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: Trouble in mirroring a bitmap
« Reply #1 on: December 29, 2010, 01:41:24 pm »
Not the most efficient code.
A few things:
- What the use of an array [0..3] of RGB triple ?
- You assume the line data is stored as 24bit RGB and not as RGBA
- you don't increase the Out pointer, so you overwrite the first pixel of every line
- For now try avoiding LoadFromIntfImage, since it loads through the BitmapHandle and MaskHandle, which converts the image to a devicedepth (and possibly destroying alpha)

Try following
Code: Pascal  [Select][+][-]
  1. type
  2.   PRGBTriple = ^TRGBTriple;
  3.  
  4. procedure MirrorVertical(Bitmap: TBitmap);
  5. var
  6.   i, j, half: Integer;
  7.   Pixel: TRGBTriple;
  8.   In: PRGBTriple;
  9.   Out: PRGBTriple;
  10. begin
  11.    auxLBMP := bitmap.CreateIntfImage;
  12.    half := Bitmap.Width div 2 - 1;
  13.    for j := 0 to Bitmap.Height - 1 do
  14.    begin
  15.       In := auxLBMP.GetDataLineStart(j);
  16.       Out := In;
  17.       Inc(In, Bitmap.Width - 1);
  18.       for i := 0 to half do
  19.       begin
  20.          Pixel := Out^;
  21.          Out^ := In^;
  22.          In^ := Pixel;
  23.          Inc(Out);
  24.          Dec(In);
  25.       end;
  26.    end;
  27.    bitmap.LoadFromIntfImage(auxLBMP);
  28.    auxLBMP.Free;
  29. end;
  30.  
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

CSGM

  • Newbie
  • Posts: 3
Re: Trouble in mirroring a bitmap
« Reply #2 on: December 29, 2010, 03:46:48 pm »
Hi Marc, thank you very much for answer my doubt. The code has worked very fine.

I'm going to check the rest of my code.

Can you indicate some material to study about graphic manipulation?

Once, Thank you very much.

 

TinyPortal © 2005-2018