[fpc-devel] Extract the color data and alpha from a PNG image

2013-02-05 Thread 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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Extract the color data and alpha from a PNG image

2013-02-05 Thread 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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Extract the color data and alpha from a PNG image

2013-02-06 Thread Mattias Gaertner

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

>  2013/2/5 Mattias Gaertner   >
>> >On Tue, 5 Feb 2013 12:37:24 -0200
> >silvioprog < silviop...@gmail.com  > 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
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel