Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1897 serge 1
 
2
 *
3
 * Last changed in libpng 1.5.1 [February 3, 2011]
4
 * Copyright (c) 1998-2011 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
 * This code is released under the libpng license.
9
 * For conditions of distribution and use, see the disclaimer
10
 * and license in png.h
11
 *
12
 */
13
14
 
15
16
 
17
18
 
19
png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr,
20
    png_uint_32 flag)
21
{
22
   if (png_ptr != NULL && info_ptr != NULL)
23
      return(info_ptr->valid & flag);
24
25
 
26
}
27
28
 
29
png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr)
30
{
31
   if (png_ptr != NULL && info_ptr != NULL)
32
      return(info_ptr->rowbytes);
33
34
 
35
}
36
37
 
38
png_bytepp PNGAPI
39
png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr)
40
{
41
   if (png_ptr != NULL && info_ptr != NULL)
42
      return(info_ptr->row_pointers);
43
44
 
45
}
46
#endif
47
48
 
49
/* Easy access to info, added in libpng-0.99 */
50
png_uint_32 PNGAPI
51
png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr)
52
{
53
   if (png_ptr != NULL && info_ptr != NULL)
54
      return info_ptr->width;
55
56
 
57
}
58
59
 
60
png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr)
61
{
62
   if (png_ptr != NULL && info_ptr != NULL)
63
      return info_ptr->height;
64
65
 
66
}
67
68
 
69
png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr)
70
{
71
   if (png_ptr != NULL && info_ptr != NULL)
72
      return info_ptr->bit_depth;
73
74
 
75
}
76
77
 
78
png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr)
79
{
80
   if (png_ptr != NULL && info_ptr != NULL)
81
      return info_ptr->color_type;
82
83
 
84
}
85
86
 
87
png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr)
88
{
89
   if (png_ptr != NULL && info_ptr != NULL)
90
      return info_ptr->filter_type;
91
92
 
93
}
94
95
 
96
png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr)
97
{
98
   if (png_ptr != NULL && info_ptr != NULL)
99
      return info_ptr->interlace_type;
100
101
 
102
}
103
104
 
105
png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr)
106
{
107
   if (png_ptr != NULL && info_ptr != NULL)
108
      return info_ptr->compression_type;
109
110
 
111
}
112
113
 
114
png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
115
{
116
#ifdef PNG_pHYs_SUPPORTED
117
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
118
      {
119
         png_debug1(1, "in %s retrieval function",
120
             "png_get_x_pixels_per_meter");
121
122
 
123
            return (info_ptr->x_pixels_per_unit);
124
      }
125
#endif
126
127
 
128
}
129
130
 
131
png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
132
{
133
#ifdef PNG_pHYs_SUPPORTED
134
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
135
   {
136
      png_debug1(1, "in %s retrieval function",
137
          "png_get_y_pixels_per_meter");
138
139
 
140
         return (info_ptr->y_pixels_per_unit);
141
   }
142
#endif
143
144
 
145
}
146
147
 
148
png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
149
{
150
#ifdef PNG_pHYs_SUPPORTED
151
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
152
   {
153
      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
154
155
 
156
          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
157
         return (info_ptr->x_pixels_per_unit);
158
   }
159
#endif
160
161
 
162
}
163
164
 
165
float PNGAPI
166
png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr)
167
{
168
#ifdef PNG_READ_pHYs_SUPPORTED
169
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
170
   {
171
      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
172
173
 
174
         return ((float)((float)info_ptr->y_pixels_per_unit
175
             /(float)info_ptr->x_pixels_per_unit));
176
   }
177
#endif
178
179
 
180
}
181
#endif
182
183
 
184
png_fixed_point PNGAPI
185
png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr,
186
    png_const_infop info_ptr)
187
{
188
#ifdef PNG_READ_pHYs_SUPPORTED
189
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
190
       && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
191
       && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
192
       && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
193
   {
194
      png_fixed_point res;
195
196
 
197
198
 
199
       * range of 0..2^31-1; otherwise the cast might overflow.
200
       */
201
      if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
202
          (png_int_32)info_ptr->x_pixels_per_unit))
