MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / EncodePixelData

Function EncodePixelData

Source/ThirdParty/tinyexr.h:8505–8825  ·  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

8503// out_data must be allocated initially with the block-header size
8504// of the current image(-part) type
8505static bool EncodePixelData(/* out */ std::vector<unsigned char>& out_data,
8506 const unsigned char* const* images,
8507 int compression_type,
8508 int /*line_order*/,
8509 int width, // for tiled : tile.width
8510 int /*height*/, // for tiled : header.tile_size_y
8511 int x_stride, // for tiled : header.tile_size_x
8512 int line_no, // for tiled : 0
8513 int num_lines, // for tiled : tile.height
8514 size_t pixel_data_size,
8515 const std::vector<ChannelInfo>& channels,
8516 const std::vector<size_t>& channel_offset_list,
8517 std::string *err,
8518 const void* compression_param = 0) // zfp compression param
8519{
8520 size_t buf_size = static_cast<size_t>(width) *
8521 static_cast<size_t>(num_lines) *
8522 static_cast<size_t>(pixel_data_size);
8523 //int last2bit = (buf_size & 3);
8524 // buf_size must be multiple of four
8525 //if(last2bit) buf_size += 4 - last2bit;
8526 std::vector<unsigned char> buf(buf_size);
8527
8528 size_t start_y = static_cast<size_t>(line_no);
8529 for (size_t c = 0; c < channels.size(); c++) {
8530 if (channels[c].pixel_type == TINYEXR_PIXELTYPE_HALF) {
8531 if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_FLOAT) {
8532 for (int y = 0; y < num_lines; y++) {
8533 // Assume increasing Y
8534 float *line_ptr = reinterpret_cast<float *>(&buf.at(
8535 static_cast<size_t>(pixel_data_size * size_t(y) * size_t(width)) +
8536 channel_offset_list[c] *
8537 static_cast<size_t>(width)));
8538 for (int x = 0; x < width; x++) {
8539 tinyexr::FP16 h16;
8540 h16.u = reinterpret_cast<const unsigned short * const *>(
8541 images)[c][(y + start_y) * size_t(x_stride) + size_t(x)];
8542
8543 tinyexr::FP32 f32 = half_to_float(h16);
8544
8545 tinyexr::swap4(&f32.f);
8546
8547 // line_ptr[x] = f32.f;
8548 tinyexr::cpy4(line_ptr + x, &(f32.f));
8549 }
8550 }
8551 } else if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_HALF) {
8552 for (int y = 0; y < num_lines; y++) {
8553 // Assume increasing Y
8554 unsigned short *line_ptr = reinterpret_cast<unsigned short *>(
8555 &buf.at(static_cast<size_t>(pixel_data_size * y *
8556 width) +
8557 channel_offset_list[c] *
8558 static_cast<size_t>(width)));
8559 for (int x = 0; x < width; x++) {
8560 unsigned short val = reinterpret_cast<const unsigned short * const *>(
8561 images)[c][(y + start_y) * x_stride + x];
8562

Callers 2

EncodeTiledLevelFunction · 0.85
EncodeChunkFunction · 0.85

Calls 12

half_to_floatFunction · 0.85
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
CompressPxr24Function · 0.85
CompressB44Function · 0.85

Tested by

no test coverage detected