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