Ticket #1144: gilPngEndian.patch

File gilPngEndian.patch, 1.5 KB (added by William Gallafent <william@…>, 15 years ago)

Swap bytes when doing bit-depth 16 PNG IO on little-endian architectures.

  • boost/gil/extension/io/png_io_private.hpp

    diff -ruBbiw gil/boost/gil/extension/io/png_io_private.hpp boost/boost/include/boost-1_34/boost/gil/extension/io/png_io_private.hpp
    old new  
    2020
    2121#include <algorithm>
    2222#include <vector>
     23#include <boost/detail/endian.hpp>
    2324#include <boost/static_assert.hpp>
    2425#include "../../gil_all.hpp"
    2526#include "io_error.hpp"
     
    162163        png_init_io(_png_ptr, get());
    163164        png_set_sig_bytes(_png_ptr,PNG_BYTES_TO_CHECK);
    164165        png_read_info(_png_ptr, _info_ptr);
     166#ifdef BOOST_LITTLE_ENDIAN
     167                                if (16 == png_get_bit_depth (_png_ptr, _info_ptr))
     168                                        png_set_swap (_png_ptr);
     169#endif
    165170    }
    166171public:
    167172    png_reader(FILE* file          ) : file_mgr(file)           { init(); }
     
    337342                     PNG_INTERLACE_NONE,
    338343                     PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
    339344        png_write_info(_png_ptr,_info_ptr);
     345#ifdef BOOST_LITTLE_ENDIAN
     346                                if (16 == png_write_support_private<typename channel_type<View>::type
     347                                        , typename color_space_type<View>::type>::bit_depth)
     348                                        png_set_swap(_png_ptr);
     349#endif
    340350        std::vector<pixel<typename channel_type<View>::type,
    341351                          layout<typename color_space_type<View>::type> > > row(view.width());
    342352        for(int y=0;y<view.height();++y) {