Encodes an image into an AVIF grid then decodes it.
| 23 | |
| 24 | // Encodes an image into an AVIF grid then decodes it. |
| 25 | void EncodeDecodeGridValid(ImagePtr image, EncoderPtr encoder, |
| 26 | DecoderPtr decoder, uint32_t grid_cols, |
| 27 | uint32_t grid_rows, bool is_encoded_data_persistent, |
| 28 | bool give_size_hint_to_decoder) { |
| 29 | ASSERT_NE(image, nullptr); |
| 30 | ASSERT_NE(encoder, nullptr); |
| 31 | |
| 32 | const std::vector<ImagePtr> cells = |
| 33 | ImageToGrid(image.get(), grid_cols, grid_rows); |
| 34 | if (cells.empty()) return; |
| 35 | const uint32_t cell_width = cells.front()->width; |
| 36 | const uint32_t cell_height = cells.front()->height; |
| 37 | const uint32_t encoded_width = std::min(image->width, grid_cols * cell_width); |
| 38 | const uint32_t encoded_height = |
| 39 | std::min(image->height, grid_rows * cell_height); |
| 40 | |
| 41 | const avifImage* gain_map = |
| 42 | image->gainMap != nullptr ? image->gainMap->image : nullptr; |
| 43 | if (gain_map != nullptr) { |
| 44 | std::vector<ImagePtr> gain_map_cells = |
| 45 | ImageToGrid(gain_map, grid_cols, grid_rows); |
| 46 | if (gain_map_cells.empty()) return; |
| 47 | ASSERT_EQ(gain_map_cells.size(), cells.size()); |
| 48 | for (size_t i = 0; i < gain_map_cells.size(); ++i) { |
| 49 | cells[i]->gainMap = avifGainMapCreate(); |
| 50 | cells[i]->gainMap->image = gain_map_cells[i].release(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | AvifRwData encoded_data; |
| 55 | const avifResult encoder_result = avifEncoderAddImageGrid( |
| 56 | encoder.get(), grid_cols, grid_rows, UniquePtrToRawPtr(cells).data(), |
| 57 | AVIF_ADD_IMAGE_FLAG_SINGLE); |
| 58 | if (((grid_cols > 1 || grid_rows > 1) && |
| 59 | !avifAreGridDimensionsValid(image->yuvFormat, encoded_width, |
| 60 | encoded_height, cell_width, cell_height, |
| 61 | nullptr))) { |
| 62 | ASSERT_TRUE(encoder_result == AVIF_RESULT_INVALID_IMAGE_GRID) |
| 63 | << avifResultToString(encoder_result); |
| 64 | return; |
| 65 | } |
| 66 | if ((gain_map != nullptr) && |
| 67 | ((grid_cols > 1 || grid_rows > 1) && |
| 68 | !avifAreGridDimensionsValid( |
| 69 | gain_map->yuvFormat, |
| 70 | std::min(gain_map->width, |
| 71 | grid_cols * cells.front()->gainMap->image->width), |
| 72 | std::min(gain_map->height, |
| 73 | grid_rows * cells.front()->gainMap->image->height), |
| 74 | cells.front()->gainMap->image->width, |
| 75 | cells.front()->gainMap->image->height, nullptr))) { |
| 76 | ASSERT_TRUE(encoder_result == AVIF_RESULT_INVALID_IMAGE_GRID) |
| 77 | << avifResultToString(encoder_result); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | ASSERT_EQ(encoder_result, AVIF_RESULT_OK) |
| 82 | << avifResultToString(encoder_result); |
nothing calls this directly
no test coverage detected