Recent

Author Topic: delphi to lazarus ...?  (Read 12092 times)

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« on: December 03, 2006, 07:49:04 pm »
hi


how to convert this code to lazarus.


Code: [Select]


procedure FindAlphaChannel(Dest, Image0, Image1: TBitmap; Bk1, Bk2: Cardinal);
var
 Index   : Integer;
 ScanIndx: Integer;

 BackValue1: Real;
 BackValue2: Real;

 Pixel1: Real;
 Pixel2: Real;

 Pixel : Real;
 Alpha : Real;

 Read0: PCardinal;
 Read1: PCardinal;
 Write: PCardinal;

 Color: Cardinal;
begin
 BackValue1:= Pixel2GrayEx(Bk1);
 BackValue2:= Pixel2GrayEx(Bk2);

 if (Image0.PixelFormat <> pf32bit) then Image0.PixelFormat:= pf32bit;
 if (Image1.PixelFormat <> pf32bit) then Image1.PixelFormat:= pf32bit;

 Dest.Width := Image0.Width;
 Dest.Height:= Image0.Height;
 if (Dest.PixelFormat <> pf32bit) then Dest.PixelFormat:= pf32bit;

 for ScanIndx:= 0 to Dest.Height - 1 do
  begin
   Read0:= Image0.Scanline[ScanIndx];
   Read1:= Image1.Scanline[ScanIndx];
   Write:= Dest.Scanline[ScanIndx];

   for Index:= 0 to Dest.Width - 1 do
    begin
     // retreive source grayscale pixels
     Pixel1:= Pixel2GrayEx(Read0^);
     Pixel2:= Pixel2GrayEx(Read1^);

     // calculate alpha-value and original pixel
     ExtractAlpha(Pixel1, Pixel2, BackValue1, BackValue2, Alpha, Pixel);

     // convert normalized pixel to color index
     Color:= Round(Pixel * 255.0);
     // prepare a 24-bit RGB color
     Color:= Color or (Color shl 8) or (Color shl 16);
     // add alpha-channel to 24-bit RGB color and write it to destination
     Write^:= Color or (Round(Alpha * 255.0) shl 24);

     // move through pixels
     Inc(Read0);
     Inc(Read1);
     Inc(Write);
    end;
  end;
end;                  


thanks

Danail

  • Full Member
  • ***
  • Posts: 151
delphi to lazarus ...?
« Reply #1 on: December 04, 2006, 06:15:27 pm »
What hapens when you simply copy- paste it ?


Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« Reply #3 on: December 04, 2006, 08:42:05 pm »
Quote from: "Danail"
What hapens when you simply copy- paste it ?


It's don't work because lazarus bitmap don't suport Scanline, but I don't want to use LazIntfImage.

Do you know how to use scanline on lazarus for windows?


thanks

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« Reply #4 on: December 04, 2006, 08:45:10 pm »
Quote from: "Legolas"
http://wiki.lazarus.freepascal.org/Developing_with_Graphics
http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=3178&highlight=



Hi

I don't understand this example =/

DO you know how to make a Tbitmap unit with suport Scanline ?

I'm using Lazarus for windows.


thanks

Legolas

  • Full Member
  • ***
  • Posts: 117
    • http://itaprogaming.free.fr
delphi to lazarus ...?
« Reply #5 on: December 04, 2006, 09:45:04 pm »
No (simple) way, IMHO. You either need to create a wrapper for GDI32.dll from scratch (HUGE work) or to use another package, eg. LazIntfImage.

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« Reply #6 on: December 04, 2006, 09:49:22 pm »
Quote from: "Legolas"
No (simple) way, IMHO. You either need to create a wrapper for GDI32.dll from scratch (HUGE work) or to use another package, eg. LazIntfImage.


ok

can you explain me how to convert that code with LazIntfImage?

thanks

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
delphi to lazarus ...?
« Reply #7 on: December 04, 2006, 10:50:02 pm »
Row := Bitmap.Scanline[y];
Row
  • //<- Pixel with TBitmap.Scanline

 
SrcIntfImg.Colors[px,py] //<-Pixel with TLazIntfImage

See Demo in "A fading example" in http://wiki.lazarus.freepascal.org/Developing_with_Graphics

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« Reply #8 on: December 04, 2006, 11:40:35 pm »
Quote from: "theo"
Row := Bitmap.Scanline[y];
Row
  • //<- Pixel with TBitmap.Scanline

 
SrcIntfImg.Colors[px,py] //<-Pixel with TLazIntfImage

See Demo in "A fading example" in http://wiki.lazarus.freepascal.org/Developing_with_Graphics



hi

Bitmap.Scanline[y]; = TPointer.

SrcIntfImg.Colors[px,py] = TPointer?


I need a  Pcardinal value, it will work?

thanks

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
delphi to lazarus ...?
« Reply #9 on: December 05, 2006, 12:52:21 am »
You don't need pointers for pixel access with TLazIntfImage, you just access the pixels array: SrcIntfImg.Colors[px,py]
It's very simple!

You're code above is buggy afaics.
This does nothing:
Code: [Select]
Image0.Scanline[ScanIndx] ;
 Image1.Scanline[ScanIndx];
 Vest.Scanline[ScanIndx];


What's "Vest" ?  Should be "Dest"?

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
delphi to lazarus ...?
« Reply #10 on: December 05, 2006, 01:10:56 am »
Quote from: "theo"
You don't need pointers for pixel access with TLazIntfImage, you just access the pixels array: SrcIntfImg.Colors[px,py]
It's very simple!

You're code above is buggy afaics.
This does nothing:
Code: [Select]
Image0.Scanline[ScanIndx] ;
 Image1.Scanline[ScanIndx];
 Vest.Scanline[ScanIndx];


What's "Vest" ?  Should be "Dest"?



hi



Sorry.



The correct code is this:


Code: [Select]


procedure FindAlphaChannel(Dest, Image0, Image1: TBitmap; Bk1, Bk2: Cardinal);
var
 Index   : Integer;
 ScanIndx: Integer;

 BackValue1: Real;
 BackValue2: Real;

 Pixel1: Real;
 Pixel2: Real;

 Pixel : Real;
 Alpha : Real;

 Read0: PCardinal;
 Read1: PCardinal;
 Write: PCardinal;

 Color: Cardinal;
begin
 BackValue1:= Pixel2GrayEx(Bk1);
 BackValue2:= Pixel2GrayEx(Bk2);

 if (Image0.PixelFormat <> pf32bit) then Image0.PixelFormat:= pf32bit;
 if (Image1.PixelFormat <> pf32bit) then Image1.PixelFormat:= pf32bit;

 Dest.Width := Image0.Width;
 Dest.Height:= Image0.Height;
 if (Dest.PixelFormat <> pf32bit) then Dest.PixelFormat:= pf32bit;

 for ScanIndx:= 0 to Dest.Height - 1 do
  begin
   Read0:= Image0.Scanline[ScanIndx];
   Read1:= Image1.Scanline[ScanIndx];
   Write:= Dest.Scanline[ScanIndx];

   for Index:= 0 to Dest.Width - 1 do
    begin
     // retreive source grayscale pixels
     Pixel1:= Pixel2GrayEx(Read0^);
     Pixel2:= Pixel2GrayEx(Read1^);

     // calculate alpha-value and original pixel
     ExtractAlpha(Pixel1, Pixel2, BackValue1, BackValue2, Alpha, Pixel);

     // convert normalized pixel to color index
     Color:= Round(Pixel * 255.0);
     // prepare a 24-bit RGB color
     Color:= Color or (Color shl 8) or (Color shl 16);
     // add alpha-channel to 24-bit RGB color and write it to destination
     Write^:= Color or (Round(Alpha * 255.0) shl 24);

     // move through pixels
     Inc(Read0);
     Inc(Read1);
     Inc(Write);
    end;
  end;
end;


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
delphi to lazarus ...?
« Reply #11 on: December 05, 2006, 01:50:27 am »
Quote from: "Pegasus_Seiya"
I need a  Pcardinal value, it will work?


If it´s not a pointer just use @ operator. You have the sources to see what it is.

Christian

  • New Member
  • *
  • Posts: 37
delphi to lazarus ...?
« Reply #12 on: December 05, 2006, 10:53:17 am »
Since now Lazarus Bitmap schould support scanline with fpc 2.1.1

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
delphi to lazarus ...?
« Reply #13 on: December 05, 2006, 11:57:15 am »
Quote from: "Christian"
Since now Lazarus Bitmap schould support scanline with fpc 2.1.1


What do you mean? Is this just your opinion ("it should") or
DOES it work now? If so, where did you read that?

Pegasus_Seiya

  • New Member
  • *
  • Posts: 25
Ye or No?
« Reply #14 on: December 07, 2006, 03:37:05 am »
Lazarus will have scanline support?

 :roll:

 

TinyPortal © 2005-2018