hedgewars/PNGh.pas
changeset 6882 0eb73121aa4c
child 6893 69cc0166be8d
equal deleted inserted replaced
6881:ee01eeaa1281 6882:0eb73121aa4c
       
     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 
       
    32 const
       
    33     // Constants for libpng, they are not defined in png unit.
       
    34     // We actually don't need all of them.
       
    35 
       
    36     // These describe the color_type field in png_info.
       
    37     // color type masks
       
    38     PNG_COLOR_MASK_PALETTE = 1;
       
    39     PNG_COLOR_MASK_COLOR   = 2;
       
    40     PNG_COLOR_MASK_ALPHA   = 4;
       
    41 
       
    42     // color types.  Note that not all combinations are legal
       
    43     PNG_COLOR_TYPE_GRAY       = 0;
       
    44     PNG_COLOR_TYPE_PALETTE    = (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_PALETTE);
       
    45     PNG_COLOR_TYPE_RGB        = (PNG_COLOR_MASK_COLOR);
       
    46     PNG_COLOR_TYPE_RGB_ALPHA  = (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_ALPHA);
       
    47     PNG_COLOR_TYPE_GRAY_ALPHA = (PNG_COLOR_MASK_ALPHA);
       
    48 
       
    49     // aliases
       
    50     PNG_COLOR_TYPE_RGBA = PNG_COLOR_TYPE_RGB_ALPHA;
       
    51     PNG_COLOR_TYPE_GA   = PNG_COLOR_TYPE_GRAY_ALPHA;
       
    52 
       
    53     // This is for compression type. PNG 1.0-1.2 only define the single type.
       
    54     PNG_COMPRESSION_TYPE_BASE    = 0; // Deflate method 8, 32K window
       
    55     PNG_COMPRESSION_TYPE_DEFAULT = PNG_COMPRESSION_TYPE_BASE;
       
    56 
       
    57     // This is for filter type. PNG 1.0-1.2 only define the single type.
       
    58     PNG_FILTER_TYPE_BASE        = 0;  // Single row per-byte filtering
       
    59     PNG_INTRAPIXEL_DIFFERENCING = 64; // Used only in MNG datastreams
       
    60     PNG_FILTER_TYPE_DEFAULT     = PNG_FILTER_TYPE_BASE;
       
    61 
       
    62     // These are for the interlacing type.  These values should NOT be changed.
       
    63     PNG_INTERLACE_NONE  = 0; // Non-interlaced image
       
    64     PNG_INTERLACE_ADAM7 = 1; // Adam7 interlacing
       
    65     PNG_INTERLACE_LAST  = 2; // Not a valid value
       
    66 
       
    67 type
       
    68     // where is better place for this definition?
       
    69     PFile = ^file;
       
    70 
       
    71 procedure png_init_pascal_io(png_ptr: png_structp; pf : PFile);
       
    72 
       
    73 implementation
       
    74 
       
    75 // We cannot get c-style FILE* pointer to pass it to libpng, so we implement our own writing functions
       
    76 procedure PngWriteData(png_ptr: png_structp; p: PByte; len: png_size_t); cdecl;
       
    77 begin
       
    78     BlockWrite( PFile(png_get_io_ptr(png_ptr))^, p^, len);
       
    79 end;
       
    80 
       
    81 procedure PngFlushData(png_ptr: png_structp); cdecl;
       
    82 begin
       
    83 end;
       
    84 
       
    85 procedure png_init_pascal_io(png_ptr: png_structp; pf : PFile);
       
    86 begin
       
    87     png_set_write_fn(png_ptr, pf, @PngWriteData, @PngFlushData);
       
    88 end;
       
    89 
       
    90 end.