Skip to content

Commit e031dc3

Browse files
authored
feat(jpeg): output hint "jpeg:iptc" (#4346)
JPEG output configuration hint "jpeg:iptc" (default: 1), if set to 0, will suppress IPTC block output to the file. In the process, we changed the return type of utility function encode_iptc_iim() to return true if anything was successfully encoded, false otherwise. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent f578096 commit e031dc3

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/doc/builtinplugins.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,10 @@ control aspects of the writing itself:
10771077
- ptr
10781078
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
10791079
example by writing to a memory buffer.
1080+
* - ``jpeg:iptc``
1081+
- int (1)
1082+
- If zero, will suppress writing the IPTC metadata block to the
1083+
JPEG file.
10801084
* - ``jpeg:progressive``
10811085
- int
10821086
- If nonzero, will write a progressive JPEG file.

src/include/OpenImageIO/tiffutils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ OIIO_API bool decode_iptc_iim (const void *iptc, int length, ImageSpec &spec);
189189
/// for multiple format plugins to support embedding IPTC metadata
190190
/// without having to duplicate functionality within each plugin. Note
191191
/// that IIM is actually considered obsolete and is replaced by an XML
192-
/// scheme called XMP.
193-
OIIO_API void encode_iptc_iim (const ImageSpec &spec, std::vector<char> &iptc);
192+
/// scheme called XMP. Return true if it was successful and any items
193+
/// were encoded.
194+
OIIO_API bool encode_iptc_iim (const ImageSpec &spec, std::vector<char> &iptc);
194195

195196
/// Add metadata to spec based on XMP data in an XML block. Return true
196197
/// if all is ok, false if the xml was somehow malformed. This is a

src/jpeg.imageio/jpegoutput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ JpgOutput::open(const std::string& name, const ImageSpec& newspec,
249249

250250
// Write IPTC IIM metadata tags, if we have anything
251251
std::vector<char> iptc;
252-
encode_iptc_iim(m_spec, iptc);
253-
if (iptc.size()) {
252+
if (m_spec.get_int_attribute("jpeg:iptc", 1)
253+
&& encode_iptc_iim(m_spec, iptc)) {
254254
static char photoshop[] = "Photoshop 3.0";
255255
std::vector<char> head(photoshop, photoshop + strlen(photoshop) + 1);
256256
static char _8BIM[] = "8BIM";

src/libOpenImageIO/iptc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ encode_iptc_iim_one_tag(int tag, string_view data, std::vector<char>& iptc)
179179

180180

181181

182-
void
182+
bool
183183
encode_iptc_iim(const ImageSpec& spec, std::vector<char>& iptc)
184184
{
185185
iptc.clear();
@@ -206,6 +206,7 @@ encode_iptc_iim(const ImageSpec& spec, std::vector<char>& iptc)
206206
encode_iptc_iim_one_tag(iimtag[i].tag, p->get_string(0), iptc);
207207
}
208208
}
209+
return iptc.size() != 0;
209210
}
210211

211212

0 commit comments

Comments
 (0)