Skip to content

Commit f942ba8

Browse files
committed
Move Photoshopb class to internal namespace
1 parent 047f6b7 commit f942ba8

File tree

14 files changed

+271
-234
lines changed

14 files changed

+271
-234
lines changed

app/exiv2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "xmp_exiv2.hpp"
1414

1515
#include <algorithm>
16+
#include <array>
1617
#include <cctype>
1718
#include <cstring>
1819
#include <fstream>

include/exiv2/exiv2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "exiv2/mrwimage.hpp"
3030
#include "exiv2/orfimage.hpp"
3131
#include "exiv2/pgfimage.hpp"
32+
#include "exiv2/photoshop.hpp"
3233

3334
#ifdef EXV_HAVE_LIBZ
3435
#include "exiv2/pngimage.hpp"

include/exiv2/jpgimage.hpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
#ifndef JPGIMAGE_HPP_
44
#define JPGIMAGE_HPP_
55

6-
// *****************************************************************************
76
#include "exiv2lib_export.h"
87

9-
#include <array>
10-
118
// included header files
129
#include "error.hpp"
1310
#include "image.hpp"
@@ -18,59 +15,6 @@ namespace Exiv2 {
1815
// *****************************************************************************
1916
// class definitions
2017

21-
/// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs).
22-
struct EXIV2API Photoshop {
23-
// Todo: Public for now
24-
static constexpr std::array irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
25-
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
26-
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
27-
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker
28-
29-
/// @brief Checks an IRB
30-
/// @param pPsData Existing IRB buffer. It is expected to be of size 4.
31-
/// @return true if the IRB marker is known
32-
/// @todo This should be an implementation detail and not exposed in the API. An attacker could try to pass
33-
/// a smaller buffer or null pointer.
34-
static bool isIrb(const byte* pPsData);
35-
36-
/// @brief Validates all IRBs
37-
/// @param pPsData Existing IRB buffer
38-
/// @param sizePsData Size of the IRB buffer, may be 0
39-
/// @return true if all IRBs are valid;<BR> false otherwise
40-
static bool valid(const byte* pPsData, size_t sizePsData);
41-
42-
/// @brief Locates the data for a %Photoshop tag in a %Photoshop formated memory buffer.
43-
/// Operates on raw data to simplify reuse.
44-
/// @param pPsData Pointer to buffer containing entire payload of %Photoshop formated data (from APP13 Jpeg segment)
45-
/// @param sizePsData Size in bytes of pPsData.
46-
/// @param psTag %Tag number of the block to look for.
47-
/// @param record Output value that is set to the start of the data block within pPsData (may not be null).
48-
/// @param sizeHdr Output value that is set to the size of the header within the data block pointed to by record
49-
/// (may not be null).
50-
/// @param sizeData Output value that is set to the size of the actual data within the data block pointed to by record
51-
/// (may not be null).
52-
/// @return 0 if successful;<BR>
53-
/// 3 if no data for psTag was found in pPsData;<BR>
54-
/// -2 if the pPsData buffer does not contain valid data.
55-
static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record,
56-
uint32_t* const sizeHdr, uint32_t* const sizeData);
57-
58-
/// @brief Forwards to locateIrb() with \em psTag = \em iptc_
59-
static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
60-
uint32_t* const sizeData);
61-
62-
/// @brief Forwards to locatePreviewIrb() with \em psTag = \em preview_
63-
static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
64-
uint32_t* const sizeData);
65-
66-
/// @brief Set the new IPTC IRB, keeps existing IRBs but removes the IPTC block if there is no new IPTC data to write.
67-
/// @param pPsData Existing IRB buffer
68-
/// @param sizePsData Size of the IRB buffer, may be 0
69-
/// @param iptcData Iptc data to embed, may be empty
70-
/// @return A data buffer containing the new IRB buffer, may have 0 size
71-
static DataBuf setIptcIrb(const byte* pPsData, size_t sizePsData, const IptcData& iptcData);
72-
};
73-
7418
/*!
7519
@brief Abstract helper base class to access JPEG images.
7620
*/

