|
18 | 18 | #ifdef USE_OPENJPH |
19 | 19 | # include <openjph/ojph_codestream.h> |
20 | 20 | # include <openjph/ojph_file.h> |
| 21 | +OIIO_PRAGMA_WARNING_PUSH |
| 22 | +OIIO_GCC_PRAGMA(GCC diagnostic ignored "-Wdelete-incomplete") |
21 | 23 | # include <openjph/ojph_mem.h> |
| 24 | +OIIO_PRAGMA_WARNING_POP |
22 | 25 | # include <openjph/ojph_message.h> |
23 | 26 | # include <openjph/ojph_params.h> |
24 | 27 | #endif |
@@ -273,7 +276,13 @@ class jph_infile : public ojph::infile_base { |
273 | 276 | return ioproxy->seek(offset, origin); |
274 | 277 | } |
275 | 278 | ojph::si64 tell() { return ioproxy->tell(); }; |
276 | | - bool eof() { return ioproxy->tell() == ioproxy->size(); } |
| 279 | + bool eof() |
| 280 | + { |
| 281 | + int64_t pos = ioproxy->tell(); |
| 282 | + if (pos < 0) |
| 283 | + return false; // Error condition, not EOF |
| 284 | + return pos == static_cast<int64_t>(ioproxy->size()); |
| 285 | + } |
277 | 286 | void close() |
278 | 287 | { |
279 | 288 | ioproxy->close(); |
@@ -385,50 +394,48 @@ Jpeg2000Input::ojph_read_image() |
385 | 394 | // We are going to read the whole image into the buffer, since with openjph |
386 | 395 | // its hard to easily grab part of the image. |
387 | 396 | if (codestream.is_planar()) { |
388 | | - for (ojph::ui32 c = 0; c < ch; ++c) |
389 | | - |
390 | | - for (ojph::ui32 i = 0; i < h; ++i) { |
| 397 | + for (int c = 0; c < ch; ++c) |
| 398 | + for (int i = 0; i < h; ++i) { |
391 | 399 | ojph::ui32 comp_num; |
392 | 400 | ojph::line_buf* line = codestream.pull(comp_num); |
393 | 401 | const ojph::si32* sp = line->i32; |
394 | | - assert(comp_num == c); |
| 402 | + OIIO_DASSERT(int(comp_num) == c); |
395 | 403 | if (m_spec.format == TypeDesc::UCHAR) { |
396 | 404 | unsigned char* dout = &m_buf[i * w * ch]; |
397 | 405 | dout += c; |
398 | | - for (ojph::ui32 j = w; j > 0; j--, dout += ch) { |
| 406 | + for (int j = w; j > 0; j--, dout += ch) { |
399 | 407 | *dout = *sp++; |
400 | 408 | } |
401 | 409 | } |
402 | 410 | if (m_spec.format == TypeDesc::USHORT) { |
403 | 411 | unsigned short* dout |
404 | 412 | = (unsigned short*)&m_buf[buffer_bpp * (i * w * ch)]; |
405 | 413 | dout += c; |
406 | | - for (ojph::ui32 j = w; j > 0; j--, dout += ch) { |
| 414 | + for (int j = w; j > 0; j--, dout += ch) { |
407 | 415 | *dout = bit_range_convert(*sp++, file_bit_depth, |
408 | 416 | buffer_bpp * 8); |
409 | 417 | } |
410 | 418 | } |
411 | 419 | } |
412 | | - |
413 | 420 | } else { |
414 | | - for (ojph::ui32 i = 0; i < h; ++i) { |
415 | | - for (ojph::ui32 c = 0; c < ch; ++c) { |
| 421 | + for (int i = 0; i < h; ++i) { |
| 422 | + for (int c = 0; c < ch; ++c) { |
416 | 423 | ojph::ui32 comp_num; |
417 | 424 | ojph::line_buf* line = codestream.pull(comp_num); |
418 | 425 | const ojph::si32* sp = line->i32; |
419 | | - assert(comp_num == c); |
| 426 | + OIIO_DASSERT(int(comp_num) == c); |
420 | 427 | if (m_spec.format == TypeDesc::UCHAR) { |
421 | 428 | unsigned char* dout = &m_buf[i * w * ch]; |
422 | 429 | dout += c; |
423 | | - for (ojph::ui32 j = w; j > 0; j--, dout += ch) { |
| 430 | + for (int j = w; j > 0; j--, dout += ch) { |
424 | 431 | *dout = *sp++; |
425 | 432 | } |
426 | 433 | } |
427 | 434 | if (m_spec.format == TypeDesc::USHORT) { |
428 | 435 | unsigned short* dout |
429 | 436 | = (unsigned short*)&m_buf[buffer_bpp * (i * w * ch)]; |
430 | 437 | dout += c; |
431 | | - for (ojph::ui32 j = w; j > 0; j--, dout += ch) { |
| 438 | + for (int j = w; j > 0; j--, dout += ch) { |
432 | 439 | *dout = bit_range_convert(*sp++, file_bit_depth, |
433 | 440 | buffer_bpp * 8); |
434 | 441 | } |
@@ -480,6 +487,9 @@ Jpeg2000Input::open(const std::string& name, ImageSpec& p_spec) |
480 | 487 | jph_infile* jphinfile = new jph_infile(ioproxy()); |
481 | 488 | ojph_reader = true; |
482 | 489 | ojph::message_error* default_error = ojph::get_error(); |
| 490 | + // Disable the default OpenJPH error stream to prevent unwanted error output. |
| 491 | + // Errors will be handled by the custom error handler (Oiio_Reader_Error_handler) configured below. |
| 492 | + ojph::set_error_stream(nullptr); |
483 | 493 |
|
484 | 494 | try { |
485 | 495 | Oiio_Reader_Error_handler error_handler(default_error); |
|
0 commit comments