Subversion Repositories Kolibri OS

Rev

Rev 6779 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8341 dunkaist 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
; row_info bit depth should be 8 (one pixel per byte).  The channels
15
; should be 1 (this only happens on grayscale and paletted images).
16
17
 
18
align 4
19
proc png_do_pack, row_info:dword, row:dword, bit_depth:dword
20
	png_debug 1, 'in png_do_pack'
21
22
 
23
;      row_info->channels == 1)
24
;   {
25
;      switch ((int)bit_depth)
26
;      {
27
;         case 1:
28
;         {
29
;            bytep sp, dp;
30
;            int mask, v;
31
;            uint_32 i;
32
;            uint_32 row_width = row_info->width;
33
34
 
35
;            dp = row;
36
;            mask = 0x80;
37
;            v = 0;
38
39
 
40
;            {
41
;               if (*sp != 0)
42
;                  v |= mask;
43
44
 
45
46
 
47
;                  mask >>= 1;
48
49
 
50
;               {
51
;                  mask = 0x80;
52
;                  *dp = (byte)v;
53
;                  dp++;
54
;                  v = 0;
55
;               }
56
;            }
57
58
 
59
;               *dp = (byte)v;
60
61
 
62
;         }
63
64
 
65
;         {
66
;            bytep sp, dp;
67
;            unsigned int shift;
68
;            int v;
69
;            uint_32 i;
70
;            uint_32 row_width = row_info->width;
71
72
 
73
;            dp = row;
74
;            shift = 6;
75
;            v = 0;
76
77
 
78
;            {
79
;               byte value;
80
81
 
82
;               v |= (value << shift);
83
84
 
85
;               {
86
;                  shift = 6;
87
;                  *dp = (byte)v;
88
;                  dp++;
89
;                  v = 0;
90
;               }
91
92
 
93
;                  shift -= 2;
94
;
95
;               sp++;
96
;            }
97
98
 
99
;               *dp = (byte)v;
100
101
 
102
;         }
103
104
 
105
;         {
106
;            bytep sp, dp;
107
;            unsigned int shift;
108
;            int v;
109
;            uint_32 i;
110
;            uint_32 row_width = row_info->width;
111
112
 
113
;            dp = row;
114
;            shift = 4;
115
;            v = 0;
116
117
 
118
;            {
119
;               byte value;
120
121
 
122
;               v |= (value << shift);
123
124
 
125
;               {
126
;                  shift = 4;
127
;                  *dp = (byte)v;
128
;                  dp++;
129
;                  v = 0;
130
;               }
131
132
 
133
;                  shift -= 4;
134
;
135
;               sp++;
136
;            }
137
138
 
139
;               *dp = (byte)v;
140
141
 
142
;         }
143
144
 
145
;            break;
146
;      }
147
148
 
149
;      row_info->pixel_depth = (byte)(bit_depth * row_info->channels);
150
;      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
151
;          row_info->width);
152
;   }
153
	ret
154
endp
155
156
 
157
; true number of bits in bit_depth.  The row should be packed
158
; according to row_info->bit_depth.  Thus, if you had a row of
159
; bit depth 4, but the pixels only had values from 0 to 7, you
160
; would pass 3 as bit_depth, and this routine would translate the
161
; data to 0 to 15.
162
163
 
164
align 4
165
proc png_do_shift, row_info:dword, row:dword, bit_depth:dword
166
	png_debug 1, 'in png_do_shift'
167
168
 
169
;   {
170
;      int shift_start[4], shift_dec[4];
171
;      int channels = 0;
172
173
 
174
;      {
175
;         shift_start[channels] = row_info->bit_depth - bit_depth->red;
176
;         shift_dec[channels] = bit_depth->red;
177
;         channels++;
178
179
 
180
;         shift_dec[channels] = bit_depth->green;
181
;         channels++;
182
183
 
184
;         shift_dec[channels] = bit_depth->blue;
185
;         channels++;
186
;      }
187
188
 
189
;      {
190
;         shift_start[channels] = row_info->bit_depth - bit_depth->gray;
191
;         shift_dec[channels] = bit_depth->gray;
192
;         channels++;
193
;      }
194
195
 
196
;      {
197
;         shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
198
;         shift_dec[channels] = bit_depth->alpha;
199
;         channels++;
200
;      }
201
202
 
203
;      if (row_info->bit_depth < 8)
204
;      {
205
;         bytep bp = row;
206
;         png_size_t i;
207
;         unsigned int mask;
208
;         png_size_t row_bytes = row_info->rowbytes;
209
210
 
211
;            mask = 0x55;
212
213
 
214
;            mask = 0x11;
215
216
 
217
;            mask = 0xff;
218
219
 
220
;         {
221
;            int j;
222
;            unsigned int v, out;
223
224
 
225
;            out = 0;
226
227
 
228
;            {
229
;               if (j > 0)
230
;                  out |= v << j;
231
232
 
233
;                  out |= (v >> (-j)) & mask;
234
;            }
235
236
 
237
;         }
238
;      }
239
240
 
241
;      {
242
;         bytep bp = row;
243
;         uint_32 i;
244
;         uint_32 istop = channels * row_info->width;
245
246
 
247
;         {
248
249
 
250
;            int j;
251
;            unsigned int v, out;
252
253
 
254
;            out = 0;
255
256
 
257
;            {
258
;               if (j > 0)
259
;                  out |= v << j;
260
261
 
262
;                  out |= v >> (-j);
263
;            }
264
265
 
266
;         }
267
;      }
268
269
 
270
;      {
271
;         bytep bp;
272
;         uint_32 i;
273
;         uint_32 istop = channels * row_info->width;
274
275
 
276
;         {
277
;            const unsigned int c = i%channels;
278
;            int j;
279
;            unsigned int value, v;
280
281
 
282
;            value = 0;
283
284
 
285
;            {
286
;               if (j > 0)
287
;                  value |= v << j;
288
289
 
290
;                  value |= v >> (-j);
291
;            }
292
;            *bp++ = (byte)((value >> 8) & 0xff);
293
;            *bp++ = (byte)(value & 0xff);
294
;         }
295
;      }
296
;   }
297
	ret
