6882
|
1 |
(*
|
|
2 |
* Hedgewars, a free turn based strategy game
|
|
3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*)
|
|
18 |
|
|
19 |
{$INCLUDE "options.inc"}
|
|
20 |
|
|
21 |
unit PNGh;
|
|
22 |
interface
|
|
23 |
|
|
24 |
uses png;
|
|
25 |
|
|
26 |
{$IFDEF FPC}
|
|
27 |
{$PACKRECORDS C}
|
|
28 |
{$ELSE}
|
|
29 |
{$DEFINE cdecl attribute(cdecl)}
|
|
30 |
{$ENDIF}
|
|
31 |
|
8685
|
32 |
{$IFDEF DARWIN}
|
|
33 |
{$linklib png}
|
|
34 |
{$ENDIF}
|
|
35 |
|
6882
|
36 |
const
|
|
37 |
// Constants for libpng, they are not defined in png unit.
|
8685
|
38 |
// We actually do not need all of them.
|
6882
|
39 |
|
|
40 |
// These describe the color_type field in png_info.
|
|
41 |
// color type masks
|
|
42 |
PNG_COLOR_MASK_PALETTE = 1;
|
|
43 |
PNG_COLOR_MASK_COLOR = 2;
|
|
44 |
PNG_COLOR_MASK_ALPHA = 4;
|
|
45 |
|
|
46 |
// color types. Note that not all combinations are legal
|
|
47 |
PNG_COLOR_TYPE_GRAY = 0;
|
6893
|
48 |
PNG_COLOR_TYPE_PALETTE = PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_PALETTE;
|
|
49 |
PNG_COLOR_TYPE_RGB = PNG_COLOR_MASK_COLOR;
|
|
50 |
PNG_COLOR_TYPE_RGB_ALPHA = PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_ALPHA;
|
|
51 |
PNG_COLOR_TYPE_GRAY_ALPHA = PNG_COLOR_MASK_ALPHA;
|
6882
|
52 |
|
|
53 |
// aliases
|
|
54 |
PNG_COLOR_TYPE_RGBA = PNG_COLOR_TYPE_RGB_ALPHA;
|
|
55 |
PNG_COLOR_TYPE_GA = PNG_COLOR_TYPE_GRAY_ALPHA;
|
|
56 |
|
|
57 |
// This is for compression type. PNG 1.0-1.2 only define the single type.
|
|
58 |
PNG_COMPRESSION_TYPE_BASE = 0; // Deflate method 8, 32K window
|
|
59 |
PNG_COMPRESSION_TYPE_DEFAULT = PNG_COMPRESSION_TYPE_BASE;
|
|
60 |
|
|
61 |
// This is for filter type. PNG 1.0-1.2 only define the single type.
|
|
62 |
PNG_FILTER_TYPE_BASE = 0; // Single row per-byte filtering
|
|
63 |
PNG_INTRAPIXEL_DIFFERENCING = 64; // Used only in MNG datastreams
|
|
64 |
PNG_FILTER_TYPE_DEFAULT = PNG_FILTER_TYPE_BASE;
|
|
65 |
|
|
66 |
// These are for the interlacing type. These values should NOT be changed.
|
|
67 |
PNG_INTERLACE_NONE = 0; // Non-interlaced image
|
|
68 |
PNG_INTERLACE_ADAM7 = 1; // Adam7 interlacing
|
|
69 |
PNG_INTERLACE_LAST = 2; // Not a valid value
|
|
70 |
|
|
71 |
type
|
|
72 |
// where is better place for this definition?
|
|
73 |
PFile = ^file;
|
|
74 |
|
|
75 |
procedure png_init_pascal_io(png_ptr: png_structp; pf : PFile);
|
|
76 |
|
|
77 |
implementation
|
|
78 |
|
|
79 |
// We cannot get c-style FILE* pointer to pass it to libpng, so we implement our own writing functions
|
|
80 |
procedure PngWriteData(png_ptr: png_structp; p: PByte; len: png_size_t); cdecl;
|
|
81 |
begin
|
|
82 |
BlockWrite( PFile(png_get_io_ptr(png_ptr))^, p^, len);
|
|
83 |
end;
|
|
84 |
|
|
85 |
procedure PngFlushData(png_ptr: png_structp); cdecl;
|
|
86 |
begin
|
|
87 |
end;
|
|
88 |
|
|
89 |
procedure png_init_pascal_io(png_ptr: png_structp; pf : PFile);
|
|
90 |
begin
|
|
91 |
png_set_write_fn(png_ptr, pf, @PngWriteData, @PngFlushData);
|
|
92 |
end;
|
|
93 |
|
|
94 |
end.
|