libimg can save 24-bit *.png images

git-svn-id: svn://kolibrios.org@6733 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-11-21 16:00:11 +00:00
parent 6b3f26b172
commit 722650c58d
19 changed files with 21461 additions and 6 deletions

View File

@ -0,0 +1,277 @@
use32
org 0x0
db 'MENUET01'
dd 1,START,I_END,MEM,STACKTOP,0,cur_dir_path
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
include '../../../../../KOSfuncs.inc'
include '../../../box_lib/load_lib.mac'
include '../../../../../dll.inc'
include '../../libimg/libimg.inc'
macro cStr dest,txt
{
local .end_t
local .m_txt
jmp .end_t
align 4
.m_txt db txt,0
align 4
.end_t:
if dest eq
mov eax,.m_txt
else
mov dest,.m_txt
end if
}
@use_library_mem mem.Alloc,mem.Free,mem.ReAlloc, dll.Load
align 4
m1size dd 16*1024
m1 rb 16*1024
align 4
START:
load_libraries l_libs_start,load_lib_end
mov ebp,lib0
.test_lib_open:
cmp dword [ebp+ll_struc_size-4],0
jz @f
mcall SF_TERMINATE_PROCESS ;exit not correct
@@:
add ebp,ll_struc_size
cmp ebp,load_lib_end
jl .test_lib_open
;create image data
stdcall [buf2d_create], buf_0
stdcall [buf2d_line], buf_0, 110, 20, 125, 90, 0xffff00
stdcall [buf2d_line], buf_0, 60, 120, 110, 20, 0xd000
stdcall [buf2d_curve_bezier], buf_0, (10 shl 16)+20,(110 shl 16)+10,(50 shl 16)+90, dword 0xff
stdcall [buf2d_circle], buf_0, 125, 90, 30, 0xffffff
stdcall [buf2d_circle], buf_0, 25, 70, 15, 0xff0000
;create image struct
stdcall [img.create], [buf_0.w], [buf_0.h], Image.bpp24
test eax,eax
jz @f
;copy image
mov edi,[eax+Image.Data]
mov esi,[buf_0]
mov ecx,[buf_0.w]
imul ecx,[buf_0.h]
imul ecx,3
rep movsb
;encode image
stdcall [img.encode], eax, LIBIMG_FORMAT_PNG, 0
test eax,eax
jz @f
;copy output image
mov edi,m1
mov esi,eax
mov [m1size],ecx
rep movsb
@@:
align 4
red:
call draw_window
align 4
still:
mcall SF_WAIT_EVENT ; äã­ªæ¨ï 10 - ¦¤ âì ᮡëâ¨ï
cmp eax,1 ; ¯¥à¥à¨á®¢ âì ®ª­® ?
je red ; ¥á«¨ ¤  - ­  ¬¥âªã red
cmp eax,2 ; ­ ¦ â  ª« ¢¨è  ?
je key ; ¥á«¨ ¤  - ­  key
cmp eax,3 ; ­ ¦ â  ª­®¯ª  ?
je button ; ¥á«¨ ¤  - ­  button
jmp still ; ¥á«¨ ¤à㣮¥ ᮡë⨥ - ¢ ­ ç «® 横« 
align 4
key: ; ­ ¦ â  ª« ¢¨è  ­  ª« ¢¨ âãà¥
mcall SF_GET_KEY ; äã­ªæ¨ï 2 - áç¨â âì ª®¤ ᨬ¢®«  (¢ ah)
cmp ah,178 ;Up
jne @f
call but_save_file
@@:
jmp still ; ¢¥à­ãâìáï ª ­ ç «ã 横« 
;---------------------------------------------------------------------
align 4
button:
mcall SF_GET_BUTTON
cmp ah, 1
jne still
.exit:
stdcall [buf2d_delete],buf_0
mcall SF_TERMINATE_PROCESS
align 4
draw_window:
mcall SF_REDRAW, SSF_BEGIN_DRAW
mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc,sizeof.system_colors
mov edx, [sc.work] ; 梥â ä®­ 
or edx, 0x33000000 ; ¨ ⨯ ®ª­  3
mcall SF_CREATE_WINDOW, <50,400>, <50,230>, , ,title
stdcall [buf2d_draw], buf_0
cStr edx,'Img. size:'
mcall SF_DRAW_TEXT, <10,130>,0x40f0,,10
mcall SF_DRAW_NUMBER, (5 shl 16)+1, m1size, <80,130>, 0
mcall SF_REDRAW, SSF_END_DRAW
ret
align 4
title db 'Press button [Up] and see '
openfile_path db '/rd/1/t1.png',0
struct FileInfoBlock
Function dd ?
Position dd ?
Flags dd ?
Count dd ?
Buffer dd ?
db ?
FileName dd ?
ends
align 4
run_file_70 FileInfoBlock
align 4
but_save_file:
pushad
mov eax,SF_FILE
mov [run_file_70.Function], SSF_CREATE_FILE
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
mov [run_file_70.Buffer], m1
mov ebx,[m1size]
mov dword[run_file_70.Count], ebx
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mov ebx,run_file_70
int 0x40
;cmp ebx,0xffffffff
;je .end_save_file
;... if error ...
;.end_save_file:
popad
ret
align 4
buf_0:
dd 0
dw 10 ;+4 left
dw 4 ;+6 top
.w: dd 360 ;+8 w
.h: dd 120 ;+12 h
dd 0x80 ;+16 color
db 24 ;+20 bit in pixel
align 4
sc system_colors
align 4
import_buf2d_lib:
dd sz_lib_init
buf2d_create dd sz_buf2d_create
buf2d_create_f_img dd sz_buf2d_create_f_img
buf2d_clear dd sz_buf2d_clear
buf2d_draw dd sz_buf2d_draw
buf2d_delete dd sz_buf2d_delete
buf2d_line dd sz_buf2d_line
buf2d_circle dd sz_buf2d_circle
buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2
buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2
buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8
buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32
buf2d_bit_blt dd sz_buf2d_bit_blt
buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp
buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha
buf2d_curve_bezier dd sz_buf2d_curve_bezier
buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix
buf2d_draw_text dd sz_buf2d_draw_text
dd 0,0
sz_lib_init db 'lib_init',0
sz_buf2d_create db 'buf2d_create',0
sz_buf2d_create_f_img db 'buf2d_create_f_img',0
sz_buf2d_clear db 'buf2d_clear',0
sz_buf2d_draw db 'buf2d_draw',0
sz_buf2d_delete db 'buf2d_delete',0
sz_buf2d_line db 'buf2d_line',0
sz_buf2d_circle db 'buf2d_circle',0
sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0
sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0
sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0
sz_buf2d_bit_blt db 'buf2d_bit_blt',0
sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0
sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0
sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0
sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
sz_buf2d_draw_text db 'buf2d_draw_text',0
align 4
import_libimg:
libimg.init dd sz_lib_init1
img.draw dd sz_img_draw
img.decode dd sz_img_decode
img.encode dd sz_img_encode
img.create dd sz_img_create
img.destroy dd sz_img_destroy
img.to_rgb2 dd sz_img_to_rgb2
img.formats_table dd sz_img_formats_table
dd 0,0
sz_lib_init1 db 'lib_init',0
sz_img_draw db 'img_draw',0
sz_img_decode db 'img_decode',0
sz_img_encode db 'img_encode',0
sz_img_create db 'img_create',0
sz_img_destroy db 'img_destroy',0
sz_img_to_rgb2 db 'img_to_rgb2',0
sz_img_formats_table db 'img_formats_table',0
;--------------------------------------------------
system_dir_0 db '/sys/lib/'
lib_name_0 db 'buf2d.obj',0
system_dir_1 db '/sys/lib/'
lib_name_1 db 'libimg.obj',0
err_message_found_lib0 db 'Sorry I cannot load library buf2d.obj',0
err_message_found_lib1 db 'Sorry I cannot load library libimg.obj',0
head_f_i:
head_f_l db 'System error',0
err_message_import0 db 'Error on load import library buf2d.obj',0
err_message_import1 db 'Error on load import library libimg.obj',0
l_libs_start:
lib0 l_libs lib_name_0, cur_dir_path, library_path, system_dir_0,\
err_message_found_lib0, head_f_l, import_buf2d_lib,err_message_import0, head_f_i
lib1 l_libs lib_name_1, cur_dir_path, library_path, system_dir_1,\
err_message_found_lib1, head_f_l, import_libimg, err_message_import1, head_f_i
load_lib_end:
;---------------------------------------------------------------------
align 16
I_END:
rd 4096
STACKTOP:
cur_dir_path:
rb 4096
library_path:
rb 4096
MEM:

View File

