⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pngfilt.pas

📁 ·ImageEn 2.3.0 ImageEn一组用于图像处理、查看和分析的Delphi控件。能够保存几种图像格式
💻 PAS
📖 第 1 页 / 共 2 页
字号:
(*
Copyright (c) 1998-2007 by HiComponents. All rights reserved.

This software comes without express or implied warranty.
In no case shall the author be liable for any damage or unwanted behavior of any
computer hardware and/or software.

HiComponents grants you the right to include the compiled component
in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE,
BUT YOU MAY NOT DISTRIBUTE THIS SOURCE CODE OR ITS COMPILED .DCU IN ANY FORM.

ImageEn, IEvolution and ImageEn ActiveX may not be included in any commercial,
shareware or freeware libraries or components.

email: support@hicomponents.com

http://www.hicomponents.com
*)

unit pngfilt;

{$R-}
{$Q-}

{$I ie.inc}

{$IFDEF IEINCLUDEPNG}

interface

uses Windows, Graphics, classes, sysutils, ImageEnProc, ImageEnIO, hyiedefs, hyieutils, iezlib;

procedure ReadPNGStream(Stream: TStream; Bitmap: TIEBitmap; var IOParams: TIOParamsVals; var xProgress: TProgressRec; Preview: boolean);
function IsPNGStream(Stream: TStream): boolean;

{$Z4}

type
  png_uint_32 = Cardinal;
  png_uint_32p = ^png_uint_32;
  png_int_32 = integer;
  png_uint_16 = Word;
  png_int_16 = Smallint;
  png_byte = Byte;
  png_size_t = png_uint_32;
  png_charpp = ^png_charp;
  png_charp = PChar;
  float = single;
  int = Integer;
  png_bytepp = ^png_bytep;
  png_bytep = ^png_byte;
  png_uint_16p = ^png_uint_16;
  png_uint_16pp = ^png_uint_16p;
  png_voidp = pointer;
  time_t = Longint;
  png_doublep = ^png_double;
  png_double = double;

  user_error_ptr = Pointer;
  png_error_ptrp = ^png_error_ptr;
  png_error_ptr = procedure(png_ptr: Pointer; msg: Pointer); cdecl;
  png_rw_ptrp = ^png_rw_ptr;
  png_rw_ptr = procedure(png_ptr: Pointer; data: Pointer;
    length: png_size_t); cdecl;
  png_flush_ptrp = ^png_flush_ptr;
  png_flush_ptr = procedure(png_ptr: Pointer); cdecl;
  png_progressive_info_ptrp = ^png_progressive_info_ptr;
  png_progressive_info_ptr = procedure(png_ptr: Pointer;
    info_ptr: Pointer); cdecl;
  png_progressive_end_ptrp = ^png_progressive_end_ptr;
  png_progressive_end_ptr = procedure(png_ptr: Pointer;
    info_ptr: Pointer); cdecl;
  png_progressive_row_ptrp = ^png_progressive_row_ptr;
  png_progressive_row_ptr = procedure(png_ptr: Pointer;
    data: Pointer; length: png_uint_32;
    count: int); cdecl;
  png_read_status_ptr = procedure(png_ptr: Pointer;
    row_number: png_uint_32; pass: int); cdecl;
  png_write_status_ptr = procedure(png_ptr: Pointer;
    row_number: png_uint_32; pass: int); cdecl;
  png_user_transform_ptr = procedure(png_ptr: Pointer;
    row_info: Pointer; data: png_bytep); cdecl;

  png_colorpp = ^png_colorp;
  png_colorp = ^png_color;
  png_color = packed record
    red, green, blue: png_byte;
  end;

  png_color_16pp = ^png_color_16p;
  png_color_16p = ^png_color_16;
  png_color_16 = packed record
    index: png_byte; //used for palette files
    red, green, blue: png_uint_16; //for use in red green blue files
    gray: png_uint_16; //for use in grayscale files
  end;

  png_color_8pp = ^png_color_8p;
  png_color_8p = ^png_color_8;
  png_color_8 = packed record
    red, green, blue: png_byte; //for use in red green blue files
    gray: png_byte; //for use in grayscale files
    alpha: png_byte; //for alpha channel files
  end;

  png_textpp = ^png_textp;
  png_textp = ^tpng_text;
  tpng_text = packed record
    compression: int; //compression value
    key: png_charp; //keyword, 1-79 character description of "text"
    text: png_charp; //comment, may be empty ("")
    text_length: png_size_t; //length of text field
  end;

  png_timepp = ^png_timep;
  png_timep = ^tpng_time;
  tpng_time = packed record
    year: png_uint_16; //yyyy
    month: png_byte; //1..12
    day: png_byte; //1..31
    hour: png_byte; //0..23
    minute: png_byte; //0..59
    second: png_byte; //0..60 (leap seconds)
  end;

  png_infopp = ^png_infop;
  png_infop = Pointer;

  png_row_infopp = ^png_row_infop;
  png_row_infop = ^png_row_info;
  png_row_info = packed record
    width: png_uint_32; //width of row
    rowbytes: png_size_t; //number of bytes in row
    color_type: png_byte; //color type of row
    bit_depth: png_byte; //bit depth of row
    channels: png_byte; //number of channels (1, 2, 3, or 4)
    pixel_depth: png_byte; //bits per pixel (depth * channels)
  end;

  png_structpp = ^png_structp;
  png_structp = Pointer;

  // Supported compression types for text in PNG files (tEXt, and zTXt).
  // The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed.

const
  PNG_TEXT_COMPRESSION_NONE_WR = -3;
  PNG_TEXT_COMPRESSION_zTXt_WR = -2;
  PNG_TEXT_COMPRESSION_NONE = -1;
  PNG_TEXT_COMPRESSION_zTXt = 0;

  // These describe the color_type field in png_info.
  // color type masks

  PNG_COLOR_MASK_PALETTE = 1;
  PNG_COLOR_MASK_COLOR = 2;
  PNG_COLOR_MASK_ALPHA = 4;

  // color types.  Note that not all combinations are legal

  PNG_COLOR_TYPE_GRAY = 0;
  PNG_COLOR_TYPE_PALETTE = PNG_COLOR_MASK_COLOR or
    PNG_COLOR_MASK_PALETTE;
  PNG_COLOR_TYPE_RGB = PNG_COLOR_MASK_COLOR;
  PNG_COLOR_TYPE_RGB_ALPHA = PNG_COLOR_MASK_COLOR or
    PNG_COLOR_MASK_ALPHA;
  PNG_COLOR_TYPE_GRAY_ALPHA = PNG_COLOR_MASK_ALPHA;

  // This is for compression type. PNG 1.0 only defines the single type.

  PNG_COMPRESSION_TYPE_BASE = 0; // Deflate method 8, 32K window
  PNG_COMPRESSION_TYPE_DEFAULT = PNG_COMPRESSION_TYPE_BASE;

  // This is for filter type. PNG 1.0 only defines the single type.

  PNG_FILTER_TYPE_BASE = 0; // Single row per-byte filtering
  PNG_FILTER_TYPE_DEFAULT = PNG_FILTER_TYPE_BASE;

  // These are for the interlacing type.  These values should NOT be changed.

  PNG_INTERLACE_NONE = 0; // Non-interlaced image
  PNG_INTERLACE_ADAM7 = 1; // Adam7 interlacing

  // These are for the oFFs chunk.  These values should NOT be changed.

  PNG_OFFSET_PIXEL = 0; // Offset in pixels
  PNG_OFFSET_MICROMETER = 1; // Offset in micrometers (1/10^6 meter)

  // These are for the pCAL chunk.  These values should NOT be changed.

  PNG_EQUATION_LINEAR = 0; // Linear transformation
  PNG_EQUATION_BASE_E = 1; // Exponential base e transform
  PNG_EQUATION_ARBITRARY = 2; // Arbitrary base exponential transform
  PNG_EQUATION_HYPERBOLIC = 3; // Hyperbolic sine transformation

  // These are for the pHYs chunk.  These values should NOT be changed.

  PNG_RESOLUTION_UNKNOWN = 0; // pixels/unknown unit (aspect ratio)
  PNG_RESOLUTION_METER = 1; // pixels/meter

  // These are for the sRGB chunk.  These values should NOT be changed.
  PNG_sRGB_INTENT_SATURATION = 0;
  PNG_sRGB_INTENT_PERCEPTUAL = 1;
  PNG_sRGB_INTENT_ABSOLUTE = 2;
  PNG_sRGB_INTENT_RELATIVE = 3;

  // Handle alpha and tRNS by replacing with a background color.
  PNG_BACKGROUND_GAMMA_UNKNOWN = 0;
  PNG_BACKGROUND_GAMMA_SCREEN = 1;
  PNG_BACKGROUND_GAMMA_FILE = 2;
  PNG_BACKGROUND_GAMMA_UNIQUE = 3;

  // Values for png_set_crc_action() to say how to handle CRC errors in
  // ancillary and critical chunks, and whether to use the data contained
  // therein.  Note that it is impossible to "discard" data in a critical
  // chunk.  For versions prior to 0.90, the action was always error/quit,
  // whereas in version 0.90 and later, the action for CRC errors in ancillary
  // chunks is warn/discard.  These values should NOT be changed.

  //      value                   action:critical     action:ancillary

  PNG_CRC_DEFAULT = 0; // error/quit          warn/discard data
  PNG_CRC_ERROR_QUIT = 1; // error/quit          error/quit
  PNG_CRC_WARN_DISCARD = 2; // (INVALID)           warn/discard data
  PNG_CRC_WARN_USE = 3; // warn/use data       warn/use data
  PNG_CRC_QUIET_USE = 4; // quiet/use data      quiet/use data
  PNG_CRC_NO_CHANGE = 5; // use current value   use current value

  // Flags for png_set_filter() to say which filters to use.  The flags
  // are chosen so that they don't conflict with real filter types
  // below, in case they are supplied instead of the #defined constants.
  // These values should NOT be changed.

  PNG_NO_FILTERS = $00;
  PNG_FILTER_NONE = $08;
  PNG_FILTER_SUB = $10;
  PNG_FILTER_UP = $20;
  PNG_FILTER_AVG = $40;
  PNG_FILTER_PAETH = $80;
  PNG_ALL_FILTERS = PNG_FILTER_NONE or PNG_FILTER_SUB or
    PNG_FILTER_UP or PNG_FILTER_AVG or
    PNG_FILTER_PAETH;

  // Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
  // These defines should NOT be changed.

  PNG_FILTER_VALUE_NONE = 0;
  PNG_FILTER_VALUE_SUB = 1;
  PNG_FILTER_VALUE_UP = 2;
  PNG_FILTER_VALUE_AVG = 3;
  PNG_FILTER_VALUE_PAETH = 4;

  // Heuristic used for row filter selection.  These defines should NOT be
  // changed.

  PNG_FILTER_HEURISTIC_DEFAULT = 0; // Currently "UNWEIGHTED"
  PNG_FILTER_HEURISTIC_UNWEIGHTED = 1; // Used by libpng < 0.95
  PNG_FILTER_HEURISTIC_WEIGHTED = 2; // Experimental feature
  PNG_FILTER_HEURISTIC_LAST = 3; // Not a valid value


implementation

uses ImageEnView, ieview;

{$R-}

var
  __turboFloat: LongBool = False;


function memcmp(buf1, buf2: pbyte; count: integer): integer;  cdecl;
begin
  if count = 0 then
    result := 0
  else
  begin
    while true do
    begin
      dec(count);
      if (count=0) or (buf1^<>buf2^) then
        break;
      inc(buf1);
      inc(buf2);
    end;
    result := buf1^ - buf2^;
  end;
end;

function strncpy(dest, src: pchar; maxlen: integer): pchar; cdecl;
begin
  result := strmove(dest, src, maxlen);
end;

function strcpy(dest, src: pchar): pchar; cdecl;
begin
  result := sysutils.StrCopy(dest, src);
end;

function fabs(v: double): double; cdecl;
begin
  result := abs(v);
end;

function IntPower(Base: Extended; Exponent: Integer): Extended;
asm
        mov     ecx, eax
        cdq
        fld1                      { Result := 1 }
        xor     eax, edx
        sub     eax, edx          { eax := Abs(Exponent) }
        jz      @@3
        fld     Base
        jmp     @@2
@@1:    fmul    ST, ST            { X := Base * Base }
@@2:    shr     eax,1
        jnc     @@1
        fmul    ST(1),ST          { Result := Result * X }
        jnz     @@1
        fstp    st                { pop X from FPU stack }
        cmp     ecx, 0
        jge     @@3
        fld1
        fdivrp                    { Result := 1 / Result }