include/exiv2/photoshop.hpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
#ifndef PHOTOSHOP_INT_HPP
4+
#define PHOTOSHOP_INT_HPP
5+
6+
#include "exiv2lib_export.h"
7+
8+
#include "types.hpp"
9+
10+
#include <array>
11+
12+
namespace Exiv2 {
13+
// Forward declarations
14+
class IptcData;
15+
16+
/// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs).
17+
struct EXIV2API Photoshop {
18+
// Todo: Public for now
19+
static constexpr std::array irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
20+
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
21+
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
22+
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker
23+
24+
/// @brief Checks an IRB
25+
/// @param pPsData Existing IRB buffer. It is expected to be of size 4.
26+
/// @return true if the IRB marker is known
27+
/// @todo This should be an implementation detail and not exposed in the API. An attacker could try to pass
28+
/// a smaller buffer or null pointer.
29+
static bool isIrb(const byte* pPsData);
30+
31+
/// @brief Validates all IRBs
32+
/// @param pPsData Existing IRB buffer
33+
/// @param sizePsData Size of the IRB buffer, may be 0
34+
/// @return true if all IRBs are valid;<BR> false otherwise
35+
static bool valid(const byte* pPsData, size_t sizePsData);
36+
37+
/// @brief Locates the data for a %Photoshop tag in a %Photoshop formated memory buffer.
38+
/// Operates on raw data to simplify reuse.
39+
/// @param pPsData Pointer to buffer containing entire payload of %Photoshop formated data (from APP13 Jpeg segment)
40+
/// @param sizePsData Size in bytes of pPsData.
41+
/// @param psTag %Tag number of the block to look for.
42+
/// @param record Output value that is set to the start of the data block within pPsData (may not be null).
43+
/// @param sizeHdr Output value that is set to the size of the header within the data block pointed to by record
44+
/// (may not be null).
45+
/// @param sizeData Output value that is set to the size of the actual data within the data block pointed to by record
46+
/// (may not be null).
47+
/// @return 0 if successful;<BR>
48+
/// 3 if no data for psTag was found in pPsData;<BR>
49+
/// -2 if the pPsData buffer does not contain valid data.
50+
static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record,
51+
uint32_t* const sizeHdr, uint32_t* const sizeData);
52+
53+
/// @brief Forwards to locateIrb() with \em psTag = \em iptc_
54+
static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
55+
uint32_t* const sizeData);
56+
57+
/// @brief Forwards to locatePreviewIrb() with \em psTag = \em preview_
58+
static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
59+
uint32_t* const sizeData);
60+
61+
/// @brief Set the new IPTC IRB, keeps existing IRBs but removes the IPTC block if there is no new IPTC data to write.
62+
/// @param pPsData Existing IRB buffer
63+
/// @param sizePsData Size of the IRB buffer, may be 0
64+
/// @param iptcData Iptc data to embed, may be empty
65+
/// @return A data buffer containing the new IRB buffer, may have 0 size
66+
static DataBuf setIptcIrb(const byte* pPsData, size_t sizePsData, const IptcData& iptcData);
67+
};
68+
} // namespace Exiv2
69+
70+
#endif // PHOTOSHOP_INT_HPP

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ set(PUBLIC_HEADERS
6565
../include/exiv2/mrwimage.hpp
6666
../include/exiv2/orfimage.hpp
6767
../include/exiv2/pgfimage.hpp
68+
../include/exiv2/photoshop.hpp
6869
../include/exiv2/preview.hpp
6970
../include/exiv2/properties.hpp
7071
../include/exiv2/psdimage.hpp
@@ -107,6 +108,7 @@ add_library( exiv2lib
107108
mrwimage.cpp
108109
orfimage.cpp
109110
pgfimage.cpp
111+
photoshop.cpp
110112
preview.cpp
111113
properties.cpp
112114
psdimage.cpp

src/image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "xmpsidecar.hpp"
3939

4040
// + standard includes
41+
#include <array>
4142
#include <cstdio>
4243
#include <cstring>
4344
#include <limits>

0 commit comments

Comments
 (0)