00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PNGPP_INFO_HPP_INCLUDED
00032 #define PNGPP_INFO_HPP_INCLUDED
00033
00034 #include <cassert>
00035 #include "info_base.hpp"
00036 #include "image_info.hpp"
00037
00038 namespace png
00039 {
00040
00045 class info
00046 : public info_base,
00047 public image_info
00048 {
00049 public:
00050 info(io_base& io, png_struct* png)
00051 : info_base(io, png)
00052 {
00053 }
00054
00055 void read()
00056 {
00057 assert(m_png);
00058 assert(m_info);
00059
00060 png_read_info(m_png, m_info);
00061 png_get_IHDR(m_png,
00062 m_info,
00063 & m_width,
00064 & m_height,
00065 reinterpret_cast< int* >(& m_bit_depth),
00066 reinterpret_cast< int* >(& m_color_type),
00067 reinterpret_cast< int* >(& m_interlace_type),
00068 reinterpret_cast< int* >(& m_compression_type),
00069 reinterpret_cast< int* >(& m_filter_type));
00070
00071 if (png_get_valid(m_png, m_info, chunk_PLTE) == chunk_PLTE)
00072 {
00073 png_color* colors = 0;
00074 int count = 0;
00075 png_get_PLTE(m_png, m_info, & colors, & count);
00076 m_palette.assign(colors, colors + count);
00077 }
00078 }
00079
00080 void write() const
00081 {
00082 assert(m_png);
00083 assert(m_info);
00084
00085 sync_ihdr();
00086 if (! m_palette.empty())
00087 {
00088 png_set_PLTE(m_png, m_info,
00089 const_cast< color* >(& m_palette[0]),
00090 m_palette.size());
00091 }
00092 png_write_info(m_png, m_info);
00093 }
00094
00095 void update()
00096 {
00097 assert(m_png);
00098 assert(m_info);
00099
00100 sync_ihdr();
00101 png_read_update_info(m_png, m_info);
00102 }
00103
00104 protected:
00105 void sync_ihdr(void) const
00106 {
00107 png_set_IHDR(m_png,
00108 m_info,
00109 m_width,
00110 m_height,
00111 m_bit_depth,
00112 m_color_type,
00113 m_interlace_type,
00114 m_compression_type,
00115 m_filter_type);
00116 }
00117 };
00118
00119 }
00120
00121 #endif // PNGPP_INFO_HPP_INCLUDED