298
endp
299
300
 
301
align 4
302
proc png_do_write_swap_alpha, row_info:dword, row:dword
303
	png_debug 1, 'in png_do_write_swap_alpha'
304
305
 
306
;      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
307
;      {
308
;         if (row_info->bit_depth == 8)
309
;         {
310
		; This converts from ARGB to RGBA
311
;            bytep sp, dp;
312
;            uint_32 i;
313
;            uint_32 row_width = row_info->width;
314
315
 
316
;            {
317
;               byte save = *(sp++);
318
;               *(dp++) = *(sp++);
319
;               *(dp++) = *(sp++);
320
;               *(dp++) = *(sp++);
321
;               *(dp++) = save;
322
;            }
323
;         }
324
325
 
326
;         else
327
;         {
328
		; This converts from AARRGGBB to RRGGBBAA
329
;            bytep sp, dp;
330
;            uint_32 i;
331
;            uint_32 row_width = row_info->width;
332
;
333
;            for (i = 0, sp = dp = row; i < row_width; i++)
334
;            {
335
;               byte save[2];
336
;               save[0] = *(sp++);
337
;               save[1] = *(sp++);
338
;               *(dp++) = *(sp++);
339
;               *(dp++) = *(sp++);
340
;               *(dp++) = *(sp++);
341
;               *(dp++) = *(sp++);
342
;               *(dp++) = *(sp++);
343
;               *(dp++) = *(sp++);
344
;               *(dp++) = save[0];
345
;               *(dp++) = save[1];
346
;            }
347
;         }
348
end if ;WRITE_16BIT
349
;      }
350
;
351
;      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
352
;      {
353
;         if (row_info->bit_depth == 8)
354
;         {
355
		; This converts from AG to GA
356
;            bytep sp, dp;
357
;            uint_32 i;
358
;            uint_32 row_width = row_info->width;
359
360
 
361
;            {
362
;               byte save = *(sp++);
363
;               *(dp++) = *(sp++);
364
;               *(dp++) = save;
365
;            }
366
;         }
367
368
 
369
;         else
370
;         {
371
	; This converts from AAGG to GGAA
372
;            bytep sp, dp;
373
;            uint_32 i;
374
;            uint_32 row_width = row_info->width;
375
376
 
377
;            {
378
;               byte save[2];
379
;               save[0] = *(sp++);
380
;               save[1] = *(sp++);
381
;               *(dp++) = *(sp++);
382
;               *(dp++) = *(sp++);
383
;               *(dp++) = save[0];
384
;               *(dp++) = save[1];
385
;            }
386
;         }
387
end if ;WRITE_16BIT
388
;      }
389
;   }
390
	ret
391
endp
392
393
 
394
align 4
395
proc png_do_write_invert_alpha, row_info:dword, row:dword
396
	png_debug 1, 'in png_do_write_invert_alpha'
397
398
 
399
;      {
400
;         if (row_info->bit_depth == 8)
401
;         {
402
	; This inverts the alpha channel in RGBA
403
;            bytep sp, dp;
404
;            uint_32 i;
405
;            uint_32 row_width = row_info->width;
406
407
 
408
;            {
409
	; Does nothing
410
	;*(dp++) = *(sp++);
411
	;*(dp++) = *(sp++);
412
	;*(dp++) = *(sp++);
413
414
 
415
;               *dp = (byte)(255 - *(sp++));
416
;            }
417
;         }
418
419
 
420
;         else
421
;         {
422
		; This inverts the alpha channel in RRGGBBAA
423
;            bytep sp, dp;
424
;            uint_32 i;
425
;            uint_32 row_width = row_info->width;
426
427
 
428
;            {
429
	; Does nothing
430
	;*(dp++) = *(sp++);
431
	;*(dp++) = *(sp++);
432
	;*(dp++) = *(sp++);
433
	;*(dp++) = *(sp++);
434
	;*(dp++) = *(sp++);
435
	;*(dp++) = *(sp++);
436
437
 
438
;               *(dp++) = (byte)(255 - *(sp++));
439
;               *dp     = (byte)(255 - *(sp++));
440
;            }
441
;         }
442
;end if /* WRITE_16BIT */
443
;      }
444
445
 
