Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-02

Extract the color data and alpha from a PNG image

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello friends,

I'm trying to extract the color data and alpha from a PNG image. In PHP it is very easy to implement, but in FPC I don't know how to do it. I tried to do it via "chunk.data", "ZData" etc., but, without success.

Attached two files to test it. To test the PHP code run this command in your terminal:

php -f fpdf.php

The in FPC code is partially complete.

Thank you!

ps. can ZData be public?

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

silvioprog
to silvioprog

Oops, files attached.

2013/2/5 silvioprog

Show quoted text 17 lines
Hello friends, I'm trying to extract the color data and alpha from a PNG image. In PHP it is very easy to implement, but in FPC I don't know how to do it. I tried to do it via "chunk.data", "ZData" etc., but, without success. Attached two files to test it. To test the PHP code run this command in your terminal: php -f fpdf.php The in FPC code is partially complete. Thank you! ps. can ZData be public?
Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Mattias Gaertner
to silvioprog: I'm trying to extract the color data and alpha from a PNG image. In PHP it is very easy…
Show quoted text 12 lines
Hello friends, I'm trying to extract the color data and alpha from a PNG image. In PHP it is very easy to implement, but in FPC I don't know how to do it. I tried to do it via "chunk.data", "ZData" etc., but, without success. Attached two files to test it. To test the PHP code run this command in your terminal: php -f fpdf.php The in FPC code is partially complete.

Have you tried fpimage?

uses
  fpreadpng, fpimage;
var
  image: TFPCustomImage;
  reader: TFPCustomImageReader;
  x,y: integer;
  c: TFPColor;
begin
  Image := TFPMemoryImage.Create(0, 0);
  Reader := TFPReaderPNG.Create;
  Image.LoadFromFile(AFileName, Reader);
  for y:=0 to Image.Height-1 do
    for x:=0 to Image.Width-1 do begin
      c:=Image.Colors[x,y];
      writeln(c.Alpha,' ',c.Blue);
    end;
  //...

Mattias

Reply by email

silvioprog
to Mattias Gaertner

2013/2/5 Mattias Gaertner

Show quoted text 40 lines
On Tue, 5 Feb 2013 12:37:24 -0200 silvioprog wrote: > Hello friends, > > I'm trying to extract the color data and alpha from a PNG image. In PHP it > is very easy to implement, but in FPC I don't know how to do it. I tried to > do it via "chunk.data", "ZData" etc., but, without success. > > Attached two files to test it. To test the PHP code run this command in > your terminal: > > php -f fpdf.php > > The in FPC code is partially complete. Have you tried fpimage? uses fpreadpng, fpimage; var image: TFPCustomImage; reader: TFPCustomImageReader; x,y: integer; c: TFPColor; begin Image := TFPMemoryImage.Create(0, 0); Reader := TFPReaderPNG.Create; Image.LoadFromFile(AFileName, Reader); for y:=0 to Image.Height-1 do for x:=0 to Image.Width-1 do begin c:=Image.Colors[x,y]; writeln(c.Alpha,' ',c.Blue); end; //... Mattias

Yes, I tried it too, but, without success. :(

See my new code in attached. It generates the data, but with wrong content.

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Mattias Gaertner
to silvioprog

silvioprog hat am 5. Februar 2013 um 16:08 geschrieben:

Show quoted text 45 lines
2013/2/5 Mattias Gaertner < > > > On Tue, 5 Feb 2013 12:37:24 -0200 > silvioprog < > wrote: > > > Hello friends, > > > > I'm trying to extract the color data and alpha from a PNG image. In PHP > > it > > is very easy to implement, but in FPC I don't know how to do it. I > > tried to > > do it via "chunk.data", "ZData" etc., but, without success. > > > > Attached two files to test it. To test the PHP code run this command in > > your terminal: > > > > php -f fpdf.php > > > > The in FPC code is partially complete. > Have you tried fpimage? > > uses > fpreadpng, fpimage; > > var > image: TFPCustomImage; > reader: TFPCustomImageReader; > x,y: integer; > c: TFPColor; > begin > Image := TFPMemoryImage.Create(0, 0); > Reader := TFPReaderPNG.Create; > Image.LoadFromFile(AFileName, Reader); > for y:=0 to Image.Height-1 do > for x:=0 to Image.Width-1 do begin > c:=Image.Colors[x,y]; > writeln(c.Alpha,' ',c.Blue); > end; > //... > > Mattias > > Yes, I tried it too, but, without success. :( See my new code in attached. It generates the data, but with wrong content.

c.Alpha, c.Blue are word, not byte.

BTW, reading and writing to/from Filestream should be done in chunks, not in bytes. That's dog slow.
Use a TMemoryStream as cache.

Mattias

Reply by email