| 427 | } |
| 428 | |
| 429 | avifResult avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker) |
| 430 | { |
| 431 | assert(stream->numUsedBitsInPartialByte == 0); // Byte alignment is required. |
| 432 | size_t boxSize = stream->offset - marker; |
| 433 | // Since marker comes from a previous avifRWStreamWriteBox() or |
| 434 | // avifRWStreamWriteFullBox() call, boxSize must be >= the size of the size |
| 435 | // and type fields. This implies that boxSize cannot be equal to the two |
| 436 | // special values 0 and 1. |
| 437 | AVIF_ASSERT_OR_RETURN(boxSize >= sizeof(uint32_t) + 4); |
| 438 | AVIF_CHECKERR(boxSize <= UINT32_MAX, AVIF_RESULT_INVALID_ARGUMENT); |
| 439 | uint32_t noSize = avifHTONL((uint32_t)boxSize); |
| 440 | memcpy(stream->raw->data + marker, &noSize, sizeof(uint32_t)); |
| 441 | return AVIF_RESULT_OK; |
| 442 | } |
| 443 | |
| 444 | avifResult avifRWStreamWriteU8(avifRWStream * stream, uint8_t v) |
| 445 | { |