Subversion Repositories Kolibri OS

Rev

Rev 6733 | Rev 6797 | Go to most recent revision | Details | Compare with Previous | 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
 
14
15
 
16
;void (png_structrp png_ptr)
17
align 4
18
proc png_set_bgr uses edi, png_ptr:dword
19
	png_debug 1, 'in png_set_bgr'
20
21
 
22
	cmp edi,0
23
	je @f ;if (..==0) return
24
		or dword[edi+png_struct.transformations], PNG_BGR
25
	@@:
26
	ret
27
endp
28
29
 
30
;void (png_structrp png_ptr)
31
align 4
32
proc png_set_swap uses edi, png_ptr:dword
33
	png_debug 1, 'in png_set_swap'
34
35
 
36
	cmp edi,0
37
	je @f ;if (..==0) return
38
39
 
40
	jne @f ;if (..==..)
41
		or dword[edi+png_struct.transformations], PNG_SWAP_BYTES
42
	@@:
43
	ret
44
endp
45
46
 
47
;void (png_structrp png_ptr)
48
align 4
49
proc png_set_packing uses edi, png_ptr:dword
50
	png_debug 1, 'in png_set_packing'
51
52
 
53
	cmp edi,0
54
	je @f ;if (..==0) return
55
56
 
57
	jge @f ;if (..<..)
58
		or dword[edi+png_struct.transformations], PNG_PACK
59
if PNG_WRITE_SUPPORTED eq 1
60
		mov byte[edi+png_struct.usr_bit_depth],8
61
end if
62
	@@:
63
	ret
64
endp
65
66
 
67
;void (png_structrp png_ptr)
68
align 4
69
proc png_set_packswap uses edi, png_ptr:dword
70
	png_debug 1, 'in png_set_packswap'
71
72
 
73
	cmp edi,0
74
	je @f ;if (..==0) return
75
76
 
77
	jge @f ;if (..<..)
78
		or dword[edi+png_struct.transformations], PNG_PACKSWAP
79
	@@:
80
	ret
81
endp
82
83
 
84
align 4
85
proc png_set_shift uses ecx edi, png_ptr:dword, true_bits:dword
86
	png_debug 1, 'in png_set_shift'
87
88
 
89
	cmp edi,0
90
	je @f ;if (..==0) return
91
92
 
93
	mov ecx,sizeof.png_color_8
94
	mov edi,[edi+png_struct.shift]
95
	mov esi,[true_bits]
96
	rep movsb
97
	@@:
98
	ret
99
endp
100
101
 
102
align 4
103
proc png_set_interlace_handling uses edi, png_ptr:dword
104
	png_debug 1, 'in png_set_interlace handling'
105
106
 
107
	cmp edi,0
108
	je @f
109
	cmp byte[edi+png_struct.interlaced],0
110
	je @f ;if(..!=0 && ..!=0)
111
		or dword[edi+png_struct.transformations], PNG_INTERLACE
112
		mov eax,7
113
		jmp .end_f
114
	@@:
115
116
 
117
	inc eax
118
.end_f:
119
	ret
120
endp
121
122
 
123
; The filler type has changed in v0.95 to allow future 2-byte fillers
124
; for 48-bit input data, as well as to avoid problems with some compilers
125
; that don't like bytes as parameters.
126
127
 
128
align 4
129
proc png_set_filler uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
130
	png_debug 1, 'in png_set_filler'
131
132
 
133
	cmp edi,0
134
	je .end_f ;if (..==0) return
135
136
 
137
	; operation and therefore to do more checking here for a valid call.
138
139
 
140
	and eax,PNG_IS_READ_STRUCT
141
	cmp eax,0
142
	je @f ;if (..!=0)
143
if PNG_READ_FILLER_SUPPORTED eq 1
144
		; On read png_set_filler is always valid, regardless of the base PNG
145
		; format, because other transformations can give a format where the
146
		; filler code can execute (basically an 8 or 16-bit component RGB or G
147
		; format.)
148
149
 
150
		; confusion in the past.)  The filler is only used in the read code.
151
152
 
153
		mov [edi+png_struct.filler],ax
154
		jmp .end0
155
else
156
		cStr ,'png_set_filler not supported on read'
157
		stdcall png_app_error, edi, eax
158
		jmp .end_f
159
end if
160
	@@: ;else ;write
161
if PNG_WRITE_FILLER_SUPPORTED eq 1
162
	; On write the usr_channels parameter must be set correctly at the
163
	; start to record the number of channels in the app-supplied data.
164
165
 
166
;         {
167
;            case PNG_COLOR_TYPE_RGB:
168
;               png_ptr->usr_channels = 4;
169
;               break;
170
171
 
172
;               if (png_ptr->bit_depth >= 8)
173
;               {
174
;                  png_ptr->usr_channels = 2;
175
;                  break;
176
;               }
177
178
 
179
;               {
180
			; There simply isn't any code in libpng to strip out bits
181
			; from bytes when the components are less than a byte in
182
			; size!
183
184
 
185
;                      "png_set_filler is invalid for"
186
;                      " low bit depth gray output");
187
;                  return;
188
;               }
189
190
 
191
;               png_app_error(png_ptr,
192
;                   "png_set_filler: inappropriate color type");
193
;               return;
194
;         }
195
else
196
		cStr ,'png_set_filler not supported on write'
197
		stdcall png_app_error, edi, eax
198
		jmp .end_f
199
end if
200
	.end0:
201
202
 
203
	; and the flag to say where the filler channel is.
204
205
 
206
207
 
208
	jne @f ;if (..==..)
209
		or dword[edi+png_struct.flags],PNG_FLAG_FILLER_AFTER
210
		jmp .end_f
211
	@@: ;else
212
		and dword[edi+png_struct.flags],not PNG_FLAG_FILLER_AFTER
213
.end_f:
214
	ret
215
endp
216
217
 
218
;void (png_structrp png_ptr, uint_32 filler, int filler_loc)
219
align 4
220
proc png_set_add_alpha uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
221
	png_debug 1, 'in png_set_add_alpha'
222
223
 
224
	cmp edi,0
225
	je .end_f ;if (..==0) return
226
227
 
228
	; The above may fail to do anything.
229
	mov eax,[edi+png_struct.transformations]
230
	and eax,PNG_FILLER
231
	cmp eax,0
232
	je .end_f ;if (..!=0)
233
		or dword[edi+png_struct.transformations],PNG_ADD_ALPHA
234
.end_f:
235
	ret
236
endp
237
238
 
239
align 4
240
proc png_set_swap_alpha uses edi, png_ptr:dword
241
	png_debug 1, 'in png_set_swap_alpha'
242
243
 
244
	cmp edi,0
245
	je .end_f ;if (..==0) return
246
247
 
248
.end_f:
249
	ret
250
endp
251
252
 
253
 
254
align 4
255
proc png_set_invert_alpha uses edi, png_ptr:dword
256
	png_debug 1, 'in png_set_invert_alpha'
257
258
 
259
	cmp edi,0
260
	je .end_f ;if (..==0) return
261
262
 
263
.end_f:
264
	ret
265
endp
266
267
 
268
align 4
269
proc png_set_invert_mono uses edi, png_ptr:dword
270
	png_debug 1, 'in png_set_invert_mono'
271
272
 
273
	cmp edi,0
274
	je .end_f ;if (..==0) return
275
276
 
277
.end_f:
278
	ret
279
endp
280
281
 
282
;void (png_row_infop row_info, bytep row)
283
align 4
284
proc png_do_invert, row_info:dword, row:dword
285
	png_debug 1, 'in png_do_invert'
286
287
 
288
	;   if (row_info->bit_depth == 1 &&
289
290
 
291
;   {
292
;      bytep rp = row;
293
;      png_size_t i;
294
;      png_size_t istop = row_info->rowbytes;
295
296
 
297
;      {
298
;         *rp = (byte)(~(*rp));
299
;         rp++;
300
;      }
301
;   }
302
303
 
304
;      row_info->bit_depth == 8)
305
;   {
306
;      bytep rp = row;
307
;      png_size_t i;
308
;      png_size_t istop = row_info->rowbytes;
309
310
 
311
;      {
312
;         *rp = (byte)(~(*rp));
313
;         rp += 2;
314
;      }
315
;   }
316
317
 
318
;   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
319
;      row_info->bit_depth == 16)
320
;   {
321
;      bytep rp = row;
322
;      png_size_t i;
323
;      png_size_t istop = row_info->rowbytes;
324
325
 
326
;      {
327
;         *rp = (byte)(~(*rp));
328
;         *(rp + 1) = (byte)(~(*(rp + 1)));
329
;         rp += 4;
330
;      }
331
;   }
332
end if
333
	ret
334
endp
335
336
 
337
;void (png_row_infop row_info, bytep row)
338
align 4
339
proc png_do_swap, row_info:dword, row:dword
340
	png_debug 1, 'in png_do_swap'
341
342
 
