1 {unit to write tbitmaps to a png using plugwashes png code}
\r
3 { Copyright (C) 2008 Peter Green
\r
4 For conditions of distribution and use, see copyright notice in zlib_license.txt
\r
5 which is included in the package
\r
6 ----------------------------------------------------------------------------- }
\r
9 unit pngwritetbitmap;
\r
27 procedure savetbitmaptopng(image:tbitmap;destination : tstream);
\r
29 procedure savetbitmaptopng(image:tbitmap;destination : tstream);
\r
31 paletteentrieswin : array[0..255] of TPaletteEntry;
\r
32 paletteentriespng : array[0..768] of byte;
\r
35 colortype : tcolortype;
\r
37 if (image.PixelFormat <> pf8bit) and (image.pixelformat <> pf24bit) then raise exception.create('unsupported image format, only 8 bit and 24 bit per pixel are currently supported.');
\r
38 if image.PixelFormat = pf24bit then begin
\r
41 colortype := ctpallette;
\r
43 pngstart(f,destination,8,colortype,image.Height,image.Width);
\r
45 if image.pixelformat = pf8bit then begin
\r
46 GetPaletteEntries(image.Palette,0,256,paletteEntrieswin);
\r
48 //writeln('about to start png write');
\r
49 //writeln('about to prepare pallette');
\r
50 for i := 0 to 255 do begin
\r
51 paletteentriespng[(i*3) ] := paletteEntrieswin[i].pered;
\r
52 paletteentriespng[(i*3)+1] := paletteEntrieswin[i].pegreen;
\r
53 paletteentriespng[(i*3)+2] := paletteEntrieswin[i].peblue;
\r
55 //writeln('about to write pallette');
\r
56 pngwritepal(f,@paletteentriespng,256 );
\r
61 for i := 0 to Image.Height -1 do begin;
\r
62 //writeln('about to write scanline ',i,'image.height=',image.height,'image.ScanLine[i]',longint(image.ScanLine[i]));
\r
63 pngwritescanline(f,image.ScanLine[i]);
\r
65 //writeln('about to close main data block');
\r
67 //writeln('about to close png');
\r