203
         return res;
204
   }
205
#endif
206
207
 
208
}
209
#endif
210
211
 
212
png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
213
{
214
#ifdef PNG_oFFs_SUPPORTED
215
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
216
   {
217
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
218
219
 
220
         return (info_ptr->x_offset);
221
   }
222
#endif
223
224
 
225
}
226
227
 
228
png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
229
{
230
#ifdef PNG_oFFs_SUPPORTED
231
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
232
   {
233
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
234
235
 
236
         return (info_ptr->y_offset);
237
   }
238
#endif
239
240
 
241
}
242
243
 
244
png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
245
{
246
#ifdef PNG_oFFs_SUPPORTED
247
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
248
   {
249
      png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
250
251
 
252
         return (info_ptr->x_offset);
253
   }
254
#endif
255
256
 
257
}
258
259
 
260
png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
261
{
262
#ifdef PNG_oFFs_SUPPORTED
263
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
264
   {
265
      png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
266
267
 
268
         return (info_ptr->y_offset);
269
   }
270
#endif
271
272
 
273
}
274
275
 
276
static png_uint_32
277
ppi_from_ppm(png_uint_32 ppm)
278
{
279
#if 0
280
   /* The conversion is *(2.54/100), in binary (32 digits):
281
    * .00000110100000001001110101001001
282
    */
283
   png_uint_32 t1001, t1101;
284
   ppm >>= 1;                  /* .1 */
285
   t1001 = ppm + (ppm >> 3);   /* .1001 */
286
   t1101 = t1001 + (ppm >> 1); /* .1101 */
287
   ppm >>= 20;                 /* .000000000000000000001 */
288
   t1101 += t1101 >> 15;       /* .1101000000000001101 */
289
   t1001 >>= 11;               /* .000000000001001 */
290
   t1001 += t1001 >> 12;       /* .000000000001001000000001001 */
291
   ppm += t1001;               /* .000000000001001000001001001 */
292
   ppm += t1101;               /* .110100000001001110101001001 */
293
   return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
294
#else
295
   /* The argument is a PNG unsigned integer, so it is not permitted
296
    * to be bigger than 2^31.
297
    */
298
   png_fixed_point result;
299
   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
300
       5000))
301
      return result;
302
303
 
304
   return 0;
305
#endif
306
}
307
308
 
309
png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
310
{
311
   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
312
}
313
314
 
315
png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
316
{
317
   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
318
}
319
320
 
321
png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
322
{
323
   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
324
}
325
326
 
327
static png_fixed_point
328
png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
329
{
330
   /* Convert from metres * 1,000,000 to inches * 100,000, meters to
331
    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
332
    * Notice that this can overflow - a warning is output and 0 is
333
    * returned.
334
    */
335
   return png_muldiv_warn(png_ptr, microns, 500, 127);
336
}
337
338
 
339
png_get_x_offset_inches_fixed(png_structp png_ptr,
340
    png_const_infop info_ptr)
341
{
342
   return png_fixed_inches_from_microns(png_ptr,
343
       png_get_x_offset_microns(png_ptr, info_ptr));
344
}
345
#endif
346
347
 
348
png_fixed_point PNGAPI
349
png_get_y_offset_inches_fixed(png_structp png_ptr,
350
    png_const_infop info_ptr)
351
{
352
   return png_fixed_inches_from_microns(png_ptr,
353
       png_get_y_offset_microns(png_ptr, info_ptr));
354
}
355
#endif
356
357
 
358
float PNGAPI
359
png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
360
{
361
   /* To avoid the overflow do the conversion directly in floating
362
    * point.
363
    */
364
   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
365
}
366
#endif
367
368
 
369
float PNGAPI
370
png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
371
{
372
   /* To avoid the overflow do the conversion directly in floating
373
    * point.
374
    */
375
   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
376
}
377
#endif
378
379
 
