56 G_EXCEPTION( Error ,
"png error" ) ;
75 explicit PngInfo( std::istream & ) ;
78 PngInfo(
const unsigned char * p ,
size_t ) ;
81 PngInfo(
const char * p ,
size_t ) ;
98 void operator=(
const PngInfo & ) ;
99 void init(
const unsigned char * ,
size_t ) ;
100 void init( std::istream & ) ;
101 static std::pair<int,int> parse(
const unsigned char * ,
size_t ) ;
114 typedef std::multimap<std::string,std::string> Map ;
116 PngReader(
int scale = 1 ,
bool monochrome_out =
false ) ;
122 void setup(
int scale ,
bool monochrome_out =
false ) ;
131 void decode(
ImageData & out ,
const unsigned char * p_in ,
size_t n ) ;
146 bool m_monochrome_out ;
156 typedef std::multimap<std::string,std::string> Map ;
160 virtual void operator()(
const unsigned char * ,
size_t ) = 0 ;
207 init( reinterpret_cast<const unsigned char *>(p) , n ) ;
216 imagebuf buf( image_buffer ) ;
217 std::istream in( &buf ) ;
224 return m_dx > 0 && m_dy > 0 ;
240 std::pair<int,int> Gr::PngInfo::parse(
const unsigned char * p ,
size_t n )
242 unsigned int dx = 0U ;
243 unsigned int dy = 0U ;
245 p[0] == 0x89 && p[1] == 0x50 && p[2] == 0x4e && p[3] == 0x47 &&
246 p[4] == 0x0d && p[5] == 0x0a && p[6] == 0x1a && p[7] == 0x0a &&
247 p[12] == 0x49 && p[13] == 0x48 && p[14] == 0x44 && p[15] == 0x52 )
249 dx += p[16] ; dx <<= 8 ;
250 dx += p[17] ; dx <<= 8 ;
251 dx += p[18] ; dx <<= 8 ;
253 dy += p[20] ; dy <<= 8 ;
254 dy += p[21] ; dy <<= 8 ;
255 dy += p[22] ; dy <<= 8 ;
258 return std::make_pair( static_cast<int>(dx) , static_cast<int>(dy) ) ;
PngInfo(std::istream &)
Constructor.
Map tags() const
Returns the text tags from the last decode().
A read interface for libpng.
A traits class that can be specialised for Gr::ImageBuffer candidates.
A holder for image data, having eight bits per sample and one or three channels.
Vectors ImageBuffer
An ImageBuffer is used to hold raw image data, typically in more than one chunk.
A class that reads a png header in order to provide the image dimensions.
PngWriter(const ImageData &, Map tags=Map())
Constructor with the raw image data prepared in a ImageData object.
A static class providing information about the png library.
A private pimple-pattern class for Gr::PngWriter.
int dy() const
Returns the image height. Returns zero on error.
void decode(ImageData &out, const G::Path &in)
Decodes a png file into an image. Throws on error.
int dx() const
Returns the image width. Returns zero on error.
bool valid() const
Returns true if successfully constructed.
PngReader(int scale=1, bool monochrome_out=false)
Constructor.
void setup(int scale, bool monochrome_out=false)
Sets the decoding scale factor.
static bool available()
Returns true if the png library is available.
A Path object represents a file system path.
An interface for writing a raw dgb image as a png file.
Abstract interface for Gr::PngWriter::write().
void write(const G::Path &path)
Writes to file.