hedgewars/PNGh.pas
author Wuzzy <Wuzzy2@mail.ru>
Mon, 28 Oct 2019 20:40:07 +0100 (2019-10-28)
changeset 15495 0039baa9895e
parent 12626 d972b31f8881
permissions -rw-r--r--
Add RopeKnocking library (generalized ropeknock challenges)
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10108
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
6882
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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6882
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
8685
c0e54583296e link png library in code on osx
koda
parents: 6893
diff changeset
    27
{$IFDEF DARWIN}
c0e54583296e link png library in code on osx
koda
parents: 6893
diff changeset
    28
    {$linklib png}
c0e54583296e link png library in code on osx
koda
parents: 6893
diff changeset
    29
{$ENDIF}
c0e54583296e link png library in code on osx
koda
parents: 6893
diff changeset
    30
6882
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    31
const
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    32
    // Constants for libpng, they are not defined in png unit.
8685
c0e54583296e link png library in code on osx
koda
parents: 6893
diff changeset
    33
    // We actually do not need all of them.
6882
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    34
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    35
    // These describe the color_type field in png_info.
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    36
    // color type masks
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    37
    PNG_COLOR_MASK_PALETTE = 1;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    38
    PNG_COLOR_MASK_COLOR   = 2;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    39
    PNG_COLOR_MASK_ALPHA   = 4;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    40
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    41
    // color types.  Note that not all combinations are legal
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    42
    PNG_COLOR_TYPE_GRAY       = 0;
6893
69cc0166be8d - Track array size to use for High function
unc0rr
parents: 6882
diff changeset
    43
    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
    44
    PNG_COLOR_TYPE_RGB        = PNG_COLOR_MASK_COLOR;
69cc0166be8d - Track array size to use for High function
unc0rr
parents: 6882
diff changeset
    45
    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
    46
    PNG_COLOR_TYPE_GRAY_ALPHA = PNG_COLOR_MASK_ALPHA;
6882
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    47
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    48
    // aliases
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    49
    PNG_COLOR_TYPE_RGBA = PNG_COLOR_TYPE_RGB_ALPHA;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    50
    PNG_COLOR_TYPE_GA   = PNG_COLOR_TYPE_GRAY_ALPHA;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    51
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    52
    // This is for compression type. PNG 1.0-1.2 only define the single type.
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    53
    PNG_COMPRESSION_TYPE_BASE    = 0; // Deflate method 8, 32K window
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    54
    PNG_COMPRESSION_TYPE_DEFAULT = PNG_COMPRESSION_TYPE_BASE;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    55
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    56
    // This is for filter type. PNG 1.0-1.2 only define the single type.
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    57
    PNG_FILTER_TYPE_BASE        = 0;  // Single row per-byte filtering
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    58
    PNG_INTRAPIXEL_DIFFERENCING = 64; // Used only in MNG datastreams
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    59
    PNG_FILTER_TYPE_DEFAULT     = PNG_FILTER_TYPE_BASE;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    60
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    61
    // These are for the interlacing type.  These values should NOT be changed.
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    62
    PNG_INTERLACE_NONE  = 0; // Non-interlaced image
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    63
    PNG_INTERLACE_ADAM7 = 1; // Adam7 interlacing
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    64
    PNG_INTERLACE_LAST  = 2; // Not a valid value
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    65
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    66
type
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    67
    // where is better place for this definition?
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    68
    PFile = ^file;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    69
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    70
procedure png_init_pascal_io(png_ptr: png_structp; pf : PFile);
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    71
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    72
implementation
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    73
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    74
// 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
    75
procedure PngWriteData(png_ptr: png_structp; p: PByte; len: png_size_t); cdecl;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    76
begin
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    77
    BlockWrite( PFile(png_get_io_ptr(png_ptr))^, p^, len);
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    78
end;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    79
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    80
procedure PngFlushData(png_ptr: png_structp); cdecl;
0eb73121aa4c Oops, forgot file
Stepan777
parents:
diff changeset
    81
begin
12626
d972b31f8881 fix some fpc hints
sheepluva
parents: 11046
diff changeset
    82
    png_ptr:= png_ptr;
6882
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.