380
png_uint_32 PNGAPI
381
png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr,
382
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
383
{
384
   png_uint_32 retval = 0;
385
386
 
387
   {
388
      png_debug1(1, "in %s retrieval function", "pHYs");
389
390
 
391
      {
392
         *res_x = info_ptr->x_pixels_per_unit;
393
         retval |= PNG_INFO_pHYs;
394
      }
395
396
 
397
      {
398
         *res_y = info_ptr->y_pixels_per_unit;
399
         retval |= PNG_INFO_pHYs;
400
      }
401
402
 
403
      {
404
         *unit_type = (int)info_ptr->phys_unit_type;
405
         retval |= PNG_INFO_pHYs;
406
407
 
408
         {
409
            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
410
            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
411
         }
412
      }
413
   }
414
415
 
416
}
417
#endif /* PNG_pHYs_SUPPORTED */
418
#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
419
420
 
421
422
 
423
424
 
425
png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr)
426
{
427
   if (png_ptr != NULL && info_ptr != NULL)
428
      return(info_ptr->channels);
429
430
 
431
}
432
433
 
434
png_get_signature(png_const_structp png_ptr, png_infop info_ptr)
435
{
436
   if (png_ptr != NULL && info_ptr != NULL)
437
      return(info_ptr->signature);
438
439
 
440
}
441
442
 
443
png_uint_32 PNGAPI
444
png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr,
445
   png_color_16p *background)
446
{
447
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
448
       && background != NULL)
449
   {
450
      png_debug1(1, "in %s retrieval function", "bKGD");
451
452
 
453
      return (PNG_INFO_bKGD);
454
   }
455
456
 
457
}
458
#endif
459
460
 
461
#  ifdef PNG_FLOATING_POINT_SUPPORTED
462
png_uint_32 PNGAPI
463
png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr,
464
    double *white_x, double *white_y, double *red_x, double *red_y,
465
    double *green_x, double *green_y, double *blue_x, double *blue_y)
466
{
467
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
468
   {
469
      png_debug1(1, "in %s retrieval function", "cHRM");
470
471
 
472
         *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
473
      if (white_y != NULL)
474
         *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
475
      if (red_x != NULL)
476
         *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
477
      if (red_y != NULL)
478
         *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
479
      if (green_x != NULL)
480
         *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
481
      if (green_y != NULL)
482
         *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
483
      if (blue_x != NULL)
484
         *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
485
      if (blue_y != NULL)
486
         *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
487
      return (PNG_INFO_cHRM);
488
   }
489
490
 
491
}
492
#  endif
493
494
 
495
png_uint_32 PNGAPI
496
png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
497
    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
498
    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
499
    png_fixed_point *blue_x, png_fixed_point *blue_y)
500
{
501
   png_debug1(1, "in %s retrieval function", "cHRM");
502
503
 
504
   {
505
      if (white_x != NULL)
506
         *white_x = info_ptr->x_white;
507
      if (white_y != NULL)
508
         *white_y = info_ptr->y_white;
509
      if (red_x != NULL)
510
         *red_x = info_ptr->x_red;
511
      if (red_y != NULL)
512
         *red_y = info_ptr->y_red;
513
      if (green_x != NULL)
514
         *green_x = info_ptr->x_green;
515
      if (green_y != NULL)
516
         *green_y = info_ptr->y_green;
517
      if (blue_x != NULL)
518
         *blue_x = info_ptr->x_blue;
519
      if (blue_y != NULL)
520
         *blue_y = info_ptr->y_blue;
521
      return (PNG_INFO_cHRM);
522
   }
523
524
 
525
}
526
#  endif
527
#endif
528
529
 
530
png_uint_32 PNGFAPI
531
png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
532
    png_fixed_point *file_gamma)
533
{
534
   png_debug1(1, "in %s retrieval function", "gAMA");
535
536
 
537
       && file_gamma != NULL)
538
   {
539
      *file_gamma = info_ptr->gamma;
540
      return (PNG_INFO_gAMA);
541
   }
542
543
 
544
}
545
#  ifdef PNG_FLOATING_POINT_SUPPORTED
546
png_uint_32 PNGAPI
547
png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr,
548
    double *file_gamma)
549
{
550
   png_fixed_point igamma;
551
   png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
552
553
 
554
      *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
555
556
 
557
}
558
559
 
560
#endif
561
562
 
563
png_uint_32 PNGAPI
564
png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr,
565
    int *file_srgb_intent)
566
{
567
   png_debug1(1, "in %s retrieval function", "sRGB");
568
569
 
570
       && file_srgb_intent != NULL)
571
   {
572
      *file_srgb_intent = (int)info_ptr->srgb_intent;
573
      return (PNG_INFO_sRGB);
574
   }
575
576
 
577
}
578
#endif
579
580
 
581
png_uint_32 PNGAPI
582
png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
583
    png_charpp name, int *compression_type,
584
    png_bytepp profile, png_uint_32 *proflen)
585
{
586
   png_debug1(1, "in %s retrieval function", "iCCP");
587
588
 
589
       && name != NULL && profile != NULL && proflen != NULL)
590
   {
591
      *name = info_ptr->iccp_name;
592
      *profile = info_ptr->iccp_profile;
593
      /* Compression_type is a dummy so the API won't have to change
594
       * if we introduce multiple compression types later.
595
       */
596
      *proflen = (int)info_ptr->iccp_proflen;
597
      *compression_type = (int)info_ptr->iccp_compression;
598
      return (PNG_INFO_iCCP);
599
   }
600
601
 
602
}
603
#endif
604
605
 
606
png_uint_32 PNGAPI
607
png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr,
608
    png_sPLT_tpp spalettes)
609
{
610
   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
611
   {
612
      *spalettes = info_ptr->splt_palettes;
613
      return ((png_uint_32)info_ptr->splt_palettes_num);
614
   }
615
616
 
617
}
618
#endif
619
620
 
621
png_uint_32 PNGAPI
622
png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr,
623
    png_uint_16p *hist)
624
{
625
   png_debug1(1, "in %s retrieval function", "hIST");
626
627
 
628
       && hist != NULL)
629
   {
630
      *hist = info_ptr->hist;
631
      return (PNG_INFO_hIST);
632
   }
633
634
 
635
}
636
#endif
637
638
 
639
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
640
    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
641
    int *color_type, int *interlace_type, int *compression_type,
642
    int *filter_type)
643
644
 
645
   png_debug1(1, "in %s retrieval function", "IHDR");
646
647
 
648
       height == NULL || bit_depth == NULL || color_type == NULL)
649
      return (0);
650
651
 
652
   *height = info_ptr->height;
653
   *bit_depth = info_ptr->bit_depth;
654
   *color_type = info_ptr->color_type;
655
656
 
657
      *compression_type = info_ptr->compression_type;
658
659
 
660
      *filter_type = info_ptr->filter_type;
661
662
 
663
      *interlace_type = info_ptr->interlace_type;
664
665
 
666
    * assigned in png_set_IHDR().  We do the check anyhow in case an
667
    * application has ignored our advice not to mess with the members
668
    * of info_ptr directly.
669
    */
670
   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
671
       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
672
       info_ptr->compression_type, info_ptr->filter_type);
673
674
 
675
}
676
677
 
678
png_uint_32 PNGAPI
679
png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr,
680
    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
681
{
682
   png_debug1(1, "in %s retrieval function", "oFFs");
683
684
 
685
       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
686
   {
687
      *offset_x = info_ptr->x_offset;
688
      *offset_y = info_ptr->y_offset;
689
      *unit_type = (int)info_ptr->offset_unit_type;
690
      return (PNG_INFO_oFFs);
691
   }
692
693
 
694
}
695
#endif
696
697
 
698
png_uint_32 PNGAPI
699
png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr,
700
    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
701
    png_charp *units, png_charpp *params)
702
{
703
   png_debug1(1, "in %s retrieval function", "pCAL");
704
705
 
706
       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
707
       nparams != NULL && units != NULL && params != NULL)
708
   {
709
      *purpose = info_ptr->pcal_purpose;
710
      *X0 = info_ptr->pcal_X0;
711
      *X1 = info_ptr->pcal_X1;
712
      *type = (int)info_ptr->pcal_type;
713
      *nparams = (int)info_ptr->pcal_nparams;
714
      *units = info_ptr->pcal_units;
715
      *params = info_ptr->pcal_params;
716
      return (PNG_INFO_pCAL);
717
   }
718
719
 
720
}
721
#endif
722
723
 
724
#  ifdef PNG_FIXED_POINT_SUPPORTED
725
#    ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
726
png_uint_32 PNGAPI
727
png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr,
728
    int *unit, png_fixed_point *width, png_fixed_point *height)
729
{
730
   if (png_ptr != NULL && info_ptr != NULL &&
731
       (info_ptr->valid & PNG_INFO_sCAL))
732
   {
733
      *unit = info_ptr->scal_unit;
734
      /*TODO: make this work without FP support */
735
      *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
736
      *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
737
         "sCAL height");
738
      return (PNG_INFO_sCAL);
739
   }
740
741
 
742
}
743
#    endif /* FLOATING_ARITHMETIC */
744
#  endif /* FIXED_POINT */
745
#  ifdef PNG_FLOATING_POINT_SUPPORTED
746
png_uint_32 PNGAPI
747
png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr,
748
    int *unit, double *width, double *height)
749
{
750
   if (png_ptr != NULL && info_ptr != NULL &&
751
       (info_ptr->valid & PNG_INFO_sCAL))
752
   {
753
      *unit = info_ptr->scal_unit;
754
      *width = atof(info_ptr->scal_s_width);
755
      *height = atof(info_ptr->scal_s_height);
756
      return (PNG_INFO_sCAL);
757
   }
758
759
 
760
}
761
#  endif /* FLOATING POINT */
762
png_uint_32 PNGAPI
763
png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr,
764
    int *unit, png_charpp width, png_charpp height)
765
{
766
   if (png_ptr != NULL && info_ptr != NULL &&
767
       (info_ptr->valid & PNG_INFO_sCAL))
768
   {
769
      *unit = info_ptr->scal_unit;
770
      *width = info_ptr->scal_s_width;
771
      *height = info_ptr->scal_s_height;
772
      return (PNG_INFO_sCAL);
773
   }
774
775
 
776
}
777
#endif /* sCAL */
778
779
 
780
png_uint_32 PNGAPI
781
png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr,
782
    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
783
{
784
   png_uint_32 retval = 0;
785
786
 
787
788
 
789
       (info_ptr->valid & PNG_INFO_pHYs))
790
   {
791
      if (res_x != NULL)
792
      {
793
         *res_x = info_ptr->x_pixels_per_unit;
794
         retval |= PNG_INFO_pHYs;
795
      }
796
797
 
798
      {
799
         *res_y = info_ptr->y_pixels_per_unit;
800
         retval |= PNG_INFO_pHYs;
801
      }
802
803
 
804
      {
805
         *unit_type = (int)info_ptr->phys_unit_type;
806
         retval |= PNG_INFO_pHYs;
807
      }
808
   }
809
810
 
811
}
812
#endif /* pHYs */
813
814
 
815
png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr,
816
    png_colorp *palette, int *num_palette)
817
{
818
   png_debug1(1, "in %s retrieval function", "PLTE");
819
820
 
821
       && palette != NULL)
822
   {
823
      *palette = info_ptr->palette;
824
      *num_palette = info_ptr->num_palette;
825
      png_debug1(3, "num_palette = %d", *num_palette);
826
      return (PNG_INFO_PLTE);
827
   }
828
829
 
830
}
831
832
 
833
png_uint_32 PNGAPI
834
png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr,
835
    png_color_8p *sig_bit)
836
{
837
   png_debug1(1, "in %s retrieval function", "sBIT");
838
839
 
840
       && sig_bit != NULL)
841
   {
842
      *sig_bit = &(info_ptr->sig_bit);
843
      return (PNG_INFO_sBIT);
844
   }
845
846
 
847
}
848
#endif
849
850
 
851
png_uint_32 PNGAPI
852
png_get_text(png_const_structp png_ptr, png_const_infop info_ptr,
853
    png_textp *text_ptr, int *num_text)
854
{
855
   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
856
   {
857
      png_debug1(1, "in %s retrieval function",
858
          (png_ptr->chunk_name[0] == '\0' ? "text" :
859
          (png_const_charp)png_ptr->chunk_name));
860
861
 
862
         *text_ptr = info_ptr->text;
863
864
 
865
         *num_text = info_ptr->num_text;
866
867
 
868
   }
869
870
 
871
      *num_text = 0;
872
873
 
874
}
875
#endif
876
877
 
878
png_uint_32 PNGAPI
879
png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
880
{
881
   png_debug1(1, "in %s retrieval function", "tIME");
882
883
 
884
       && mod_time != NULL)
885
   {
886
      *mod_time = &(info_ptr->mod_time);
887
      return (PNG_INFO_tIME);
888
   }
889
890
 
891
}
892
#endif
893
894
 
895
png_uint_32 PNGAPI
896
png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr,
897
    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
898
{
899
   png_uint_32 retval = 0;
900
   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
901
   {
902
      png_debug1(1, "in %s retrieval function", "tRNS");
903
904
 
905
      {
906
         if (trans_alpha != NULL)
907
         {
908
            *trans_alpha = info_ptr->trans_alpha;
909
            retval |= PNG_INFO_tRNS;
910
         }
911
912
 
913
            *trans_color = &(info_ptr->trans_color);
914
      }
915
916
 
917
      {
918
         if (trans_color != NULL)
919
         {
920
            *trans_color = &(info_ptr->trans_color);
921
            retval |= PNG_INFO_tRNS;
922
         }
923
924
 
925
            *trans_alpha = NULL;
926
      }
927
928
 
929
      {
930
         *num_trans = info_ptr->num_trans;
931
         retval |= PNG_INFO_tRNS;
932
      }
933
   }
934
935
 
936
}
937
#endif
938
939
 
940
int PNGAPI
941
png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr,
942
    png_unknown_chunkpp unknowns)
943
{
944
   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
945
   {
946
      *unknowns = info_ptr->unknown_chunks;
947
      return info_ptr->unknown_chunks_num;
948
   }
949
950
 
951
}
952
#endif
953
954
 
955
png_byte PNGAPI
956
png_get_rgb_to_gray_status (png_const_structp png_ptr)
957
{
958
   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
959
}
960
#endif
961
962
 
963
png_voidp PNGAPI
964
png_get_user_chunk_ptr(png_const_structp png_ptr)
965
{
966
   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
967
}
968
#endif
969
970
 
971
png_get_compression_buffer_size(png_const_structp png_ptr)
972
{
973
   return (png_ptr ? png_ptr->zbuf_size : 0L);
974
}
975
976
 
977
 
978
/* These functions were added to libpng 1.2.6 and were enabled
979
 * by default in libpng-1.4.0 */
980
png_uint_32 PNGAPI
981
png_get_user_width_max (png_const_structp png_ptr)
982
{
983
   return (png_ptr ? png_ptr->user_width_max : 0);
984
}
985
986
 
987
png_get_user_height_max (png_const_structp png_ptr)
988
{
989
   return (png_ptr ? png_ptr->user_height_max : 0);
990
}
991
992
 
993
png_uint_32 PNGAPI
994
png_get_chunk_cache_max (png_const_structp png_ptr)
995
{
996
   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
997
}
998
999
 
1000
png_alloc_size_t PNGAPI
1001
png_get_chunk_malloc_max (png_const_structp png_ptr)
1002
{
1003
   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1004
}
1005
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1006
1007
 
1008
#ifdef PNG_IO_STATE_SUPPORTED
1009
png_uint_32 PNGAPI
1010
png_get_io_state (png_structp png_ptr)
1011
{
1012
   return png_ptr->io_state;
1013
}
1014
1015
 
1016
png_get_io_chunk_type (png_const_structp png_ptr)
1017
{
1018
   return ((png_ptr->chunk_name[0] << 24) +
1019
           (png_ptr->chunk_name[1] << 16) +
1020
           (png_ptr->chunk_name[2] <<  8) +
1021
           (png_ptr->chunk_name[3]));
1022
}
1023
1024
 
1025
png_get_io_chunk_name (png_structp png_ptr)
1026
{
1027
   return png_ptr->chunk_name;
1028
}
1029
#endif /* ?PNG_IO_STATE_SUPPORTED */
1030
1031
 
1032