@ -68,6 +68,11 @@ proc lib_init ;/////////////////////////////////////////////////////////////////
mov [mem.realloc], ecx
mov [dll.load], edx
or edx,edx
jz @f
invoke dll.load, @IMPORT
@@:
call img.initialize.jpeg
xor eax, eax
@ -2417,7 +2422,7 @@ img.formats_table:
.ico dd LIBIMG_FORMAT_ICO, img.is.ico, img.decode.ico_cur, img.encode.ico, 0
.cur dd LIBIMG_FORMAT_CUR, img.is.cur, img.decode.ico_cur, img.encode.cur, 0
.gif dd LIBIMG_FORMAT_GIF, img.is.gif, img.decode.gif, img.encode.gif, 0
.png dd LIBIMG_FORMAT_PNG, img.is.png, img.decode.png, img.encode.png, 0
.png dd LIBIMG_FORMAT_PNG, img.is.png, img.decode.png, img.encode.png, 1 + (1 SHL Image.bpp24)
.jpg dd LIBIMG_FORMAT_JPEG, img.is.jpg, img.decode.jpg, img.encode.jpg, 0
.tga dd LIBIMG_FORMAT_TGA, img.is.tga, img.decode.tga, img.encode.tga, 0
.pcx dd LIBIMG_FORMAT_PCX, img.is.pcx, img.decode.pcx, img.encode.pcx, 0
@ -2771,12 +2776,17 @@ export \
; import from deflate unpacker
; is initialized only when PNG loading is requested
align 4
align 16
@IMPORT:
library archiver, 'archiver.obj'
import archiver, \
deflate_unpack2, 'deflate_unpack2'
deflate_unpack2, 'deflate_unpack2',\
deflateInit2, 'deflateInit2',\
deflateReset, 'deflateReset',\
deflate, 'deflate',\
deflateEnd, 'deflateEnd',\
calc_crc32, 'calc_crc32'
align 4
; mutex for unpacker loading

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,897 @@
; pngerror.asm - stub functions for i/o and memory allocation
; Last changed in libpng 1.6.24 [August 4, 2016]
; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.h
; This file provides a location for all error handling. Users who
; need special error handling are expected to write replacement functions
; and use png_set_error_fn() to use those functions. See the instructions
; at each function.
; This function is called whenever there is a fatal error. This function
; should not be changed. If there is a need to handle errors differently,
; you should supply a replacement error function and use png_set_error_fn()
; to replace the error function at run-time.
;if PNG_ERROR_TEXT_SUPPORTED
;void png_error(png_const_structrp png_ptr, charp error_message)
;{
if PNG_ERROR_NUMBERS_SUPPORTED eq 1
; char msg[16];
; if (png_ptr != NULL)
; {
; if ((png_ptr->flags &
; (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
; {
; if (*error_message == PNG_LITERAL_SHARP)
; {
;Strip "#nnnn " from beginning of error message.
; int offset;
; for (offset = 1; offset<15; offset++)
; if (error_message[offset] == ' ')
; break;
; if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
; {
; int i;
; for (i = 0; i < offset - 1; i++)
; msg[i] = error_message[i + 1];
; msg[i - 1] = '\0';
; error_message = msg;
; }
; else
; error_message += offset;
; }
; else
; {
; if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
; {
; msg[0] = '0';
; msg[1] = '\0';
; error_message = msg;
; }
; }
; }
; }
end if
; if (png_ptr != NULL && png_ptr->error_fn != NULL)
; (*(png_ptr->error_fn))(png_ptr, error_message);
; If the custom handler doesn't exist, or if it returns,
; use the default handler, which will not return.
; png_default_error(png_ptr, error_message);
;}
;#else
;void png_err(png_const_structrp png_ptr)
;{
; Prior to 1.5.2 the error_fn received a NULL pointer, expressed
; erroneously as '\0', instead of the empty string "". This was
; apparently an error, introduced in libpng-1.2.20, and png_default_error
; will crash in this case.
; if (png_ptr != NULL && png_ptr->error_fn != NULL)
; (*(png_ptr->error_fn))(png_ptr, "");
; If the custom handler doesn't exist, or if it returns,
; use the default handler, which will not return.
; png_default_error(png_ptr, "");
;}
;end if /* ERROR_TEXT */
; Utility to safely appends strings to a buffer. This never errors out so
; error checking is not required in the caller.
;size_t (charp buffer, size_t bufsize, size_t pos, charp string)
align 4
proc png_safecat uses ebx ecx edi esi, buffer:dword, bufsize:dword, pos:dword, string:dword
mov edi,[buffer]
cmp edi,0
je .end0
mov ebx,[pos]
mov ecx,[bufsize]
cmp ebx,ecx
jge .end0 ;if (..!=0 && ..<..)
mov esi,[string]
cmp esi,0
je .end1 ;if (..!=0)
dec ecx
@@:
cmp byte[esi],0
je .end1
cmp ebx,ecx
jge .end1
movsb
inc ebx
jmp @b
align 4
.end1:
xor al,al
stosb
.end0:
mov eax,ebx
ret
endp
;#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
; Utility to dump an unsigned value into a buffer, given a start pointer and
; and end pointer (which should point just *beyond* the end of the buffer!)
; Returns the pointer to the start of the formatted string.
;charp png_format_number(charp start, charp end, int format,
; png_alloc_size_t number)
;{
; int count = 0; /* number of digits output */
; int mincount = 1; /* minimum number required */
; int output = 0; /* digit output (for the fixed point format) */
; *--end = '\0';
; /* This is written so that the loop always runs at least once, even with
; * number zero.
; while (end > start && (number != 0 || count < mincount))
; {
; char digits[] = "0123456789ABCDEF";
; switch (format)
; {
; case PNG_NUMBER_FORMAT_fixed:
; /* Needs five digits (the fraction) */
; mincount = 5;
; if (output != 0 || number % 10 != 0)
; {
; *--end = digits[number % 10];
; output = 1;
; }
; number /= 10;
; break;
; case PNG_NUMBER_FORMAT_02u:
; /* Expects at least 2 digits. */
; mincount = 2;
; /* FALL THROUGH */
; case PNG_NUMBER_FORMAT_u:
; *--end = digits[number % 10];
; number /= 10;
; break;
; case PNG_NUMBER_FORMAT_02x:
; /* This format expects at least two digits */
; mincount = 2;
; /* FALL THROUGH */
; case PNG_NUMBER_FORMAT_x:
; *--end = digits[number & 0xf];
; number >>= 4;
; break;
; default: /* an error */
; number = 0;
; break;
; }
; Keep track of the number of digits added
; ++count;
; Float a fixed number here:
; if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
; {
; End of the fraction, but maybe nothing was output? In that case
; drop the decimal point. If the number is a true zero handle that
; here.
; if (output != 0)
; *--end = '.';
; else if (number == 0) /* and !output */
; *--end = '0';
; }
; }
; return end;
;}
;end if
;if PNG_WARNINGS_SUPPORTED
; This function is called whenever there is a non-fatal error. This function
; should not be changed. If there is a need to handle warnings differently,
; you should supply a replacement warning function and use
; png_set_error_fn() to replace the warning function at run-time.
;void png_warning(png_const_structrp png_ptr, charp warning_message)
;{
; int offset = 0;
; if (png_ptr != NULL)
; {
if PNG_ERROR_NUMBERS_SUPPORTED eq 1
; if ((png_ptr->flags &
; (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
end if
; {
; if (*warning_message == PNG_LITERAL_SHARP)
; {
; for (offset = 1; offset < 15; offset++)
; if (warning_message[offset] == ' ')
; break;
; }
; }
; }
; if (png_ptr != NULL && png_ptr->warning_fn != NULL)
; (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
; else
; png_default_warning(png_ptr, warning_message + offset);
;}
; These functions support 'formatted' warning messages with up to
; PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter
; is introduced by @<number>, where 'number' starts at 1. This follows the
; standard established by X/Open for internationalizable error messages.
;void
;png_warning_parameter(png_warning_parameters p, int number,
; charp string)
;{
; if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
; (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
;}
;void
;png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
; png_alloc_size_t value)
;{
; char buffer[PNG_NUMBER_BUFFER_SIZE];
; png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
;}
;void (png_warning_parameters p, int number, int format, int_32 value)
align 4
proc png_warning_parameter_signed, p:dword, number:dword, format:dword, value:dword
; png_alloc_size_t u;
; charp str;
; char buffer[PNG_NUMBER_BUFFER_SIZE];
; Avoid overflow by doing the negate in a png_alloc_size_t:
; u = (png_alloc_size_t)value;
; if (value < 0)
; u = ~u + 1;
; str = PNG_FORMAT_NUMBER(buffer, format, u);
; if (value < 0 && str > buffer)
; *--str = '-';
; png_warning_parameter(p, number, str);
ret
endp
;void (png_const_structrp png_ptr, png_warning_parameters p, charp message)
align 4
proc png_formatted_warning, png_ptr:dword, p:dword, message:dword
; The internal buffer is just 192 bytes - enough for all our messages,
; overflow doesn't happen because this code checks! If someone figures
; out how to send us a message longer than 192 bytes, all that will
; happen is that the message will be truncated appropriately.
; size_t i = 0; /* Index in the msg[] buffer: */
; char msg[192];
; Each iteration through the following loop writes at most one character
; to msg[i++] then returns here to validate that there is still space for
; the trailing '\0'. It may (in the case of a parameter) read more than
; one character from message[]; it must check for '\0' and continue to the
; test if it finds the end of string.
; while (i<(sizeof msg)-1 && *message != '\0')
; {
; '@' at end of string is now just printed (previously it was skipped);
; it is an error in the calling code to terminate the string with @.
; if (p != NULL && *message == '@' && message[1] != '\0')
; {
; int parameter_char = *++message; /* Consume the '@' */
; char valid_parameters[] = "123456789";
; int parameter = 0;
; Search for the parameter digit, the index in the string is the
; parameter to use.
; while (valid_parameters[parameter] != parameter_char &&
; valid_parameters[parameter] != '\0')
; ++parameter;
; If the parameter digit is out of range it will just get printed.
; if (parameter < PNG_WARNING_PARAMETER_COUNT)
; {
; Append this parameter
; charp parm = p[parameter];
; charp pend = p[parameter] + (sizeof p[parameter]);
; No need to copy the trailing '\0' here, but there is no guarantee
; that parm[] has been initialized, so there is no guarantee of a
; trailing '\0':
; while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend)
; msg[i++] = *parm++;
; Consume the parameter digit too:
; ++message;
; continue;
; }
; else not a parameter and there is a character after the @ sign; just
; copy that. This is known not to be '\0' because of the test above.
; }
; At this point *message can't be '\0', even in the bad parameter case
; above where there is a lone '@' at the end of the message string.
; msg[i++] = *message++;
; }
; i is always less than (sizeof msg), so:
; msg[i] = '\0';
; And this is the formatted message. It may be larger than
; PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these
; are not (currently) formatted.
; png_warning(png_ptr, msg);
ret
endp
;end if /* WARNINGS */
;void png_benign_error(png_const_structrp png_ptr, charp error_message)
;{
; if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
; {
;# ifdef PNG_READ_SUPPORTED
; if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
; png_ptr->chunk_name != 0)
; png_chunk_warning(png_ptr, error_message);
; else
;# endif
; png_warning(png_ptr, error_message);
; }
; else
; {
;# ifdef PNG_READ_SUPPORTED
; if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
; png_ptr->chunk_name != 0)
; png_chunk_error(png_ptr, error_message);
; else
;# endif
; png_error(png_ptr, error_message);
; }
;}
;void png_app_warning(png_const_structrp png_ptr, charp error_message)
;{
; if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
; png_warning(png_ptr, error_message);
; else
; png_error(png_ptr, error_message);
;}
;void (png_structrp png_ptr, charp error_message)
align 4
proc png_app_error uses eax edi, png_ptr:dword, error_message:dword
mov edi,[png_ptr]
mov eax,[edi+png_struct.flags]
and eax,PNG_FLAG_APP_ERRORS_WARN
cmp eax,0
je @f ;if (..!=0)
png_warning edi, [error_message]
jmp .end0
@@: ;else
png_error edi, [error_message]
.end0:
ret
endp
PNG_MAX_ERROR_TEXT equ 196 ;Currently limited by profile_error in png.asm
if (PNG_WARNINGS_SUPPORTED eq 1) | \
((PNG_READ_SUPPORTED eq 1) & (PNG_ERROR_TEXT_SUPPORTED eq 1))
; These utilities are used internally to build an error message that relates
; to the current chunk. The chunk name comes from png_ptr->chunk_name,
; which is used to prefix the message. The message is limited in length
; to 63 bytes. The name characters are output as hex digits wrapped in []
; if the character is invalid.
;#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
align 4
png_digit db \ ;char[16]
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', \
'A', 'B', 'C', 'D', 'E', 'F'
;void (png_const_structrp png_ptr, charp buffer, charp error_message)
align 4
proc png_format_buffer, png_ptr:dword, buffer:dword, error_message:dword
; uint_32 chunk_name = png_ptr->chunk_name;
; int iout = 0, ishift = 24;
; while (ishift >= 0)
; {
; int c = (int)(chunk_name >> ishift) & 0xff;
; ishift -= 8;
; if (isnonalpha(c) != 0)
; {
; buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
; buffer[iout++] = png_digit[(c & 0xf0) >> 4];
; buffer[iout++] = png_digit[c & 0x0f];
; buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
; }
; else
; {
; buffer[iout++] = (char)c;
; }
; }
; if (error_message == NULL)
; buffer[iout] = '\0';
; else
; {
; int iin = 0;
; buffer[iout++] = ':';
; buffer[iout++] = ' ';
; while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
; buffer[iout++] = error_message[iin++];
;iin < PNG_MAX_ERROR_TEXT, so the following is safe:
; buffer[iout] = '\0';
; }
ret
endp
end if ;WARNINGS || ERROR_TEXT
;void (png_const_structrp png_ptr, charp error_message)
align 4
proc png_chunk_error, png_ptr:dword, error_message:dword
; char msg[18+PNG_MAX_ERROR_TEXT];
; if (png_ptr == NULL)
; png_error(png_ptr, error_message);
; else
; {
; png_format_buffer(png_ptr, msg, error_message);
; png_error(png_ptr, msg);
; }
ret
endp
;void (png_const_structrp png_ptr, charp warning_message)
align 4
proc png_chunk_warning, png_ptr:dword, warning_message:dword
; char msg[18+PNG_MAX_ERROR_TEXT];
; if (png_ptr == NULL)
; png_warning(png_ptr, warning_message);
; else
; {
; png_format_buffer(png_ptr, msg, warning_message);
; png_warning(png_ptr, msg);
; }
ret
endp
;void (png_const_structrp png_ptr, charp error_message)
align 4
proc png_chunk_benign_error, png_ptr:dword, error_message:dword
; if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
; png_chunk_warning(png_ptr, error_message);
; else
; png_chunk_error(png_ptr, error_message);
ret
endp
;void (png_const_structrp png_ptr, charp message, int error)
align 4
proc png_chunk_report, png_ptr:dword, message:dword, error:dword
; This is always supported, but for just read or just write it
; unconditionally does the right thing.
;# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
; if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
;# endif
if PNG_READ_SUPPORTED eq 1
; {
; if (error < PNG_CHUNK_ERROR)
; png_chunk_warning(png_ptr, message);
; else
; png_chunk_benign_error(png_ptr, message);
; }
end if
;# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
; else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
;# endif
if PNG_WRITE_SUPPORTED eq 1
; {
; if (error < PNG_CHUNK_WRITE_ERROR)
; png_app_warning(png_ptr, message);
;
; else
; png_app_error(png_ptr, message);
; }
end if
ret
endp
;void (png_const_structrp png_ptr, charp name)
align 4
proc png_fixed_error, png_ptr:dword, name:dword
;# define fixed_message "fixed point overflow in "
;# define fixed_message_ln ((sizeof fixed_message)-1)
; int iin;
; char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
; memcpy(msg, fixed_message, fixed_message_ln);
; iin = 0;
; if (name != NULL)
; while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
; {
; msg[fixed_message_ln + iin] = name[iin];
; ++iin;
; }
; msg[fixed_message_ln + iin] = 0;
; png_error(png_ptr, msg);
ret
endp
; This API only exists if ANSI-C style error handling is used,
; otherwise it is necessary for png_default_error to be overridden.
;jmp_buf* (png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
; size_t jmp_buf_size)
align 4
proc png_set_longjmp_fn, png_ptr:dword, longjmp_fn:dword, jmp_buf_size:dword
; From libpng 1.6.0 the app gets one chance to set a 'jmpbuf_size' value
; and it must not change after that. Libpng doesn't care how big the
; buffer is, just that it doesn't change.
; If the buffer size is no *larger* than the size of jmp_buf when libpng is
; compiled a built in jmp_buf is returned; this preserves the pre-1.6.0
; semantics that this call will not fail. If the size is larger, however,
; the buffer is allocated and this may fail, causing the function to return
; NULL.
; if (png_ptr == NULL)
; return NULL;
; if (png_ptr->jmp_buf_ptr == NULL)
; {
; png_ptr->jmp_buf_size = 0; /* not allocated */
; if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local))
; png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local;
; else
; {
; png_ptr->jmp_buf_ptr = png_malloc_warn(png_ptr, jmp_buf_size);
; if (png_ptr->jmp_buf_ptr == NULL)
; return NULL; /* new NULL return on OOM */
; png_ptr->jmp_buf_size = jmp_buf_size;
; }
; }
; else /* Already allocated: check the size */
; {
; size_t size = png_ptr->jmp_buf_size;
; if (size == 0)
; {
; size = (sizeof png_ptr->jmp_buf_local);
; if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local)
; {
; This is an internal error in libpng: somehow we have been left
; with a stack allocated jmp_buf when the application regained
; control. It's always possible to fix this up, but for the moment
; this is a png_error because that makes it easy to detect.
; png_error(png_ptr, "Libpng jmp_buf still allocated");
; /* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */
; }
; }
; if (size != jmp_buf_size)
; {
; png_warning(png_ptr, "Application jmp_buf size changed");
; return NULL; /* caller will probably crash: no choice here */
; }
; }
; Finally fill in the function, now we have a satisfactory buffer. It is
; valid to change the function on every call.
; png_ptr->longjmp_fn = longjmp_fn;
; return png_ptr->jmp_buf_ptr;
.end_f:
ret
endp
;void (png_structrp png_ptr)
align 4
proc png_free_jmpbuf, png_ptr:dword
; if (png_ptr != NULL)
; {
; jmp_buf *jb = png_ptr->jmp_buf_ptr;
; A size of 0 is used to indicate a local, stack, allocation of the
; pointer; used here and in png.c
; if (jb != NULL && png_ptr->jmp_buf_size > 0)
; {
; This stuff is so that a failure to free the error control structure
; does not leave libpng in a state with no valid error handling: the
; free always succeeds, if there is an error it gets ignored.
; if (jb != &png_ptr->jmp_buf_local)
; {
; /* Make an internal, libpng, jmp_buf to return here */
; jmp_buf free_jmp_buf;
; if (!setjmp(free_jmp_buf))
; {
; png_ptr->jmp_buf_ptr = &free_jmp_buf; /* come back here */
; png_ptr->jmp_buf_size = 0; /* stack allocation */
; png_ptr->longjmp_fn = longjmp;
; png_free(png_ptr, jb); /* Return to setjmp on error */
; }
; }
; }
; *Always* cancel everything out:
; png_ptr->jmp_buf_size = 0;
; png_ptr->jmp_buf_ptr = NULL;
; png_ptr->longjmp_fn = 0;
; }
ret
endp
; This is the default error handling function. Note that replacements for
; this function MUST NOT RETURN, or the program will likely crash. This
; function is used by default, or if the program supplies NULL for the
; error function pointer in png_set_error_fn().
;void (png_const_structrp png_ptr, charp error_message)
align 4
proc png_default_error, png_ptr:dword, error_message:dword
if PNG_CONSOLE_IO_SUPPORTED eq 1
if PNG_ERROR_NUMBERS_SUPPORTED eq 1
; Check on NULL only added in 1.5.4
; if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)
; {
; Strip "#nnnn " from beginning of error message.
; int offset;
; char error_number[16];
; for (offset = 0; offset<15; offset++)
; {
; error_number[offset] = error_message[offset + 1];
; if (error_message[offset] == ' ')
; break;
; }
; if ((offset > 1) && (offset < 15))
; {
; error_number[offset - 1] = '\0';
; fprintf(stderr, "libpng error no. %s: %s",
; error_number, error_message + offset + 1);
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
; else
; {
; fprintf(stderr, "libpng error: %s, offset=%d",
; error_message, offset);
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
; }
; else
end if
; {
; fprintf(stderr, "libpng error: %s", error_message ? error_message :
; "undefined");
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
end if
; png_longjmp(png_ptr, 1);
ret
endp
; This function is called when there is a warning, but the library thinks
; it can continue anyway. Replacement functions don't have to do anything
; here if you don't want them to. In the default configuration, png_ptr is
; not used, but it is passed in case it may be useful.
;void (png_const_structrp png_ptr, charp warning_message)
align 4
proc png_default_warning, png_ptr:dword, warning_message:dword
if PNG_CONSOLE_IO_SUPPORTED eq 1
if PNG_ERROR_NUMBERS_SUPPORTED eq 1
; if (*warning_message == PNG_LITERAL_SHARP)
; {
; int offset;
; char warning_number[16];
; for (offset = 0; offset < 15; offset++)
; {
; warning_number[offset] = warning_message[offset + 1];
; if (warning_message[offset] == ' ')
; break;
; }
; if ((offset > 1) && (offset < 15))
; {
; warning_number[offset + 1] = '\0';
; fprintf(stderr, "libpng warning no. %s: %s",
; warning_number, warning_message + offset);
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
; else
; {
; fprintf(stderr, "libpng warning: %s",
; warning_message);
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
; }
; else
end if
; {
; fprintf(stderr, "libpng warning: %s", warning_message);
; fprintf(stderr, PNG_STRING_NEWLINE);
; }
end if
ret
endp
; This function is called when the application wants to use another method
; of handling errors and warnings. Note that the error function MUST NOT
; return to the calling routine or serious problems will occur. The return
; method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1)
;void (png_structrp png_ptr, voidp error_ptr,
; png_error_ptr error_fn, png_error_ptr warning_fn)
align 4
proc png_set_error_fn, png_ptr:dword, error_ptr:dword, error_fn:dword, warning_fn:dword
; if (png_ptr == NULL)
; return;
; png_ptr->error_ptr = error_ptr;
; png_ptr->error_fn = error_fn;
if PNG_WARNINGS_SUPPORTED eq 1
; png_ptr->warning_fn = warning_fn;
end if
ret
endp
; This function returns a pointer to the error_ptr associated with the user
; functions. The application should free any memory associated with this
; pointer before png_write_destroy and png_read_destroy are called.
;voidp (png_const_structrp png_ptr)
align 4
proc png_get_error_ptr, png_ptr:dword
; if (png_ptr == NULL)
; return NULL;
; return ((voidp)png_ptr->error_ptr);
ret
endp
;void (png_structrp png_ptr, uint_32 strip_mode)
align 4
proc png_set_strip_error_numbers, png_ptr:dword, strip_mode:dword
; if (png_ptr != NULL)
; {
; png_ptr->flags &=
; ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
; PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
; }
ret
endp
; Currently the above both depend on SETJMP_SUPPORTED, however it would be
; possible to implement without setjmp support just so long as there is some
; way to handle the error return here:
;void (png_structp png_nonconst_ptr, charp error_message)
align 4
proc png_safe_error uses eax ebx, png_nonconst_ptr:dword, error_message:dword
mov ebx,[png_nonconst_ptr]
mov ebx,[ebx+png_struct.error_ptr]
; An error is always logged here, overwriting anything (typically a warning)
; that is already there:
cmp ebx,0
je .end0 ;if (..!=0)
stdcall png_safecat, dword[ebx+png_image.message], sizeof.png_image.message, 0, [error_message]
or dword[ebx+png_image.warning_or_error], PNG_IMAGE_ERROR
; Retrieve the jmp_buf from within the png_control, making this work for
; C++ compilation too is pretty tricky: C++ wants a pointer to the first
; element of a jmp_buf, but C doesn't tell us the type of that.
; if (image->opaque != NULL && image->opaque->error_buf != NULL)
; longjmp(png_control_jmp_buf(image->opaque), 1);
; Missing longjmp buffer, the following is to help debugging:
; {
; size_t pos = png_safecat(image->message, (sizeof image->message), 0,
; "bad longjmp: ");
; png_safecat(image->message, (sizeof image->message), pos,
; error_message);
; }
.end0:
; Here on an internal programming error.
; abort();
ret
endp
;void (png_structp png_nonconst_ptr, charp warning_message)
align 4
proc png_safe_warning uses eax ebx, png_nonconst_ptr:dword, warning_message:dword
mov ebx,[png_nonconst_ptr]
mov ebx,[ebx+png_struct.error_ptr]
; A warning is only logged if there is no prior warning or error.
cmp dword[ebx+png_image.warning_or_error],0
jne @f ;if (..==0)
stdcall png_safecat, dword[ebx+png_image.message], sizeof.png_image.message, 0, [warning_message]
or dword[ebx+png_image.warning_or_error], PNG_IMAGE_WARNING
@@:
ret
endp
;int (png_imagep image_in, int (*function)(voidp), voidp arg)
align 4
proc png_safe_execute uses ebx, image_in:dword, function:dword, arg:dword
; volatile png_imagep image = image_in;
; volatile int result;
; volatile voidp saved_error_buf;
; jmp_buf safe_jmpbuf;
; Safely execute function(arg) with png_error returning to this function.
mov ebx,[image_in]
; saved_error_buf = image->opaque->error_buf;
; result = setjmp(safe_jmpbuf) == 0;
; if (result != 0)
; {
; image->opaque->error_buf = safe_jmpbuf;
stdcall [function], [arg]
; }
; image->opaque->error_buf = saved_error_buf;
; And do the cleanup prior to any failure return.
cmp eax,0
jne @f ;if (..==0)
stdcall png_image_free, ebx
@@:
ret
endp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,254 @@
; pnginfo.inc - header file for PNG reference library
; Last changed in libpng 1.6.1 [March 28, 2013]
; Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; png_info is a structure that holds the information in a PNG file so
; that the application can find out the characteristics of the image.
; If you are reading the file, this structure will tell you what is
; in the PNG file. If you are writing the file, fill in the information
; you want to put into the PNG file, using png_set_*() functions, then
; call png_write_info().
; The names chosen should be very close to the PNG specification, so
; consult that document for information about the meaning of each field.
; With libpng < 0.95, it was only possible to directly set and read the
; the values in the png_info_struct, which meant that the contents and
; order of the values had to remain fixed. With libpng 0.95 and later,
; however, there are now functions that abstract the contents of
; png_info_struct from the application, so this makes it easier to use
; libpng with dynamic libraries, and even makes it possible to use
; libraries that don't have all of the libpng ancillary chunk-handing
; functionality. In libpng-1.5.0 this was moved into a separate private
; file that is not visible to applications.
; The following members may have allocated storage attached that should be
; cleaned up before the structure is discarded: palette, trans, text,
; pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
; splt_palettes, scal_unit, row_pointers, and unknowns. By default, these
; are automatically freed when the info structure is deallocated, if they were
; allocated internally by libpng. This behavior can be changed by means
; of the png_data_freer() function.
; More allocation details: all the chunk-reading functions that
; change these members go through the corresponding png_set_*
; functions. A function to clear these members is available: see
; png_free_data(). The png_set_* functions do not depend on being
; able to point info structure members to any of the storage they are
; passed (they make their own copies), EXCEPT that the png_set_text
; functions use the same storage passed to them in the text_ptr or
; itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
; functions do not make their own copies.
struct png_info_def
; The following are necessary for every PNG file
width dd ? ;uint_32 ;width of image in pixels (from IHDR)
height dd ? ;uint_32 ;height of image in pixels (from IHDR)
valid dd ? ;uint_32 ;valid chunk data (see PNG_INFO_ below)
rowbytes dd ? ;png_size_t ;bytes needed to hold an untransformed row
palette dd ? ;png_colorp ; array of color values (valid & PNG_INFO_PLTE)
num_palette dw ? ;uint_16 ;number of color entries in "palette" (PLTE)
num_trans dw ? ;uint_16 ;number of transparent palette color (tRNS)
bit_depth db ? ;byte ;1, 2, 4, 8, or 16 bits/channel (from IHDR)
color_type db ? ;byte ;see PNG_COLOR_TYPE_ below (from IHDR)
; The following three should have been named *_method not *_type
compression_type db ? ;byte ;must be PNG_COMPRESSION_TYPE_BASE (IHDR)
filter_type db ? ;byte ;must be PNG_FILTER_TYPE_BASE (from IHDR)
interlace_type db ? ;byte ;One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7
; The following are set by png_set_IHDR, called from the application on
; write, but the are never actually used by the write code.
channels db ? ;byte ;number of data channels per pixel (1, 2, 3, 4)
pixel_depth db ? ;byte ;number of bits per pixel
spare_byte db ? ;byte ;to align the data, and for future use
if PNG_READ_SUPPORTED eq 1
; This is never set during write
signature db 8 ;byte[8] ;magic bytes read by libpng from start of file
end if
; The rest of the data is optional. If you are reading, check the
; valid field to see if the information in these are valid. If you
; are writing, set the valid field to those chunks you want written,
; and initialize the appropriate fields below.
if (PNG_COLORSPACE_SUPPORTED eq 1) | (PNG_GAMMA_SUPPORTED eq 1)
; png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are
; defined. When COLORSPACE is switched on all the colorspace-defining
; chunks should be enabled, when GAMMA is switched on all the gamma-defining
; chunks should be enabled. If this is not done it becomes possible to read
; inconsistent PNG files and assign a probably incorrect interpretation to
; the information. (In other words, by carefully choosing which chunks to
; recognize the system configuration can select an interpretation for PNG
; files containing ambiguous data and this will result in inconsistent
; behavior between different libpng builds!)
colorspace png_colorspace
end if
if PNG_iCCP_SUPPORTED eq 1
; iCCP chunk data.
iccp_name dd ? ;charp ;profile name
iccp_profile dd ? ;bytep ;International Color Consortium profile data
iccp_proflen dd ? ;uint_32 ;ICC profile data length
end if
if PNG_TEXT_SUPPORTED eq 1
; The tEXt, and zTXt chunks contain human-readable textual data in
; uncompressed, compressed, and optionally compressed forms, respectively.
; The data in "text" is an array of pointers to uncompressed,
; null-terminated C strings. Each chunk has a keyword that describes the
; textual data contained in that chunk. Keywords are not required to be
; unique, and the text string may be empty. Any number of text chunks may
; be in an image.
num_text dd ? ;int ;number of comments read or comments to write
max_text dd ? ;int ;current size of text array
text dd ? ;png_textp ;array of comments read or comments to write
end if ;TEXT
if PNG_tIME_SUPPORTED eq 1
; The tIME chunk holds the last time the displayed image data was
; modified. See the png_time struct for the contents of this struct.
mod_time png_time
end if
if PNG_sBIT_SUPPORTED eq 1
; The sBIT chunk specifies the number of significant high-order bits
; in the pixel data. Values are in the range [1, bit_depth], and are
; only specified for the channels in the pixel data. The contents of
; the low-order bits is not specified. Data is valid if
; (valid & PNG_INFO_sBIT) is non-zero.
sig_bit png_color_8 ; significant bits in color channels
end if
;#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
;defined(PNG_READ_BACKGROUND_SUPPORTED)
; The tRNS chunk supplies transparency data for paletted images and
; other image types that don't need a full alpha channel. There are
; "num_trans" transparency values for a paletted image, stored in the
; same order as the palette colors, starting from index 0. Values
; for the data are in the range [0, 255], ranging from fully transparent
; to fully opaque, respectively. For non-paletted images, there is a
; single color specified that should be treated as fully transparent.
; Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
trans_alpha dd ? ;bytep ; alpha values for paletted image
trans_color png_color_16 ;transparent color for non-palette image
;end if
if (PNG_bKGD_SUPPORTED eq 1) | (PNG_READ_BACKGROUND_SUPPORTED eq 1)
; The bKGD chunk gives the suggested image background color if the
; display program does not have its own background color and the image
; is needs to composited onto a background before display. The colors
; in "background" are normally in the same color space/depth as the
; pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
background png_color_16
end if
if PNG_oFFs_SUPPORTED eq 1
; The oFFs chunk gives the offset in "offset_unit_type" units rightwards
; and downwards from the top-left corner of the display, page, or other
; application-specific co-ordinate space. See the PNG_OFFSET_ defines
; below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
x_offset dd ? ;int_32 ;x offset on page
y_offset dd ? ;int_32 ;y offset on page
offset_unit_type db ? ;byte ;offset units type
end if
if PNG_pHYs_SUPPORTED eq 1
; The pHYs chunk gives the physical pixel density of the image for
; display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
; defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
x_pixels_per_unit dd ? ;uint_32 ;horizontal pixel density
y_pixels_per_unit dd ? ;uint_32 ;vertical pixel density
phys_unit_type db ? ;byte ;resolution type (see PNG_RESOLUTION_ below)
end if
if PNG_hIST_SUPPORTED eq 1
; The hIST chunk contains the relative frequency or importance of the
; various palette entries, so that a viewer can intelligently select a
; reduced-color palette, if required. Data is an array of "num_palette"
; values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
; is non-zero.
hist dd ? ;uint_16p
end if
if PNG_pCAL_SUPPORTED eq 1
; The pCAL chunk describes a transformation between the stored pixel
; values and original physical data values used to create the image.
; The integer range [0, 2^bit_depth - 1] maps to the floating-point
; range given by [pcal_X0, pcal_X1], and are further transformed by a
; (possibly non-linear) transformation function given by "pcal_type"
; and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
; defines below, and the PNG-Group's PNG extensions document for a
; complete description of the transformations and how they should be
; implemented, and for a description of the ASCII parameter strings.
; Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
pcal_purpose dd ? ;charp ;pCAL chunk description string
pcal_X0 dd ? ;int_32 ;minimum value
pcal_X1 dd ? ;int_32 ;maximum value
pcal_units dd ? ;charp ;Latin-1 string giving physical units
pcal_params dd ? ;charpp ;ASCII strings containing parameter values
pcal_type db ? ;byte ;equation type (see PNG_EQUATION_ below)
pcal_nparams db ? ;byte ;number of parameters given in pcal_params
end if
; New members added in libpng-1.0.6
free_me dd ? ;uint_32 ;flags items libpng is responsible for freeing
if PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED eq 1
; Storage for unknown chunks that the library doesn't recognize.
unknown_chunks dd ? ;png_unknown_chunkp
; The type of this field is limited by the type of
; png_struct::user_chunk_cache_max, else overflow can occur.
unknown_chunks_num dd ? ;int
end if
if PNG_sPLT_SUPPORTED eq 1
; Data on sPLT chunks (there may be more than one).
splt_palettes dd ? ;png_sPLT_tp
splt_palettes_num dd ? ;int ;Match type returned by png_get API
end if
if PNG_sCAL_SUPPORTED eq 1
; The sCAL chunk describes the actual physical dimensions of the
; subject matter of the graphic. The chunk contains a unit specification
; a byte value, and two ASCII strings representing floating-point
; values. The values are width and height corresponsing to one pixel
; in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
; non-zero.
scal_unit db ? ;byte ;unit of physical scale
scal_s_width dd ? ;charp ;string containing height
scal_s_height dd ? ;charp ;string containing width
end if
if PNG_INFO_IMAGE_SUPPORTED eq 1
; Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
; non-zero
; Data valid if (valid & PNG_INFO_IDAT) non-zero
row_pointers dd ? ;bytepp ;the image bits
end if
ends

View File

@ -0,0 +1,209 @@
; libpng 1.6.25 STANDARD API DEFINITION
; pnglibconf.inc - library build configuration
; Libpng version 1.6.25 - September 1, 2016
; Copyright (c) 1998-2015 Glenn Randers-Pehrson
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; pnglibconf.inc
; Machine generated file: DO NOT EDIT
; Derived from: scripts/pnglibconf.dfa
; options
PNG_16BIT_SUPPORTED equ 1
PNG_ALIGNED_MEMORY_SUPPORTED equ 1
;/*#undef PNG_ARM_NEON_API_SUPPORTED*/
;/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/
PNG_BENIGN_ERRORS_SUPPORTED equ 1
PNG_BENIGN_READ_ERRORS_SUPPORTED equ 1
;/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/
PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED equ 1
PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED equ 1
PNG_COLORSPACE_SUPPORTED equ 1
PNG_CONSOLE_IO_SUPPORTED equ 1
PNG_CONVERT_tIME_SUPPORTED equ 1
PNG_EASY_ACCESS_SUPPORTED equ 1
;/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
PNG_ERROR_TEXT_SUPPORTED equ 1
PNG_FIXED_POINT_SUPPORTED equ 1
PNG_FLOATING_ARITHMETIC_SUPPORTED equ 1
PNG_FLOATING_POINT_SUPPORTED equ 1
PNG_FORMAT_AFIRST_SUPPORTED equ 1
PNG_FORMAT_BGR_SUPPORTED equ 1
PNG_GAMMA_SUPPORTED equ 1
PNG_GET_PALETTE_MAX_SUPPORTED equ 1
PNG_HANDLE_AS_UNKNOWN_SUPPORTED equ 1
PNG_INCH_CONVERSIONS_SUPPORTED equ 1
PNG_INFO_IMAGE_SUPPORTED equ 1
PNG_IO_STATE_SUPPORTED equ 1
PNG_MNG_FEATURES_SUPPORTED equ 0
PNG_POINTER_INDEXING_SUPPORTED equ 1
PNG_PROGRESSIVE_READ_SUPPORTED equ 0
PNG_READ_16BIT_SUPPORTED equ 0
PNG_READ_ALPHA_MODE_SUPPORTED equ 0
PNG_READ_ANCILLARY_CHUNKS_SUPPORTED equ 0
PNG_READ_BACKGROUND_SUPPORTED equ 0
PNG_READ_BGR_SUPPORTED equ 0
PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED equ 0
PNG_READ_COMPOSITE_NODIV_SUPPORTED equ 0
PNG_READ_COMPRESSED_TEXT_SUPPORTED equ 0
PNG_READ_EXPAND_16_SUPPORTED equ 0
PNG_READ_EXPAND_SUPPORTED equ 0
PNG_READ_FILLER_SUPPORTED equ 0
PNG_READ_GAMMA_SUPPORTED equ 0
PNG_READ_GET_PALETTE_MAX_SUPPORTED equ 0
PNG_READ_GRAY_TO_RGB_SUPPORTED equ 0
PNG_READ_INTERLACING_SUPPORTED equ 0
PNG_READ_INT_FUNCTIONS_SUPPORTED equ 0
PNG_READ_INVERT_ALPHA_SUPPORTED equ 0
PNG_READ_INVERT_SUPPORTED equ 0
PNG_READ_OPT_PLTE_SUPPORTED equ 0
PNG_READ_PACKSWAP_SUPPORTED equ 0
PNG_READ_PACK_SUPPORTED equ 0
PNG_READ_QUANTIZE_SUPPORTED equ 0
PNG_READ_RGB_TO_GRAY_SUPPORTED equ 0
PNG_READ_SCALE_16_TO_8_SUPPORTED equ 0
PNG_READ_SHIFT_SUPPORTED equ 0
PNG_READ_STRIP_16_TO_8_SUPPORTED equ 0
PNG_READ_STRIP_ALPHA_SUPPORTED equ 0
PNG_READ_SUPPORTED equ 0
PNG_READ_SWAP_ALPHA_SUPPORTED equ 0
PNG_READ_SWAP_SUPPORTED equ 0
PNG_READ_TEXT_SUPPORTED equ 0
PNG_READ_TRANSFORMS_SUPPORTED equ 0
PNG_READ_UNKNOWN_CHUNKS_SUPPORTED equ 0
PNG_READ_USER_CHUNKS_SUPPORTED equ 0
PNG_READ_USER_TRANSFORM_SUPPORTED equ 0
PNG_READ_bKGD_SUPPORTED equ 0
PNG_READ_cHRM_SUPPORTED equ 0
PNG_READ_gAMA_SUPPORTED equ 0
PNG_READ_hIST_SUPPORTED equ 0
PNG_READ_iCCP_SUPPORTED equ 0
PNG_READ_iTXt_SUPPORTED equ 0
PNG_READ_oFFs_SUPPORTED equ 0
PNG_READ_pCAL_SUPPORTED equ 0
PNG_READ_pHYs_SUPPORTED equ 0
PNG_READ_sBIT_SUPPORTED equ 0
PNG_READ_sCAL_SUPPORTED equ 0
PNG_READ_sPLT_SUPPORTED equ 0
PNG_READ_sRGB_SUPPORTED equ 0
PNG_READ_tEXt_SUPPORTED equ 0
PNG_READ_tIME_SUPPORTED equ 0
PNG_READ_tRNS_SUPPORTED equ 0
PNG_READ_zTXt_SUPPORTED equ 0
PNG_SAVE_INT_32_SUPPORTED equ 1
PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED equ 1
PNG_SEQUENTIAL_READ_SUPPORTED equ 1
PNG_SETJMP_SUPPORTED equ 0 ;1 ;setjmp.h заголовочный файл стандартной библиотеки языка Си
PNG_SET_OPTION_SUPPORTED equ 1
PNG_SET_UNKNOWN_CHUNKS_SUPPORTED equ 1
PNG_SET_USER_LIMITS_SUPPORTED equ 1
PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED equ 1
PNG_SIMPLIFIED_READ_BGR_SUPPORTED equ 1
PNG_SIMPLIFIED_READ_SUPPORTED equ 1
PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED equ 1
PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED equ 1
PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED equ 0 ;1
PNG_SIMPLIFIED_WRITE_SUPPORTED equ 1
PNG_STDIO_SUPPORTED equ 1
PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED equ 1
PNG_TEXT_SUPPORTED equ 1
PNG_TIME_RFC1123_SUPPORTED equ 1
PNG_UNKNOWN_CHUNKS_SUPPORTED equ 1
PNG_USER_CHUNKS_SUPPORTED equ 1
PNG_USER_LIMITS_SUPPORTED equ 1
PNG_USER_MEM_SUPPORTED equ 1
PNG_USER_TRANSFORM_INFO_SUPPORTED equ 1
PNG_USER_TRANSFORM_PTR_SUPPORTED equ 1
PNG_WARNINGS_SUPPORTED equ 1
PNG_WRITE_16BIT_SUPPORTED equ 1
PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED equ 1
PNG_WRITE_BGR_SUPPORTED equ 1
PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED equ 1
PNG_WRITE_COMPRESSED_TEXT_SUPPORTED equ 1
PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED equ 1
PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED equ 1
PNG_WRITE_FILLER_SUPPORTED equ 1
PNG_WRITE_FILTER_SUPPORTED equ 1
PNG_WRITE_FLUSH_SUPPORTED equ 1
PNG_WRITE_GET_PALETTE_MAX_SUPPORTED equ 1
PNG_WRITE_INTERLACING_SUPPORTED equ 1
PNG_WRITE_INT_FUNCTIONS_SUPPORTED equ 1
PNG_WRITE_INVERT_ALPHA_SUPPORTED equ 1
PNG_WRITE_INVERT_SUPPORTED equ 1
PNG_WRITE_OPTIMIZE_CMF_SUPPORTED equ 1
PNG_WRITE_PACKSWAP_SUPPORTED equ 1
PNG_WRITE_PACK_SUPPORTED equ 1
PNG_WRITE_SHIFT_SUPPORTED equ 1
PNG_WRITE_SUPPORTED equ 1
PNG_WRITE_SWAP_ALPHA_SUPPORTED equ 1
PNG_WRITE_SWAP_SUPPORTED equ 1
PNG_WRITE_TEXT_SUPPORTED equ 1
PNG_WRITE_TRANSFORMS_SUPPORTED equ 1
PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED equ 1
PNG_WRITE_USER_TRANSFORM_SUPPORTED equ 1
PNG_WRITE_WEIGHTED_FILTER_SUPPORTED equ 1
PNG_WRITE_bKGD_SUPPORTED equ 1
PNG_WRITE_cHRM_SUPPORTED equ 1
PNG_WRITE_gAMA_SUPPORTED equ 1
PNG_WRITE_hIST_SUPPORTED equ 1
PNG_WRITE_iCCP_SUPPORTED equ 1
PNG_WRITE_iTXt_SUPPORTED equ 1
PNG_WRITE_oFFs_SUPPORTED equ 1
PNG_WRITE_pCAL_SUPPORTED equ 1
PNG_WRITE_pHYs_SUPPORTED equ 1
PNG_WRITE_sBIT_SUPPORTED equ 1
PNG_WRITE_sCAL_SUPPORTED equ 1
PNG_WRITE_sPLT_SUPPORTED equ 1
PNG_WRITE_sRGB_SUPPORTED equ 1
PNG_WRITE_tEXt_SUPPORTED equ 1
PNG_WRITE_tIME_SUPPORTED equ 1
PNG_WRITE_tRNS_SUPPORTED equ 1
PNG_WRITE_zTXt_SUPPORTED equ 1
PNG_bKGD_SUPPORTED equ 1
PNG_cHRM_SUPPORTED equ 1
PNG_gAMA_SUPPORTED equ 1
PNG_hIST_SUPPORTED equ 1
PNG_iCCP_SUPPORTED equ 1
PNG_iTXt_SUPPORTED equ 1
PNG_oFFs_SUPPORTED equ 1
PNG_pCAL_SUPPORTED equ 1
PNG_pHYs_SUPPORTED equ 1
PNG_sBIT_SUPPORTED equ 1
PNG_sCAL_SUPPORTED equ 1
PNG_sPLT_SUPPORTED equ 1
PNG_sRGB_SUPPORTED equ 1
PNG_tEXt_SUPPORTED equ 1
PNG_tIME_SUPPORTED equ 1
PNG_tRNS_SUPPORTED equ 1
PNG_zTXt_SUPPORTED equ 1
; end of options
; settings
PNG_API_RULE equ 0
PNG_DEFAULT_READ_MACROS equ 1
PNG_GAMMA_THRESHOLD_FIXED equ 5000
PNG_ZBUF_SIZE equ 8192
PNG_IDAT_READ_SIZE equ PNG_ZBUF_SIZE
PNG_INFLATE_BUF_SIZE equ 1024
PNG_MAX_GAMMA_8 equ 11
PNG_QUANTIZE_BLUE_BITS equ 5
PNG_QUANTIZE_GREEN_BITS equ 5
PNG_QUANTIZE_RED_BITS equ 5
PNG_TEXT_Z_DEFAULT_COMPRESSION equ (-1)
PNG_TEXT_Z_DEFAULT_STRATEGY equ 0
PNG_USER_CHUNK_CACHE_MAX equ 1000
PNG_USER_CHUNK_MALLOC_MAX equ 8000000
PNG_USER_HEIGHT_MAX equ 1000000
PNG_USER_WIDTH_MAX equ 1000000
PNG_ZLIB_VERNUM equ 0 ;unknown
PNG_Z_DEFAULT_COMPRESSION equ (-1)
PNG_Z_DEFAULT_NOFILTER_STRATEGY equ 0
PNG_Z_DEFAULT_STRATEGY equ 1
PNG_sCAL_PRECISION equ 5
PNG_sRGB_PROFILE_CHECKS equ 2
; end of settings

View File

@ -0,0 +1,303 @@
; pngmem.asm - stub functions for memory allocation
; Last changed in libpng 1.6.24 [August 4, 2016%]
; Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; This file provides a location for all memory allocation. Users who
; need special memory handling are expected to supply replacement
; functions for png_malloc() and png_free(), and to use
; png_create_read_struct_2() and png_create_write_struct_2() to
; identify the replacement functions.
; Free a png_struct
;void (png_structrp png_ptr)
align 4
proc png_destroy_png_struct uses eax ecx edi esi, png_ptr:dword
locals
dummy_struct png_struct
endl
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..!=0)
; png_free might call png_error and may certainly call
; png_get_mem_ptr, so fake a temporary png_struct to support this.
mov ecx,sizeof.png_struct
mov esi,edi
mov edi,ebp
sub edi,ecx
rep movsb ;dummy_struct = *png_ptr
mov edi,[png_ptr]
xor eax,eax
mov ecx,sizeof.png_struct
rep stosb ;memset(png_ptr, 0, (sizeof *png_ptr))
mov esi,ebp
sub esi,sizeof.png_struct
stdcall png_free, esi, [png_ptr]
if PNG_SETJMP_SUPPORTED eq 1
; We may have a jmp_buf left to deallocate.
stdcall png_free_jmpbuf, esi
end if
@@:
ret
endp
; Allocate memory. For reasonable files, size should never exceed
; 64K. However, zlib may allocate more than 64K if you don't tell
; it not to. See zconf.h and png.h for more information. zlib does
; need to allocate exactly 64K, so whatever you call here must
; have the ability to do that.
;voidp (const_structrp png_ptr, png_alloc_size_t size)
align 4
proc png_calloc uses ebx ecx edi, png_ptr:dword, size:dword
stdcall png_malloc, [png_ptr], [size]
cmp eax,0
je @f ;if (..!=0)
mov ebx,eax
mov edi,eax
mov ecx,[size]
xor eax,eax
rep stosb ;memset(ret, 0, size)
mov eax,ebx
@@:
ret
endp
; png_malloc_base, an internal function added at libpng 1.6.0, does the work of
; allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED.
; Checking and error handling must happen outside this routine; it returns NULL
; if the allocation cannot be done (for any reason.)
;voidp (const_structrp png_ptr, png_alloc_size_t size)
align 4
proc png_malloc_base uses ebx ecx, png_ptr:dword, size:dword
; Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
; allocators have also been removed in 1.6.0, so any 16-bit system now has
; to implement a user memory handler. This checks to be sure it isn't
; called with big numbers.
; Some compilers complain that this is always true. However, it
; can be false when integer overflow happens.
cmp dword[size],0
jle .end0
cmp dword[size],PNG_SIZE_MAX
jg .end0 ; if (..>.. && ..<=..)
if PNG_MAX_MALLOC_64K eq 1
cmp dword[size],65536
jg .end0
end if
if PNG_USER_MEM_SUPPORTED eq 1
mov ebx,[png_ptr]
cmp ebx,0
je @f
cmp dword[ebx+png_struct.malloc_fn],0
je @f ;if (..!=0 && ..!=0)
stdcall [ebx+png_struct.malloc_fn], ebx, [size]
jmp .end_f
@@: ;else
end if
;stdcall [mem.alloc], [size]
mcall SF_SYS_MISC, SSF_MEM_ALLOC, [size]
jmp .end_f ;checked for truncation above
.end0: ;else
xor eax,eax
.end_f:
ret
endp
; This is really here only to work round a spurious warning in GCC 4.6 and 4.7
; that arises because of the checks in png_realloc_array that are repeated in
; png_malloc_array.
;voidp (const_structrp png_ptr, int nelements, size_t element_size)
align 4
proc png_malloc_array_checked, png_ptr:dword, nelements:dword, element_size:dword
; png_alloc_size_t req = nelements; /* known to be > 0 */
; if (req <= PNG_SIZE_MAX/element_size)
; return png_malloc_base(png_ptr, req * element_size);
; The failure case when the request is too large
xor eax,eax
.end_f:
ret
endp
;voidp (const_structrp png_ptr, int nelements, size_t element_size)
align 4
proc png_malloc_array, png_ptr:dword, nelements:dword, element_size:dword
; if (nelements <= 0 || element_size == 0)
; png_error(png_ptr, "internal error: array alloc");
stdcall png_malloc_array_checked, [png_ptr], [nelements], [element_size]
ret
endp
;voidp (const_structrp png_ptr, const_voidp old_array,
; int old_elements, int add_elements, size_t element_size)
align 4
proc png_realloc_array, png_ptr:dword, old_array:dword, old_elements:dword, add_elements:dword, element_size:dword
; These are internal errors:
; if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
; (old_array == NULL && old_elements > 0))
; png_error(png_ptr, "internal error: array realloc");
; Check for overflow on the elements count (so the caller does not have to
; check.)
; if (add_elements <= INT_MAX - old_elements)
; {
; voidp new_array = png_malloc_array_checked(png_ptr,
; old_elements+add_elements, element_size);
;
; if (new_array != NULL)
; {
; Because png_malloc_array worked the size calculations below cannot
; overflow.
; if (old_elements > 0)
; memcpy(new_array, old_array, element_size*(unsigned)old_elements);
;
; memset((char*)new_array + element_size*(unsigned)old_elements, 0,
; element_size*(unsigned)add_elements);
;
; return new_array;
; }
; }
xor eax,eax ;error
.end_f:
ret
endp
; Various functions that have different error handling are derived from this.
; png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate
; function png_malloc_default is also provided.
;voidp (const_structrp png_ptr, png_alloc_size_t size)
align 4
proc png_malloc uses edi, png_ptr:dword, size:dword
xor eax,eax
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return 0
stdcall png_malloc_base, edi, [size]
cmp eax,0
jne @f ;if (..==0)
png_error edi, 'Out of memory' ;'m' means png_malloc
@@:
ret
endp
;voidp (const_structrp png_ptr, png_alloc_size_t size)
align 4
proc png_malloc_default uses edi, png_ptr:dword, size:dword
xor eax,eax
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return 0
; Passing 'NULL' here bypasses the application provided memory handler.
stdcall png_malloc_base, 0, [size] ;0 - use malloc
cmp eax,0
jne @f ;if (..==0)
png_error edi, 'Out of Memory' ;'M' means png_malloc_default
@@:
ret
endp
; This function was added at libpng version 1.2.3. The png_malloc_warn()
; function will issue a png_warning and return NULL instead of issuing a
; png_error, if it fails to allocate the requested memory.
;voidp (const_structrp png_ptr, png_alloc_size_t size)
align 4
proc png_malloc_warn uses edi, png_ptr:dword, size:dword
mov edi,[png_ptr]
cmp edi,0
je .end0 ;if (..!=0)
stdcall png_malloc_base, edi, [size]
cmp eax,0
jne .end_f ;if (..!=0) return ret
png_warning edi, 'Out of memory'
.end0:
xor eax,eax
.end_f:
ret
endp
; Free a pointer allocated by png_malloc(). If ptr is NULL, return
; without taking any action.
;void (const_structrp png_ptr, voidp ptr)
align 4
proc png_free uses eax ebx ecx, png_ptr:dword, p2ptr:dword
mov ebx,[png_ptr]
cmp ebx,0
je .end_f
mov ecx,[p2ptr]
cmp ecx,0
je .end_f ;if (..==0 || ..==0) return
if PNG_USER_MEM_SUPPORTED eq 1
cmp dword[ebx+png_struct.free_fn],0
je @f ;if (..!=0)
stdcall dword[ebx+png_struct.free_fn], ebx, [p2ptr]
jmp .end_f
@@: ;else
end if
mcall SF_SYS_MISC, SSF_MEM_FREE, [p2ptr]
.end_f:
ret
endp
; This function is called when the application wants to use another method
; of allocating and freeing memory.
;void (png_structrp png_ptr, voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)
align 4
proc png_set_mem_fn uses eax edi, png_ptr:dword, mem_ptr:dword, malloc_fn:dword, free_fn:dword
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..!=0)
mov eax,[mem_ptr]
mov [edi+png_struct.mem_ptr],eax
mov eax,[malloc_fn]
mov [edi+png_struct.malloc_fn],eax
mov eax,[free_fn]
mov [edi+png_struct.free_fn],eax
@@:
ret
endp
; This function returns a pointer to the mem_ptr associated with the user
; functions. The application should free any memory associated with this
; pointer before png_write_destroy and png_read_destroy are called.
;voidp (const_structrp png_ptr)
align 4
proc png_get_mem_ptr uses edi, png_ptr:dword
xor eax,eax
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return 0
mov eax,[edi+png_struct.mem_ptr]
@@:
ret
endp

View File

@ -0,0 +1,306 @@
;
; Options
;
PNG_RELEASE_BUILD equ 1
;---
; Various modes of operation. Note that after an init, mode is set to
; zero automatically when the structure is created. Three of these
; are defined in png.inc because they need to be visible to applications
; that call png_set_unknown_chunk().
;PNG_HAVE_IHDR 0x01 (defined in png.inc)
;PNG_HAVE_PLTE 0x02 (defined in png.inc)
PNG_HAVE_IDAT equ 0x04
;PNG_AFTER_IDAT 0x08 (defined in png.inc)
PNG_HAVE_IEND equ 0x10
;0x20 (unused)
;0x40 (unused)
;0x80 (unused)
PNG_HAVE_CHUNK_HEADER equ 0x100
PNG_WROTE_tIME equ 0x200
PNG_WROTE_INFO_BEFORE_PLTE equ 0x400
PNG_BACKGROUND_IS_GRAY equ 0x800
PNG_HAVE_PNG_SIGNATURE equ 0x1000
PNG_HAVE_CHUNK_AFTER_IDAT equ 0x2000 ;Have another chunk after IDAT
;0x4000 (unused)
PNG_IS_READ_STRUCT equ 0x8000 ;Else is a write struct
; Flags for the transformations the PNG library does on the image data
PNG_BGR equ 0x0001
PNG_INTERLACE equ 0x0002
PNG_PACK equ 0x0004
PNG_SHIFT equ 0x0008
PNG_SWAP_BYTES equ 0x0010
PNG_INVERT_MONO equ 0x0020
PNG_QUANTIZE equ 0x0040
PNG_COMPOSE equ 0x0080 ;Was PNG_BACKGROUND
PNG_BACKGROUND_EXPAND equ 0x0100
PNG_EXPAND_16 equ 0x0200 ;Added to libpng 1.5.2
PNG_16_TO_8 equ 0x0400 ;Becomes 'chop' in 1.5.4
PNG_RGBA equ 0x0800
PNG_EXPAND equ 0x1000
PNG_GAMMA equ 0x2000
PNG_GRAY_TO_RGB equ 0x4000
PNG_FILLER equ 0x8000
PNG_PACKSWAP equ 0x10000
PNG_SWAP_ALPHA equ 0x20000
PNG_STRIP_ALPHA equ 0x40000
PNG_INVERT_ALPHA equ 0x80000
PNG_USER_TRANSFORM equ 0x100000
PNG_RGB_TO_GRAY_ERR equ 0x200000
PNG_RGB_TO_GRAY_WARN equ 0x400000
PNG_RGB_TO_GRAY equ 0x600000 ;two bits, RGB_TO_GRAY_ERR|WARN
PNG_ENCODE_ALPHA equ 0x800000 ;Added to libpng-1.5.4
PNG_ADD_ALPHA equ 0x1000000 ;Added to libpng-1.2.7
PNG_EXPAND_tRNS equ 0x2000000 ;Added to libpng-1.2.9
PNG_SCALE_16_TO_8 equ 0x4000000 ;Added to libpng-1.5.4
;0x8000000 unused
;0x10000000 unused
;0x20000000 unused
;0x40000000 unused
; Flags for png_create_struct
PNG_STRUCT_PNG equ 0x0001
PNG_STRUCT_INFO equ 0x0002
; Flags for the png_ptr->flags rather than declaring a byte for each one
PNG_FLAG_ZLIB_CUSTOM_STRATEGY equ 0x0001
PNG_FLAG_ZSTREAM_INITIALIZED equ 0x0002 ;Added to libpng-1.6.0
;0x0004 unused
PNG_FLAG_ZSTREAM_ENDED equ 0x0008 ;Added to libpng-1.6.0
;0x0010 unused
;0x0020 unused
PNG_FLAG_ROW_INIT equ 0x0040
PNG_FLAG_FILLER_AFTER equ 0x0080
PNG_FLAG_CRC_ANCILLARY_USE equ 0x0100
PNG_FLAG_CRC_ANCILLARY_NOWARN equ 0x0200
PNG_FLAG_CRC_CRITICAL_USE equ 0x0400
PNG_FLAG_CRC_CRITICAL_IGNORE equ 0x0800
PNG_FLAG_ASSUME_sRGB equ 0x1000 ;Added to libpng-1.5.4
PNG_FLAG_OPTIMIZE_ALPHA equ 0x2000 ;Added to libpng-1.5.4
PNG_FLAG_DETECT_UNINITIALIZED equ 0x4000 ;Added to libpng-1.5.4
;PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000
;PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000
PNG_FLAG_LIBRARY_MISMATCH equ 0x20000
PNG_FLAG_STRIP_ERROR_NUMBERS equ 0x40000
PNG_FLAG_STRIP_ERROR_TEXT equ 0x80000
PNG_FLAG_BENIGN_ERRORS_WARN equ 0x100000 ;Added to libpng-1.4.0
PNG_FLAG_APP_WARNINGS_WARN equ 0x200000 ;Added to libpng-1.6.0
PNG_FLAG_APP_ERRORS_WARN equ 0x400000 ;Added to libpng-1.6.0
; Gamma values (new at libpng-1.5.4):
PNG_GAMMA_MAC_OLD equ 151724 ;Assume '1.8' is really 2.2/1.45!
PNG_GAMMA_MAC_INVERSE equ 65909
PNG_GAMMA_sRGB_INVERSE equ 45455
macro PNG_ROWBYTES pixel_bits, width
{
local .end0
if pixel_bits eq eax
else
mov eax,pixel_bits
end if
cmp eax,8
jge .end0
add eax,7
.end0:
shr eax,3
imul eax,width
}
; In 1.7.0 the definitions will be made public in png.inc to avoid having to
; duplicate the same definitions in application code.
png_IDAT equ 'IDAT'
png_IEND equ 'IEND'
png_IHDR equ 'IHDR'
png_PLTE equ 'PLTE'
png_bKGD equ 'bKGD'
png_cHRM equ 'cHRM'
png_fRAc equ 'fRAc' ;registered, not defined
png_gAMA equ 'gAMA'
png_gIFg equ 'gIFg'
png_gIFt equ 'gIFt' ;deprecated
png_gIFx equ 'gIFx'
png_hIST equ 'hIST'
png_iCCP equ 'iCCP'
png_iTXt equ 'iTXt'
png_oFFs equ 'oFFs'
png_pCAL equ 'pCAL'
png_pHYs equ 'pHYs'
png_sBIT equ 'sBIT'
png_sCAL equ 'sCAL'
png_sPLT equ 'sPLT'
png_sRGB equ 'sRGB'
png_sTER equ 'sTER'
png_tEXt equ 'tEXt'
png_tIME equ 'tIME'
png_tRNS equ 'tRNS'
png_zTXt equ 'zTXt'
;Test on flag values as defined in the spec (section 5.4):
macro PNG_CHUNK_ANCILLARY c
{
mov eax,c
shr eax,29
and eax,1
}
macro PNG_CHUNK_CRITICAL c
{
PNG_CHUNK_ANCILLARY c
xor eax,1
}
macro PNG_CHUNK_PRIVATE c
{
mov eax,c
shr eax,21
and eax,1
}
macro PNG_CHUNK_RESERVED c
{
mov eax,c
shr eax,13
and eax,1
}
macro PNG_CHUNK_SAFE_TO_COPY c
{
mov eax,c
shr eax,5
and eax,1
}
PNG_FLAG_CRC_ANCILLARY_MASK equ (PNG_FLAG_CRC_ANCILLARY_USE or PNG_FLAG_CRC_ANCILLARY_NOWARN)
PNG_FLAG_CRC_CRITICAL_MASK equ (PNG_FLAG_CRC_CRITICAL_USE or PNG_FLAG_CRC_CRITICAL_IGNORE)
PNG_FLAG_CRC_MASK equ (PNG_FLAG_CRC_ANCILLARY_MASK or PNG_FLAG_CRC_CRITICAL_MASK)
macro PNG_sRGB_FROM_LINEAR linear
{
mov eax,linear
shr eax,15
shl eax,1
add eax,png_sRGB_base
movzx eax,word[eax]
push ebx ecx
mov ebx,linear
shr ebx,15
add ebx,png_sRGB_delta
mov ecx,linear
and ecx,0x7fff
imul ecx,ebx
shr ecx,12
add eax,ecx
pop ecx ebx
shr eax,8
;;;and eax,0xff
}
; Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB
; encoded value with maximum error 0.646365. Note that the input is not a
; 16-bit value; it has been multiplied by 255!
PNG_UNEXPECTED_ZLIB_RETURN equ (-7)
;...
; Suggested size for a number buffer (enough for 64 bits and a sign!)
PNG_NUMBER_BUFFER_SIZE equ 24
; These are the integer formats currently supported, the name is formed from
; the standard printf(3) format string.
PNG_NUMBER_FORMAT_u equ 1 ;chose unsigned API!
PNG_NUMBER_FORMAT_02u equ 2
PNG_NUMBER_FORMAT_d equ 1 ;chose signed API!
PNG_NUMBER_FORMAT_02d equ 2
PNG_NUMBER_FORMAT_x equ 3
PNG_NUMBER_FORMAT_02x equ 4
PNG_NUMBER_FORMAT_fixed equ 5 ;choose the signed API
; New defines and members adding in libpng-1.5.4
PNG_WARNING_PARAMETER_SIZE equ 32
PNG_WARNING_PARAMETER_COUNT equ 8 ;Maximum 9; see pngerror.asm
PNG_CHUNK_WARNING equ 0 ;never an error
PNG_CHUNK_WRITE_ERROR equ 1 ;an error only on write
PNG_CHUNK_ERROR equ 2 ;always an error
; ASCII to FP interfaces, currently only implemented if sCAL
; support is required.
; MAX_DIGITS is actually the maximum number of characters in an sCAL
; width or height, derived from the precision (number of significant
; digits - a build time settable option) and assumptions about the
; maximum ridiculous exponent.
PNG_sCAL_MAX_DIGITS equ PNG_sCAL_PRECISION+1+1+10 ;. E exponent
; An internal API to validate the format of a floating point number.
; The result is the index of the next character. If the number is
; not valid it will be the index of a character in the supposed number.
; The format of a number is defined in the PNG extensions specification
; and this API is strictly conformant to that spec, not anyone elses!
; The format as a regular expression is:
; [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
; or:
; [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
; The complexity is that either integer or fraction must be present and the
; fraction is permitted to have no digits only if the integer is present.
; NOTE: The dangling E problem.
; There is a PNG valid floating point number in the following:
; PNG floating point numbers are not greedy.
; Working this out requires *TWO* character lookahead (because of the
; sign), the parser does not do this - it will fail at the 'r' - this
; doesn't matter for PNG sCAL chunk values, but it requires more care
; if the value were ever to be embedded in something more complex. Use
; ANSI-C strtod if you need the lookahead.
; State table for the parser.
PNG_FP_INTEGER equ 0 ;before or in integer
PNG_FP_FRACTION equ 1 ;before or in fraction
PNG_FP_EXPONENT equ 2 ;before or in exponent
PNG_FP_STATE equ 3 ;mask for the above
PNG_FP_SAW_SIGN equ 4 ;Saw +/- in current state
PNG_FP_SAW_DIGIT equ 8 ;Saw a digit in current state
PNG_FP_SAW_DOT equ 16 ;Saw a dot in current state
PNG_FP_SAW_E equ 32 ;Saw an E (or e) in current state
PNG_FP_SAW_ANY equ 60 ;Saw any of the above 4
; These three values don't affect the parser. They are set but not used.
PNG_FP_WAS_VALID equ 64 ;Preceding substring is a valid fp number
PNG_FP_NEGATIVE equ 128 ;A negative number, including "-0"
PNG_FP_NONZERO equ 256 ;A non-zero value
PNG_FP_STICKY equ 448 ;The above three flags
; This is available for the caller to store in 'state' if required. Do not
; call the parser after setting it (the parser sometimes clears it.)
PNG_FP_INVALID equ 512 ;Available for callers as a distinct value
; Result codes for the parser (boolean - true meants ok, false means
; not ok yet.)
PNG_FP_MAYBE equ 0 ;The number may be valid in the future
PNG_FP_OK equ 1 ;The number is valid
; The internal structure that png_image::opaque points to.
struct png_control
png_ptr dd ? ;png_structp
info_ptr dd ? ;png_infop
error_buf dd ? ;voidp ;Always a jmp_buf at present.
memory dd ? ;bytep ;Memory buffer.
size dd ? ;png_size_t ;Size of the memory buffer.
for_write dd ? ;uint ;:1;Otherwise it is a read structure
owned_file dd ? ;uint ;:1;We own the file in io_ptr
ends

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,443 @@
; pngstruct.inc - header file for PNG reference library
; Last changed in libpng 1.6.24 [August 4, 2016]
; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; The structure that holds the information to read and write PNG files.
; The only people who need to care about what is inside of this are the
; people who will be modifying the library for their own special needs.
; It should NOT be accessed directly by an application.
; zlib.inc defines the structure z_stream, an instance of which is included
; in this structure and is required for decompressing the LZ compressed
; data in PNG files.
include '../../../../../../fs/kfar/trunk/zlib/zlib.inc'
; zlib.inc declares a magic type 'uInt' that limits the amount of data that zlib
; can handle at once. This type need be no larger than 16 bits (so maximum of
; 65535), this define allows us to discover how big it is, but limited by the
; maximuum for png_size_t. The value can be overriden in a library build
; (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
; lower value (e.g. 255 works). A lower value may help memory usage (slightly)
; and may even improve performance on some systems (and degrade it on others.)
ZLIB_IO_MAX equ 0xffff ;-1 ;uInt
; The type of a compression buffer list used by the write code.
struct png_compression_buffer
next dd ? ;struct png_compression_buffer *
output db ? ;byte[1] ;actually zbuf_size
ends
macro PNG_COMPRESSION_BUFFER_SIZE pp
{
mov eax,png_compression_buffer.output
add eax,[pp+png_struct.zbuffer_size]
}
; Colorspace support; structures used in png_struct, png_info and in internal
; functions to hold and communicate information about the color space.
; PNG_COLORSPACE_SUPPORTED is only required if the application will perform
; colorspace corrections, otherwise all the colorspace information can be
; skipped and the size of libpng can be reduced (significantly) by compiling
; out the colorspace support.
if PNG_COLORSPACE_SUPPORTED eq 1
; The chromaticities of the red, green and blue colorants and the chromaticity
; of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).
struct png_xy
redx dd ? ;png_fixed_point
redy dd ?
greenx dd ?
greeny dd ?
bluex dd ?
bluey dd ?
whitex dd ?
whitey dd ?
ends
; The same data as above but encoded as CIE XYZ values. When this data comes
; from chromaticities the sum of the Y values is assumed to be 1.0
struct png_XYZ
red_X dd ? ;png_fixed_point
red_Y dd ?
red_Z dd ?
green_X dd ?
green_Y dd ?
green_Z dd ?
blue_X dd ?
blue_Y dd ?
blue_Z dd ?
ends
end if ;COLORSPACE
if (PNG_COLORSPACE_SUPPORTED eq 1) | (PNG_GAMMA_SUPPORTED eq 1)
; A colorspace is all the above plus, potentially, profile information;
; however at present libpng does not use the profile internally so it is only
; stored in the png_info struct (if iCCP is supported.) The rendering intent
; is retained here and is checked.
; The file gamma encoding information is also stored here and gamma correction
; is done by libpng, whereas color correction must currently be done by the
; application.
struct png_colorspace
if PNG_GAMMA_SUPPORTED eq 1
gamma dd ? ;png_fixed_point ;File gamma
end if
if PNG_COLORSPACE_SUPPORTED eq 1
end_points_xy png_xy ;End points as chromaticities
end_points_XYZ png_XYZ ;End points as CIE XYZ colorant values
rendering_intent dw ? ;uint_16 ;Rendering intent of a profile
end if
; Flags are always defined to simplify the code.
flags dw ? ;uint_16 ;As defined below
ends
; General flags for the 'flags' field
PNG_COLORSPACE_HAVE_GAMMA equ 0x0001
PNG_COLORSPACE_HAVE_ENDPOINTS equ 0x0002
PNG_COLORSPACE_HAVE_INTENT equ 0x0004
PNG_COLORSPACE_FROM_gAMA equ 0x0008
PNG_COLORSPACE_FROM_cHRM equ 0x0010
PNG_COLORSPACE_FROM_sRGB equ 0x0020
PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB equ 0x0040
PNG_COLORSPACE_MATCHES_sRGB equ 0x0080 ;exact match on profile
PNG_COLORSPACE_INVALID equ 0x8000
macro PNG_COLORSPACE_CANCEL flags {(0xffff xor (flags))}
end if ;COLORSPACE || GAMMA
struct png_struct
if PNG_SETJMP_SUPPORTED eq 1
jmp_buf_local dd ? ;jmp_buf ;New name in 1.6.0 for jmp_buf in png_struct
longjmp_fn dd ? ;png_longjmp_ptr ;setjmp non-local goto function.
jmp_buf_ptr dd ? ;jmp_buf * ;passed to longjmp_fn
jmp_buf_size dd ? ;size_t ;size of the above, if allocated
end if
error_fn dd ? ;png_error_ptr ;function for printing errors and aborting
if PNG_WARNINGS_SUPPORTED eq 1
warning_fn dd ? ;png_error_ptr ;function for printing warnings
end if
error_ptr dd ? ;voidp ;user supplied struct for error functions
write_data_fn dd ? ;png_rw_ptr ;function for writing output data
read_data_fn dd ? ;png_rw_ptr ;function for reading input data
io_ptr dd ? ;voidp ;ptr to application struct for I/O functions
if PNG_READ_USER_TRANSFORM_SUPPORTED eq 1
read_user_transform_fn dd ? ;png_user_transform_ptr ;user read transform
end if
if PNG_WRITE_USER_TRANSFORM_SUPPORTED eq 1
write_user_transform_fn dd ? ;png_user_transform_ptr ; user write transform
end if
; These were added in libpng-1.0.2
if PNG_USER_TRANSFORM_PTR_SUPPORTED eq 1
if (PNG_READ_USER_TRANSFORM_SUPPORTED eq 1) | (PNG_WRITE_USER_TRANSFORM_SUPPORTED eq 1)
user_transform_ptr dd ? ;voidp ;user supplied struct for user transform
user_transform_depth db ? ;byte ;bit depth of user transformed pixels
user_transform_channels db ? ;byte ;channels in user transformed pixels
end if
end if
mode dd ? ;uint_32 ;tells us where we are in the PNG file
flags dd ? ;uint_32 ;flags indicating various things to libpng
transformations dd ? ;uint_32 ;which transformations to perform
zowner dd ? ;uint_32 ;ID (chunk type) of zstream owner, 0 if none
zstream z_stream ;decompression structure
zbuffer_list dd ? ;png_compression_bufferp ;Created on demand during write
zbuffer_size dd ? ;uInt ;size of the actual buffer
zlib_level dd ? ;int ;holds zlib compression level
zlib_method dd ? ;int ;holds zlib compression method
zlib_window_bits dd ? ;int ;holds zlib compression window bits
zlib_mem_level dd ? ;int ;holds zlib compression memory level
zlib_strategy dd ? ;int ;holds zlib compression strategy
; Added at libpng 1.5.4
if PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED eq 1
zlib_text_level dd ? ;int ;holds zlib compression level
zlib_text_method dd ? ;int ;holds zlib compression method
zlib_text_window_bits dd ? ;int ;holds zlib compression window bits
zlib_text_mem_level dd ? ;int ;holds zlib compression memory level
zlib_text_strategy dd ? ;int ;holds zlib compression strategy
end if
;End of material added at libpng 1.5.4
;Added at libpng 1.6.0
zlib_set_level dd ? ;int ;Actual values set into the zstream on write
zlib_set_method dd ? ;int
zlib_set_window_bits dd ? ;int
zlib_set_mem_level dd ? ;int
zlib_set_strategy dd ? ;int
width dd ? ;uint_32 ;width of image in pixels
height dd ? ;uint_32 ;height of image in pixels
num_rows dd ? ;uint_32 ;number of rows in current pass
usr_width dd ? ;uint_32 ;width of row at start of write
rowbytes dd ? ;png_size_t ;size of row in bytes
iwidth dd ? ;uint_32 ;width of current interlaced row in pixels
row_number dd ? ;uint_32 ;current row in interlace pass
chunk_name dd ? ;uint_32 ;PNG_CHUNK() id of current chunk
prev_row dd ? ;bytep ;buffer to save previous (unfiltered) row.
;While reading this is a pointer into
;big_prev_row; while writing it is separately
;allocated if needed.
row_buf dd ? ;bytep ;buffer to save current (unfiltered) row.
;While reading, this is a pointer into
;big_row_buf; while writing it is separately
;allocated.
if PNG_WRITE_FILTER_SUPPORTED eq 1
try_row dd ? ;bytep ;buffer to save trial row when filtering
tst_row dd ? ;bytep ;buffer to save best trial row when filtering
end if
info_rowbytes dd ? ;png_size_t ;Added in 1.5.4: cache of updated row bytes
idat_size dd ? ;uint_32 ;current IDAT size for read
crc dd ? ;uint_32 ;current chunk CRC value
palette dd ? ;png_colorp ;palette from the input file
num_palette dw ? ;uint_16 ;number of color entries in palette
; Added at libpng-1.5.10
if PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED eq 1
num_palette_max dd ? ;int ;maximum palette index found in IDAT
end if
num_trans dw ? ;uint_16 ;number of transparency values
compression db ? ;byte ;file compression type (always 0)
filter db ? ;byte ;file filter type (always 0)
interlaced db ? ;byte ;PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7
pass db ? ;byte ;current interlace pass (0 - 6)
do_filter db ? ;byte ;row filter flags (see PNG_FILTER_ in png.inc)
color_type db ? ;byte ;color type of file
bit_depth db ? ;byte ;bit depth of file
usr_bit_depth db ? ;byte ;bit depth of users row: write only
pixel_depth db ? ;byte ;number of bits per pixel
channels db ? ;byte ;number of channels in file
usr_channels db ? ;byte ;channels at start of write: write only
sig_bytes db ? ;byte ;magic bytes read/written from start of file
maximum_pixel_depth db ? ;byte ;pixel depth used for the row buffers
transformed_pixel_depth db ? ;byte ;pixel depth after read/write transforms
;#if PNG_ZLIB_VERNUM >= 0x1240
zstream_start db ? ;byte ;at start of an input zlib stream
;end if /* Zlib >= 1.2.4 */
if (PNG_READ_FILLER_SUPPORTED eq 1) | (PNG_WRITE_FILLER_SUPPORTED eq 1)
filler dw ? ;uint_16 ; filler bytes for pixel expansion
end if
if (PNG_bKGD_SUPPORTED eq 1) | (PNG_READ_BACKGROUND_SUPPORTED eq 1) | \
(PNG_READ_ALPHA_MODE_SUPPORTED eq 1)
background_gamma_type db ? ;byte
background_gamma dd ? ;png_fixed_point
background png_color_16 ;background color in screen gamma space
if PNG_READ_GAMMA_SUPPORTED eq 1
background_1 png_color_16 ;background normalized to gamma 1.0
end if
end if ;bKGD
if PNG_WRITE_FLUSH_SUPPORTED eq 1
output_flush_fn dd ? ;png_flush_ptr ;Function for flushing output
flush_dist dd ? ;uint_32 ;how many rows apart to flush, 0 - no flush
flush_rows dd ? ;uint_32 ;number of rows written since last flush
end if
if PNG_READ_GAMMA_SUPPORTED eq 1
gamma_shift dd ? ;int ;number of "insignificant" bits in 16-bit gamma
screen_gamma dd ? ;png_fixed_point ;screen gamma value (display_exponent)
gamma_table dd ? ;bytep ;gamma table for 8-bit depth files
gamma_16_table dd ? ;uint_16pp ;gamma table for 16-bit depth files
if (PNG_READ_BACKGROUND_SUPPORTED eq 1) | \
(PNG_READ_ALPHA_MODE_SUPPORTED eq 1) | \
(PNG_READ_RGB_TO_GRAY_SUPPORTED eq 1)
gamma_from_1 dd ? ;bytep ;converts from 1.0 to screen
gamma_to_1 dd ? ;bytep ;converts from file to 1.0
gamma_16_from_1 dd ? ;uint_16pp ;converts from 1.0 to screen
gamma_16_to_1 dd ? ;uint_16pp ;converts from file to 1.0
end if ;READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY
end if
if (PNG_READ_GAMMA_SUPPORTED eq 1) | (PNG_sBIT_SUPPORTED eq 1)
sig_bit png_color_8 ;significant bits in each available channel
end if
if (PNG_READ_SHIFT_SUPPORTED eq 1) | (PNG_WRITE_SHIFT_SUPPORTED eq 1)
shift png_color_8 ;shift for significant bit tranformation
end if
if (PNG_tRNS_SUPPORTED eq 1) | (PNG_READ_BACKGROUND_SUPPORTED eq 1) \
| (PNG_READ_EXPAND_SUPPORTED eq 1) | (PNG_READ_BACKGROUND_SUPPORTED eq 1)
trans_alpha dd ? ;bytep ;alpha values for paletted files
trans_color png_color_16 ;transparent color for non-paletted files
end if
read_row_fn dd ? ;png_read_status_ptr ;called after each row is decoded
write_row_fn dd ? ;png_write_status_ptr ;called after each row is encoded
if PNG_PROGRESSIVE_READ_SUPPORTED eq 1
info_fn dd ? ;png_progressive_info_ptr ;called after header data fully read
row_fn dd ? ;png_progressive_row_ptr ;called after a prog. row is decoded
end_fn dd ? ;png_progressive_end_ptr ;called after image is complete
save_buffer_ptr dd ? ;bytep ;current location in save_buffer
save_buffer dd ? ;bytep ;buffer for previously read data
current_buffer_ptr dd ? ;bytep ;current location in current_buffer
current_buffer dd ? ;bytep ;buffer for recently used data
push_length dd ? ;uint_32 ;size of current input chunk
skip_length dd ? ;uint_32 ;bytes to skip in input data
save_buffer_size dd ? ;png_size_t ;amount of data now in save_buffer
save_buffer_max dd ? ;png_size_t ;total size of save_buffer
buffer_size dd ? ;png_size_t ;total amount of available input data
current_buffer_size dd ? ;png_size_t ;amount of data now in current_buffer
process_mode dd ? ;int ;what push library is currently doing
cur_palette dd ? ;int ;current push library palette index
end if ;PROGRESSIVE_READ
if PNG_READ_QUANTIZE_SUPPORTED eq 1
palette_lookup dd ? ;bytep ;lookup table for quantizing
quantize_index dd ? ;bytep ;index translation for palette files
end if
; Options
if PNG_SET_OPTION_SUPPORTED eq 1
options db ? ;byte ;On/off state (up to 4 options)
end if
;#if PNG_LIBPNG_VER < 10700
; To do: remove this from libpng-1.7
if PNG_TIME_RFC1123_SUPPORTED eq 1
time_buffer rb 29 ;char[29] ;String to hold RFC 1123 time text
end if
;end if
; New members added in libpng-1.0.6
free_me dd ? ;uint_32 ;flags items libpng is responsible for freeing
if PNG_USER_CHUNKS_SUPPORTED eq 1
user_chunk_ptr dd ? ;voidp
if PNG_READ_USER_CHUNKS_SUPPORTED eq 1
read_user_chunk_fn dd ? ;png_user_chunk_ptr ;user read chunk handler
end if
end if
if PNG_SET_UNKNOWN_CHUNKS_SUPPORTED eq 1
unknown_default dd ? ;int ; As PNG_HANDLE_*
num_chunk_list dd ? ;unsigned int ; Number of entries in the list
chunk_list dd ? ;bytep ; List of byte[5]; the textual chunk name
; followed by a PNG_HANDLE_* byte
end if
; New members added in libpng-1.0.3
if PNG_READ_RGB_TO_GRAY_SUPPORTED eq 1
rgb_to_gray_status db ? ;byte
; Added in libpng 1.5.5 to record setting of coefficients:
rgb_to_gray_coefficients_set db ? ;byte
; These were changed from byte in libpng-1.0.6
rgb_to_gray_red_coeff dw ? ;uint_16
rgb_to_gray_green_coeff dw ? ;uint_16
; deleted in 1.5.5: rgb_to_gray_blue_coeff;
end if
if PNG_MNG_FEATURES_SUPPORTED eq 1
; New member added in libpng-1.0.4 (renamed in 1.0.9)
; Changed from byte to uint_32 at version 1.2.0
mng_features_permitted dd ? ;uint_32
; New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0
filter_type db ? ;byte
end if
; New members added in libpng-1.2.0
; New members added in libpng-1.0.2 but first enabled by default in 1.2.0
if PNG_USER_MEM_SUPPORTED eq 1
mem_ptr dd ? ;voidp ;user supplied struct for mem functions
malloc_fn dd ? ;malloc_ptr ;function for allocating memory
free_fn dd ? ;free_ptr ;function for freeing memory
end if
; New member added in libpng-1.0.13 and 1.2.0
big_row_buf dd ? ;bytep ;buffer to save current (unfiltered) row
if PNG_READ_QUANTIZE_SUPPORTED eq 1
; The following three members were added at version 1.0.14 and 1.2.4
quantize_sort dd ? ;bytep ;working sort array
index_to_palette dd ? ;bytep ;where the original index currently is in the palette
palette_to_index dd ? ;bytep ;which original index points to this palette color
end if
; New members added in libpng-1.0.16 and 1.2.6
compression_type db ? ;byte
if PNG_USER_LIMITS_SUPPORTED eq 1
user_width_max dd ? ;uint_32
user_height_max dd ? ;uint_32
; Added in libpng-1.4.0: Total number of sPLT, text, and unknown
; chunks that can be stored (0 means unlimited).
user_chunk_cache_max dd ? ;uint_32
; Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
; can occupy when decompressed. 0 means unlimited.
user_chunk_malloc_max dd ? ;png_alloc_size_t
end if
; New member added in libpng-1.0.25 and 1.2.17
if PNG_READ_UNKNOWN_CHUNKS_SUPPORTED eq 1
; Temporary storage for unknown chunk that the library doesn't recognize,
; used while reading the chunk.
; png_unknown_chunk unknown_chunk;
end if
; New member added in libpng-1.2.26
old_big_row_buf_size dd ? ;png_size_t
if PNG_READ_SUPPORTED eq 1
; New member added in libpng-1.2.30
read_buffer dd ? ;bytep ;buffer for reading chunk data
read_buffer_size dd ? ;png_alloc_size_t ;current size of the buffer
end if
if PNG_SEQUENTIAL_READ_SUPPORTED eq 1
IDAT_read_size dd ? ;uInt ;limit on read buffer size for IDAT
end if
if PNG_IO_STATE_SUPPORTED eq 1
; New member added in libpng-1.4.0
io_state dd ? ;uint_32
end if
; New member added in libpng-1.5.6
big_prev_row dd ? ;bytep
; New member added in libpng-1.5.7
; void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
; bytep row, bytep prev_row);
if PNG_READ_SUPPORTED eq 1
if (PNG_COLORSPACE_SUPPORTED eq 1) | (PNG_GAMMA_SUPPORTED eq 1)
colorspace png_colorspace
end if
end if
ends

View File

@ -0,0 +1,299 @@
txt_zv db '*',0
txt_sp db ' ',0
txt_buf db '1234',0
rd 1
buf_param rb 80
macro cStr dest,txt
{
local .end_t
local .m_txt
jmp .end_t
align 4
.m_txt db txt,0
align 4
.end_t:
if dest eq
mov eax,.m_txt
else
mov dest,.m_txt
end if
}
align 4
proc f_png_warning, h:dword, m_txt:dword
stdcall hex_in_str,txt_buf,[h],5
mov byte[txt_buf+5],0
stdcall dbg_print,txt_buf,[m_txt]
ret
endp
align 4
proc f_png_error, h:dword, m_txt:dword
stdcall hex_in_str,txt_buf,[h],5
mov byte[txt_buf+5],0
stdcall dbg_print,txt_buf,[m_txt]
ret
endp
align 4
proc f_png_debug, n:dword, m_txt:dword
stdcall dbg_print,txt_sp,[m_txt]
ret
endp
align 4
proc dbg_print, fun:dword, mes:dword
pushad
mov eax,SF_BOARD
mov ebx,SSF_DEBUG_WRITE
mov esi,[fun]
cmp esi,0
je .end0
@@:
mov cl,byte[esi]
int 0x40
inc esi
cmp byte[esi],0
jne @b
mov cl,':'
int 0x40
mov cl,' '
int 0x40
.end0:
mov esi,[mes]
cmp esi,0
je .end_f
@@:
mov cl,byte[esi]
cmp cl,0
je .end_f
int 0x40
inc esi
jmp @b
.end_f:
popad
ret
endp
;input:
; zif - 1...8
align 4
proc hex_in_str, buf:dword,val:dword,zif:dword
pushad
mov edi,dword[buf]
mov ecx,dword[zif]
add edi,ecx
dec edi
mov ebx,dword[val]
.cycle:
mov al,bl
and al,0xf
cmp al,10
jl @f
add al,'a'-'0'-10
@@:
add al,'0'
mov byte[edi],al
dec edi
shr ebx,4
loop .cycle
popad
ret
endp
;---
macro png_warning h,txt
{
if txt eqtype ''
local .end_t
local .m_txt
jmp .end_t
.m_txt db txt,13,10,0
.end_t:
stdcall f_png_warning,h,.m_txt
else
stdcall f_png_warning,h,txt
push eax ebx ecx
mcall SF_BOARD,SSF_DEBUG_WRITE,13
mcall ,,10
pop ecx ebx eax
end if
}
macro png_app_warning h,txt
{
png_warning h,<txt>
}
macro png_error h,txt
{
if txt eqtype ''
local .end_t
local .m_txt
jmp .end_t
.m_txt db txt,13,10,0
.end_t:
stdcall f_png_error,h,.m_txt
else
stdcall f_png_error,h,txt
push eax ebx ecx
mcall SF_BOARD,SSF_DEBUG_WRITE,13
mcall ,,10
pop ecx ebx eax
end if
}
macro png_debug n,txt
{
if DEBUG eq 1
local .end_t
local .m_txt
jmp .end_t
.m_txt db txt,13,10,0
align 4
.end_t:
stdcall f_png_debug,n,.m_txt
end if
}
macro png_debug1 n,fmt,p1
{
if DEBUG eq 1
local .end_t
if p1 eqtype ''
local .m_txt1
local .m_txt2
jmp .end_t
.m_txt1 db fmt,0
.m_txt2 db p1,13,10,0
align 4
.end_t:
stdcall dbg_print,.m_txt1,.m_txt2
else
local .m_fmt
jmp .end_t
.m_fmt db fmt,13,10,0
align 4
.end_t:
stdcall str_format_dbg, buf_param,.m_fmt,p1
end if
end if
}
;output:
; eax = strlen
align 4
proc strlen, str1:dword
mov eax,[str1]
@@:
cmp byte[eax],0
je @f
inc eax
jmp @b
@@:
sub eax,[str1]
ret
endp
align 4
proc str_format_dbg, buf:dword, fmt:dword, p1:dword
pushad
mov esi,[fmt]
mov edi,[buf]
mov ecx,80-1
.cycle0:
lodsb
cmp al,'%'
jne .no_param
lodsb
dec ecx
cmp al,0
je .cycle0end
cmp al,'d'
je @f
cmp al,'u'
je @f
cmp al,'l'
je .end1
jmp .end0
.end1: ;%lu %lx
lodsb
dec ecx
cmp al,'u'
jne .end0
@@:
mov eax,[p1]
stdcall convert_int_to_str,ecx
xor al,al
repne scasb
dec edi
.end0:
loop .cycle0
.no_param:
stosb
cmp al,0
je .cycle0end
loop .cycle0
.cycle0end:
xor al,al
stosb
stdcall dbg_print,txt_sp,[buf]
popad
ret
endp
;input:
; eax - число
; edi - буфер для строки
; len - длинна буфера
;output:
align 4
proc convert_int_to_str, len:dword
pushad
mov esi,[len]
add esi,edi
dec esi
call .str
popad
ret
endp
align 4
.str:
mov ecx,0x0a
cmp eax,ecx
jb @f
xor edx,edx
div ecx
push edx
call .str
pop eax
@@:
cmp edi,esi
jge @f
or al,0x30
stosb
mov byte[edi],0
@@:
ret
macro std_png_image_error n,txt
{
local .end_t
local .m_txt
jmp .end_t
.m_txt db txt,13,10,0
align 4
.end_t:
stdcall png_image_error,n,.m_txt
}

View File

@ -0,0 +1,886 @@
; pngtrans.asm - transforms the data in a row (used by both readers and writers)
; Last changed in libpng 1.6.24 [August 4, 2016]
; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
if (PNG_READ_SUPPORTED eq 1) | (PNG_WRITE_SUPPORTED eq 1)
; Turn on BGR-to-RGB mapping
;void (png_structrp png_ptr)
align 4
proc png_set_bgr uses edi, png_ptr:dword
png_debug 1, 'in png_set_bgr'
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
or dword[edi+png_struct.transformations], PNG_BGR
@@:
ret
endp
; Turn on 16-bit byte swapping
;void (png_structrp png_ptr)
align 4
proc png_set_swap uses edi, png_ptr:dword
png_debug 1, 'in png_set_swap'
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
cmp byte[edi+png_struct.bit_depth],16
jne @f ;if (..==..)
or dword[edi+png_struct.transformations], PNG_SWAP_BYTES
@@:
ret
endp
; Turn on pixel packing
;void (png_structrp png_ptr)
align 4
proc png_set_packing uses edi, png_ptr:dword
png_debug 1, 'in png_set_packing'
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
cmp byte[edi+png_struct.bit_depth],8
jge @f ;if (..<..)
or dword[edi+png_struct.transformations], PNG_PACK
if PNG_WRITE_SUPPORTED eq 1
mov byte[edi+png_struct.usr_bit_depth],8
end if
@@:
ret
endp
; Turn on packed pixel swapping
;void (png_structrp png_ptr)
align 4
proc png_set_packswap uses edi, png_ptr:dword
png_debug 1, 'in png_set_packswap'
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
cmp byte[edi+png_struct.bit_depth],8
jge @f ;if (..<..)
or dword[edi+png_struct.transformations], PNG_PACKSWAP
@@:
ret
endp
;void (png_structrp png_ptr, png_const_color_8p true_bits)
align 4
proc png_set_shift uses ecx edi, png_ptr:dword, true_bits:dword
png_debug 1, 'in png_set_shift'
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
or dword[edi+png_struct.transformations], PNG_SHIFT
mov ecx,sizeof.png_color_8
mov edi,[edi+png_struct.shift]
mov esi,[true_bits]
rep movsb
@@:
ret
endp
;int (png_structrp png_ptr)
align 4
proc png_set_interlace_handling uses edi, png_ptr:dword
png_debug 1, 'in png_set_interlace handling'
mov edi,[png_ptr]
cmp edi,0
je @f
cmp byte[edi+png_struct.interlaced],0
je @f ;if(..!=0 && ..!=0)
or dword[edi+png_struct.transformations], PNG_INTERLACE
mov eax,7
jmp .end_f
@@:
xor eax,eax
inc eax
.end_f:
ret
endp
; Add a filler byte on read, or remove a filler or alpha byte on write.
; The filler type has changed in v0.95 to allow future 2-byte fillers
; for 48-bit input data, as well as to avoid problems with some compilers
; that don't like bytes as parameters.
;void (png_structrp png_ptr, uint_32 filler, int filler_loc)
align 4
proc png_set_filler uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
png_debug 1, 'in png_set_filler'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
; In libpng 1.6 it is possible to determine whether this is a read or write
; operation and therefore to do more checking here for a valid call.
mov eax,[edi+png_struct.mode]
and eax,PNG_IS_READ_STRUCT
cmp eax,0
je @f ;if (..!=0)
if PNG_READ_FILLER_SUPPORTED eq 1
; On read png_set_filler is always valid, regardless of the base PNG
; format, because other transformations can give a format where the
; filler code can execute (basically an 8 or 16-bit component RGB or G
; format.)
; NOTE: usr_channels is not used by the read code! (This has led to
; confusion in the past.) The filler is only used in the read code.
mov eax,[filler]
mov [edi+png_struct.filler],ax
jmp .end0
else
cStr ,'png_set_filler not supported on read'
stdcall png_app_error, edi, eax
jmp .end_f
end if
@@: ;else ;write
if PNG_WRITE_FILLER_SUPPORTED eq 1
; On write the usr_channels parameter must be set correctly at the
; start to record the number of channels in the app-supplied data.
; switch (png_ptr->color_type)
; {
; case PNG_COLOR_TYPE_RGB:
; png_ptr->usr_channels = 4;
; break;
; case PNG_COLOR_TYPE_GRAY:
; if (png_ptr->bit_depth >= 8)
; {
; png_ptr->usr_channels = 2;
; break;
; }
; else
; {
; There simply isn't any code in libpng to strip out bits
; from bytes when the components are less than a byte in
; size!
; png_app_error(png_ptr,
; "png_set_filler is invalid for"
; " low bit depth gray output");
; return;
; }
; default:
; png_app_error(png_ptr,
; "png_set_filler: inappropriate color type");
; return;
; }
else
cStr ,'png_set_filler not supported on write'
stdcall png_app_error, edi, eax
jmp .end_f
end if
.end0:
; Here on success - libpng supports the operation, set the transformation
; and the flag to say where the filler channel is.
or dword[edi+png_struct.transformations],PNG_FILLER
cmp dword[filler_loc],PNG_FILLER_AFTER
jne @f ;if (..==..)
or dword[edi+png_struct.flags],PNG_FLAG_FILLER_AFTER
jmp .end_f
@@: ;else
and dword[edi+png_struct.flags],not PNG_FLAG_FILLER_AFTER
.end_f:
ret
endp
; Added to libpng-1.2.7
;void (png_structrp png_ptr, uint_32 filler, int filler_loc)
align 4
proc png_set_add_alpha uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
png_debug 1, 'in png_set_add_alpha'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
stdcall png_set_filler, edi, [filler], [filler_loc]
; The above may fail to do anything.
mov eax,[edi+png_struct.transformations]
and eax,PNG_FILLER
cmp eax,0
je .end_f ;if (..!=0)
or dword[edi+png_struct.transformations],PNG_ADD_ALPHA
.end_f:
ret
endp
;void (png_structrp png_ptr)
align 4
proc png_set_swap_alpha uses edi, png_ptr:dword
png_debug 1, 'in png_set_swap_alpha'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
; png_ptr->transformations |= PNG_SWAP_ALPHA;
.end_f:
ret
endp
;void (png_structrp png_ptr)
align 4
proc png_set_invert_alpha uses edi, png_ptr:dword
png_debug 1, 'in png_set_invert_alpha'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
; png_ptr->transformations |= PNG_INVERT_ALPHA;
.end_f:
ret
endp
;void (png_structrp png_ptr)
align 4
proc png_set_invert_mono uses edi, png_ptr:dword
png_debug 1, 'in png_set_invert_mono'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
; png_ptr->transformations |= PNG_INVERT_MONO;
.end_f:
ret
endp
; Invert monochrome grayscale data
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_invert, row_info:dword, row:dword
png_debug 1, 'in png_do_invert'
; This test removed from libpng version 1.0.13 and 1.2.0:
; if (row_info->bit_depth == 1 &&
; if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
; {
; bytep rp = row;
; png_size_t i;
; png_size_t istop = row_info->rowbytes;
; for (i = 0; i < istop; i++)
; {
; *rp = (byte)(~(*rp));
; rp++;
; }
; }
; else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
; row_info->bit_depth == 8)
; {
; bytep rp = row;
; png_size_t i;
; png_size_t istop = row_info->rowbytes;
; for (i = 0; i < istop; i += 2)
; {
; *rp = (byte)(~(*rp));
; rp += 2;
; }
; }
if PNG_16BIT_SUPPORTED eq 1
; else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
; row_info->bit_depth == 16)
; {
; bytep rp = row;
; png_size_t i;
; png_size_t istop = row_info->rowbytes;
; for (i = 0; i < istop; i += 4)
; {
; *rp = (byte)(~(*rp));
; *(rp + 1) = (byte)(~(*(rp + 1)));
; rp += 4;
; }
; }
end if
ret
endp
; Swaps byte order on 16-bit depth images
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_swap, row_info:dword, row:dword
png_debug 1, 'in png_do_swap'
; if (row_info->bit_depth == 16)
; {
; bytep rp = row;
; uint_32 i;
; uint_32 istop= row_info->width * row_info->channels;
; for (i = 0; i < istop; i++, rp += 2)
; {
if PNG_BUILTIN_BSWAP16_SUPPORTED eq 1
; Feature added to libpng-1.6.11 for testing purposes, not
; enabled by default.
; *(uint_16*)rp = __builtin_bswap16(*(uint_16*)rp);
else
; byte t = *rp;
; *rp = *(rp + 1);
; *(rp + 1) = t;
end if
; }
; }
ret
endp
if (PNG_READ_PACKSWAP_SUPPORTED eq 1) | (PNG_WRITE_PACKSWAP_SUPPORTED eq 1)
align 4
onebppswaptable db 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,\
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,\
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,\
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,\
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,\
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,\
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,\
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,\
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,\
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,\
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,\
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,\
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,\
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,\
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,\
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,\
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,\
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,\
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,\
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,\
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,\
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,\
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,\
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,\
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,\
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,\
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,\
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,\
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,\
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,\
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,\
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
align 4
twobppswaptable db 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,\
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,\
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,\
0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,\
0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,\
0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,\
0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,\
0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,\
0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,\
0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,\
0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,\
0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,\
0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,\
0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,\
0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,\
0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,\
0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,\
0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,\
0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,\
0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,\
0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,\
0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,\
0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,\
0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,\
0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,\
0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,\
0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,\
0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,\
0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,\
0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,\
0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,\
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
align 4
fourbppswaptable db 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,\
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,\
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,\
0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,\
0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,\
0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,\
0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,\
0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,\
0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,\
0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,\
0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,\
0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,\
0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,\
0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,\
0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,\
0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,\
0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,\
0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,\
0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,\
0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,\
0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,\
0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,\
0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,\
0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,\
0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,\
0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,\
0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,\
0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,\
0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,\
0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,\
0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,\
0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
end if ;PACKSWAP || WRITE_PACKSWAP
; Swaps pixel packing order within bytes
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_packswap uses eax edx edi esi, row_info:dword, row:dword
png_debug 1, 'in png_do_packswap'
mov eax,[row_info]
cmp byte[eax+png_row_info.bit_depth],8
jge .end_f ;if (..<..)
;edi = rp
;esi = table
mov edx,[eax+png_row_info.rowbytes]
mov edi,[row]
add edx,edi
cmp byte[eax+png_row_info.bit_depth],1
jne @f ;if (..==..)
mov esi,onebppswaptable
jmp .cycle0
@@:
cmp byte[eax+png_row_info.bit_depth],2
jne @f ;else if (..==..)
mov esi,twobppswaptable
jmp .cycle0
@@:
cmp byte[eax+png_row_info.bit_depth],4
jne .end_f ;else if (..==..)
mov esi,fourbppswaptable
align 4
.cycle0: ;for (..=..;..<..;..)
cmp edi,edx
jge .end_f
movzx eax,byte[edi]
mov al,byte[esi+eax]
stosb ;*rp = table[*rp]
jmp .cycle0
.end_f:
ret
endp
; Remove a channel - this used to be 'png_do_strip_filler' but it used a
; somewhat weird combination of flags to determine what to do. All the calls
; to png_do_strip_filler are changed in 1.5.2 to call this instead with the
; correct arguments.
; The routine isn't general - the channel must be the channel at the start or
; end (not in the middle) of each pixel.
;void (png_row_infop row_info, bytep row, int at_start)
align 4
proc png_do_strip_channel, row_info:dword, row:dword, at_start:dword
; bytep sp = row; /* source pointer */
; bytep dp = row; /* destination pointer */
; bytep ep = row + row_info->rowbytes; /* One beyond end of row */
; At the start sp will point to the first byte to copy and dp to where
; it is copied to. ep always points just beyond the end of the row, so
; the loop simply copies (channels-1) channels until sp reaches ep.
; at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc.
; nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
; GA, GX, XG cases
; if (row_info->channels == 2)
; {
; if (row_info->bit_depth == 8)
; {
; if (at_start != 0) /* Skip initial filler */
; ++sp;
; else /* Skip initial channel and, for sp, the filler */
; sp += 2, ++dp;
; For a 1 pixel wide image there is nothing to do
; while (sp < ep)
; *dp++ = *sp, sp += 2;
; row_info->pixel_depth = 8;
; }
; else if (row_info->bit_depth == 16)
; {
; if (at_start != 0) /* Skip initial filler */
; sp += 2;
; else /* Skip initial channel and, for sp, the filler */
; sp += 4, dp += 2;
; while (sp < ep)
; *dp++ = *sp++, *dp++ = *sp, sp += 3;
; row_info->pixel_depth = 16;
; }
; else
; return; /* bad bit depth */
; row_info->channels = 1;
; Finally fix the color type if it records an alpha channel
; if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
; row_info->color_type = PNG_COLOR_TYPE_GRAY;
; }
; RGBA, RGBX, XRGB cases
; else if (row_info->channels == 4)
; {
; if (row_info->bit_depth == 8)
; {
; if (at_start != 0) /* Skip initial filler */
; ++sp;
; else /* Skip initial channels and, for sp, the filler */
; sp += 4, dp += 3;
; Note that the loop adds 3 to dp and 4 to sp each time.
; while (sp < ep)
; *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
; row_info->pixel_depth = 24;
; }
; else if (row_info->bit_depth == 16)
; {
; if (at_start != 0) /* Skip initial filler */
; sp += 2;
; else /* Skip initial channels and, for sp, the filler */
; sp += 8, dp += 6;
; while (sp < ep)
; {
; /* Copy 6 bytes, skip 2 */
; *dp++ = *sp++, *dp++ = *sp++;
; *dp++ = *sp++, *dp++ = *sp++;
; *dp++ = *sp++, *dp++ = *sp, sp += 3;
; }
; row_info->pixel_depth = 48;
; }
; else
; return; /* bad bit depth */
; row_info->channels = 3;
; Finally fix the color type if it records an alpha channel
; if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
; row_info->color_type = PNG_COLOR_TYPE_RGB;
; }
; else
; return; /* The filler channel has gone already */
; Fix the rowbytes value.
; row_info->rowbytes = dp-row;
ret
endp
; Swaps red and blue bytes within a pixel
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_bgr, row_info:dword, row:dword
png_debug 1, 'in png_do_bgr'
; if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
; {
; uint_32 row_width = row_info->width;
; if (row_info->bit_depth == 8)
; {
; if (row_info->color_type == PNG_COLOR_TYPE_RGB)
; {
; bytep rp;
; uint_32 i;
; for (i = 0, rp = row; i < row_width; i++, rp += 3)
; {
; byte save = *rp;
; *rp = *(rp + 2);
; *(rp + 2) = save;
; }
; }
; else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
; {
; bytep rp;
; uint_32 i;
; for (i = 0, rp = row; i < row_width; i++, rp += 4)
; {
; byte save = *rp;
; *rp = *(rp + 2);
; *(rp + 2) = save;
; }
; }
; }
if PNG_16BIT_SUPPORTED eq 1
; else if (row_info->bit_depth == 16)
; {
; if (row_info->color_type == PNG_COLOR_TYPE_RGB)
; {
; bytep rp;
; uint_32 i;
; for (i = 0, rp = row; i < row_width; i++, rp += 6)
; {
; byte save = *rp;
; *rp = *(rp + 4);
; *(rp + 4) = save;
; save = *(rp + 1);
; *(rp + 1) = *(rp + 5);
; *(rp + 5) = save;
; }
; }
; else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
; {
; bytep rp;
; uint_32 i;
; for (i = 0, rp = row; i < row_width; i++, rp += 8)
; {
; byte save = *rp;
; *rp = *(rp + 4);
; *(rp + 4) = save;
; save = *(rp + 1);
; *(rp + 1) = *(rp + 5);
; *(rp + 5) = save;
; }
; }
; }
end if
; }
ret
endp
; Added at libpng-1.5.10
;void (png_structrp png_ptr, png_row_infop row_info)
align 4
proc png_do_check_palette_indexes, png_ptr:dword, row_info:dword
; if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
; png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
; {
; Calculations moved outside switch in an attempt to stop different
; compiler warnings. 'padding' is in *bits* within the last byte, it is
; an 'int' because pixel_depth becomes an 'int' in the expression below,
; and this calculation is used because it avoids warnings that other
; forms produced on either GCC or MSVC.
; int padding = (-row_info->pixel_depth * row_info->width) & 7;
; bytep rp = png_ptr->row_buf + row_info->rowbytes;
; switch (row_info->bit_depth)
; {
; case 1:
; {
; /* in this case, all bytes must be 0 so we don't need
; to unpack the pixels except for the rightmost one.
; for (; rp > png_ptr->row_buf; rp--)
; {
; if ((*rp >> padding) != 0)
; png_ptr->num_palette_max = 1;
; padding = 0;
; }
; break;
; }
; case 2:
; {
; for (; rp > png_ptr->row_buf; rp--)
; {
; int i = ((*rp >> padding) & 0x03);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; i = (((*rp >> padding) >> 2) & 0x03);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; i = (((*rp >> padding) >> 4) & 0x03);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; i = (((*rp >> padding) >> 6) & 0x03);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; padding = 0;
; }
; break;
; }
; case 4:
; {
; for (; rp > png_ptr->row_buf; rp--)
; {
; int i = ((*rp >> padding) & 0x0f);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; i = (((*rp >> padding) >> 4) & 0x0f);
; if (i > png_ptr->num_palette_max)
; png_ptr->num_palette_max = i;
; padding = 0;
; }
; break;
; }
; case 8:
; {
; for (; rp > png_ptr->row_buf; rp--)
; {
; if (*rp > png_ptr->num_palette_max)
; png_ptr->num_palette_max = (int) *rp;
; }
; break;
; }
; default:
; break;
; }
; }
ret
endp
;void (png_structrp png_ptr, voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)
align 4
proc png_set_user_transform_info uses eax edi, png_ptr:dword, user_transform_ptr:dword, user_transform_depth:dword, user_transform_channels:dword
png_debug 1, 'in png_set_user_transform_info'
mov edi,[png_ptr]
cmp edi,0
je .end_f
if PNG_READ_USER_TRANSFORM_SUPPORTED eq 1
mov eax,[edi+png_struct.mode]
and eax,PNG_IS_READ_STRUCT
cmp eax,0
je @f
mov eax,[edi+png_struct.flags]
and eax,PNG_FLAG_ROW_INIT
cmp eax,0
je @f ;if (..!=0 && ..!=0)
cStr ,'info change after png_start_read_image or png_read_update_info'
stdcall png_app_error edi, eax
jmp .end_f
@@:
end if
mov eax,[user_transform_ptr]
mov [edi+png_struct.user_transform_ptr],eax
mov eax,[user_transform_depth]
mov [edi+png_struct.user_transform_depth],al
mov eax,[user_transform_channels]
mov [edi+png_struct.user_transform_channels],al
.end_f:
ret
endp
; This function returns a pointer to the user_transform_ptr associated with
; the user transform functions. The application should free any memory
; associated with this pointer before png_write_destroy and png_read_destroy
; are called.
;voidp (png_const_structrp png_ptr)
align 4
proc png_get_user_transform_ptr, png_ptr:dword
mov eax,[png_ptr]
cmp eax,0
je @f
mov eax,[eax+png_struct.user_transform_ptr]
@@:
ret
endp
;uint_32 (png_const_structrp png_ptr)
align 4
proc png_get_current_row_number, png_ptr:dword
; See the comments in png.inc - this is the sub-image row when reading an
; interlaced image.
mov eax,[png_ptr]
cmp eax,0
je @f ;if (..!=0)
mov eax,[eax+png_struct.row_number]
jmp .end_f
@@:
mov eax,PNG_UINT_32_MAX ;help the app not to fail silently
.end_f:
ret
endp
;byte (png_const_structrp png_ptr)
align 4
proc png_get_current_pass_number, png_ptr:dword
mov eax,[png_ptr]
cmp eax,0
je @f ;if (..!=0)
mov eax,[eax+png_struct.pass]
jmp .end_f
@@:
mov eax,8 ;invalid
.end_f:
ret
endp
end if

View File

@ -0,0 +1,165 @@
; pngwio.asm - functions for data output
; Last changed in libpng 1.6.24 [August 4, 2016]
; Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; This file provides a location for all output. Users who need
; special handling are expected to write functions that have the same
; arguments as these and perform similar functions, but that possibly
; use different output methods. Note that you shouldn't change these
; functions, but rather write replacement functions and then change
; them at run time with png_set_write_fn(...).
; Write the data to whatever output you are using. The default routine
; writes to a file pointer. Note that this routine sometimes gets called
; with very small lengths, so you should implement some kind of simple
; buffering if you are using unbuffered writes. This should never be asked
; to write more than 64K on a 16-bit machine.
;void (png_structrp png_ptr, bytep data, png_size_t length)
align 4
proc png_write_data uses edi, png_ptr:dword, p2data:dword, length:dword
; NOTE: write_data_fn must not change the buffer!
mov edi,[png_ptr]
cmp dword[edi+png_struct.write_data_fn],0
je @f ;if (..!=0)
stdcall dword[edi+png_struct.write_data_fn], edi, [p2data], [length]
jmp .end_f
@@: ;else
png_error edi, 'Call to NULL write function'
.end_f:
ret
endp
; This is the function that does the actual writing of data. If you are
; not writing to a standard C stream, you should create a replacement
; write_data function and use it at run time with png_set_write_fn(), rather
; than changing the library.
;void (png_structp png_ptr, bytep data, png_size_t length)
align 4
proc png_default_write_data uses eax edi, png_ptr:dword, p2data:dword, length:dword
; png_size_t check;
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
; check = fwrite(p2data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
; if (check != length)
; png_error(png_ptr, "Write Error");
.end_f:
ret
endp
; This function is called to output any data pending writing (normally
; to disk). After png_flush is called, there should be no data pending
; writing in any buffers.
;void (png_structrp png_ptr)
align 4
proc png_flush uses edi, png_ptr:dword
mov edi,[png_ptr]
cmp dword[edi+png_struct.output_flush_fn],0
je @f ;if (..!=..)
stdcall dword[edi+png_struct.output_flush_fn],edi
@@:
ret
endp
;void (png_structp png_ptr)
align 4
proc png_default_flush uses eax edi, png_ptr:dword
mov edi,[png_ptr]
cmp edi,0
je @f ;if (..==0) return
;;; stdcall fflush, [edi+png_struct.io_ptr]
@@:
ret
endp
; This function allows the application to supply new output functions for
; libpng if standard C streams aren't being used.
; This function takes as its arguments:
; png_ptr - pointer to a png output data structure
; io_ptr - pointer to user supplied structure containing info about
; the output functions. May be NULL.
; write_data_fn - pointer to a new output function that takes as its
; arguments a pointer to a png_struct, a pointer to
; data to be written, and a 32-bit unsigned int that is
; the number of bytes to be written. The new write
; function should call png_error(png_ptr, "Error msg")
; to exit and output any fatal error messages. May be
; NULL, in which case libpng's default function will
; be used.
; flush_data_fn - pointer to a new flush function that takes as its
; arguments a pointer to a png_struct. After a call to
; the flush function, there should be no data in any buffers
; or pending transmission. If the output method doesn't do
; any buffering of output, a function prototype must still be
; supplied although it doesn't have to do anything. If
; PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
; time, output_flush_fn will be ignored, although it must be
; supplied for compatibility. May be NULL, in which case
; libpng's default function will be used, if
; PNG_WRITE_FLUSH_SUPPORTED is defined. This is not
; a good idea if io_ptr does not point to a standard
; *FILE structure.
;void (png_structrp png_ptr, voidp io_ptr,
; png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
align 4
proc png_set_write_fn uses eax edi, png_ptr:dword, io_ptr:dword, write_data_fn:dword, output_flush_fn:dword
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
mov eax,[io_ptr]
mov [edi+png_struct.io_ptr],eax
if PNG_STDIO_SUPPORTED eq 1
mov eax,png_default_write_data ;else
cmp dword[write_data_fn],0
je @f ;if (..!=0)
mov eax,[write_data_fn]
@@:
else
mov eax,[write_data_fn]
end if
mov [edi+png_struct.write_data_fn],eax
if PNG_WRITE_FLUSH_SUPPORTED eq 1
if PNG_STDIO_SUPPORTED eq 1
mov eax,[png_default_flush] ;else
cmp dword[output_flush_fn],0
je @f ;if (..!=0)
mov eax,[output_flush_fn]
@@:
else
mov eax,[output_flush_fn]
end if
mov [edi+png_struct.output_flush_fn],eax
end if ;WRITE_FLUSH
if PNG_READ_SUPPORTED eq 1
; It is an error to read while writing a png file
cmp dword[edi+png_struct.read_data_fn],0
je @f ;if (..!=0)
mov dword[edi+png_struct.read_data_fn], 0
png_warning edi, <'Can',39,'t set both read_data_fn and write_data_fn in the same structure'>
@@:
end if
.end_f:
ret
endp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,610 @@
; pngwtran.asm - transforms the data in a row for PNG writers
; Last changed in libpng 1.6.24 [August 4, 2016]
; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
; This code is released under the libpng license.
; For conditions of distribution and use, see the disclaimer
; and license in png.inc
; Pack pixels into bytes. Pass the true bit depth in bit_depth. The
; row_info bit depth should be 8 (one pixel per byte). The channels
; should be 1 (this only happens on grayscale and paletted images).
;void (png_row_infop row_info, bytep row, uint_32 bit_depth)
align 4
proc png_do_pack, row_info:dword, row:dword, bit_depth:dword
png_debug 1, 'in png_do_pack'
; if (row_info->bit_depth == 8 &&
; row_info->channels == 1)
; {
; switch ((int)bit_depth)
; {
; case 1:
; {
; bytep sp, dp;
; int mask, v;
; uint_32 i;
; uint_32 row_width = row_info->width;
; sp = row;
; dp = row;
; mask = 0x80;
; v = 0;
; for (i = 0; i < row_width; i++)
; {
; if (*sp != 0)
; v |= mask;
; sp++;
; if (mask > 1)
; mask >>= 1;
; else
; {
; mask = 0x80;
; *dp = (byte)v;
; dp++;
; v = 0;
; }
; }
; if (mask != 0x80)
; *dp = (byte)v;
; break;
; }
; case 2:
; {
; bytep sp, dp;
; unsigned int shift;
; int v;
; uint_32 i;
; uint_32 row_width = row_info->width;
; sp = row;
; dp = row;
; shift = 6;
; v = 0;
; for (i = 0; i < row_width; i++)
; {
; byte value;
; value = (byte)(*sp & 0x03);
; v |= (value << shift);
; if (shift == 0)
; {
; shift = 6;
; *dp = (byte)v;
; dp++;
; v = 0;
; }
; else
; shift -= 2;
;
; sp++;
; }
; if (shift != 6)
; *dp = (byte)v;
; break;
; }
; case 4:
; {
; bytep sp, dp;
; unsigned int shift;
; int v;
; uint_32 i;
; uint_32 row_width = row_info->width;
; sp = row;
; dp = row;
; shift = 4;
; v = 0;
; for (i = 0; i < row_width; i++)
; {
; byte value;
; value = (byte)(*sp & 0x0f);
; v |= (value << shift);
; if (shift == 0)
; {
; shift = 4;
; *dp = (byte)v;
; dp++;
; v = 0;
; }
; else
; shift -= 4;
;
; sp++;
; }
; if (shift != 4)
; *dp = (byte)v;
; break;
; }
; default:
; break;
; }
; row_info->bit_depth = (byte)bit_depth;
; row_info->pixel_depth = (byte)(bit_depth * row_info->channels);
; row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
; row_info->width);
; }
ret
endp
; Shift pixel values to take advantage of whole range. Pass the
; true number of bits in bit_depth. The row should be packed
; according to row_info->bit_depth. Thus, if you had a row of
; bit depth 4, but the pixels only had values from 0 to 7, you
; would pass 3 as bit_depth, and this routine would translate the
; data to 0 to 15.
;void (png_row_infop row_info, bytep row, png_const_color_8p bit_depth)
align 4
proc png_do_shift, row_info:dword, row:dword, bit_depth:dword
png_debug 1, 'in png_do_shift'
; if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
; {
; int shift_start[4], shift_dec[4];
; int channels = 0;
; if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
; {
; shift_start[channels] = row_info->bit_depth - bit_depth->red;
; shift_dec[channels] = bit_depth->red;
; channels++;
; shift_start[channels] = row_info->bit_depth - bit_depth->green;
; shift_dec[channels] = bit_depth->green;
; channels++;
; shift_start[channels] = row_info->bit_depth - bit_depth->blue;
; shift_dec[channels] = bit_depth->blue;
; channels++;
; }
; else
; {
; shift_start[channels] = row_info->bit_depth - bit_depth->gray;
; shift_dec[channels] = bit_depth->gray;
; channels++;
; }
; if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
; {
; shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
; shift_dec[channels] = bit_depth->alpha;
; channels++;
; }
; With low row depths, could only be grayscale, so one channel
; if (row_info->bit_depth < 8)
; {
; bytep bp = row;
; png_size_t i;
; unsigned int mask;
; png_size_t row_bytes = row_info->rowbytes;
; if (bit_depth->gray == 1 && row_info->bit_depth == 2)
; mask = 0x55;
; else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
; mask = 0x11;
; else
; mask = 0xff;
; for (i = 0; i < row_bytes; i++, bp++)
; {
; int j;
; unsigned int v, out;
; v = *bp;
; out = 0;
; for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
; {
; if (j > 0)
; out |= v << j;
; else
; out |= (v >> (-j)) & mask;
; }
; *bp = (byte)(out & 0xff);
; }
; }
; else if (row_info->bit_depth == 8)
; {
; bytep bp = row;
; uint_32 i;
; uint_32 istop = channels * row_info->width;
; for (i = 0; i < istop; i++, bp++)
; {
; const unsigned int c = i%channels;
; int j;
; unsigned int v, out;
; v = *bp;
; out = 0;
; for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
; {
; if (j > 0)
; out |= v << j;
; else
; out |= v >> (-j);
; }
; *bp = (byte)(out & 0xff);
; }
; }
; else
; {
; bytep bp;
; uint_32 i;
; uint_32 istop = channels * row_info->width;
; for (bp = row, i = 0; i < istop; i++)
; {
; const unsigned int c = i%channels;
; int j;
; unsigned int value, v;
; v = png_get_uint_16(bp);
; value = 0;
; for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
; {
; if (j > 0)
; value |= v << j;
; else
; value |= v >> (-j);
; }
; *bp++ = (byte)((value >> 8) & 0xff);
; *bp++ = (byte)(value & 0xff);
; }
; }
; }
ret
endp
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_write_swap_alpha, row_info:dword, row:dword
png_debug 1, 'in png_do_write_swap_alpha'
; {
; if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
; {
; if (row_info->bit_depth == 8)
; {
; This converts from ARGB to RGBA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; byte save = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = save;
; }
; }
if PNG_WRITE_16BIT_SUPPORTED eq 1
; else
; {
; This converts from AARRGGBB to RRGGBBAA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; byte save[2];
; save[0] = *(sp++);
; save[1] = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = save[0];
; *(dp++) = save[1];
; }
; }
end if ;WRITE_16BIT
; }
;
; else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
; {
; if (row_info->bit_depth == 8)
; {
; This converts from AG to GA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; byte save = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = save;
; }
; }
if PNG_WRITE_16BIT_SUPPORTED eq 1
; else
; {
; This converts from AAGG to GGAA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; byte save[2];
; save[0] = *(sp++);
; save[1] = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = *(sp++);
; *(dp++) = save[0];
; *(dp++) = save[1];
; }
; }
end if ;WRITE_16BIT
; }
; }
ret
endp
;void (png_row_infop row_info, bytep row)
align 4
proc png_do_write_invert_alpha, row_info:dword, row:dword
png_debug 1, 'in png_do_write_invert_alpha'
; if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
; {
; if (row_info->bit_depth == 8)
; {
; This inverts the alpha channel in RGBA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; Does nothing
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
; sp+=3; dp = sp;
; *dp = (byte)(255 - *(sp++));
; }
; }
;if PNG_WRITE_16BIT_SUPPORTED
; else
; {
; This inverts the alpha channel in RRGGBBAA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; Does nothing
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
; sp+=6; dp = sp;
; *(dp++) = (byte)(255 - *(sp++));
; *dp = (byte)(255 - *(sp++));
; }
; }
;end if /* WRITE_16BIT */
; }
; else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
; {
; if (row_info->bit_depth == 8)
; {
; This inverts the alpha channel in GA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; *(dp++) = *(sp++);
; *(dp++) = (byte)(255 - *(sp++));
; }
; }
if PNG_WRITE_16BIT_SUPPORTED eq 1
; else
; {
; This inverts the alpha channel in GGAA
; bytep sp, dp;
; uint_32 i;
; uint_32 row_width = row_info->width;
;
; for (i = 0, sp = dp = row; i < row_width; i++)
; {
; Does nothing
;*(dp++) = *(sp++);
;*(dp++) = *(sp++);
; sp+=2; dp = sp;
; *(dp++) = (byte)(255 - *(sp++));
; *dp = (byte)(255 - *(sp++));
; }
; }
end if ;WRITE_16BIT
; }
ret
endp
; Transform the data according to the user's wishes. The order of
; transformations is significant.
;void (png_structrp png_ptr, png_row_infop row_info)
align 4
proc png_do_write_transformations uses eax ebx edi esi, png_ptr:dword, row_info:dword
png_debug 1, 'in png_do_write_transformations'
mov edi,[png_ptr]
cmp edi,0
je .end_f ;if (..==0) return
mov esi,[row_info]
mov ebx,[edi+png_struct.row_buf]
inc ebx ;start of pixel data for row
if PNG_WRITE_USER_TRANSFORM_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_USER_TRANSFORM
cmp eax,0
je @f ;if (..!=0)
mov eax,[edi+png_struct.write_user_transform_fn]
cmp eax,0
je @f ;if (..!=0)
stdcall eax, edi, esi, ebx ;User write transform function
; row_info:
; uint_32 width ;width of row
; png_size_t rowbytes ;number of bytes in row
; byte color_type ;color type of pixels
; byte bit_depth ;bit depth of samples
; byte channels ;number of channels (1-4)
; byte pixel_depth ;bits per pixel (depth*channels)
@@:
end if
if PNG_WRITE_FILLER_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_FILLER
cmp eax,0
je @f ;if (..!=0)
mov eax,[edi+png_struct.flags]
and eax,PNG_FLAG_FILLER_AFTER
not eax
stdcall png_do_strip_channel, esi, ebx, eax
@@:
end if
if PNG_WRITE_PACKSWAP_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_PACKSWAP
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_packswap, esi, ebx
@@:
end if
if PNG_WRITE_PACK_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_PACK
cmp eax,0
je @f ;if (..!=0)
movzx eax,byte[edi+png_struct.bit_depth]
stdcall png_do_pack, esi, ebx, eax
@@:
end if
if PNG_WRITE_SWAP_SUPPORTED eq 1
if PNG_16BIT_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_SWAP_BYTES
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_swap, esi, ebx
@@:
end if
end if
if PNG_WRITE_SHIFT_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_SHIFT
cmp eax,0
je @f ;if (..!=0)
mov eax,edi
add eax,png_struct.shift
stdcall png_do_shift, esi, ebx, eax
@@:
end if
if PNG_WRITE_SWAP_ALPHA_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_SWAP_ALPHA
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_write_swap_alpha, esi, ebx
@@:
end if
if PNG_WRITE_INVERT_ALPHA_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_INVERT_ALPHA
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_write_invert_alpha, esi, ebx
@@:
end if
if PNG_WRITE_BGR_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_BGR
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_bgr, esi, ebx
@@:
end if
if PNG_WRITE_INVERT_SUPPORTED eq 1
mov eax,[edi+png_struct.transformations]
and eax,PNG_INVERT_MONO
cmp eax,0
je @f ;if (..!=0)
stdcall png_do_invert, esi, ebx
@@:
end if
.end_f:
ret
endp

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,8 @@
;; ;;
;;================================================================================================;;
include 'libpng/png.asm'
;;================================================================================================;;
;;proc img.is.png _data, _length ;////////////////////////////////////////////////////////////////;;
img.is.png:
@ -1076,6 +1078,64 @@ local .l1
ret
;endp
img.encode.png:
xor eax, eax
ret 12
;;================================================================================================;;
align 4
proc img.encode.png uses ebx edx, _img:dword, _common:dword, _specific:dword
;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in png format ;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to image ;;
;> [_common] = format independent options ;;
;> [_specific] = 0 / pointer to the structure of format specific options ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to encoded data ;;
;< ecx = error code / the size of encoded data ;;
;;================================================================================================;;
locals
encoded_file rd 1
encoded_file_size rd 1
simag png_image
endl
mov ebx,[_img]
mov eax,[ebx+Image.Type]
cmp eax,Image.bpp24
je @f
mov ecx,LIBIMG_ERROR_BIT_DEPTH
jmp .error
@@:
mov edx,ebp
sub edx,sizeof.png_image
mov dword[edx+png_image.version],PNG_IMAGE_VERSION
mov ecx,[ebx+Image.Width]
mov [edx+png_image.width],ecx ;Image width in pixels (columns)
mov eax,[ebx+Image.Height]
mov [edx+png_image.height],eax ;Image height in pixels (rows)
mov dword[edx+png_image.format],PNG_COLOR_TYPE_RGB
;mov dword[edx+png_image.flags],PNG_IMAGE_FLAG_???
imul ecx,3
mov edi,ecx
imul edi,[ebx+Image.Height]
mov [encoded_file_size],edi
stdcall [mem.alloc],edi
test eax,eax
jnz @f
mov ecx,LIBIMG_ERROR_OUT_OF_MEMORY
jmp .error
@@:
mov [encoded_file],eax
mov edi,edx
sub edi,4
stdcall png_image_write_to_memory, edx,eax,edi,0,[ebx+Image.Data],ecx,0
mov eax,[encoded_file]
mov ecx,[encoded_file_size]
jmp .quit
.error:
xor eax,eax
.quit:
ret
endp