Subversion Repositories Kolibri OS

Rev

Rev 6779 | Rev 6891 | 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
 
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
	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
	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
	cmp edi,0
224
	je .end_f ;if (..==0) return
225
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
	cmp edi,0
243
	je .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
	cmp edi,0
257
	je .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
	cmp edi,0
270
	je .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, row_info:dword, row:dword
280
	png_debug 1, 'in png_do_invert'
281
282
 
283
	;   if (row_info->bit_depth == 1 &&
284
285
 
286
;   {
287
;      bytep rp = row;
288
;      png_size_t i;
289
;      png_size_t istop = row_info->rowbytes;
290
291
 
292
;      {
293
;         *rp = (byte)(~(*rp));
294
;         rp++;
295
;      }
296
;   }
297
298
 
299
;      row_info->bit_depth == 8)
300
;   {
301
;      bytep rp = row;
302
;      png_size_t i;
303
;      png_size_t istop = row_info->rowbytes;
304
305
 
306
;      {
307
;         *rp = (byte)(~(*rp));
308
;         rp += 2;
309
;      }
310
;   }
311
312
 
313
;   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
314
;      row_info->bit_depth == 16)
315
;   {
316
;      bytep rp = row;
317
;      png_size_t i;
318
;      png_size_t istop = row_info->rowbytes;
319
320
 
321
;      {
322
;         *rp = (byte)(~(*rp));
323
;         *(rp + 1) = (byte)(~(*(rp + 1)));
324
;         rp += 4;
325
;      }
326
;   }
327
end if
328
	ret
329
endp
330
331
 
332
;void (png_row_infop row_info, bytep row)
333
align 4
334
proc png_do_swap, row_info:dword, row:dword
335
	png_debug 1, 'in png_do_swap'
336
337
 
338
;   {
339
;      bytep rp = row;
340
;      uint_32 i;
341
;      uint_32 istop= row_info->width * row_info->channels;
342
343
 
344
;      {
345
if PNG_BUILTIN_BSWAP16_SUPPORTED eq 1
346
	; Feature added to libpng-1.6.11 for testing purposes, not
347
	; enabled by default.
348
349
 
350
else
351
;         byte t = *rp;
352
;         *rp = *(rp + 1);
353
;         *(rp + 1) = t;
354
end if
355
;      }
356
;   }
357
	ret
358
endp
359
360
 
361
align 4
362
onebppswaptable db 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,\
363
   0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,\
364
   0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,\
365
   0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,\
366
   0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,\
367
   0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,\
368
   0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,\
369
   0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,\
370
   0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,\
371
   0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,\
372
   0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,\
373
   0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,\
374
   0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,\
375
   0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,\
376
   0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,\
377
   0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,\
378
   0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,\
379
   0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,\
380
   0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,\
381
   0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,\
382
   0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,\
383
   0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,\
384
   0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,\
385
   0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,\
386
   0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,\
387
   0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,\
388
   0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,\
389
   0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,\
390
   0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,\
391
   0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,\
392
   0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,\
393
   0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
394
395
 
396
twobppswaptable db 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,\
397
   0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,\
398
   0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,\
399
   0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,\
400
   0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,\
401
   0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,\
402
   0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,\
403
   0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,\
404
   0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,\
405
   0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,\
406
   0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,\
407
   0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,\
408
   0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,\
409
   0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,\
410
   0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,\
411
   0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,\
412
   0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,\
413
   0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,\
414
   0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,\
415
   0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,\
416
   0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,\
417
   0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,\
418
   0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,\
419
   0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,\
420
   0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,\
421
   0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,\
422
   0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,\
423
   0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,\
424
   0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,\
425
   0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,\
426
   0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,\
427
   0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
428
429
 
430
fourbppswaptable db 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,\
431
   0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,\
432
   0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,\
433
   0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,\
434
   0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,\
435
   0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,\
436
   0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,\
437
   0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,\
438
   0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,\
439
   0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,\
440
   0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,\
441
   0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,\
442
   0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,\
443
   0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,\
444
   0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,\
445
   0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,\
446
   0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,\
447
   0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,\
448
   0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,\
449
   0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,\
450
   0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,\
451
   0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,\
452
   0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,\
453
   0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,\
454
   0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,\
455
   0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,\
456
   0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,\
457
   0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,\
458
   0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,\
459
   0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,\
460
   0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,\
461
   0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
462
end if ;PACKSWAP || WRITE_PACKSWAP
463
464
 
465
;void (png_row_infop row_info, bytep row)
466
align 4
467
proc png_do_packswap uses eax edx edi esi, row_info:dword, row:dword
468
	png_debug 1, 'in png_do_packswap'
469
470
 
471
	cmp byte[eax+png_row_info.bit_depth],8
472
	jge .end_f ;if (..<..)
473
		;edi = rp
474
		;esi = table
475
476
 
477
		mov edi,[row]
478
		add edx,edi
479
480
 
481
		jne @f ;if (..==..)
482
			mov esi,onebppswaptable
483
			jmp .cycle0
484
		@@:
