Only ever create one iref box, filled with multiple cdsc boxes
Fixes: #247
diff --git a/src/write.c b/src/write.c
index b21b55b..d3ac127 100644
--- a/src/write.c
+++ b/src/write.c
@@ -633,18 +633,23 @@
// -----------------------------------------------------------------------
// Write iref boxes
+ avifBoxMarker iref = 0;
for (uint32_t itemIndex = 0; itemIndex < encoder->data->items.count; ++itemIndex) {
avifEncoderItem * item = &encoder->data->items.item[itemIndex];
if (item->irefToID != 0) {
- avifBoxMarker iref = avifRWStreamWriteFullBox(&s, "iref", AVIF_BOX_SIZE_TBD, 0, 0);
+ if (!iref) {
+ iref = avifRWStreamWriteFullBox(&s, "iref", AVIF_BOX_SIZE_TBD, 0, 0);
+ }
avifBoxMarker refType = avifRWStreamWriteBox(&s, item->irefType, AVIF_BOX_SIZE_TBD);
avifRWStreamWriteU16(&s, item->id); // unsigned int(16) from_item_ID;
avifRWStreamWriteU16(&s, 1); // unsigned int(16) reference_count;
avifRWStreamWriteU16(&s, item->irefToID); // unsigned int(16) to_item_ID;
avifRWStreamFinishBox(&s, refType);
- avifRWStreamFinishBox(&s, iref);
}
}
+ if (iref) {
+ avifRWStreamFinishBox(&s, iref);
+ }
// -----------------------------------------------------------------------
// Write iprp -> ipco/ipma