2
2
/* pngwutil.c - utilities to write a PNG file
4
* libpng version 1.2.8 - December 3, 2004
4
* Last changed in libpng 1.2.13 November 13, 2006
5
5
* For conditions of distribution and use, see copyright notice in png.h
6
* Copyright (c) 1998-2004 Glenn Randers-Pehrson
6
* Copyright (c) 1998-2006 Glenn Randers-Pehrson
7
7
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8
8
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
25
25
buf[3] = (png_byte)(i & 0xff);
28
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
29
28
/* The png_save_int_32 function assumes integers are stored in two's
30
29
* complement format. If this isn't the case, then this routine needs to
31
30
* be modified to write data in two's complement format.
34
33
png_save_int_32(png_bytep buf, png_int_32 i)
36
35
buf[0] = (png_byte)((i >> 24) & 0xff);
38
37
buf[2] = (png_byte)((i >> 8) & 0xff);
39
38
buf[3] = (png_byte)(i & 0xff);
43
41
/* Place a 16-bit number into a buffer in PNG byte order.
44
42
* The parameter is declared unsigned int, not png_uint_16,
45
43
* just to avoid potential problems on pre-ANSI C compilers.
48
46
png_save_uint_16(png_bytep buf, unsigned int i)
50
48
buf[0] = (png_byte)((i >> 8) & 0xff);
64
62
png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
65
63
png_bytep data, png_size_t length)
65
if(png_ptr == NULL) return;
67
66
png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
68
67
png_write_chunk_data(png_ptr, data, length);
69
68
png_write_chunk_end(png_ptr);
743
756
if (profile == NULL)
760
embedded_profile_len = ((*(profile ))<<24) | ((*(profile+1))<<16) |
761
((*(profile+2))<< 8) | ((*(profile+3)) );
763
if (profile_len < embedded_profile_len)
766
"Embedded profile length too large in iCCP chunk");
770
if (profile_len > embedded_profile_len)
773
"Truncating profile to actual length in iCCP chunk");
774
profile_len = embedded_profile_len;
747
778
profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
748
779
PNG_COMPRESSION_TYPE_BASE, &comp);
1552
1591
/* write the sCAL chunk */
1553
1592
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
1554
1593
void /* PRIVATE */
1555
png_write_sCAL(png_structp png_ptr, int unit, double width,double height)
1594
png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
1557
1596
#ifdef PNG_USE_LOCAL_ARRAYS
1560
1600
png_size_t total_len;
1561
char wbuf[32], hbuf[32];
1562
png_byte bunit = unit;
1564
1602
png_debug(1, "in png_write_sCAL\n");
1604
buf[0] = (char)unit;
1566
1605
#if defined(_WIN32_WCE)
1567
1606
/* sprintf() function is not supported on WindowsCE */
1569
1608
wchar_t wc_buf[32];
1570
1610
swprintf(wc_buf, TEXT("%12.12e"), width);
1571
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, wbuf, 32, NULL, NULL);
1611
wc_len = wcslen(wc_buf);
1612
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
1613
total_len = wc_len + 2;
1572
1614
swprintf(wc_buf, TEXT("%12.12e"), height);
1573
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, hbuf, 32, NULL, NULL);
1615
wc_len = wcslen(wc_buf);
1616
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
1618
total_len += wc_len;
1576
sprintf(wbuf, "%12.12e", width);
1577
sprintf(hbuf, "%12.12e", height);
1621
sprintf(buf + 1, "%12.12e", width);
1622
total_len = 1 + png_strlen(buf + 1) + 1;
1623
sprintf(buf + total_len, "%12.12e", height);
1624
total_len += png_strlen(buf + total_len);
1579
total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf);
1581
png_debug1(3, "sCAL total length = %d\n", (int)total_len);
1582
png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len);
1583
png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1);
1584
png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1);
1585
png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf));
1587
png_write_chunk_end(png_ptr);
1627
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
1628
png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
1590
1631
#ifdef PNG_FIXED_POINT_SUPPORTED
1595
1636
#ifdef PNG_USE_LOCAL_ARRAYS
1598
png_size_t total_len;
1599
char wbuf[32], hbuf[32];
1600
png_byte bunit = unit;
1640
png_size_t wlen, hlen, total_len;
1602
1642
png_debug(1, "in png_write_sCAL_s\n");
1604
png_strcpy(wbuf,(const char *)width);
1605
png_strcpy(hbuf,(const char *)height);
1606
total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf);
1608
png_debug1(3, "sCAL total length = %d\n", total_len);
1609
png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len);
1610
png_write_chunk_data(png_ptr, (png_bytep)&bunit, 1);
1611
png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1);
1612
png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf));
1614
png_write_chunk_end(png_ptr);
1644
wlen = png_strlen(width);
1645
hlen = png_strlen(height);
1646
total_len = wlen + hlen + 2;
1649
png_warning(png_ptr, "Can't write sCAL (buffer too small)");
1653
buf[0] = (png_byte)unit;
1654
png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
1655
png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
1657
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
1658
png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);