Rev 6779 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6733 | IgorA | 1 | |
2 | |||
3 | |||
4 | ; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson |
||
5 | ; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
||
6 | ; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
||
7 | |||
8 | |||
9 | ; For conditions of distribution and use, see the disclaimer |
||
10 | ; and license in png.inc |
||
11 | |||
12 | |||
13 | ; with unsigned numbers for convenience, although one supported |
||
14 | ; ancillary chunk uses signed (two's complement) numbers. |
||
15 | |||
16 | |||
17 | align 4 |
||
18 | proc png_save_uint_32 uses eax edi, buf:dword, i:dword |
||
19 | mov eax,[i] |
||
20 | bswap eax |
||
21 | mov edi,[buf] |
||
22 | stosd |
||
23 | ret |
||
24 | endp |
||
25 | |||
26 | |||
27 | ; The parameter is declared unsigned int, not uint_16, |
||
28 | ; just to avoid potential problems on pre-ANSI C compilers. |
||
29 | |||
30 | |||
31 | align 4 |
||
32 | proc png_save_uint_16 uses eax edi, buf:dword, i:dword |
||
33 | mov eax,[i] |
||
34 | ror eax,16 |
||
35 | bswap eax |
||
36 | mov edi,[buf] |
||
37 | stosw |
||
38 | ret |
||
39 | endp |
||
40 | |||
41 | |||
42 | ; the magic bytes of the signature, or more likely, the PNG stream is |
||
43 | ; being embedded into another stream and doesn't need its own signature, |
||
44 | ; we should call png_set_sig_bytes() to tell libpng how many of the |
||
45 | ; bytes have already been written. |
||
46 | |||
47 | |||
48 | png_signature db 137, 80, 78, 71, 13, 10, 26, 10 |
||
49 | |||
50 | |||
51 | align 4 |
||
52 | proc png_write_sig uses eax ebx edi, png_ptr:dword |
||
53 | if PNG_IO_STATE_SUPPORTED eq 1 |
||
54 | ; Inform the I/O callback that the signature is being written |
||
55 | mov edi,[png_ptr] |
||
56 | mov dword[edi+png_struct.io_state], PNG_IO_WRITING or PNG_IO_SIGNATURE |
||
57 | end if |
||
58 | |||
59 | |||
60 | movzx eax,byte[edi+png_struct.sig_bytes] |
||
61 | mov ebx,8 |
||
62 | sub ebx,eax |
||
63 | add eax,png_signature |
||
64 | stdcall png_write_data, edi, eax, ebx |
||
65 | |||
66 | |||
67 | jge @f |
||
68 | or dword[edi+png_struct.mode], PNG_HAVE_PNG_SIGNATURE |
||
69 | @@: |
||
70 | ret |
||
71 | endp |
||
72 | |||
73 | |||
74 | ; The total_length is the sum of the lengths of all the data you will be |
||
75 | ; passing in png_write_chunk_data(). |
||
76 | |||
77 | |||
78 | align 4 |
||
79 | proc png_write_chunk_header uses ebx edi, png_ptr:dword, chunk_name:dword, length:dword |
||
80 | locals |
||
81 | buf rb 8 ;ebp-8 |
||
82 | endl |
||
83 | |||
84 | |||
85 | ; PNG_CSTRING_FROM_CHUNK(buf, chunk_name); |
||
86 | ; png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length); |
||
87 | ;end if |
||
88 | |||
89 | |||
90 | cmp edi,0 |
||
91 | je .end_f ;if (png_ptr == NULL) return |
||
92 | |||
93 | |||
94 | ; Inform the I/O callback that the chunk header is being written. |
||
95 | ; PNG_IO_CHUNK_HDR requires a single I/O call. |
||
96 | |||
97 | |||
98 | end if |
||
99 | |||
100 | |||
101 | mov ebx,ebp |
||
102 | sub ebx,8 |
||
103 | stdcall png_save_uint_32, ebx, [length] |
||
104 | m2m dword[ebx+4],dword[chunk_name] |
||
105 | stdcall png_write_data, edi, ebx, 8 |
||
106 | |||
107 | |||
108 | m2m dword[edi+png_struct.chunk_name],dword[chunk_name] |
||
109 | |||
110 | |||
111 | stdcall png_reset_crc, edi |
||
112 | |||
113 | |||
114 | sub ebx,4 ;buf + 4 |
||
115 | stdcall png_calculate_crc, edi, ebx, 4 |
||
116 | |||
117 | |||
118 | ; Inform the I/O callback that chunk data will (possibly) be written. |
||
119 | ; PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. |
||
120 | |||
121 | |||
122 | end if |
||
123 | .end_f: |
||
124 | ret |
||
125 | endp |
||
126 | |||
127 | |||
128 | align 4 |
||
129 | proc png_write_chunk_start uses eax, png_ptr:dword, chunk_string:dword, length:dword |
||
130 | mov eax,[chunk_string] |
||
131 | stdcall png_write_chunk_header, [png_ptr], [eax], [length] |
||
132 | ret |
||
133 | endp |
||
134 | |||
135 | |||
136 | ; Note that multiple calls to this function are allowed, and that the |
||
137 | ; sum of the lengths from these calls *must* add up to the total_length |
||
138 | ; given to png_write_chunk_header(). |
||
139 | |||
140 | |||
141 | align 4 |
||
142 | proc png_write_chunk_data uses edi, png_ptr:dword, p2data:dword, length:dword |
||
143 | ; Write the data, and run the CRC over it |
||
144 | mov edi,[png_ptr] |
||
145 | cmp edi,0 |
||
146 | je .end_f ;if (..==0) return |
||
147 | |||
148 | |||
149 | je .end_f |
||
150 | cmp dword[length],0 |
||
151 | jle .end_f ;if (..!=0 && ..>0) |
||
152 | stdcall png_write_data, edi, [p2data], [length] |
||
153 | ; Update the CRC after writing the data, |
||
154 | ; in case the user I/O routine alters it. |
||
155 | stdcall png_calculate_crc, edi, [p2data], [length] |
||
156 | .end_f: |
||
157 | ret |
||
158 | endp |
||
159 | |||
160 | |||
161 | ;void (png_structrp png_ptr) |
||
162 | align 4 |
||
163 | proc png_write_chunk_end uses ebx edi, png_ptr:dword |
||
164 | locals |
||
165 | buf rb 4 ;ebp-4 |
||
166 | endl |
||
167 | mov edi,[png_ptr] |
||
168 | cmp edi,0 |
||
169 | je .end_f ;if (..==0) return |
||
170 | |||
171 | |||
172 | ; Inform the I/O callback that the chunk CRC is being written. |
||
173 | ; PNG_IO_CHUNK_CRC requires a single I/O function call. |
||
174 | |||
175 | |||
176 | end if |
||
177 | |||
178 | |||
179 | mov ebx,ebp |
||
180 | sub ebx,4 |
||
181 | stdcall png_save_uint_32, ebx, [edi+png_struct.crc] |
||
182 | |||
183 | |||
184 | .end_f: |
||
185 | ret |
||
186 | endp |
||
187 | |||
188 | |||
189 | ; representing the chunk name. The array must be at least 4 bytes in |
||
190 | ; length, and does not need to be null terminated. To be safe, pass the |
||
191 | ; pre-defined chunk names here, and if you need a new one, define it |
||
192 | ; where the others are defined. The length is the length of the data. |
||
193 | ; All the data must be present. If that is not possible, use the |
||
194 | ; png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() |
||
195 | ; functions instead. |
||
196 | |||
197 | |||
198 | align 4 |
||
199 | proc png_write_complete_chunk uses edi, png_ptr:dword, chunk_name:dword, p3data:dword, length:dword |
||
200 | mov edi,[png_ptr] |
||
201 | cmp edi,0 |
||
202 | je .end_f ;if (..==0) return |
||
203 | |||
204 | |||
205 | cmp dword[length],PNG_UINT_31_MAX ;if(..>..) |
||
206 | jle @f |
||
207 | png_error edi, 'length exceeds PNG maximum' |
||
208 | @@: |
||
209 | stdcall png_write_chunk_header, edi, [chunk_name], [length] |
||
210 | stdcall png_write_chunk_data, edi, [p3data], [length] |
||
211 | stdcall png_write_chunk_end, edi |
||
212 | .end_f: |
||
213 | ret |
||
214 | endp |
||
215 | |||
216 | |||
217 | ;void (png_structrp png_ptr, bytep chunk_string, bytep data, png_size_t length) |
||
218 | align 4 |
||
219 | proc png_write_chunk, png_ptr:dword, chunk_string:dword, p3data:dword, length:dword |
||
220 | stdcall png_write_complete_chunk, [png_ptr], [chunk_string], [p3data], [length] |
||
221 | ret |
||
222 | endp |
||
223 | |||
224 | |||
225 | ; so it only needs to be accurate if the size is less than 16384 bytes (the |
||
226 | ; point at which a lower LZ window size can be used.) |
||
227 | |||
228 | |||
229 | align 4 |
||
230 | proc png_image_size uses ebx ecx edx edi esi, png_ptr:dword |
||
231 | ; Only return sizes up to the maximum of a uint_32; do this by limiting |
||
232 | ; the width and height used to 15 bits. |
||
233 | |||
234 | |||
235 | mov ebx,[edi+png_struct.height] |
||
236 | |||
237 | |||
238 | jge .end0 |
||
239 | cmp ebx,32768 |
||
240 | jge .end0 ;if (..<.. && ..<..) |
||
241 | cmp byte[edi+png_struct.interlaced],0 |
||
242 | je .end1 ;if (..!=0) |
||
243 | ; Interlacing makes the image larger because of the replication of |
||
244 | ; both the filter byte and the padding to a byte boundary. |
||
245 | |||
246 | |||
247 | xor ecx,ecx |
||
248 | .cycle0: |
||
249 | PNG_PASS_COLS [edi+png_struct.width], ecx |
||
250 | ;eax = pw |
||
251 | |||
252 | |||
253 | jle @f ;if (..>0) |
||
254 | mov edx,eax |
||
255 | movzx eax,byte[edi+png_struct.pixel_depth] |
||
256 | PNG_ROWBYTES eax, edx |
||
257 | inc eax |
||
258 | mov edx,eax |
||
259 | PNG_PASS_ROWS ebx, ecx |
||
260 | imul eax,edx |
||
261 | add esi,eax |
||
262 | @@: |
||
263 | inc ecx |
||
264 | cmp ecx,6 |
||
265 | jle .cycle0 |
||
266 | |||
267 | |||
268 | jmp .end_f |
||
269 | .end1: ;else |
||
270 | mov eax,[edi+png_struct.rowbytes] |
||
271 | inc eax |
||
272 | imul eax,ebx |
||
273 | jmp .end_f |
||
274 | .end0: ;else |
||