Finds the encoded base image and decodes it. Callers of this function must free codec and *decodedBaseImage if not null, whether the function succeeds or not.
| 1393 | // Finds the encoded base image and decodes it. Callers of this function must free |
| 1394 | // *codec and *decodedBaseImage if not null, whether the function succeeds or not. |
| 1395 | static avifResult avifEncoderDecodeSatoBaseImage(avifEncoder * encoder, |
| 1396 | uint32_t cellIndex, |
| 1397 | const avifImage * original, |
| 1398 | uint32_t numBits, |
| 1399 | avifPlanesFlag planes, |
| 1400 | avifCodec ** codec, |
| 1401 | avifImage ** decodedBaseImage) |
| 1402 | { |
| 1403 | avifDecodeSample sample; |
| 1404 | memset(&sample, 0, sizeof(sample)); |
| 1405 | sample.spatialID = AVIF_SPATIAL_ID_UNSET; |
| 1406 | |
| 1407 | // Find the encoded bytes of the base image item. |
| 1408 | for (uint32_t itemIndex = 0; itemIndex < encoder->data->items.count; ++itemIndex) { |
| 1409 | avifEncoderItem * item = &encoder->data->items.item[itemIndex]; |
| 1410 | if (item->codec == NULL) { |
| 1411 | continue; // Non-image item such as metadata. |
| 1412 | } |
| 1413 | if ((item->itemCategory != AVIF_ITEM_COLOR || planes != AVIF_PLANES_YUV) && |
| 1414 | (item->itemCategory != AVIF_ITEM_ALPHA || planes != AVIF_PLANES_A)) { |
| 1415 | continue; |
| 1416 | } |
| 1417 | if (item->cellIndex != cellIndex) { |
| 1418 | continue; |
| 1419 | } |
| 1420 | |
| 1421 | AVIF_ASSERT_OR_RETURN(item->encodeOutput != NULL); |
| 1422 | AVIF_ASSERT_OR_RETURN(item->encodeOutput->samples.count == 1); |
| 1423 | AVIF_ASSERT_OR_RETURN(item->encodeOutput->samples.sample[0].data.size != 0); |
| 1424 | AVIF_ASSERT_OR_RETURN(sample.data.size == 0); // There should be only one base item. |
| 1425 | sample.data.data = item->encodeOutput->samples.sample[0].data.data; |
| 1426 | sample.data.size = item->encodeOutput->samples.sample[0].data.size; |
| 1427 | } |
| 1428 | AVIF_ASSERT_OR_RETURN(sample.data.size != 0); // There should be at least one base item. |
| 1429 | |
| 1430 | AVIF_CHECKRES(avifCodecCreate(AVIF_CODEC_CHOICE_AUTO, AVIF_CODEC_FLAG_CAN_DECODE, codec)); |
| 1431 | (*codec)->diag = &encoder->diag; |
| 1432 | (*codec)->maxThreads = encoder->maxThreads; |
| 1433 | (*codec)->imageSizeLimit = AVIF_DEFAULT_IMAGE_SIZE_LIMIT; |
| 1434 | (*codec)->imageDimensionLimit = AVIF_DEFAULT_IMAGE_DIMENSION_LIMIT; |
| 1435 | AVIF_CHECKRES(avifImageCreateAllocate(decodedBaseImage, original, numBits, planes)); |
| 1436 | avifBool isLimitedRangeAlpha = AVIF_FALSE; // Ignored. |
| 1437 | AVIF_CHECKERR((*codec)->getNextImage(*codec, &sample, planes == AVIF_PLANES_A, &isLimitedRangeAlpha, *decodedBaseImage), |
| 1438 | AVIF_RESULT_ENCODE_SAMPLE_TRANSFORM_FAILED); |
| 1439 | return AVIF_RESULT_OK; |
| 1440 | } |
| 1441 | |
| 1442 | static avifResult avifEncoderCreateSatoImage(avifEncoder * encoder, |
| 1443 | const avifEncoderItem * item, |
no test coverage detected