@@3:
        fwait
end;

function pow(Base, Exponent: double): double; cdecl;
begin
  if Exponent = 0.0 then
    Result := 1.0 { n**0 = 1 }
  else if (Base = 0.0) and (Exponent > 0.0) then
    Result := 0.0 { 0**n = 0, n > 0 }
  else if (Frac(Exponent) = 0.0) and (Abs(Exponent) <= MaxInt) then
    Result := IntPower(Base, Trunc(Exponent))
  else
    Result := Exp(Exponent * Ln(Base))
end;

function strtod(s: pchar; var vp: pchar): double; cdecl;
begin
  vp := @s[strlen(s) - 1]; // !!
  result := IEStrToFloatDef(s, 0);
end;

function malloc(size: Integer): Pointer; cdecl;
begin
  result := allocmem(size);
end;

procedure free(P: Pointer); cdecl;
begin
  FreeMem(P);
end;

function memset(P: Pointer; B: Byte; count: Integer): pointer; cdecl;
begin
  FillChar(P^, count, B);
  result := P;
end;

function memcpy(dest, source: Pointer; count: Integer): pointer; cdecl;
begin
  Move(source^, dest^, count);
  result := dest;
end;

function _ftol: integer; cdecl;
var
  f: double;
begin
  asm
   	lea    eax, f             //  BC++ passes floats on the FPU stack
    	fstp  qword ptr [eax]     //  Delphi passes floats on the CPU stack
  end;
  if f > 2147483647.0 then
    f := 2147483647.0;
  if f < -2147483648.0 then
    f := 2147483648.0;
  result := integer(Trunc(f));
end;

procedure _assert(__cond: pchar; __file: pchar; __line: integer); cdecl;
begin
end;

function memmove(dest, source: Pointer; count: Integer): pointer; cdecl;
begin
  Move(source^, dest^, count);
  result := dest;
end;

function strlen(str: pchar): integer; cdecl;
begin
  result := sysutils.strlen(str);
end;

function realloc(block: pointer; size: integer): pointer; cdecl;
begin
  reallocmem(block, size);
  result := block;
end;

function fscanf(f: pointer; format: pchar): integer; cdecl; 
begin
  result := 0;
end;


{$L pngread.obj}
{$L pngset.obj}
{$L pngtrans.obj}
{$L pngrtran.obj}
{$L pngrio.obj}
{$L pngmem.obj}
{$L pngerror.obj}
{$L pngrutil.obj}
{$L pngget.obj}
{$L png.obj}

function png_create_read_struct(user_png_ver: png_charp;
  error_ptr: user_error_ptr; error_fn: png_error_ptr;
  warn_fn: png_error_ptr): png_structp;
  cdecl; external;
procedure png_chunk_warning(png_ptr: png_structp;
  const mess: png_charp);
  cdecl; external;
procedure png_chunk_error(png_ptr: png_structp;
  const mess: png_charp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -