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