MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / EncodePixelData

Function EncodePixelData

Source/ThirdParty/tinyexr/tinyexr.h:6977–7232  ·  view source on GitHub ↗

out_data must be allocated initially with the block-header size of the current image(-part) type

Source from the content-addressed store, hash-verified

6975// out_data must be allocated initially with the block-header size
6976// of the current image(-part) type
6977static bool EncodePixelData(/* out */ std::vector<unsigned char>& out_data,
6978 const unsigned char* const* images,
6979 int compression_type,
6980 int /*line_order*/,
6981 int width, // for tiled : tile.width
6982 int /*height*/, // for tiled : header.tile_size_y
6983 int x_stride, // for tiled : header.tile_size_x
6984 int line_no, // for tiled : 0
6985 int num_lines, // for tiled : tile.height
6986 size_t pixel_data_size,
6987 const std::vector<ChannelInfo>& channels,
6988 const std::vector<size_t>& channel_offset_list,
6989 std::string *err,
6990 const void* compression_param = 0) // zfp compression param
6991{
6992 size_t buf_size = static_cast<size_t>(width) *
6993 static_cast<size_t>(num_lines) *
6994 static_cast<size_t>(pixel_data_size);
6995 //int last2bit = (buf_size & 3);
6996 // buf_size must be multiple of four
6997 //if(last2bit) buf_size += 4 - last2bit;
6998 std::vector<unsigned char> buf(buf_size);
6999
7000 size_t start_y = static_cast<size_t>(line_no);
7001 for (size_t c = 0; c < channels.size(); c++) {
7002 if (channels[c].pixel_type == TINYEXR_PIXELTYPE_HALF) {
7003 if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_FLOAT) {
7004 for (int y = 0; y < num_lines; y++) {
7005 // Assume increasing Y
7006 float *line_ptr = reinterpret_cast<float *>(&buf.at(
7007 static_cast<size_t>(pixel_data_size * size_t(y) * size_t(width)) +
7008 channel_offset_list[c] *
7009 static_cast<size_t>(width)));
7010 for (int x = 0; x < width; x++) {
7011 tinyexr::FP16 h16;
7012 h16.u = reinterpret_cast<const unsigned short * const *>(
7013 images)[c][(y + start_y) * size_t(x_stride) + size_t(x)];
7014
7015 tinyexr::FP32 f32 = half_to_float(h16);
7016
7017 tinyexr::swap4(&f32.f);
7018
7019 // line_ptr[x] = f32.f;
7020 tinyexr::cpy4(line_ptr + x, &(f32.f));
7021 }
7022 }
7023 } else if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_HALF) {
7024 for (int y = 0; y < num_lines; y++) {
7025 // Assume increasing Y
7026 unsigned short *line_ptr = reinterpret_cast<unsigned short *>(
7027 &buf.at(static_cast<size_t>(pixel_data_size * y *
7028 width) +
7029 channel_offset_list[c] *
7030 static_cast<size_t>(width)));
7031 for (int x = 0; x < width; x++) {
7032 unsigned short val = reinterpret_cast<const unsigned short * const *>(
7033 images)[c][(y + start_y) * x_stride + x];
7034

Callers 2

EncodeTiledLevelFunction · 0.85
EncodeChunkFunction · 0.85

Calls 15

swap4Function · 0.85
cpy4Function · 0.85
swap2Function · 0.85
cpy2Function · 0.85
float_to_half_fullFunction · 0.85
CompressZipFunction · 0.85
CompressRleFunction · 0.85
CompressPizFunction · 0.85
CompressZfpFunction · 0.85
half_to_floatFunction · 0.70
mz_compressBoundFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected