Subversion Repositories Kolibri OS

Rev

Rev 1897 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1897 Rev 3928
Line 1... Line 1...
1
/* pngwtran.c - transforms the data in a row for PNG writers
1
/* pngwtran.c - transforms the data in a row for PNG writers
2
 *
2
 *
3
 * Last changed in libpng 1.5.0 [January 6, 2011]
3
 * Last changed in libpng 1.6.0 [February 14, 2013]
4
 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
4
 * Copyright (c) 1998-2013 Glenn Randers-Pehrson
5
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
5
 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
6
 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7
 *
7
 *
8
 * This code is released under the libpng license.
8
 * This code is released under the libpng license.
9
 * For conditions of distribution and use, see the disclaimer
9
 * For conditions of distribution and use, see the disclaimer
Line 13... Line 13...
13
#include "pngpriv.h"
13
#include "pngpriv.h"
Line 14... Line 14...
14
 
14
 
Line -... Line 15...
-
 
15
#ifdef PNG_WRITE_SUPPORTED
15
#ifdef PNG_WRITE_SUPPORTED
16
 
16
 
17
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
17
/* Transform the data according to the user's wishes.  The order of
18
/* Transform the data according to the user's wishes.  The order of
18
 * transformations is significant.
19
 * transformations is significant.
19
 */
20
 */
