TODO(syoyo): Refactor function arguments.
| 3596 | |
| 3597 | // TODO(syoyo): Refactor function arguments. |
| 3598 | static bool DecodePixelData(/* out */ unsigned char **out_images, |
| 3599 | const int *requested_pixel_types, |
| 3600 | const unsigned char *data_ptr, size_t data_len, |
| 3601 | int compression_type, int line_order, int width, |
| 3602 | int height, int x_stride, int y, int line_no, |
| 3603 | int num_lines, size_t pixel_data_size, |
| 3604 | size_t num_attributes, |
| 3605 | const EXRAttribute *attributes, size_t num_channels, |
| 3606 | const EXRChannelInfo *channels, |
| 3607 | const std::vector<size_t> &channel_offset_list) { |
| 3608 | if (compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { // PIZ |
| 3609 | #if TINYEXR_USE_PIZ |
| 3610 | if ((width == 0) || (num_lines == 0) || (pixel_data_size == 0)) { |
| 3611 | // Invalid input #90 |
| 3612 | return false; |
| 3613 | } |
| 3614 | |
| 3615 | // Allocate original data size. |
| 3616 | std::vector<unsigned char> outBuf(static_cast<size_t>( |
| 3617 | static_cast<size_t>(width * num_lines) * pixel_data_size)); |
| 3618 | size_t tmpBufLen = outBuf.size(); |
| 3619 | |
| 3620 | bool ret = tinyexr::DecompressPiz( |
| 3621 | reinterpret_cast<unsigned char *>(&outBuf.at(0)), data_ptr, tmpBufLen, |
| 3622 | data_len, static_cast<int>(num_channels), channels, width, num_lines); |
| 3623 | |
| 3624 | if (!ret) { |
| 3625 | return false; |
| 3626 | } |
| 3627 | |
| 3628 | // For PIZ_COMPRESSION: |
| 3629 | // pixel sample data for channel 0 for scanline 0 |
| 3630 | // pixel sample data for channel 1 for scanline 0 |
| 3631 | // pixel sample data for channel ... for scanline 0 |
| 3632 | // pixel sample data for channel n for scanline 0 |
| 3633 | // pixel sample data for channel 0 for scanline 1 |
| 3634 | // pixel sample data for channel 1 for scanline 1 |
| 3635 | // pixel sample data for channel ... for scanline 1 |
| 3636 | // pixel sample data for channel n for scanline 1 |
| 3637 | // ... |
| 3638 | for (size_t c = 0; c < static_cast<size_t>(num_channels); c++) { |
| 3639 | if (channels[c].pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 3640 | for (size_t v = 0; v < static_cast<size_t>(num_lines); v++) { |
| 3641 | const unsigned short *line_ptr = reinterpret_cast<unsigned short *>( |
| 3642 | &outBuf.at(v * pixel_data_size * static_cast<size_t>(width) + |
| 3643 | channel_offset_list[c] * static_cast<size_t>(width))); |
| 3644 | for (size_t u = 0; u < static_cast<size_t>(width); u++) { |
| 3645 | FP16 hf; |
| 3646 | |
| 3647 | // hf.u = line_ptr[u]; |
| 3648 | // use `cpy` to avoid unaligned memory access when compiler's |
| 3649 | // optimization is on. |
| 3650 | tinyexr::cpy2(&(hf.u), line_ptr + u); |
| 3651 | |
| 3652 | tinyexr::swap2(reinterpret_cast<unsigned short *>(&hf.u)); |
| 3653 | |
| 3654 | if (requested_pixel_types[c] == TINYEXR_PIXELTYPE_HALF) { |
| 3655 | unsigned short *image = |
no test coverage detected