⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 png_io_private.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/*    Copyright 2005-2007 Adobe Systems Incorporated       Use, modification and distribution are subject to the Boost Software License,    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at    http://www.boost.org/LICENSE_1_0.txt).    See http://stlab.adobe.com/gil for most recent version including documentation.*//*************************************************************************************************/#ifndef GIL_PNG_IO_PRIVATE_H#define GIL_PNG_IO_PRIVATE_H/// \file/// \brief  Internal support for reading and writing PNG files/// \author Hailin Jin and Lubomir Bourdev \n///         Adobe Systems Incorporated/// \date   2005-2007 \n Last updated August 14, 2007#include <algorithm>#include <vector>#include <boost/static_assert.hpp>#include "../../gil_all.hpp"#include "io_error.hpp"namespace boost { namespace gil {namespace detail {static const std::size_t PNG_BYTES_TO_CHECK = 4;// lbourdev: These can be greatly simplified, for example:template <typename Cs> struct png_color_type {BOOST_STATIC_CONSTANT(int,color_type=0);};template<> struct png_color_type<gray_t> { BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_GRAY); };template<> struct png_color_type<rgb_t>  { BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGB); };template<> struct png_color_type<rgba_t> { BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGBA); };template <typename Channel,typename ColorSpace> struct png_is_supported {BOOST_STATIC_CONSTANT(bool,value=false);};template <> struct png_is_supported<bits8,gray_t>  {BOOST_STATIC_CONSTANT(bool,value=true);};template <> struct png_is_supported<bits8,rgb_t>   {BOOST_STATIC_CONSTANT(bool,value=true);};template <> struct png_is_supported<bits8,rgba_t>  {BOOST_STATIC_CONSTANT(bool,value=true);};template <> struct png_is_supported<bits16,gray_t> {BOOST_STATIC_CONSTANT(bool,value=true);};template <> struct png_is_supported<bits16,rgb_t>  {BOOST_STATIC_CONSTANT(bool,value=true);};template <> struct png_is_supported<bits16,rgba_t> {BOOST_STATIC_CONSTANT(bool,value=true);};template <typename Channel> struct png_bit_depth {BOOST_STATIC_CONSTANT(int,bit_depth=sizeof(Channel)*8);};template <typename Channel,typename ColorSpace>struct png_read_support_private {    BOOST_STATIC_CONSTANT(bool,is_supported=false);    BOOST_STATIC_CONSTANT(int,bit_depth=0);    BOOST_STATIC_CONSTANT(int,color_type=0);};template <>struct png_read_support_private<bits8,gray_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_GRAY);};template <>struct png_read_support_private<bits8,rgb_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGB);};template <>struct png_read_support_private<bits8,rgba_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGBA);};template <>struct png_read_support_private<bits16,gray_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_GRAY);};template <>struct png_read_support_private<bits16,rgb_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGB);};template <>struct png_read_support_private<bits16,rgba_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGBA);};template <typename Channel,typename ColorSpace>struct png_write_support_private {    BOOST_STATIC_CONSTANT(bool,is_supported=false);    BOOST_STATIC_CONSTANT(int,bit_depth=0);    BOOST_STATIC_CONSTANT(int,color_type=0);};template <>struct png_write_support_private<bits8,gray_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_GRAY);};template <>struct png_write_support_private<bits8,rgb_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGB);};template <>struct png_write_support_private<bits8,rgba_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=8);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGBA);};template <>struct png_write_support_private<bits16,gray_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_GRAY);};template <>struct png_write_support_private<bits16,rgb_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGB);};template <>struct png_write_support_private<bits16,rgba_t> {    BOOST_STATIC_CONSTANT(bool,is_supported=true);    BOOST_STATIC_CONSTANT(int,bit_depth=16);    BOOST_STATIC_CONSTANT(int,color_type=PNG_COLOR_TYPE_RGBA);};class png_reader : public file_mgr {protected:    png_structp _png_ptr;    png_infop _info_ptr;    void init() {        char buf[PNG_BYTES_TO_CHECK];        // read in some of the signature bytes        io_error_if(fread(buf, 1, PNG_BYTES_TO_CHECK, get()) != detail::PNG_BYTES_TO_CHECK,                    "png_check_validity: fail to read file");        // compare the first PNG_BYTES_TO_CHECK bytes of the signature.        io_error_if(png_sig_cmp((png_bytep)buf, (png_size_t)0, detail::PNG_BYTES_TO_CHECK)!=0,                    "png_check_validity: invalid png file");        _png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);        io_error_if(_png_ptr==NULL,"png_get_file_size: fail to call png_create_write_struct()");        // allocate/initialize the image information data        _info_ptr = png_create_info_struct(_png_ptr);        if (_info_ptr == NULL) {            png_destroy_read_struct(&_png_ptr,png_infopp_NULL,png_infopp_NULL);            io_error("png_get_file_size: fail to call png_create_info_struct()");        }        if (setjmp(png_jmpbuf(_png_ptr))) {            //free all of the memory associated with the png_ptr and info_ptr            png_destroy_read_struct(&_png_ptr, &_info_ptr, png_infopp_NULL);            io_error("png_get_file_size: fail to call setjmp()");        }        png_init_io(_png_ptr, get());        png_set_sig_bytes(_png_ptr,PNG_BYTES_TO_CHECK);        png_read_info(_png_ptr, _info_ptr);        if (little_endian() && png_get_bit_depth(_png_ptr,_info_ptr)>8)            png_set_swap(_png_ptr);    }public:    png_reader(FILE* file          ) : file_mgr(file)           { init(); }    png_reader(const char* filename) : file_mgr(filename, "rb") { init(); }    ~png_reader() {        png_destroy_read_struct(&_png_ptr,&_info_ptr,png_infopp_NULL);    }    point2<std::ptrdiff_t> get_dimensions() {        return point2<std::ptrdiff_t>(png_get_image_width(_png_ptr,_info_ptr),                                      png_get_image_height(_png_ptr,_info_ptr));    }    template <typename View>    void apply(const View& view) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -