From c1b25607db2ca42c6a68083bfd07ccbd03336a14 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 19 Apr 2013 13:49:16 +0100 Subject: [PATCH] + fix compiling miniz codec in c++11 mode FIXME: we should compile legacy "C" code with special flags.. --- src/build.py | 1 + src/miniz.c | 8 ++++---- src/miniz_png.cpp | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/build.py b/src/build.py index dbadb71cb..73d9d3b5e 100644 --- a/src/build.py +++ b/src/build.py @@ -117,6 +117,7 @@ source = Split( well_known_srs.cpp params.cpp image_filter_types.cpp + miniz_png.cpp color.cpp css_color_grammar.cpp conversions.cpp diff --git a/src/miniz.c b/src/miniz.c index 03be47f2f..34a3c537b 100644 --- a/src/miniz.c +++ b/src/miniz.c @@ -789,7 +789,7 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void // Compresses an image to a compressed PNG file in memory. // On entry: -// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. +// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. // The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. // On return: // Function returns a pointer to the compressed data, or NULL on failure. @@ -2778,8 +2778,8 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, *pLen_out = out_buf.m_size-41; { mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, - 0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8,"\0\0\04\02\06"[num_chans],0,0,0,0,0,0,0, - (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54}; + 0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8, (mz_uint8)"\0\0\04\02\06"[num_chans],0,0,0,0,0,0,0, + (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54}; c=(mz_uint32)mz_crc32(MZ_CRC32_INIT,pnghdr+12,17); for (i=0; i<4; ++i, c<<=8) ((mz_uint8*)(pnghdr+29))[i]=(mz_uint8)(c>>24); memcpy(out_buf.m_pBuf, pnghdr, 41); } @@ -4831,4 +4831,4 @@ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to -*/ \ No newline at end of file +*/ diff --git a/src/miniz_png.cpp b/src/miniz_png.cpp index ec445d0ba..8278032d0 100644 --- a/src/miniz_png.cpp +++ b/src/miniz_png.cpp @@ -30,8 +30,10 @@ #define MINIZ_NO_ARCHIVE_APIS #define MINIZ_NO_STDIO #define MINIZ_NO_ZLIB_COMPATIBLE_NAMES -#include "miniz.c" +extern "C" { +#include "miniz.c" +} // zlib #include @@ -142,7 +144,10 @@ void PNGWriter::finishChunk(size_t start) // Write CRC32 checksum. Don't include the 4-byte length, but /do/ include // the 4-byte chunk name. mz_uint32 crc = mz_crc32(MZ_CRC32_INIT, buffer->m_pBuf + start + 4, payloadLength + 4); - mz_uint8 checksum[] = { crc >> 24, crc >> 16, crc >> 8, crc }; + mz_uint8 checksum[] = { static_cast(crc >> 24), + static_cast(crc >> 16), + static_cast(crc >> 8), + static_cast(crc) }; mz_bool status = tdefl_output_buffer_putter(checksum, 4, buffer); if (status != MZ_TRUE) { @@ -362,4 +367,3 @@ template void PNGWriter::writeIDATStripAlpha(image_data_32 const& template void PNGWriter::writeIDATStripAlpha >(image_view const& image); }} -