| 7456 | } |
| 7457 | |
| 7458 | static int EncodeChunk(const EXRImage* exr_image, const EXRHeader* exr_header, |
| 7459 | const std::vector<ChannelInfo>& channels, |
| 7460 | int num_blocks, |
| 7461 | tinyexr_uint64 chunk_offset, // starting offset of current chunk |
| 7462 | bool is_multipart, |
| 7463 | OffsetData& offset_data, // output block offsets, must be initialized |
| 7464 | std::vector<std::vector<unsigned char> >& data_list, // output |
| 7465 | tinyexr_uint64& total_size, // output: ending offset of current chunk |
| 7466 | std::string* err) { |
| 7467 | int num_scanlines = NumScanlines(exr_header->compression_type); |
| 7468 | |
| 7469 | data_list.resize(num_blocks); |
| 7470 | |
| 7471 | std::vector<size_t> channel_offset_list( |
| 7472 | static_cast<size_t>(exr_header->num_channels)); |
| 7473 | |
| 7474 | int pixel_data_size = 0; |
| 7475 | { |
| 7476 | size_t channel_offset = 0; |
| 7477 | for (size_t c = 0; c < static_cast<size_t>(exr_header->num_channels); c++) { |
| 7478 | channel_offset_list[c] = channel_offset; |
| 7479 | if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 7480 | pixel_data_size += sizeof(unsigned short); |
| 7481 | channel_offset += sizeof(unsigned short); |
| 7482 | } else if (channels[c].requested_pixel_type == |
| 7483 | TINYEXR_PIXELTYPE_FLOAT) { |
| 7484 | pixel_data_size += sizeof(float); |
| 7485 | channel_offset += sizeof(float); |
| 7486 | } else if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_UINT) { |
| 7487 | pixel_data_size += sizeof(unsigned int); |
| 7488 | channel_offset += sizeof(unsigned int); |
| 7489 | } else { |
| 7490 | if (err) { |
| 7491 | (*err) += "Invalid requested_pixel_type.\n"; |
| 7492 | } |
| 7493 | return TINYEXR_ERROR_INVALID_DATA; |
| 7494 | } |
| 7495 | } |
| 7496 | } |
| 7497 | |
| 7498 | const void* compression_param = 0; |
| 7499 | #if TINYEXR_USE_ZFP |
| 7500 | tinyexr::ZFPCompressionParam zfp_compression_param; |
| 7501 | |
| 7502 | // Use ZFP compression parameter from custom attributes(if such a parameter |
| 7503 | // exists) |
| 7504 | { |
| 7505 | std::string e; |
| 7506 | bool ret = tinyexr::FindZFPCompressionParam( |
| 7507 | &zfp_compression_param, exr_header->custom_attributes, |
| 7508 | exr_header->num_custom_attributes, &e); |
| 7509 | |
| 7510 | if (!ret) { |
| 7511 | // Use predefined compression parameter. |
| 7512 | zfp_compression_param.type = 0; |
| 7513 | zfp_compression_param.rate = 2; |
| 7514 | } |
| 7515 | compression_param = &zfp_compression_param; |
no test coverage detected