out_data must be allocated initially with the block-header size of the current image(-part) type
| 7059 | // out_data must be allocated initially with the block-header size |
| 7060 | // of the current image(-part) type |
| 7061 | static bool EncodePixelData(/* out */ std::vector<unsigned char>& out_data, |
| 7062 | const unsigned char* const* images, |
| 7063 | int compression_type, |
| 7064 | int /*line_order*/, |
| 7065 | int width, // for tiled : tile.width |
| 7066 | int /*height*/, // for tiled : header.tile_size_y |
| 7067 | int x_stride, // for tiled : header.tile_size_x |
| 7068 | int line_no, // for tiled : 0 |
| 7069 | int num_lines, // for tiled : tile.height |
| 7070 | size_t pixel_data_size, |
| 7071 | const std::vector<ChannelInfo>& channels, |
| 7072 | const std::vector<size_t>& channel_offset_list, |
| 7073 | std::string *err, |
| 7074 | const void* compression_param = 0) // zfp compression param |
| 7075 | { |
| 7076 | size_t buf_size = static_cast<size_t>(width) * |
| 7077 | static_cast<size_t>(num_lines) * |
| 7078 | static_cast<size_t>(pixel_data_size); |
| 7079 | //int last2bit = (buf_size & 3); |
| 7080 | // buf_size must be multiple of four |
| 7081 | //if(last2bit) buf_size += 4 - last2bit; |
| 7082 | std::vector<unsigned char> buf(buf_size); |
| 7083 | |
| 7084 | size_t start_y = static_cast<size_t>(line_no); |
| 7085 | for (size_t c = 0; c < channels.size(); c++) { |
| 7086 | if (channels[c].pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 7087 | if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_FLOAT) { |
| 7088 | for (int y = 0; y < num_lines; y++) { |
| 7089 | // Assume increasing Y |
| 7090 | float *line_ptr = reinterpret_cast<float *>(&buf.at( |
| 7091 | static_cast<size_t>(pixel_data_size * size_t(y) * size_t(width)) + |
| 7092 | channel_offset_list[c] * |
| 7093 | static_cast<size_t>(width))); |
| 7094 | for (int x = 0; x < width; x++) { |
| 7095 | tinyexr::FP16 h16; |
| 7096 | h16.u = reinterpret_cast<const unsigned short * const *>( |
| 7097 | images)[c][(y + start_y) * size_t(x_stride) + size_t(x)]; |
| 7098 | |
| 7099 | tinyexr::FP32 f32 = half_to_float(h16); |
| 7100 | |
| 7101 | tinyexr::swap4(&f32.f); |
| 7102 | |
| 7103 | // line_ptr[x] = f32.f; |
| 7104 | tinyexr::cpy4(line_ptr + x, &(f32.f)); |
| 7105 | } |
| 7106 | } |
| 7107 | } else if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 7108 | for (int y = 0; y < num_lines; y++) { |
| 7109 | // Assume increasing Y |
| 7110 | unsigned short *line_ptr = reinterpret_cast<unsigned short *>( |
| 7111 | &buf.at(static_cast<size_t>(pixel_data_size * y * |
| 7112 | width) + |
| 7113 | channel_offset_list[c] * |
| 7114 | static_cast<size_t>(width))); |
| 7115 | for (int x = 0; x < width; x++) { |
| 7116 | unsigned short val = reinterpret_cast<const unsigned short * const *>( |
| 7117 | images)[c][(y + start_y) * x_stride + x]; |
| 7118 |
no test coverage detected