Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/jpeg2000.imageio/jpeg2000output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ Jpeg2000Output::write_scanline(int y, int z, TypeDesc format, const void* data,
stride_t xstride)
{
y -= m_spec.y;
if (y > m_spec.height) {
errorfmt("Attempt to write too many scanlines to {}", m_filename);
if (y < 0 || y >= m_spec.height) {
Comment thread
lgritz marked this conversation as resolved.
errorfmt("Attempt to write scanline {} outside the image to {}",
y + m_spec.y, m_filename);
return false;
}

Expand Down Expand Up @@ -350,9 +351,14 @@ Jpeg2000Output::write_tile(int x, int y, int z, TypeDesc format,
bool
Jpeg2000Output::close()
{
if (!m_stream) { // Already closed
// m_stream only exists after save_image(), which tiled output has not
// yet reached, so test for the images instead.
bool is_open = m_image != nullptr;
#ifdef USE_OPENJPH
is_open |= m_jph_image != nullptr;
#endif
if (!is_open) // Already closed
return true;
}

bool ok = true;
if (m_spec.tile_width) {
Expand Down Expand Up @@ -541,7 +547,7 @@ Jpeg2000Output::copy_scanline(int y, int /*z*/, const void* data)
{
int bits = sizeof(T) * 8;
const T* scanline = static_cast<const T*>(data);
const size_t scanline_pos = (y - m_spec.y) * m_spec.width;
const size_t scanline_pos = size_t(y) * m_spec.width;
for (int i = 0, j = 0; i < m_spec.width; i++) {
for (int c = 0; c < m_spec.nchannels; ++c) {
unsigned int val = scanline[j++];
Expand Down
2 changes: 2 additions & 0 deletions testsuite/htj2k/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Comparing "../oiio-images/tahoe-gps.jpg" and "test.j2c"
PASS
Comparing "../oiio-images/dpx/dpx_nuke_10bits_rgb.dpx" and "testdpx.j2c"
PASS
Comparing "../oiio-images/tahoe-gps.jpg" and "testtiled.j2c"
PASS
Comparing "../oiio-images/tahoe-gps.jpg" and "testcompress.j2c"
PASS
oiiotool ERROR: read : "src/bomb-resolution.j2c": jpeg2000 image dimension 2000000000x2000000000 exceeds "limits:resolution" = 1048576 for a single dimension. Possible corrupt input?
Expand Down
5 changes: 5 additions & 0 deletions testsuite/htj2k/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

command += diff_command(OIIO_TESTSUITE_IMAGEDIR+"/dpx/dpx_nuke_10bits_rgb.dpx", "testdpx.j2c")

# Tiled output is emulated by buffering, and must still be written on close.
command += oiiotool(OIIO_TESTSUITE_IMAGEDIR+"/tahoe-gps.jpg"
" --tile 64 64 -o testtiled.j2c")
command += diff_command(OIIO_TESTSUITE_IMAGEDIR+"/tahoe-gps.jpg", "testtiled.j2c")


command += oiiotool(OIIO_TESTSUITE_IMAGEDIR+"/tahoe-gps.jpg"
" --attrib qstep 0.03 -o testcompress.j2c")
Expand Down
2 changes: 2 additions & 0 deletions testsuite/jpeg2000/ref/out-icc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ idiff ERROR: Could not read ../oiio-images/jpeg2000/broken/issue_3427.jp2:
Failed to decode the codestream in the JP2 file
Invalid image file "../oiio-images/jpeg2000/broken/issue_3427.jp2": Tile part length size inconsistent with stream length
Failed to decode the codestream in the JP2 file
Comparing "../common/tahoe-tiny.tif" and "tiled.jp2"
PASS
ICCProfile of tahoe-icc.jp2
ICCProfile: 0, 0, 2, 48, 65, 68, 66, 69, 2, 16, 0, 0, 109, 110, 116, 114, ... [560 x uint8]
ICCProfile:attributes: "Reflective, Glossy, Positive, Color"
Expand Down
2 changes: 2 additions & 0 deletions testsuite/jpeg2000/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ idiff ERROR: Could not read ../oiio-images/jpeg2000/broken/issue_3427.jp2:
Failed to decode the codestream in the JP2 file
Invalid image file "../oiio-images/jpeg2000/broken/issue_3427.jp2": Tile part length size inconsistent with stream length
Failed to decode the codestream in the JP2 file
Comparing "../common/tahoe-tiny.tif" and "tiled.jp2"
PASS
4 changes: 4 additions & 0 deletions testsuite/jpeg2000/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
for f in files:
command += rw_command (imagedir, f, printinfo=False)

# Tiled output is emulated by buffering, and must still be written on close.
command += oiiotool("../common/tahoe-tiny.tif --tile 16 16 -o tiled.jp2")
command += diff_command("../common/tahoe-tiny.tif", "tiled.jp2")

# Try to parse library_list to find the OpenJPEG version. If found, return it as
# a single number, e.g. 2.5.3 -> 20503. Return -1 if not found.
def get_openjp_ver():
Expand Down
Loading