485
		cmp byte[eax+png_row_info.bit_depth],2
486
		jne @f ;else if (..==..)
487
			mov esi,twobppswaptable
488
			jmp .cycle0
489
		@@:
490
		cmp byte[eax+png_row_info.bit_depth],4
491
		jne .end_f ;else if (..==..)
492
			mov esi,fourbppswaptable
493
align 4
494
		.cycle0: ;for (..=..;..<..;..)
495
			cmp edi,edx
496
			jge .end_f
497
			movzx eax,byte[edi]
498
			mov al,byte[esi+eax]
499
			stosb ;*rp = table[*rp]
500
			jmp .cycle0
501
.end_f:
502
	ret
503
endp
504
505
 
506
; somewhat weird combination of flags to determine what to do.  All the calls
507
; to png_do_strip_filler are changed in 1.5.2 to call this instead with the
508
; correct arguments.
509
510
 
511
; end (not in the middle) of each pixel.
512
513
 
514
align 4
515
proc png_do_strip_channel, row_info:dword, row:dword, at_start:dword
516
;   bytep sp = row; /* source pointer */
517
;   bytep dp = row; /* destination pointer */
518
;   bytep ep = row + row_info->rowbytes; /* One beyond end of row */
519
520
 
521
	; it is copied to.  ep always points just beyond the end of the row, so
522
	; the loop simply copies (channels-1) channels until sp reaches ep.
523
524
 
525
	;            nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
526
527
 
528
 
529
;   if (row_info->channels == 2)
530
;   {
531
;      if (row_info->bit_depth == 8)
532
;      {
533
;         if (at_start != 0) /* Skip initial filler */
534
;            ++sp;
535
;         else          /* Skip initial channel and, for sp, the filler */
536
;            sp += 2, ++dp;
537
538
 
539
;         while (sp < ep)
540
;            *dp++ = *sp, sp += 2;
541
542
 
543
;      }
544
545
 
546
;      {
547
;         if (at_start != 0) /* Skip initial filler */
548
;            sp += 2;
549
;         else          /* Skip initial channel and, for sp, the filler */
550
;            sp += 4, dp += 2;
551
552
 
553
;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
554
555
 
556
;      }
557
558
 
559
;         return; /* bad bit depth */
560
561
 
562
563
 
564
;      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
565
;         row_info->color_type = PNG_COLOR_TYPE_GRAY;
566
;   }
567
568
 
569
;   else if (row_info->channels == 4)
570
;   {
571
;      if (row_info->bit_depth == 8)
572
;      {
573
;         if (at_start != 0) /* Skip initial filler */
574
;            ++sp;
575
;         else          /* Skip initial channels and, for sp, the filler */
576
;            sp += 4, dp += 3;
577
578
 
579
;         while (sp < ep)
580
;            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
581
582
 
583
;      }
584
585
 
586
;      {
587
;         if (at_start != 0) /* Skip initial filler */
588
;            sp += 2;
589
;         else          /* Skip initial channels and, for sp, the filler */
590
;            sp += 8, dp += 6;
591
592
 
593
;         {
594
;            /* Copy 6 bytes, skip 2 */
595
;            *dp++ = *sp++, *dp++ = *sp++;
596
;            *dp++ = *sp++, *dp++ = *sp++;
597
;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
598
;         }
599
600
 
601
;      }
602
603
 
604
;         return; /* bad bit depth */
605
606
 
607
608
 
609
;      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
610
;         row_info->color_type = PNG_COLOR_TYPE_RGB;
611
;   }
612
613
 
614
;      return; /* The filler channel has gone already */
615
616
 
617
;   row_info->rowbytes = dp-row;
618
	ret
619
endp
620
621
 
622
;void (png_row_infop row_info, bytep row)
623
align 4
624
proc png_do_bgr, row_info:dword, row:dword
625
	png_debug 1, 'in png_do_bgr'
626
627
 
628
;   {
629
;      uint_32 row_width = row_info->width;
630
;      if (row_info->bit_depth == 8)
631
;      {
632
;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
633
;         {
634
;            bytep rp;
635
;            uint_32 i;
636
637
 
638
;            {
639
;               byte save = *rp;
640
;               *rp = *(rp + 2);
641
;               *(rp + 2) = save;
642
;            }
643
;         }
644
645
 
646
;         {
647
;            bytep rp;
648
;            uint_32 i;
649
650
 
651
;            {
652
;               byte save = *rp;
653
;               *rp = *(rp + 2);
654
;               *(rp + 2) = save;
655
;            }
656
;         }
657
;      }
658
659
 
660
;      else if (row_info->bit_depth == 16)
661
;      {
662
;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
663
;         {
664
;            bytep rp;
665
;            uint_32 i;
666
667
 
668
;            {
669
;               byte save = *rp;
670
;               *rp = *(rp + 4);
671
;               *(rp + 4) = save;
672
;               save = *(rp + 1);
673
;               *(rp + 1) = *(rp + 5);
674
;               *(rp + 5) = save;
675
;            }
676
;         }
677
678
 
679
;         {
680
;            bytep rp;
681
;            uint_32 i;
682
683
 
684
;            {
685
;               byte save = *rp;
686
;               *rp = *(rp + 4);
687
;               *(rp + 4) = save;
688
;               save = *(rp + 1);
689
;               *(rp + 1) = *(rp + 5);
690
;               *(rp + 5) = save;
691
;            }
692
;         }
693
;      }
694
end if
695
;   }
696
	ret
697
endp
698
699
 
700
;void (png_structrp png_ptr, png_row_infop row_info)
701
align 4
702
proc png_do_check_palette_indexes, png_ptr:dword, row_info:dword
703
;   if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
704
;      png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
705
;   {
706
	; Calculations moved outside switch in an attempt to stop different
707
	; compiler warnings.  'padding' is in *bits* within the last byte, it is
708
	; an 'int' because pixel_depth becomes an 'int' in the expression below,
709
	; and this calculation is used because it avoids warnings that other
710
	; forms produced on either GCC or MSVC.
711
712
 
713
;      bytep rp = png_ptr->row_buf + row_info->rowbytes;
714
715
 
716
;      {
717
;         case 1:
718
;         {
719
;            /* in this case, all bytes must be 0 so we don't need
720
	; to unpack the pixels except for the rightmost one.
721
722
 
723
;            {
724
;              if ((*rp >> padding) != 0)
725
;                 png_ptr->num_palette_max = 1;
726
;              padding = 0;
727
;            }
728
729
 
730
;         }
731
732
 
733
;         {
734
;            for (; rp > png_ptr->row_buf; rp--)
735
;            {
736
;              int i = ((*rp >> padding) & 0x03);
737
738
 
739
;                 png_ptr->num_palette_max = i;
740
741
 
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
 
760
;         }
761
762
 
763
;         {
764
;            for (; rp > png_ptr->row_buf; rp--)
765
;            {
766
;              int i = ((*rp >> padding) & 0x0f);
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
 
780
;         }
781
782
 
783
;         {
784
;            for (; rp > png_ptr->row_buf; rp--)
785
;            {
786
;               if (*rp > png_ptr->num_palette_max)
787
;                  png_ptr->num_palette_max = (int) *rp;
788
;            }
789
790
 
791
;         }
792
793
 
794
;            break;
795
;      }
796
;   }
797
	ret
798
endp
799
800
 
801
align 4
802
proc png_set_user_transform_info uses eax edi, png_ptr:dword, user_transform_ptr:dword, user_transform_depth:dword, user_transform_channels:dword
803
	png_debug 1, 'in png_set_user_transform_info'
804
805
 
806
	cmp edi,0
807
	je .end_f
808
809
 
810
	mov eax,[edi+png_struct.mode]
811
	and eax,PNG_IS_READ_STRUCT
812
	jz @f
6797 IgorA 813
	mov eax,[edi+png_struct.flags]
6733 IgorA 814
	and eax,PNG_FLAG_ROW_INIT
815
	jz @f ;if (..!=0 && ..!=0)
6797 IgorA 816
		cStr ,'info change after png_start_read_image or png_read_update_info'
6733 IgorA 817
		stdcall png_app_error, edi, eax
6779 IgorA 818
		jmp .end_f
6733 IgorA 819
	@@:
820
end if
821
822
 
823
	mov [edi+png_struct.user_transform_ptr],eax
824
	mov eax,[user_transform_depth]
825
	mov [edi+png_struct.user_transform_depth],al
826
	mov eax,[user_transform_channels]
827
	mov [edi+png_struct.user_transform_channels],al
828
.end_f:
829
	ret
830
endp
831
832
 
833
; the user transform functions.  The application should free any memory
834
; associated with this pointer before png_write_destroy and png_read_destroy
835
; are called.
836
837
 
6797 IgorA 838
align 4
6733 IgorA 839
proc png_get_user_transform_ptr, png_ptr:dword
840
	mov eax,[png_ptr]
841
	cmp eax,0
842
	je @f
843
		mov eax,[eax+png_struct.user_transform_ptr]
844
	@@:
845
	ret
846
endp
847
848
 
6797 IgorA 849
align 4
6733 IgorA 850
proc png_get_current_row_number, png_ptr:dword
851
	; See the comments in png.inc - this is the sub-image row when reading an
852
	; interlaced image.
853
854
 
855
	cmp eax,0
856
	je @f ;if (..!=0)
857
		mov eax,[eax+png_struct.row_number]
858
		jmp .end_f
859
	@@:
860
	mov eax,PNG_UINT_32_MAX ;help the app not to fail silently
861
.end_f:
862
	ret
863
endp
864
865
 
6797 IgorA 866
align 4
6733 IgorA 867
proc png_get_current_pass_number, png_ptr:dword
868
	mov eax,[png_ptr]
869
	cmp eax,0
870
	je @f ;if (..!=0)
871
		mov eax,[eax+png_struct.pass]
872
		jmp .end_f
873
	@@:
874
	mov eax,8 ;invalid
875
.end_f:
876
	ret
877
endp
878
end if
879
>