446
;      {
447
;         if (row_info->bit_depth == 8)
448
;         {
449
		; This inverts the alpha channel in GA
450
;            bytep sp, dp;
451
;            uint_32 i;
452
;            uint_32 row_width = row_info->width;
453
;
454
;            for (i = 0, sp = dp = row; i < row_width; i++)
455
;            {
456
;               *(dp++) = *(sp++);
457
;               *(dp++) = (byte)(255 - *(sp++));
458
;            }
459
;         }
460
461
 
462
;         else
463
;         {
464
	; This inverts the alpha channel in GGAA
465
;            bytep sp, dp;
466
;            uint_32 i;
467
;            uint_32 row_width = row_info->width;
468
;
469
;            for (i = 0, sp = dp = row; i < row_width; i++)
470
;            {
471
	; Does nothing
472
	;*(dp++) = *(sp++);
473
	;*(dp++) = *(sp++);
474
475
 
476
;               *(dp++) = (byte)(255 - *(sp++));
477
;               *dp     = (byte)(255 - *(sp++));
478
;            }
479
;         }
480
end if ;WRITE_16BIT
481
;      }
482
	ret
483
endp
484
485
 
486
; transformations is significant.
487
488
 
489
align 4
490
proc png_do_write_transformations uses eax ebx edi esi, png_ptr:dword, row_info:dword
491
	png_debug 1, 'in png_do_write_transformations'
492
493
 
494
	cmp edi,0
495
	je .end_f ;if (..==0) return
496
	mov esi,[row_info]
497
	mov ebx,[edi+png_struct.row_buf]
498
	inc ebx ;start of pixel data for row
499
500
 
501
	mov eax,[edi+png_struct.transformations]
502
	and eax,PNG_USER_TRANSFORM
503
	jz @f ;if (..!=0)
504
	mov eax,[edi+png_struct.write_user_transform_fn]
505
	test eax,eax
506
	jz @f ;if (..!=0)
507
		stdcall eax, edi, esi, ebx ;User write transform function
508
		; row_info:
509
		;  uint_32 width    ;width of row
510
		;  png_size_t rowbytes ;number of bytes in row
511
		;  byte  color_type ;color type of pixels
512
		;  byte  bit_depth  ;bit depth of samples
513
		;  byte  channels   ;number of channels (1-4)
514
		;  byte  pixel_depth ;bits per pixel (depth*channels)
515
	@@:
516
end if
517
518
 
519
	mov eax,[edi+png_struct.transformations]
520
	and eax,PNG_FILLER
521
	jz @f ;if (..!=0)
522
		mov eax,[edi+png_struct.flags]
523
		and eax,PNG_FLAG_FILLER_AFTER
524
		not eax
525
		stdcall png_do_strip_channel, esi, ebx, eax
526
	@@:
527
end if
528
529
 
530
	mov eax,[edi+png_struct.transformations]
531
	and eax,PNG_PACKSWAP
532
	jz @f ;if (..!=0)
533
		stdcall png_do_packswap, esi, ebx
534
	@@:
535
end if
536
537
 
538
	mov eax,[edi+png_struct.transformations]
539
	and eax,PNG_PACK
540
	jz @f ;if (..!=0)
541
		movzx eax,byte[edi+png_struct.bit_depth]
542
		stdcall png_do_pack, esi, ebx, eax
543
	@@:
544
end if
545
546
 
547
if PNG_16BIT_SUPPORTED eq 1
548
	mov eax,[edi+png_struct.transformations]
549
	and eax,PNG_SWAP_BYTES
550
	jz @f ;if (..!=0)
551
		stdcall png_do_swap, esi, ebx
552
	@@:
553
end if
554
end if
555
556
 
557
	mov eax,[edi+png_struct.transformations]
558
	and eax,PNG_SHIFT
559
	jz @f ;if (..!=0)
560
		mov eax,edi
561
		add eax,png_struct.shift
562
		stdcall png_do_shift, esi, ebx, eax
563
	@@:
564
end if
565
566
 
567
	mov eax,[edi+png_struct.transformations]
568
	and eax,PNG_SWAP_ALPHA
569
	jz @f ;if (..!=0)
570
		stdcall png_do_write_swap_alpha, esi, ebx
571
	@@:
572
end if
573
574
 
575
	mov eax,[edi+png_struct.transformations]
576
	and eax,PNG_INVERT_ALPHA
577
	jz @f ;if (..!=0)
578
		stdcall png_do_write_invert_alpha, esi, ebx
579
	@@:
580
end if
581
582
 
583
	mov eax,[edi+png_struct.transformations]
584
	and eax,PNG_BGR
585
	jz @f ;if (..!=0)
586
		stdcall png_do_bgr, esi, ebx
587
	@@:
588
end if
589
590
 
591
	mov eax,[edi+png_struct.transformations]
592
	and eax,PNG_INVERT_MONO
593
	jz @f ;if (..!=0)
594
		stdcall png_do_invert, esi, ebx
595
	@@:
596
end if
597
.end_f:
598
	ret
599
endp
600