TODO(syoyo): Refactor function arguments.
| 4846 | |
| 4847 | // TODO(syoyo): Refactor function arguments. |
| 4848 | static bool DecodePixelData(/* out */ unsigned char **out_images, |
| 4849 | const int *requested_pixel_types, |
| 4850 | const unsigned char *data_ptr, size_t data_len, |
| 4851 | int compression_type, int line_order, int width, |
| 4852 | int height, int x_stride, int y, int line_no, |
| 4853 | int num_lines, size_t pixel_data_size, |
| 4854 | size_t num_attributes, |
| 4855 | const EXRAttribute *attributes, size_t num_channels, |
| 4856 | const EXRChannelInfo *channels, |
| 4857 | const std::vector<size_t> &channel_offset_list) { |
| 4858 | if (compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { // PIZ |
| 4859 | #if TINYEXR_USE_PIZ |
| 4860 | if ((width == 0) || (num_lines == 0) || (pixel_data_size == 0)) { |
| 4861 | // Invalid input #90 |
| 4862 | return false; |
| 4863 | } |
| 4864 | |
| 4865 | // Allocate original data size. |
| 4866 | std::vector<unsigned char> outBuf(static_cast<size_t>( |
| 4867 | static_cast<size_t>(width * num_lines) * pixel_data_size)); |
| 4868 | size_t tmpBufLen = outBuf.size(); |
| 4869 | |
| 4870 | bool ret = tinyexr::DecompressPiz( |
| 4871 | reinterpret_cast<unsigned char *>(&outBuf.at(0)), data_ptr, tmpBufLen, |
| 4872 | data_len, static_cast<int>(num_channels), channels, width, num_lines); |
| 4873 | |
| 4874 | if (!ret) { |
| 4875 | return false; |
| 4876 | } |
| 4877 | |
| 4878 | // For PIZ_COMPRESSION: |
| 4879 | // pixel sample data for channel 0 for scanline 0 |
| 4880 | // pixel sample data for channel 1 for scanline 0 |
| 4881 | // pixel sample data for channel ... for scanline 0 |
| 4882 | // pixel sample data for channel n for scanline 0 |
| 4883 | // pixel sample data for channel 0 for scanline 1 |
| 4884 | // pixel sample data for channel 1 for scanline 1 |
| 4885 | // pixel sample data for channel ... for scanline 1 |
| 4886 | // pixel sample data for channel n for scanline 1 |
| 4887 | // ... |
| 4888 | for (size_t c = 0; c < static_cast<size_t>(num_channels); c++) { |
| 4889 | if (channels[c].pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 4890 | for (size_t v = 0; v < static_cast<size_t>(num_lines); v++) { |
| 4891 | const unsigned short *line_ptr = reinterpret_cast<unsigned short *>( |
| 4892 | &outBuf.at(v * pixel_data_size * static_cast<size_t>(width) + |
| 4893 | channel_offset_list[c] * static_cast<size_t>(width))); |
| 4894 | for (size_t u = 0; u < static_cast<size_t>(width); u++) { |
| 4895 | FP16 hf; |
| 4896 | |
| 4897 | // hf.u = line_ptr[u]; |
| 4898 | // use `cpy` to avoid unaligned memory access when compiler's |
| 4899 | // optimization is on. |
| 4900 | tinyexr::cpy2(&(hf.u), line_ptr + u); |
| 4901 | |
| 4902 | tinyexr::swap2(reinterpret_cast<unsigned short *>(&hf.u)); |
| 4903 | |
| 4904 | if (requested_pixel_types[c] == TINYEXR_PIXELTYPE_HALF) { |
| 4905 | unsigned short *image = |
no test coverage detected