📄 teepng.pas
字号:
{*******************************************************}
{ TeeChart PNG Graphic Format }
{ Copyright (c) 2000-2003 by David Berneda }
{ All Rights Reserved }
{ }
{ Windows systems: }
{ The LPng.DLL is required in \Windows\System folder }
{*******************************************************}
unit TeePNG;
{$I TeeDefs.inc}
interface
uses
{$IFNDEF LINUX}
Windows, Messages,
{$ENDIF}
{$IFDEF CLX}
QComCtrls, QStdCtrls, QControls, QGraphics, QForms, Qt,
{$ELSE}
Forms, Graphics, ComCtrls, Controls, StdCtrls,
{$ENDIF}
SysUtils, Classes, TeeProcs, TeeExport, TeCanvas;
type
TPNGExportFormat=class;
TTeePNGOptions = class(TForm)
Label1: TLabel;
Edit1: TEdit;
UpDown1: TUpDown;
procedure FormCreate(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
IFormat : TPNGExportFormat;
public
{ Public declarations }
end;
{$IFNDEF LINUX}
TPicData = record
Stream : TMemoryStream;
APtr : Pointer;
BLineWidth,
LineWidth,
Width,
Height : Integer;
end;
{$ENDIF}
TPNGExportFormat=class(TTeeExportFormat)
private
FCompression : Integer;
FPixel : TPixelFormat;
{$IFNDEF LINUX}
PicData : TPicData;
RowPtrs : PByte;
SaveBuf : Array[0..8192] of Byte;
{$ENDIF}
Procedure CheckProperties;
Procedure SetCompression(const Value:Integer);
protected
FProperties: TTeePNGOptions;
Procedure DoCopyToClipboard; override;
public
Constructor Create; override;
Function Bitmap:TBitmap;
property Compression:Integer read FCompression write SetCompression;
function Description:String; override;
function FileExtension:String; override;
function FileFilter:String; override;
Function Options(Check:Boolean=True):TForm; override;
property PixelFormat:TPixelFormat read FPixel write FPixel;
procedure SaveToStream(AStream:TStream); override;
procedure SaveToStreamCompression(AStream:TStream; CompressionLevel:Integer);
end;
Procedure TeeSaveToPNG( APanel:TCustomTeePanel;
Const AFileName: WideString;
AWidth, AHeight: Integer);
implementation
{$IFNDEF CLX}
{$R *.DFM}
{$ELSE}
{$R *.xfm}
{$ENDIF}
Uses {$IFDEF CLX}
QClipbrd,
{$ELSE}
Clipbrd,
{$ENDIF}
{$IFDEF TEEOCX}
SyncObjs,
{$ENDIF}
TeeConst;
Procedure TeeSaveToPNG( APanel:TCustomTeePanel;
Const AFileName: WideString;
AWidth, AHeight: Integer);
begin
with TPNGExportFormat.Create do
try
Panel:=APanel;
Width:=AWidth;
Height:=AHeight;
SaveToFile(AFileName);
finally
Free;
end;
end;
Const TeePNG_DefaultCompressionLevel=9;
{$IFDEF TEEOCX}
var PNGSection : TCriticalSection;
{$ENDIF}
{$IFNDEF LINUX}
type
TPng_Row_Info=record
width : Cardinal;
rowbytes : Cardinal;
color_type : Byte;
bit_depth : Byte;
channels : Byte;
pixel_depth : Byte;
end;
PPng_Row_Info=^TPng_Row_Info;
TPng_Color=record
red : Byte;
green : Byte;
blue : Byte;
end;
PPng_Color=^TPng_Color;
TPng_Color_16=record
index: Byte;
red: Word;
green: Word;
blue: Word;
gray: Word;
end;
PPng_Color_16=^TPng_Color_16;
PPWord = ^PWord;
TPng_Color_8=record
red: Byte;
green: Byte;
blue: Byte;
gray: Byte;
alpha: Byte;
end;
PPng_Color_8 = ^TPng_Color_8;
TPng_Struct=record
jmpbuf : Array[0..10] of Integer;
error_fn : Pointer;
warning_fn : Pointer;
error_ptr : Pointer;
write_data_fn : Pointer;
read_data_fn : Pointer;
read_user_transform_fn: Pointer;
write_user_transform_fn: Pointer;
io_ptr : Integer;
mode : Cardinal;
flags : Cardinal;
transformations : Cardinal;
zstream : Pointer;
zbuf : PByte;
zbuf_size : Integer;
zlib_level : Integer;
zlib_method : Integer;
zlib_window_bits : Integer;
zlib_mem_level : Integer;
zlib_strategy : Integer;
width : Cardinal;
height : Cardinal;
num_rows : Cardinal;
usr_width : Cardinal;
rowbytes : Cardinal;
irowbytes : Cardinal;
iwidth : Cardinal;
row_number : Cardinal;
prev_row : PByte;
row_buf : PByte;
sub_row : PByte;
up_row : PByte;
avg_row : PByte;
paeth_row : PByte;
row_info : TPng_Row_Info;
idat_size : Cardinal;
crc : Cardinal;
palette : PPng_Color;
num_palette : Word;
num_trans : Word;
chunk_name : Array[0..4] of Byte;
compression : Byte;
filter : Byte;
interlaced : Byte;
pass : Byte;
do_filter : Byte;
color_type : Byte;
bit_depth : Byte;
usr_bit_depth : Byte;
pixel_depth : Byte;
channels : Byte;
usr_channels : Byte;
sig_bytes : Byte;
filler : Byte;
background_gamma_type: Byte;
background_gamma : Single;
background : TPng_Color_16;
background_1 : TPng_Color_16;
output_flush_fn : Pointer;
flush_dist : Cardinal;
flush_rows : Cardinal;
gamma_shift : Integer;
gamma : Single;
screen_gamma : Single;
gamma_table : PByte;
gamma_from_1 : PByte;
gamma_to_1 : PByte;
gamma_16_table : PPWord;
gamma_16_from_1 : PPWord;
gamma_16_to_1 : PPWord;
sig_bit : TPng_Color_8;
shift : TPng_Color_8;
trans : PByte;
trans_values : TPng_Color_16;
read_row_fn : Pointer;
write_row_fn : Pointer;
info_fn : Pointer;
row_fn : Pointer;
end_fn : Pointer;
save_buffer_ptr : PByte;
save_buffer : PByte;
current_buffer_ptr: PByte;
current_buffer : PByte;
push_length : Cardinal;
skip_length : Cardinal;
save_buffer_size : Integer;
save_buffer_max : Integer;
buffer_size : Integer;
current_buffer_size: Integer;
process_mode : Integer;
cur_palette : Integer;
current_text_size: Integer;
current_text_left: Integer;
current_text : PByte;
current_text_ptr : PByte;
palette_lookup : PByte;
dither_index : PByte;
hist : PWord;
heuristic_method : Byte;
num_prev_filters : Byte;
prev_filters : PByte;
filter_weights : PWord;
inv_filter_weights: PWord;
filter_costs : PWord;
inv_filter_costs : PWord;
time_buffer : PByte;
end;
PPng_Struct = ^TPng_Struct;
PPPng_Struct = ^PPng_Struct;
TPng_Text = record
compression: Integer;
key: PChar;
text: PChar;
text_length: Integer;
end;
PPng_Text = ^TPng_Text;
TPng_Time = record
year: Word;
month: Byte;
day: Byte;
hour: Byte;
minute: Byte;
second: Byte;
end;
PPng_Time = ^TPng_Time;
PPChar = ^PChar;
TPng_Info = record
width: Cardinal;
height: Cardinal;
valid: Cardinal;
rowbytes: Cardinal;
palette: PPng_Color;
num_palette: Word;
num_trans: Word;
bit_depth: Byte;
color_type: Byte;
compression_type: Byte;
filter_type: Byte;
interlace_type: Byte;
channels: Byte;
pixel_depth: Byte;
spare_byte: Byte;
signature: array[0..7] of Byte;
gamma: Single;
srgb_intent: Byte;
num_text: Integer;
max_text: Integer;
text: PPng_Text;
mod_time: TPng_Time;
sig_bit: TPng_Color_8;
trans: PByte;
trans_values: TPng_Color_16;
background: TPng_Color_16;
x_offset: Cardinal;
y_offset: Cardinal;
offset_unit_type: Byte;
x_pixels_per_unit: Cardinal;
y_pixels_per_unit: Cardinal;
phys_unit_type: Byte;
hist: PWord;
x_white: Single;
y_white: Single;
x_red: Single;
y_red: Single;
x_green: Single;
y_green: Single;
x_blue: Single;
y_blue: Single;
pcal_purpose: PChar;
pcal_X0: Integer;
pcal_X1: Integer;
pcal_units: PChar;
pcal_params: PPChar;
pcal_type: Byte;
pcal_nparams: Byte;
end;
PPng_Info = ^TPng_Info;
PPPng_Info = ^PPng_Info;
PPByte = ^PByte;
png_rw_ptr = procedure(png_ptr: Pointer; var Data: Pointer; Length: Cardinal); stdcall;
png_flush_ptr = procedure(png_ptr: Pointer); stdcall;
Var png_create_write_struct: function(user_png_ver: PChar;
error_ptr, error_fn, warn_fn: Pointer): PPng_Struct; stdcall;
png_create_info_struct : function(png_ptr: PPng_Struct): PPng_Info; stdcall;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -