| 7369 | } |
| 7370 | |
| 7371 | static int EncodeChunk(const EXRImage* exr_image, const EXRHeader* exr_header, |
| 7372 | const std::vector<ChannelInfo>& channels, |
| 7373 | int num_blocks, |
| 7374 | tinyexr_uint64 chunk_offset, // starting offset of current chunk |
| 7375 | bool is_multipart, |
| 7376 | OffsetData& offset_data, // output block offsets, must be initialized |
| 7377 | std::vector<std::vector<unsigned char> >& data_list, // output |
| 7378 | tinyexr_uint64& total_size, // output: ending offset of current chunk |
| 7379 | std::string* err) { |
| 7380 | int num_scanlines = NumScanlines(exr_header->compression_type); |
| 7381 | |
| 7382 | data_list.resize(num_blocks); |
| 7383 | |
| 7384 | std::vector<size_t> channel_offset_list( |
| 7385 | static_cast<size_t>(exr_header->num_channels)); |
| 7386 | |
| 7387 | int pixel_data_size = 0; |
| 7388 | { |
| 7389 | size_t channel_offset = 0; |
| 7390 | for (size_t c = 0; c < static_cast<size_t>(exr_header->num_channels); c++) { |
| 7391 | channel_offset_list[c] = channel_offset; |
| 7392 | if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_HALF) { |
| 7393 | pixel_data_size += sizeof(unsigned short); |
| 7394 | channel_offset += sizeof(unsigned short); |
| 7395 | } else if (channels[c].requested_pixel_type == |
| 7396 | TINYEXR_PIXELTYPE_FLOAT) { |
| 7397 | pixel_data_size += sizeof(float); |
| 7398 | channel_offset += sizeof(float); |
| 7399 | } else if (channels[c].requested_pixel_type == TINYEXR_PIXELTYPE_UINT) { |
| 7400 | pixel_data_size += sizeof(unsigned int); |
| 7401 | channel_offset += sizeof(unsigned int); |
| 7402 | } else { |
| 7403 | if (err) { |
| 7404 | (*err) += "Invalid requested_pixel_type.\n"; |
| 7405 | } |
| 7406 | return TINYEXR_ERROR_INVALID_DATA; |
| 7407 | } |
| 7408 | } |
| 7409 | } |
| 7410 | |
| 7411 | const void* compression_param = 0; |
| 7412 | #if TINYEXR_USE_ZFP |
| 7413 | tinyexr::ZFPCompressionParam zfp_compression_param; |
| 7414 | |
| 7415 | // Use ZFP compression parameter from custom attributes(if such a parameter |
| 7416 | // exists) |
| 7417 | { |
| 7418 | std::string e; |
| 7419 | bool ret = tinyexr::FindZFPCompressionParam( |
| 7420 | &zfp_compression_param, exr_header->custom_attributes, |
| 7421 | exr_header->num_custom_attributes, &e); |
| 7422 | |
| 7423 | if (!ret) { |
| 7424 | // Use predefined compression parameter. |
| 7425 | zfp_compression_param.type = 0; |
| 7426 | zfp_compression_param.rate = 2; |
| 7427 | } |
| 7428 | compression_param = &zfp_compression_param; |
no test coverage detected