343
;   {
344
;      bytep rp = row;
345
;      uint_32 i;
346
;      uint_32 istop= row_info->width * row_info->channels;
347
348
 
349
;      {
350
if PNG_BUILTIN_BSWAP16_SUPPORTED eq 1
351
	; Feature added to libpng-1.6.11 for testing purposes, not
352
	; enabled by default.
353
354
 
355
else
356
;         byte t = *rp;
357
;         *rp = *(rp + 1);
358
;         *(rp + 1) = t;
359
end if
360
;      }
361
;   }
362
	ret
363
endp
364
365
 
366
align 4
367
onebppswaptable db 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,\
368
   0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,\
369
   0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,\
370
   0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,\
371
   0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,\
372
   0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,\
373
   0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,\
374
   0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,\
375
   0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,\
376
   0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,\
377
   0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,\
378
   0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,\
379
   0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,\
380
   0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,\
381
   0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,\
382
   0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,\
383
   0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,\
384
   0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,\
385
   0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,\
386
   0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,\
387
   0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,\
388
   0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,\
389
   0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,\
390
   0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,\
391
   0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,\
392
   0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,\
393
   0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,\
394
   0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,\
395
   0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,\
396
   0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,\
397
   0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,\
398
   0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
399
400
 
401
twobppswaptable db 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,\
402
   0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,\
403
   0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,\
404
   0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,\
405
   0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,\
406
   0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,\
407
   0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,\
408
   0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,\
409
   0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,\
410
   0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,\
411
   0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,\
412
   0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,\
413
   0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,\
414
   0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,\
415
   0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,\
416
   0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,\
417
   0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,\
418
   0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,\
419
   0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,\
420
   0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,\
421
   0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,\
422
   0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,\
423
   0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,\
424
   0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,\
425
   0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,\
426
   0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,\
427
   0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,\
428
   0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,\
429
   0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,\
430
   0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,\
431
   0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,\
432
   0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
433
434
 
435
fourbppswaptable db 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,\
436
   0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,\
437
   0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,\
438
   0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,\
439
   0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,\
440
   0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,\
441
   0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,\
442
   0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,\
443
   0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,\
444
   0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,\
445
   0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,\
446
   0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,\
447
   0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,\
448
   0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,\
449
   0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,\
450
   0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,\
451
   0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,\
452
   0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,\
453
   0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,\
454
   0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,\
455
   0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,\
456
   0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,\
457
   0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,\
458
   0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,\
459
   0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,\
460
   0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,\
461
   0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,\
462
   0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,\
463
   0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,\
464
   0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,\
465
   0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,\
466
   0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
467
end if ;PACKSWAP || WRITE_PACKSWAP
468
469
 
470
;void (png_row_infop row_info, bytep row)
471
align 4
472
proc png_do_packswap uses eax edx edi esi, row_info:dword, row:dword
473
	png_debug 1, 'in png_do_packswap'
474
475
 
476
	cmp byte[eax+png_row_info.bit_depth],8
477
	jge .end_f ;if (..<..)
478
		;edi = rp
479
		;esi = table
480
481
 
482
		mov edi,[row]
483
		add edx,edi
484
485
 
486
		jne @f ;if (..==..)
487
			mov esi,onebppswaptable
488
			jmp .cycle0
489
		@@:
490
		cmp byte[eax+png_row_info.bit_depth],2
491
		jne @f ;else if (..==..)
492
			mov esi,twobppswaptable
493
			jmp .cycle0
494
		@@:
495
		cmp byte[eax+png_row_info.bit_depth],4
496
		jne .end_f ;else if (..==..)
497
			mov esi,fourbppswaptable
498
align 4
499
		.cycle0: ;for (..=..;..<..;..)
500
			cmp edi,edx
501
			jge .end_f
502
			movzx eax,byte[edi]
503
			mov al,byte[esi+eax]
504
			stosb ;*rp = table[*rp]
505
			jmp .cycle0
506
.end_f:
507
	ret
508
endp
509
510
 
511
; somewhat weird combination of flags to determine what to do.  All the calls
512
; to png_do_strip_filler are changed in 1.5.2 to call this instead with the
513
; correct arguments.
514
515
 
516
; end (not in the middle) of each pixel.
517
518
 
519
align 4
520
proc png_do_strip_channel, row_info:dword, row:dword, at_start:dword
521
;   bytep sp = row; /* source pointer */
522
;   bytep dp = row; /* destination pointer */
523
;   bytep ep = row + row_info->rowbytes; /* One beyond end of row */
524
525
 
526
	; it is copied to.  ep always points just beyond the end of the row, so
