Skip to content

Commit

Permalink
int: Added check_open for PNG, JPEG, and EXR readers (#4452)
Browse files Browse the repository at this point in the history
This PR is ment to address this feature request:
#3974

I added `check_open` for these file format's ImageInput while following
each file specfication:
- PNG: https://www.w3.org/TR/png/#11IHDR
- JPEG:
https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_APP0_marker_segment
- EXR:
https://openexr.com/en/latest/OpenEXRFileLayout.html#header-attributes-all-files

---------

Signed-off-by: Dharshan Vishwanatha <[email protected]>
  • Loading branch information
DharshanV authored Sep 28, 2024
1 parent 0391796 commit 243b3b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/jpeg.imageio/jpeginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ JpgInput::open(const std::string& name, ImageSpec& newspec)
m_spec = ImageSpec(m_cinfo.output_width, m_cinfo.output_height, nchannels,
TypeDesc::UINT8);

if (!check_open(m_spec, { 0, 1 << 16, 0, 1 << 16, 0, 1, 0, 3 }))
return false;

// Assume JPEG is in sRGB unless the Exif or XMP tags say otherwise.
m_spec.attribute("oiio:ColorSpace", "sRGB");

Expand Down
3 changes: 3 additions & 0 deletions src/openexr.imageio/exrinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,9 @@ OpenEXRInput::seek_subimage(int subimage, int miplevel)
m_miplevel = miplevel;
m_spec = part.spec;

if (!check_open(m_spec, { 0, 1 << 20, 0, 1 << 20, 0, 1 << 16, 0, 1 << 12 }))
return false;

if (miplevel == 0 && part.levelmode == Imf::ONE_LEVEL) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/png.imageio/pnginput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ PNGInput::open(const std::string& name, ImageSpec& newspec)
bool ok = PNG_pvt::read_info(m_png, m_info, m_bit_depth, m_color_type,
m_interlace_type, m_bg, m_spec,
m_keep_unassociated_alpha);
if (!ok || m_err) {
if (!ok || m_err
|| !check_open(m_spec, { 0, 1 << 16, 0, 1 << 16, 0, 1, 0, 4 })) {
close();
return false;
}
Expand Down

0 comments on commit 243b3b6

Please sign in to comment.