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