527
	; the loop simply copies (channels-1) channels until sp reaches ep.
528
529
 
530
	;            nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
531
532
 
533
 
534
;   if (row_info->channels == 2)
535
;   {
536
;      if (row_info->bit_depth == 8)
537
;      {
538
;         if (at_start != 0) /* Skip initial filler */
539
;            ++sp;
540
;         else          /* Skip initial channel and, for sp, the filler */
541
;            sp += 2, ++dp;
542
543
 
544
;         while (sp < ep)
545
;            *dp++ = *sp, sp += 2;
546
547
 
548
;      }
549
550
 
551
;      {
552
;         if (at_start != 0) /* Skip initial filler */
553
;            sp += 2;
554
;         else          /* Skip initial channel and, for sp, the filler */
555
;            sp += 4, dp += 2;
556
557
 
558
;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
559
560
 
561
;      }
562
563
 
564
;         return; /* bad bit depth */
565
566
 
567
568
 
569
;      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
570
;         row_info->color_type = PNG_COLOR_TYPE_GRAY;
571
;   }
572
573
 
574
;   else if (row_info->channels == 4)
575
;   {
576
;      if (row_info->bit_depth == 8)
577
;      {
578
;         if (at_start != 0) /* Skip initial filler */
579
;            ++sp;
580
;         else          /* Skip initial channels and, for sp, the filler */
581
;            sp += 4, dp += 3;
582
583
 
584
;         while (sp < ep)
585
;            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
586
587
 
588
;      }
589
590
 
591
;      {
592
;         if (at_start != 0) /* Skip initial filler */
593
;            sp += 2;
594
;         else          /* Skip initial channels and, for sp, the filler */
595
;            sp += 8, dp += 6;
596
597
 
598
;         {
599
;            /* Copy 6 bytes, skip 2 */
600
;            *dp++ = *sp++, *dp++ = *sp++;
601
;            *dp++ = *sp++, *dp++ = *sp++;
602
;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
603
;         }
604
605
 
606
;      }
607
608
 
609
;         return; /* bad bit depth */
610
611
 
612
613
 
614
;      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
615
;         row_info->color_type = PNG_COLOR_TYPE_RGB;
616
;   }
617
618
 
619
;      return; /* The filler channel has gone already */
620
621
 
622
;   row_info->rowbytes = dp-row;
623
	ret
624
endp
625
626
 
627
;void (png_row_infop row_info, bytep row)
628
align 4
629
proc png_do_bgr, row_info:dword, row:dword
630
	png_debug 1, 'in png_do_bgr'
631
632
 
633
;   {
634
;      uint_32 row_width = row_info->width;
635
;      if (row_info->bit_depth == 8)
636
;      {
637
;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
638
;         {
639
;            bytep rp;
640
;            uint_32 i;
641
642
 
643
;            {
644
;               byte save = *rp;
645
;               *rp = *(rp + 2);
646
;               *(rp + 2) = save;
647
;            }
648
;         }
649
650
 
651
;         {
652
;            bytep rp;
653
;            uint_32 i;
654
655
 
656
;            {
657
;               byte save = *rp;
658
;               *rp = *(rp + 2);
659
;               *(rp + 2) = save;
660
;            }
661
;         }
662
;      }
663
664
 
665
;      else if (row_info->bit_depth == 16)
666
;      {
667
;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
668
;         {
669
;            bytep rp;
670
;            uint_32 i;
671
672
 
673
;            {
674
;               byte save = *rp;
675
;               *rp = *(rp + 4);
676
;               *(rp + 4) = save;
677
;               save = *(rp + 1);
678
;               *(rp + 1) = *(rp + 5);
679
;               *(rp + 5) = save;
680
;            }
681
;         }
682
683
 
684
;         {
685
;            bytep rp;
686
;            uint_32 i;
687
688
 
689
;            {
690
;               byte save = *rp;
691
;               *rp = *(rp + 4);
692
;               *(rp + 4) = save;
693
;               save = *(rp + 1);
694
;               *(rp + 1) = *(rp + 5);
695
;               *(rp + 5) = save;
696
;            }
697
;         }
698
;      }
699
end if
700
;   }
701
	ret
702
endp
703
704
 
705
;void (png_structrp png_ptr, png_row_infop row_info)
706
align 4
707
proc png_do_check_palette_indexes, png_ptr:dword, row_info:dword
708
;   if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
709
;      png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
710
;   {
711
	; Calculations moved outside switch in an attempt to stop different
712
	; compiler warnings.  'padding' is in *bits* within the last byte, it is
713
	; an 'int' because pixel_depth becomes an 'int' in the expression below,
714
	; and this calculation is used because it avoids warnings that other
715
	; forms produced on either GCC or MSVC.
716
717
 
718
;      bytep rp = png_ptr->row_buf + row_info->rowbytes;
719
720
 
721
;      {
722
;         case 1:
723
;         {
724
;            /* in this case, all bytes must be 0 so we don't need
725
	; to unpack the pixels except for the rightmost one.
726
727
 
728
;            {
729
;              if ((*rp >> padding) != 0)
730
;                 png_ptr->num_palette_max = 1;
731
;              padding = 0;
732
;            }
733
734
 
735
;         }
736
737
 
738
;         {
739
;            for (; rp > png_ptr->row_buf; rp--)
740
;            {
741
;              int i = ((*rp >> padding) & 0x03);
742
743
 
744
;                 png_ptr->num_palette_max = i;
745
746
 
747
748
 
749
;                 png_ptr->num_palette_max = i;
750
751
 
752
753
 
754
;                 png_ptr->num_palette_max = i;
755
756
 
757
758
 
759
;                 png_ptr->num_palette_max = i;
760
761
 
762
;            }
763
764
 
765
;         }
766
767
 
768
;         {
769
;            for (; rp > png_ptr->row_buf; rp--)
770
;            {
771
;              int i = ((*rp >> padding) & 0x0f);
772
773
 
774
;                 png_ptr->num_palette_max = i;
775
776
 
777
778
 
779
;                 png_ptr->num_palette_max = i;
780
781
 
782
;            }
783
784
 
785
;         }
786
787
 
788
;         {
789
;            for (; rp > png_ptr->row_buf; rp--)
790
;            {
791
;               if (*rp > png_ptr->num_palette_max)
792
;                  png_ptr->num_palette_max = (int) *rp;
793
;            }
794
795
 
796
;         }
797
798
 
799
;            break;
800
;      }
801
;   }
802
	ret
803
endp
804
805
 
806
align 4
807
proc png_set_user_transform_info uses eax edi, png_ptr:dword, user_transform_ptr:dword, user_transform_depth:dword, user_transform_channels:dword
808
	png_debug 1, 'in png_set_user_transform_info'
809
810
 
811
	cmp edi,0
812
	je .end_f
813
814
 
815
	mov eax,[edi+png_struct.mode]
816
	and eax,PNG_IS_READ_STRUCT
817
	cmp eax,0
818
	je @f
819
	mov eax,[edi+png_struct.flags]
820
	and eax,PNG_FLAG_ROW_INIT
821
	cmp eax,0
822
	je @f ;if (..!=0 && ..!=0)
823
		cStr ,'info change after png_start_read_image or png_read_update_info'
824
		stdcall png_app_error, edi, eax
6779 IgorA 825
		jmp .end_f
6733 IgorA 826
	@@:
827
end if
828
829
 
830
	mov [edi+png_struct.user_transform_ptr],eax
831
	mov eax,[user_transform_depth]
832
	mov [edi+png_struct.user_transform_depth],al
833
	mov eax,[user_transform_channels]
834
	mov [edi+png_struct.user_transform_channels],al
835
.end_f:
836
	ret
837
endp
838
839
 
840
; the user transform functions.  The application should free any memory
841
; associated with this pointer before png_write_destroy and png_read_destroy
842
; are called.
843
844
 
845
align 4
846
proc png_get_user_transform_ptr, png_ptr:dword
847
	mov eax,[png_ptr]
848
	cmp eax,0
849
	je @f
850
		mov eax,[eax+png_struct.user_transform_ptr]
851
	@@:
852
	ret
853
endp
854
855
 
856
align 4
857
proc png_get_current_row_number, png_ptr:dword
858
	; See the comments in png.inc - this is the sub-image row when reading an
859
	; interlaced image.
860
861
 
862
	cmp eax,0
863
	je @f ;if (..!=0)
864
		mov eax,[eax+png_struct.row_number]
865
		jmp .end_f
866
	@@:
867
	mov eax,PNG_UINT_32_MAX ;help the app not to fail silently
868
.end_f:
869
	ret
870
endp
871
872
 
873
align 4
874
proc png_get_current_pass_number, png_ptr:dword
875
	mov eax,[png_ptr]
876
	cmp eax,0
877
	je @f ;if (..!=0)
878
		mov eax,[eax+png_struct.pass]
879
		jmp .end_f
880
	@@:
881
	mov eax,8 ;invalid
882
.end_f:
883
	ret
884
endp
885
end if
886
>