📄 depng.pas
字号:
{$INCLUDE switches}
unit DePNG;
{ Load TBitmap from PNG file
Reduced version of the PngImage unit by Edmund H. Hand
Modifications by Steffen Gerlach <mail@steffengerlach.de>
PngImage.Pas - Copyright 1998 Edmund H. Hand
For conditions of distribution and use, see the COPYRIGHT NOTICE below.
COPYRIGHT NOTICE:
The unit is supplied "AS IS". The Author disclaims all warranties,
expressed or implied, including, without limitation, the warranties of
merchantability and of fitness for any purpose. The Author assumes no
liability for direct, indirect, incidental, special, exemplary, or
consequential damages, which may result from the use of this unit, even
if advised of the possibility of such damage.
Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
1. The origin of this source code must not be misrepresented.
2. Altered versions must be plainly marked as such and must not be
misrepresented as being the original source.
3. This Copyright notice may not be removed or altered from any source or
altered source distribution.
If you use this source code in a product, acknowledgment is not required
but would be appreciated. I would also like to know of any projects,
especially commercial ones, that use this code.
}
interface
uses Graphics;
function LoadBitmapFromPNG(var self: TBitmap; const FileName: string): boolean;
implementation
uses SysUtils, Windows;
{ Reduced version of the PngLib unit by Edmund H. Hand
Modifications by Steffen Gerlach <mail@steffengerlach.de>
Conversion from C header file to Pascal Unit by Edmund H. Hand in
April of 1998.
For conditions of distribution and use, see the COPYRIGHT NOTICE from the
orginal C Header file below.
This unit is intended for use with LPng.DLL. LPng.DLL was compiled with
Microsoft Visual C++ 5.0 and is comprised of the standard PNG library
version 1.0.1. LPng.DLL uses ZLib 1.1.2 internally for compression and
decompression. The ZLib functions are also exported in the DLL, but they
have not yet been defined here.
The primary word of warning I must offer is that most of the function
pointers for callback functions have merely been declared as the pascal
Pointer type. I have only defined one procedure type for read and write
callback functions. So if you plan to use other callback types, check the
included header file for the function definition.
The header comments of the original C Header file follow.
* png.h - header file for PNG reference library
*
* libpng 1.0.1
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson
* March 15, 1998
*
* Note about libpng version numbers:
*
* Due to various miscommunications, unforeseen code incompatibilities
* and occasional factors outside the authors' control, version numbering
* on the library has not always been consistent and straightforward.
* The following table summarizes matters since version 0.89c, which was
* the first widely used release:
*
* source png.h png.h shared-lib
* version string int version
* ------- ------ ------ ----------
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
* 0.97c 0.97 97 2.0.97
* 0.98 0.98 98 2.0.98
* 0.99 0.99 98 2.0.99
* 0.99a-m 0.99 99 2.0.99
* 1.00 1.00 100 2.1.0 [int should be 10000]
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
* 1.0.1 1.0.1 10001 2.1.0
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended.
* The PNG_PNGLIB_VER macro, which is not used within libpng but
* is available for applications, is an unsigned integer of the form
* xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
*
*
* See libpng.txt for more information. The PNG specification is available
* as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
*
* Contributing Authors:
* John Bowler
* Kevin Bracey
* Sam Bushell
* Andreas Dilger
* Magnus Holmgren
* Tom Lane
* Dave Martindale
* Glenn Randers-Pehrson
* Greg Roelofs
* Guy Eric Schalnat
* Paul Schmidt
* Tom Tanner
* Willem van Schaik
* Tim Wegner
*
* The contributing authors would like to thank all those who helped
* with testing, bug fixes, and patience. This wouldn't have been
* possible without all of you.
*
* Thanks to Frank J. T. Wojcik for helping with the documentation.
*
* COPYRIGHT NOTICE:
*
* The PNG Reference Library is supplied "AS IS". The Contributing Authors
* and Group 42, Inc. disclaim all warranties, expressed or implied,
* including, without limitation, the warranties of merchantability and of
* fitness for any purpose. The Contributing Authors and Group 42, Inc.
* assume no liability for direct, indirect, incidental, special, exemplary,
* or consequential damages, which may result from the use of the PNG
* Reference Library, even if advised of the possibility of such damage.
*
* Permission is hereby granted to use, copy, modify, and distribute this
* source code, or portions hereof, for any purpose, without fee, subject
* to the following restrictions:
* 1. The origin of this source code must not be misrepresented.
* 2. Altered versions must be plainly marked as such and must not be
* misrepresented as being the original source.
* 3. This Copyright notice may not be removed or altered from any source or
* altered source distribution.
*
* The Contributing Authors and Group 42, Inc. specifically permit, without
* fee, and encourage the use of this source code as a component to
* supporting the PNG file format in commercial products. If you use this
* source code in a product, acknowledgment is not required but would be
* appreciated.
*}
type PByte = ^Byte;
type PPByte = ^PByte;
type PPChar = ^PChar;
type PWord = ^Word;
type PPWord = ^PWord;
type PDouble = ^Double;
type PSmallint = ^Smallint;
type PCardinal = ^Cardinal;
type PPCardinal = ^PCardinal;
type PInteger = ^Integer;
type PPInteger = ^PInteger;
const Lib = 'lpng.dll';
const
PNG_LIBPNG_VER_STRING = '1.0.1';
PNG_COLOR_TYPE_GRAY: Integer = 0;
PNG_COLOR_TYPE_PALETTE: Integer = 3;
PNG_INFO_tRNS: Cardinal = $0010;
{* Three color definitions. The order of the red, green, and blue, (and the
* exact size) is not important, although the size of the fields need to
* be png_byte or png_uint_16 (as defined below).
*}
type TPng_Color = record
red: Byte;
green: Byte;
blue: Byte;
end;
type PPng_Color = ^TPng_Color;
type PPPng_Color = ^PPng_Color;
type TPng_Color_16 = record
index: Byte; // Used for palette files
red: Word; // For use in reg, green, blue files
green: Word;
blue: Word;
gray: Word; // For use in grayscale files
end;
type PPng_Color_16 = ^TPng_Color_16;
type PPPng_Color_16 = ^PPng_Color_16;
type TPng_Color_8 = record
red: Byte; // for use in red green blue files
green: Byte;
blue: Byte;
gray: Byte; // for use in grayscale files
alpha: Byte; // for alpha channel files
end;
type PPng_Color_8 = ^TPng_Color_8;
type PPPng_Color_8 = ^PPng_Color_8;
{* png_text holds the text in a PNG file, and whether they are compressed
* in the PNG file or not. The "text" field points to a regular C string.
*}
type TPng_Text = record
compression: Integer; // compression value, see PNG_TEXT_COMPRESSION_
key: PChar; // keyword, 1-79 character description of "text"
text: PChar; // comment, may be an empty string (ie "")
text_length: Integer; // length of "text" field
end;
type PPng_Text = ^TPng_Text;
type PPPng_Text = ^PPng_Text;
type TPng_Text_Array = array[0..65535] of TPng_Text;
type PPng_Text_Array = ^TPng_Text_Array;
{* png_time is a way to hold the time in an machine independent way.
* Two conversions are provided, both from time_t and struct tm. There
* is no portable way to convert to either of these structures, as far
* as I know. If you know of a portable way, send it to me. As a side
* note - PNG is Year 2000 compliant!
*}
type TPng_Time = record
year: Word; // full year, as in, 1995
month: Byte; // month of year, 1 - 12
day: Byte; // day of month, 1 - 31
hour: Byte; // hour of day, 0 - 23
minute: Byte; // minute of hour, 0 - 59
second: Byte; // second of minute, 0 - 60 (for leap seconds)
end;
type PPng_Time = ^TPng_Time;
type PPPng_Time = ^PPng_Time;
type TPng_Info = record
//the following are necessary for every PNG file
width: Cardinal; // width of image in pixels (from IHDR)
height: Cardinal; // height of image in pixels (from IHDR)
valid: Cardinal; // valid chunk data (see PNG_INFO_ below)
rowbytes: Cardinal; // bytes needed to hold an untransformed row
palette: PPng_Color;// array of color values (valid & PNG_INFO_PLTE)
num_palette: Word; // number of color entries in "palette" (PLTE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -