Exiv2
pngchunk_int.hpp
Go to the documentation of this file.
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2018 Exiv2 authors
4  * This program is part of the Exiv2 distribution.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19  */
29  /*
30  File: pngchunk.cpp
31  */
32 
33 #ifndef PNGCHUNK_INT_HPP_
34 #define PNGCHUNK_INT_HPP_
35 
36 // *****************************************************************************
37 // included header files
38 #include "types.hpp"
39 #include "pngimage.hpp"
40 
41 // + standard includes
42 #include <iosfwd>
43 #include <cassert>
44 #include <cstdarg>
45 
46 // *****************************************************************************
47 // namespace extensions
48 namespace Exiv2 {
49 
50 // *****************************************************************************
51 // class declarations
52  class Image;
53 
54  namespace Internal {
55 
56 // *****************************************************************************
57 // class definitions
58 
63  class PngChunk {
64  public:
68  enum TxtChunkType {
69  tEXt_Chunk = 0,
70  zTXt_Chunk = 1,
71  iTXt_Chunk = 2
72  };
73 
74  public:
83  static void decodeIHDRChunk(const DataBuf& data,
84  int* outWidth,
85  int* outHeight);
86 
95  static void decodeTXTChunk(Image* pImage,
96  const DataBuf& data,
97  TxtChunkType type);
98 
106  static DataBuf decodeTXTChunk(const DataBuf& data,
107  TxtChunkType type);
108 
109 
116  static DataBuf keyTXTChunk(const DataBuf& data, bool stripHeader=false);
117 
126  static std::string makeMetadataChunk(const std::string& metadata,
127  MetadataId type);
128 
129  private:
134  static DataBuf parseTXTChunk(const DataBuf& data,
135  int keysize,
136  TxtChunkType type);
137 
147  static void parseChunkContent( Image* pImage,
148  const byte* key,
149  long keySize,
150  const DataBuf arr);
151 
162  static std::string makeAsciiTxtChunk(const std::string& keyword,
163  const std::string& text,
164  bool compress);
165 
174  static std::string makeUtf8TxtChunk(const std::string& keyword,
175  const std::string& text,
176  bool compress);
177 
181  static void zlibUncompress(const byte* compressedText,
182  unsigned int compressedTextSize,
183  DataBuf& arr);
184 
188  static std::string zlibCompress(const std::string& text);
189 
193  static DataBuf readRawProfile(const DataBuf& text,bool iTXt);
194 
199  static std::string writeRawProfile(const std::string& profileData,
200  const char* profileType);
201 
202  friend class Exiv2::PngImage;
203 
204  }; // class PngChunk
205 
206 }} // namespace Internal, Exiv2
207 
208 #endif // #ifndef PNGCHUNK_INT_HPP_
exif.hpp
Encoding and decoding of Exif data.
Exiv2::Internal::PngChunk::TxtChunkType
TxtChunkType
Text Chunk types.
Definition: pngchunk_int.hpp:68
types.hpp
Type definitions for Exiv2 and related functionality.
Exiv2::IptcParser::decode
static int decode(IptcData &iptcData, const byte *pData, uint32_t size)
Decode binary IPTC data in IPTC IIM4 format from a buffer pData of length size to the provided metada...
Definition: iptc.cpp:432
Exiv2::Photoshop::locateIptcIrb
static int locateIptcIrb(const byte *pPsData, long sizePsData, const byte **record, uint32_t *const sizeHdr, uint32_t *const sizeData)
Forwards to locateIrb() with psTag = iptc_.
Definition: jpgimage.cpp:219
Exiv2::Internal::PngChunk::decodeIHDRChunk
static void decodeIHDRChunk(const DataBuf &data, int *outWidth, int *outHeight)
Decode PNG IHDR chunk data from a data buffer data and return image size to outWidth and outHeight.
Exiv2::Internal::PngChunk
Stateless parser class for data in PNG chunk format. Images use this class to decode and encode PNG-b...
Definition: pngchunk_int.hpp:63
Exiv2::TiffParser::decode
static ByteOrder decode(ExifData &exifData, IptcData &iptcData, XmpData &xmpData, const byte *pData, uint32_t size)
Decode metadata from a buffer pData of length size with data in TIFF format to the provided metadata ...
Definition: tiffimage.cpp:251
string_from_unterminated
std::string string_from_unterminated(const char *data, size_t data_length)
Convert a (potentially not null terminated) array into a std::string.
Definition: helper_functions.cpp:33
Exiv2::PngImage
Class to access PNG images. Exif and IPTC metadata are supported directly.
Definition: pngimage.hpp:58
enforce.hpp
Port of D's enforce() to C++ & Exiv2.
Exiv2::MetadataId
MetadataId
An identifier for each type of metadata.
Definition: types.hpp:119
Exiv2::append
EXIV2API void append(Exiv2::Blob &blob, const byte *buf, uint32_t len)
Append len bytes pointed to by buf to blob.
Definition: image.cpp:992
MetadataId
MetadataId
Metadata identifiers.
Definition: exiv2app.hpp:75
enforce
void enforce(bool condition, const T &arg1)
Ensure that condition is true, otherwise throw an exception of the type exception_t.
Definition: enforce.hpp:43
helper_functions.hpp
A collection of helper functions.
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:204
Exiv2::getLong
EXIV2API int32_t getLong(const byte *buf, ByteOrder byteOrder)
Read a 4 byte signed long value from the data buffer.
Definition: types.cpp:328
pngchunk_int.hpp
Class PngChunk to parse PNG chunk data implemented using the following references: PNG iTXt chunk st...
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
image.hpp
Exiv2::ul2Data
EXIV2API long ul2Data(byte *buf, uint32_t l, ByteOrder byteOrder)
Convert an unsigned long to data, write the data to the buffer, return number of bytes written.
Definition: types.cpp:408
safe_op.hpp
Overflow checks for integers.
EXV_WARNING
#define EXV_WARNING
Shorthand for a temp warning log message object and return its ostringstream.
Definition: error.hpp:148
Exiv2::ByteOrder
ByteOrder
Type to express the byte order (little or big endian)
Definition: types.hpp:113
Exiv2::Internal::PngChunk::makeMetadataChunk
static std::string makeMetadataChunk(const std::string &metadata, MetadataId type)
Return a complete PNG chunk data compressed or not as buffer. Data returned is formated accordingly w...
Exiv2::Internal::PngChunk::keyTXTChunk
static DataBuf keyTXTChunk(const DataBuf &data, bool stripHeader=false)
Return PNG TXT chunk key as data buffer.
pngimage.hpp
PNG image, implemented using the following references: PNG specification by W3C PNG tags list by Phi...
Safe::add
T add(T summand_1, T summand_2)
Safe addition, throws an exception on overflow.
Definition: safe_op.hpp:295
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:323
Exiv2::string
@ string
IPTC string type.
Definition: types.hpp:147
Exiv2::Internal::PngChunk::decodeTXTChunk
static void decodeTXTChunk(Image *pImage, const DataBuf &data, TxtChunkType type)
Decode PNG tEXt, zTXt, or iTXt chunk data from pImage passed by data buffer data and extract Comment,...
Exiv2::Image
Abstract base class defining the interface for an image. This is the top-level interface to the Exiv2...
Definition: image.hpp:81
Exiv2::XmpParser::decode
static int decode(XmpData &xmpData, const std::string &xmpPacket)
Decode XMP metadata from an XMP packet xmpPacket into xmpData. The format of the XMP packet must foll...
Definition: xmp.cpp:723
error.hpp
Error class for exceptions, log message class.
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition: types.hpp:162
jpgimage.hpp
Class JpegImage to access JPEG images.
iptc.hpp
Encoding and decoding of IPTC data.