Exiv2
pngchunk_int.hpp
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2021 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  */
20 #ifndef PNGCHUNK_INT_HPP_
21 #define PNGCHUNK_INT_HPP_
22 
23 // *****************************************************************************
24 // included header files
25 #include "types.hpp"
26 #include "pngimage.hpp"
27 
28 // + standard includes
29 #include <iosfwd>
30 #include <cassert>
31 #include <cstdarg>
32 
33 // *****************************************************************************
34 // namespace extensions
35 namespace Exiv2 {
36 
37 // *****************************************************************************
38 // class declarations
39  class Image;
40 
41  namespace Internal {
42 
43 // *****************************************************************************
44 // class definitions
45 
50  class PngChunk {
51  public:
55  enum TxtChunkType {
56  tEXt_Chunk = 0,
57  zTXt_Chunk = 1,
58  iTXt_Chunk = 2
59  };
60 
61  public:
70  static void decodeIHDRChunk(const DataBuf& data,
71  int* outWidth,
72  int* outHeight);
73 
82  static void decodeTXTChunk(Image* pImage,
83  const DataBuf& data,
84  TxtChunkType type);
85 
93  static DataBuf decodeTXTChunk(const DataBuf& data,
94  TxtChunkType type);
95 
96 
103  static DataBuf keyTXTChunk(const DataBuf& data, bool stripHeader=false);
104 
113  static std::string makeMetadataChunk(const std::string& metadata,
114  MetadataId type);
115 
116  private:
121  static DataBuf parseTXTChunk(const DataBuf& data,
122  int keysize,
123  TxtChunkType type);
124 
134  static void parseChunkContent( Image* pImage,
135  const byte* key,
136  long keySize,
137  const DataBuf arr);
138 
149  static std::string makeAsciiTxtChunk(const std::string& keyword,
150  const std::string& text,
151  bool compress);
152 
161  static std::string makeUtf8TxtChunk(const std::string& keyword,
162  const std::string& text,
163  bool compress);
164 
168  static void zlibUncompress(const byte* compressedText,
169  unsigned int compressedTextSize,
170  DataBuf& arr);
171 
175  static std::string zlibCompress(const std::string& text);
176 
180  static DataBuf readRawProfile(const DataBuf& text,bool iTXt);
181 
186  static std::string writeRawProfile(const std::string& profileData,
187  const char* profileType);
188 
189  friend class Exiv2::PngImage;
190 
191  }; // class PngChunk
192 
193 }} // namespace Internal, Exiv2
194 
195 #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:55
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:433
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:229
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:50
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:248
Exiv2::PngImage
Class to access PNG images. Exif and IPTC metadata are supported directly.
Definition: pngimage.hpp:47
Exiv2::MetadataId
MetadataId
An identifier for each type of metadata.
Definition: types.hpp:108
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:1013
MetadataId
MetadataId
Metadata identifiers.
Definition: exiv2app.hpp:75
Exiv2::DataBuf
Utility class containing a character array. All it does is to take care of memory allocation and dele...
Definition: types.hpp:193
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:323
Exiv2
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
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:403
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:102
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.
Safe::add
T add(T summand_1, T summand_2)
Safe addition, throws an exception on overflow.
Definition: safe_op.hpp:288
Exiv2::Error
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324
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:78
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:887
error.hpp
Error class for exceptions, log message class.
Exiv2::Blob
std::vector< byte > Blob
Container for binary data.
Definition: types.hpp:151
iptc.hpp
Encoding and decoding of IPTC data.