20
void /* PRIVATE */
21
void /* PRIVATE */
21
png_do_write_transformations(png_structp png_ptr)
22
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
Line 22... Line 23...
22
{
23
{
23
   png_debug(1, "in png_do_write_transformations");
24
   png_debug(1, "in png_do_write_transformations");
Line 30... Line 31...
30
      if (png_ptr->write_user_transform_fn != NULL)
31
      if (png_ptr->write_user_transform_fn != NULL)
31
         (*(png_ptr->write_user_transform_fn)) /* User write transform
32
         (*(png_ptr->write_user_transform_fn)) /* User write transform
32
                                                 function */
33
                                                 function */
33
             (png_ptr,                    /* png_ptr */
34
             (png_ptr,  /* png_ptr */
34
             &(png_ptr->row_info),           /* row_info: */
35
             row_info,  /* row_info: */
35
                /*  png_uint_32 width;       width of row */
36
                /*  png_uint_32 width;       width of row */
36
                /*  png_size_t rowbytes;     number of bytes in row */
37
                /*  png_size_t rowbytes;     number of bytes in row */
37
                /*  png_byte color_type;     color type of pixels */
38
                /*  png_byte color_type;     color type of pixels */
38
                /*  png_byte bit_depth;      bit depth of samples */
39
                /*  png_byte bit_depth;      bit depth of samples */
39
                /*  png_byte channels;       number of channels (1-4) */
40
                /*  png_byte channels;       number of channels (1-4) */
40
                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
41
                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
Line 42... Line 43...
42
#endif
43
#endif
43
 
44
 
Line 44... Line 45...
44
#ifdef PNG_WRITE_FILLER_SUPPORTED
45
#ifdef PNG_WRITE_FILLER_SUPPORTED
45
   if (png_ptr->transformations & PNG_FILLER)
46
   if (png_ptr->transformations & PNG_FILLER)
46
      png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
47
      png_do_strip_channel(row_info, png_ptr->row_buf + 1,
47
          png_ptr->flags);
48
         !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
48
#endif
49
#endif
Line 49... Line 50...
49
 
50
 
50
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
51
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
51
   if (png_ptr->transformations & PNG_PACKSWAP)
52
   if (png_ptr->transformations & PNG_PACKSWAP)
52
      png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
53
      png_do_packswap(row_info, png_ptr->row_buf + 1);
Line 53... Line 54...
53
#endif
54
#endif
54
 
55
 
55
#ifdef PNG_WRITE_PACK_SUPPORTED
56
#ifdef PNG_WRITE_PACK_SUPPORTED
56
   if (png_ptr->transformations & PNG_PACK)
57
   if (png_ptr->transformations & PNG_PACK)
57
      png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
58
      png_do_pack(row_info, png_ptr->row_buf + 1,
Line 58... Line 59...
58
          (png_uint_32)png_ptr->bit_depth);
59
          (png_uint_32)png_ptr->bit_depth);
59
#endif
60
#endif
60
 
61
 
61
#ifdef PNG_WRITE_SWAP_SUPPORTED
62
#ifdef PNG_WRITE_SWAP_SUPPORTED
Line 62... Line 63...
62
   if (png_ptr->transformations & PNG_SWAP_BYTES)
63
   if (png_ptr->transformations & PNG_SWAP_BYTES)
63
      png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
64
      png_do_swap(row_info, png_ptr->row_buf + 1);
64
#endif
65
#endif
65
 
66
 
66
#ifdef PNG_WRITE_SHIFT_SUPPORTED
67
#ifdef PNG_WRITE_SHIFT_SUPPORTED
Line 67... Line 68...
67
   if (png_ptr->transformations & PNG_SHIFT)
68
   if (png_ptr->transformations & PNG_SHIFT)
68
      png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
69
      png_do_shift(row_info, png_ptr->row_buf + 1,
69
          &(png_ptr->shift));
70
          &(png_ptr->shift));
70
#endif
71
#endif
Line 71... Line 72...
71
 
72
 
72
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
73
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
73
   if (png_ptr->transformations & PNG_SWAP_ALPHA)
74
   if (png_ptr->transformations & PNG_SWAP_ALPHA)
74
      png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
75
      png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
Line 75... Line 76...
75
#endif
76
#endif
76
 
77
 
77
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
78
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
78
   if (png_ptr->transformations & PNG_INVERT_ALPHA)
79
   if (png_ptr->transformations & PNG_INVERT_ALPHA)
Line 79... Line 80...
79
      png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
80
      png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
80
#endif
81
#endif
81
 
82
 
82
#ifdef PNG_WRITE_BGR_SUPPORTED
83
#ifdef PNG_WRITE_BGR_SUPPORTED
83
   if (png_ptr->transformations & PNG_BGR)
84
   if (png_ptr->transformations & PNG_BGR)
Line 84... Line 85...
84
      png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
85
      png_do_bgr(row_info, png_ptr->row_buf + 1);
85
#endif
86
#endif
Line 284... Line 285...
284
      if (row_info->bit_depth < 8)
285
      if (row_info->bit_depth < 8)
285
      {
286
      {
286
         png_bytep bp = row;
287
         png_bytep bp = row;
287
         png_size_t i;
288
         png_size_t i;
288
         png_byte mask;
289
         unsigned int mask;
289
         png_size_t row_bytes = row_info->rowbytes;
290
         png_size_t row_bytes = row_info->rowbytes;
290
 
291
 
Line 291... Line 292...
291
         if (bit_depth->gray == 1 && row_info->bit_depth == 2)
292
         if (bit_depth->gray == 1 && row_info->bit_depth == 2)
292
            mask = 0x55;
293
            mask = 0x55;
Line 298... Line 299...
298
            mask = 0xff;
299
            mask = 0xff;
299
 
300
 
Line 300... Line 301...
300
         for (i = 0; i < row_bytes; i++, bp++)
301
         for (i = 0; i < row_bytes; i++, bp++)
301
         {
302
         {
302
            png_uint_16 v;
-
 
303
            int j;
303
            int j;
-
 
304
            unsigned int v, out;
Line 304... Line 305...
304
 
305
 
305
            v = *bp;
306
            v = *bp;
Line 306... Line 307...
306
            *bp = 0;
307
            out = 0;
307
 
308
 
308
            for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
309
            for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
309
            {
310
            {
Line 310... Line 311...
310
               if (j > 0)
311
               if (j > 0)
311
                  *bp |= (png_byte)((v << j) & 0xff);
312
                  out |= v << j;
312
 
313
 
-
 
314
               else
-
 
315
                  out |= (v >> (-j)) & mask;
313
               else
316
            }
314
                  *bp |= (png_byte)((v >> (-j)) & mask);
317
 
Line 315... Line 318...
315
            }
318
            *bp = (png_byte)(out & 0xff);
316
         }
319
         }
Line 324... Line 327...
324
 
327
 
Line 325... Line 328...
325
         for (i = 0; i < istop; i++, bp++)
328
         for (i = 0; i < istop; i++, bp++)
326
         {
329
         {
Line 327... Line 330...
327
 
330
 
328
            png_uint_16 v;
331
            const unsigned int c = i%channels;
329
            int j;
332
            int j;
Line 330... Line 333...
330
            int c = (int)(i%channels);
333
            unsigned int v, out;
331
 
334
 
Line 332... Line 335...
332
            v = *bp;
335
            v = *bp;
333
            *bp = 0;
336
            out = 0;
334
 
337
 
335
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
338
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
Line 336... Line 339...
336
            {
339
            {
337
               if (j > 0)
340
               if (j > 0)
338
                  *bp |= (png_byte)((v << j) & 0xff);
341
                  out |= v << j;
-
 
342
 
-
 
343
               else
339
 
344
                  out |= v >> (-j);
340
               else
345
            }
Line 341... Line 346...
341
                  *bp |= (png_byte)((v >> (-j)) & 0xff);
346
 
342
            }
347
            *bp = (png_byte)(out & 0xff);
Line 350... Line 355...
350
         png_uint_32 istop = channels * row_info->width;
355
         png_uint_32 istop = channels * row_info->width;
351
 
356
 
Line 352... Line 357...
352
         for (bp = row, i = 0; i < istop; i++)
357
         for (bp = row, i = 0; i < istop; i++)
353
         {
358
         {
354
            int c = (int)(i%channels);
359
            const unsigned int c = i%channels;
355
            png_uint_16 value, v;
-
 
356
            int j;
360
            int j;
-
 
361
            unsigned int value, v;
Line 357... Line 362...
357
 
362
 
358
            v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
363
            v = png_get_uint_16(bp);
Line 359... Line 364...
359
            value = 0;
364
            value = 0;
360
 
365
 
361
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
366
            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
362
            {
367
            {
Line 363... Line 368...
363
               if (j > 0)
368
               if (j > 0)
364
                  value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
369
                  value |= v << j;
365
 
370
 
366
               else
371
               else
367
                  value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
372
                  value |= v >> (-j);
368
            }
373
            }
369
            *bp++ = (png_byte)(value >> 8);
374
            *bp++ = (png_byte)((value >> 8) & 0xff);
370
            *bp++ = (png_byte)(value & 0xff);
375
            *bp++ = (png_byte)(value & 0xff);
371
         }
376
         }
Line 561... Line 566...
561
      }
566
      }
562
   }
567
   }
563
}
568
}
564
#endif
569
#endif
565
 
570
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
-
 
571
 
Line 566... Line 572...
566
#ifdef PNG_MNG_FEATURES_SUPPORTED
572
#ifdef PNG_MNG_FEATURES_SUPPORTED
567
/* Undoes intrapixel differencing  */
573
/* Undoes intrapixel differencing  */
568
void /* PRIVATE */
574
void /* PRIVATE */
569
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
575
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)