Subversion Repositories Kolibri OS

Rev

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