MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifEncoderAddImageItems

Function avifEncoderAddImageItems

src/write.c:1250–1291  ·  view source on GitHub ↗

Adds the items for a single cell or a grid of cells. Outputs the topLevelItemID which is the only item if there is exactly one cell, or the grid item for multiple cells. Note: The topLevelItemID output argument has the type uint16_t* instead of avifEncoderItem** because the avifEncoderItem pointer may be invalidated by a call to avifEncoderDataCreateItem().

Source from the content-addressed store, hash-verified

1248// Note: The topLevelItemID output argument has the type uint16_t* instead of avifEncoderItem** because
1249// the avifEncoderItem pointer may be invalidated by a call to avifEncoderDataCreateItem().
1250static avifResult avifEncoderAddImageItems(avifEncoder * encoder,
1251 uint32_t gridCols,
1252 uint32_t gridRows,
1253 uint32_t gridWidth,
1254 uint32_t gridHeight,
1255 avifItemCategory itemCategory,
1256 uint16_t * topLevelItemID)
1257{
1258 const uint32_t cellCount = gridCols * gridRows;
1259 const char * infeName = getInfeName(itemCategory);
1260 const size_t infeNameSize = strlen(infeName) + 1;
1261
1262 if (cellCount > 1) {
1263 avifEncoderItem * gridItem = avifEncoderDataCreateItem(encoder->data, "grid", infeName, infeNameSize, 0);
1264 AVIF_CHECKRES(avifWriteGridPayload(&gridItem->metadataPayload, gridCols, gridRows, gridWidth, gridHeight));
1265 gridItem->itemCategory = itemCategory;
1266 gridItem->gridCols = gridCols;
1267 gridItem->gridRows = gridRows;
1268 gridItem->gridWidth = gridWidth;
1269 gridItem->gridHeight = gridHeight;
1270 *topLevelItemID = gridItem->id;
1271 }
1272
1273 for (uint32_t cellIndex = 0; cellIndex < cellCount; ++cellIndex) {
1274 avifEncoderItem * item =
1275 avifEncoderDataCreateItem(encoder->data, encoder->data->imageItemType, infeName, infeNameSize, cellIndex);
1276 AVIF_CHECKERR(item, AVIF_RESULT_OUT_OF_MEMORY);
1277 AVIF_CHECKRES(avifCodecCreate(encoder->codecChoice, AVIF_CODEC_FLAG_CAN_ENCODE, &item->codec));
1278 item->codec->csOptions = encoder->csOptions;
1279 item->codec->diag = &encoder->diag;
1280 item->itemCategory = itemCategory;
1281 item->extraLayerCount = encoder->extraLayerCount;
1282
1283 if (cellCount > 1) {
1284 item->dimgFromID = *topLevelItemID;
1285 item->hiddenImage = AVIF_TRUE;
1286 } else {
1287 *topLevelItemID = item->id;
1288 }
1289 }
1290 return AVIF_RESULT_OK;
1291}
1292
1293static avifResult avifEncoderCreateBitDepthExtensionItems(avifEncoder * encoder,
1294 uint32_t gridCols,

Calls 4

getInfeNameFunction · 0.85
avifWriteGridPayloadFunction · 0.85
avifCodecCreateFunction · 0.85

Tested by

no test coverage detected