Path: blob/master/thirdparty/libwebp/src/mux/muxedit.c
21344 views
// Copyright 2011 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Set and delete APIs for mux.10//11// Authors: Urvang ([email protected])12// Vikas ([email protected])1314#include <assert.h>15#include <stddef.h>16#include <string.h>1718#include "src/dec/vp8_dec.h"19#include "src/mux/muxi.h"20#include "src/utils/utils.h"21#include "src/webp/format_constants.h"22#include "src/webp/mux.h"23#include "src/webp/mux_types.h"24#include "src/webp/types.h"2526//------------------------------------------------------------------------------27// Life of a mux object.2829static void MuxInit(WebPMux* const mux) {30assert(mux != NULL);31memset(mux, 0, sizeof(*mux));32mux->canvas_width = 0; // just to be explicit33mux->canvas_height = 0;34}3536WebPMux* WebPNewInternal(int version) {37if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_MUX_ABI_VERSION)) {38return NULL;39} else {40WebPMux* const mux = (WebPMux*)WebPSafeMalloc(1ULL, sizeof(WebPMux));41if (mux != NULL) MuxInit(mux);42return mux;43}44}4546// Delete all images in 'wpi_list'.47static void DeleteAllImages(WebPMuxImage** const wpi_list) {48while (*wpi_list != NULL) {49*wpi_list = MuxImageDelete(*wpi_list);50}51}5253static void MuxRelease(WebPMux* const mux) {54assert(mux != NULL);55DeleteAllImages(&mux->images);56ChunkListDelete(&mux->vp8x);57ChunkListDelete(&mux->iccp);58ChunkListDelete(&mux->anim);59ChunkListDelete(&mux->exif);60ChunkListDelete(&mux->xmp);61ChunkListDelete(&mux->unknown);62}6364void WebPMuxDelete(WebPMux* mux) {65if (mux != NULL) {66MuxRelease(mux);67WebPSafeFree(mux);68}69}7071//------------------------------------------------------------------------------72// Helper method(s).7374// Handy MACRO, makes MuxSet() very symmetric to MuxGet().75#define SWITCH_ID_LIST(INDEX, LIST) \76do { \77if (idx == (INDEX)) { \78err = ChunkAssignData(&chunk, data, copy_data, tag); \79if (err == WEBP_MUX_OK) { \80err = ChunkSetHead(&chunk, (LIST)); \81if (err != WEBP_MUX_OK) ChunkRelease(&chunk); \82} \83return err; \84} \85} while (0)8687static WebPMuxError MuxSet(WebPMux* const mux, uint32_t tag,88const WebPData* const data, int copy_data) {89WebPChunk chunk;90WebPMuxError err = WEBP_MUX_NOT_FOUND;91const CHUNK_INDEX idx = ChunkGetIndexFromTag(tag);92assert(mux != NULL);93assert(!IsWPI(kChunks[idx].id));9495ChunkInit(&chunk);96SWITCH_ID_LIST(IDX_VP8X, &mux->vp8x);97SWITCH_ID_LIST(IDX_ICCP, &mux->iccp);98SWITCH_ID_LIST(IDX_ANIM, &mux->anim);99SWITCH_ID_LIST(IDX_EXIF, &mux->exif);100SWITCH_ID_LIST(IDX_XMP, &mux->xmp);101SWITCH_ID_LIST(IDX_UNKNOWN, &mux->unknown);102return err;103}104#undef SWITCH_ID_LIST105106// Create data for frame given image data, offsets and duration.107static WebPMuxError CreateFrameData(108int width, int height, const WebPMuxFrameInfo* const info,109WebPData* const frame) {110uint8_t* frame_bytes;111const size_t frame_size = kChunks[IDX_ANMF].size;112113assert(width > 0 && height > 0 && info->duration >= 0);114assert(info->dispose_method == (info->dispose_method & 1));115// Note: assertion on upper bounds is done in PutLE24().116117frame_bytes = (uint8_t*)WebPSafeMalloc(1ULL, frame_size);118if (frame_bytes == NULL) return WEBP_MUX_MEMORY_ERROR;119120PutLE24(frame_bytes + 0, info->x_offset / 2);121PutLE24(frame_bytes + 3, info->y_offset / 2);122123PutLE24(frame_bytes + 6, width - 1);124PutLE24(frame_bytes + 9, height - 1);125PutLE24(frame_bytes + 12, info->duration);126frame_bytes[15] =127(info->blend_method == WEBP_MUX_NO_BLEND ? 2 : 0) |128(info->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ? 1 : 0);129130frame->bytes = frame_bytes;131frame->size = frame_size;132return WEBP_MUX_OK;133}134135// Outputs image data given a bitstream. The bitstream can either be a136// single-image WebP file or raw VP8/VP8L data.137// Also outputs 'is_lossless' to be true if the given bitstream is lossless.138static WebPMuxError GetImageData(const WebPData* const bitstream,139WebPData* const image, WebPData* const alpha,140int* const is_lossless) {141WebPDataInit(alpha); // Default: no alpha.142if (bitstream->size < TAG_SIZE ||143memcmp(bitstream->bytes, "RIFF", TAG_SIZE)) {144// It is NOT webp file data. Return input data as is.145*image = *bitstream;146} else {147// It is webp file data. Extract image data from it.148const WebPMuxImage* wpi;149WebPMux* const mux = WebPMuxCreate(bitstream, 0);150if (mux == NULL) return WEBP_MUX_BAD_DATA;151wpi = mux->images;152assert(wpi != NULL && wpi->img != NULL);153*image = wpi->img->data;154if (wpi->alpha != NULL) {155*alpha = wpi->alpha->data;156}157WebPMuxDelete(mux);158}159*is_lossless = VP8LCheckSignature(image->bytes, image->size);160return WEBP_MUX_OK;161}162163static WebPMuxError DeleteChunks(WebPChunk** chunk_list, uint32_t tag) {164WebPMuxError err = WEBP_MUX_NOT_FOUND;165assert(chunk_list);166while (*chunk_list) {167WebPChunk* const chunk = *chunk_list;168if (chunk->tag == tag) {169*chunk_list = ChunkDelete(chunk);170err = WEBP_MUX_OK;171} else {172chunk_list = &chunk->next;173}174}175return err;176}177178static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, uint32_t tag) {179const WebPChunkId id = ChunkGetIdFromTag(tag);180assert(mux != NULL);181if (IsWPI(id)) return WEBP_MUX_INVALID_ARGUMENT;182return DeleteChunks(MuxGetChunkListFromId(mux, id), tag);183}184185//------------------------------------------------------------------------------186// Set API(s).187188WebPMuxError WebPMuxSetChunk(WebPMux* mux, const char fourcc[4],189const WebPData* chunk_data, int copy_data) {190uint32_t tag;191WebPMuxError err;192if (mux == NULL || fourcc == NULL || chunk_data == NULL ||193chunk_data->bytes == NULL || chunk_data->size > MAX_CHUNK_PAYLOAD) {194return WEBP_MUX_INVALID_ARGUMENT;195}196tag = ChunkGetTagFromFourCC(fourcc);197198// Delete existing chunk(s) with the same 'fourcc'.199err = MuxDeleteAllNamedData(mux, tag);200if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err;201202// Add the given chunk.203return MuxSet(mux, tag, chunk_data, copy_data);204}205206// Creates a chunk from given 'data' and sets it as 1st chunk in 'chunk_list'.207static WebPMuxError AddDataToChunkList(208const WebPData* const data, int copy_data, uint32_t tag,209WebPChunk** chunk_list) {210WebPChunk chunk;211WebPMuxError err;212ChunkInit(&chunk);213err = ChunkAssignData(&chunk, data, copy_data, tag);214if (err != WEBP_MUX_OK) goto Err;215err = ChunkSetHead(&chunk, chunk_list);216if (err != WEBP_MUX_OK) goto Err;217return WEBP_MUX_OK;218Err:219ChunkRelease(&chunk);220return err;221}222223// Extracts image & alpha data from the given bitstream and then sets wpi.alpha224// and wpi.img appropriately.225static WebPMuxError SetAlphaAndImageChunks(226const WebPData* const bitstream, int copy_data, WebPMuxImage* const wpi) {227int is_lossless = 0;228WebPData image, alpha;229WebPMuxError err = GetImageData(bitstream, &image, &alpha, &is_lossless);230const int image_tag =231is_lossless ? kChunks[IDX_VP8L].tag : kChunks[IDX_VP8].tag;232if (err != WEBP_MUX_OK) return err;233if (alpha.bytes != NULL) {234err = AddDataToChunkList(&alpha, copy_data, kChunks[IDX_ALPHA].tag,235&wpi->alpha);236if (err != WEBP_MUX_OK) return err;237}238err = AddDataToChunkList(&image, copy_data, image_tag, &wpi->img);239if (err != WEBP_MUX_OK) return err;240return MuxImageFinalize(wpi) ? WEBP_MUX_OK : WEBP_MUX_INVALID_ARGUMENT;241}242243WebPMuxError WebPMuxSetImage(WebPMux* mux, const WebPData* bitstream,244int copy_data) {245WebPMuxImage wpi;246WebPMuxError err;247248if (mux == NULL || bitstream == NULL || bitstream->bytes == NULL ||249bitstream->size > MAX_CHUNK_PAYLOAD) {250return WEBP_MUX_INVALID_ARGUMENT;251}252253if (mux->images != NULL) {254// Only one 'simple image' can be added in mux. So, remove present images.255DeleteAllImages(&mux->images);256}257258MuxImageInit(&wpi);259err = SetAlphaAndImageChunks(bitstream, copy_data, &wpi);260if (err != WEBP_MUX_OK) goto Err;261262// Add this WebPMuxImage to mux.263err = MuxImagePush(&wpi, &mux->images);264if (err != WEBP_MUX_OK) goto Err;265266// All is well.267return WEBP_MUX_OK;268269Err: // Something bad happened.270MuxImageRelease(&wpi);271return err;272}273274WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* info,275int copy_data) {276WebPMuxImage wpi;277WebPMuxError err;278279if (mux == NULL || info == NULL) return WEBP_MUX_INVALID_ARGUMENT;280281if (info->id != WEBP_CHUNK_ANMF) return WEBP_MUX_INVALID_ARGUMENT;282283if (info->bitstream.bytes == NULL ||284info->bitstream.size > MAX_CHUNK_PAYLOAD) {285return WEBP_MUX_INVALID_ARGUMENT;286}287288if (mux->images != NULL) {289const WebPMuxImage* const image = mux->images;290const uint32_t image_id = (image->header != NULL) ?291ChunkGetIdFromTag(image->header->tag) : WEBP_CHUNK_IMAGE;292if (image_id != info->id) {293return WEBP_MUX_INVALID_ARGUMENT; // Conflicting frame types.294}295}296297MuxImageInit(&wpi);298err = SetAlphaAndImageChunks(&info->bitstream, copy_data, &wpi);299if (err != WEBP_MUX_OK) goto Err;300assert(wpi.img != NULL); // As SetAlphaAndImageChunks() was successful.301302{303WebPData frame;304const uint32_t tag = kChunks[IDX_ANMF].tag;305WebPMuxFrameInfo tmp = *info;306tmp.x_offset &= ~1; // Snap offsets to even.307tmp.y_offset &= ~1;308if (tmp.x_offset < 0 || tmp.x_offset >= MAX_POSITION_OFFSET ||309tmp.y_offset < 0 || tmp.y_offset >= MAX_POSITION_OFFSET ||310(tmp.duration < 0 || tmp.duration >= MAX_DURATION) ||311tmp.dispose_method != (tmp.dispose_method & 1)) {312err = WEBP_MUX_INVALID_ARGUMENT;313goto Err;314}315err = CreateFrameData(wpi.width, wpi.height, &tmp, &frame);316if (err != WEBP_MUX_OK) goto Err;317// Add frame chunk (with copy_data = 1).318err = AddDataToChunkList(&frame, 1, tag, &wpi.header);319WebPDataClear(&frame); // frame owned by wpi.header now.320if (err != WEBP_MUX_OK) goto Err;321}322323// Add this WebPMuxImage to mux.324err = MuxImagePush(&wpi, &mux->images);325if (err != WEBP_MUX_OK) goto Err;326327// All is well.328return WEBP_MUX_OK;329330Err: // Something bad happened.331MuxImageRelease(&wpi);332return err;333}334335WebPMuxError WebPMuxSetAnimationParams(WebPMux* mux,336const WebPMuxAnimParams* params) {337WebPMuxError err;338uint8_t data[ANIM_CHUNK_SIZE];339const WebPData anim = { data, ANIM_CHUNK_SIZE };340341if (mux == NULL || params == NULL) return WEBP_MUX_INVALID_ARGUMENT;342if (params->loop_count < 0 || params->loop_count >= MAX_LOOP_COUNT) {343return WEBP_MUX_INVALID_ARGUMENT;344}345346// Delete any existing ANIM chunk(s).347err = MuxDeleteAllNamedData(mux, kChunks[IDX_ANIM].tag);348if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err;349350// Set the animation parameters.351PutLE32(data, params->bgcolor);352PutLE16(data + 4, params->loop_count);353return MuxSet(mux, kChunks[IDX_ANIM].tag, &anim, 1);354}355356WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux,357int width, int height) {358WebPMuxError err;359if (mux == NULL) {360return WEBP_MUX_INVALID_ARGUMENT;361}362if (width < 0 || height < 0 ||363width > MAX_CANVAS_SIZE || height > MAX_CANVAS_SIZE) {364return WEBP_MUX_INVALID_ARGUMENT;365}366if (width * (uint64_t)height >= MAX_IMAGE_AREA) {367return WEBP_MUX_INVALID_ARGUMENT;368}369if ((width * height) == 0 && (width | height) != 0) {370// one of width / height is zero, but not both -> invalid!371return WEBP_MUX_INVALID_ARGUMENT;372}373// If we already assembled a VP8X chunk, invalidate it.374err = MuxDeleteAllNamedData(mux, kChunks[IDX_VP8X].tag);375if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err;376377mux->canvas_width = width;378mux->canvas_height = height;379return WEBP_MUX_OK;380}381382//------------------------------------------------------------------------------383// Delete API(s).384385WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]) {386if (mux == NULL || fourcc == NULL) return WEBP_MUX_INVALID_ARGUMENT;387return MuxDeleteAllNamedData(mux, ChunkGetTagFromFourCC(fourcc));388}389390WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth) {391if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;392return MuxImageDeleteNth(&mux->images, nth);393}394395//------------------------------------------------------------------------------396// Assembly of the WebP RIFF file.397398static WebPMuxError GetFrameInfo(399const WebPChunk* const frame_chunk,400int* const x_offset, int* const y_offset, int* const duration) {401const WebPData* const data = &frame_chunk->data;402const size_t expected_data_size = ANMF_CHUNK_SIZE;403assert(frame_chunk->tag == kChunks[IDX_ANMF].tag);404assert(frame_chunk != NULL);405if (data->size != expected_data_size) return WEBP_MUX_INVALID_ARGUMENT;406407*x_offset = 2 * GetLE24(data->bytes + 0);408*y_offset = 2 * GetLE24(data->bytes + 3);409*duration = GetLE24(data->bytes + 12);410return WEBP_MUX_OK;411}412413static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi,414int* const x_offset, int* const y_offset,415int* const duration,416int* const width, int* const height) {417const WebPChunk* const frame_chunk = wpi->header;418WebPMuxError err;419assert(wpi != NULL);420assert(frame_chunk != NULL);421422// Get offsets and duration from ANMF chunk.423err = GetFrameInfo(frame_chunk, x_offset, y_offset, duration);424if (err != WEBP_MUX_OK) return err;425426// Get width and height from VP8/VP8L chunk.427if (width != NULL) *width = wpi->width;428if (height != NULL) *height = wpi->height;429return WEBP_MUX_OK;430}431432// Returns the tightest dimension for the canvas considering the image list.433static WebPMuxError GetAdjustedCanvasSize(const WebPMux* const mux,434int* const width, int* const height) {435WebPMuxImage* wpi = NULL;436assert(mux != NULL);437assert(width != NULL && height != NULL);438439wpi = mux->images;440assert(wpi != NULL);441assert(wpi->img != NULL);442443if (wpi->next != NULL) {444int max_x = 0, max_y = 0;445// if we have a chain of wpi's, header is necessarily set446assert(wpi->header != NULL);447// Aggregate the bounding box for animation frames.448for (; wpi != NULL; wpi = wpi->next) {449int x_offset = 0, y_offset = 0, duration = 0, w = 0, h = 0;450const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset,451&duration, &w, &h);452const int max_x_pos = x_offset + w;453const int max_y_pos = y_offset + h;454if (err != WEBP_MUX_OK) return err;455assert(x_offset < MAX_POSITION_OFFSET);456assert(y_offset < MAX_POSITION_OFFSET);457458if (max_x_pos > max_x) max_x = max_x_pos;459if (max_y_pos > max_y) max_y = max_y_pos;460}461*width = max_x;462*height = max_y;463} else {464// For a single image, canvas dimensions are same as image dimensions.465*width = wpi->width;466*height = wpi->height;467}468return WEBP_MUX_OK;469}470471// VP8X format:472// Total Size : 10,473// Flags : 4 bytes,474// Width : 3 bytes,475// Height : 3 bytes.476static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {477WebPMuxError err = WEBP_MUX_OK;478uint32_t flags = 0;479int width = 0;480int height = 0;481uint8_t data[VP8X_CHUNK_SIZE];482const WebPData vp8x = { data, VP8X_CHUNK_SIZE };483const WebPMuxImage* images = NULL;484485assert(mux != NULL);486images = mux->images; // First image.487if (images == NULL || images->img == NULL ||488images->img->data.bytes == NULL) {489return WEBP_MUX_INVALID_ARGUMENT;490}491492// If VP8X chunk(s) is(are) already present, remove them (and later add new493// VP8X chunk with updated flags).494err = MuxDeleteAllNamedData(mux, kChunks[IDX_VP8X].tag);495if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err;496497// Set flags.498if (mux->iccp != NULL && mux->iccp->data.bytes != NULL) {499flags |= ICCP_FLAG;500}501if (mux->exif != NULL && mux->exif->data.bytes != NULL) {502flags |= EXIF_FLAG;503}504if (mux->xmp != NULL && mux->xmp->data.bytes != NULL) {505flags |= XMP_FLAG;506}507if (images->header != NULL) {508if (images->header->tag == kChunks[IDX_ANMF].tag) {509// This is an image with animation.510flags |= ANIMATION_FLAG;511}512}513if (MuxImageCount(images, WEBP_CHUNK_ALPHA) > 0) {514flags |= ALPHA_FLAG; // Some images have an alpha channel.515}516517err = GetAdjustedCanvasSize(mux, &width, &height);518if (err != WEBP_MUX_OK) return err;519520if (width <= 0 || height <= 0) {521return WEBP_MUX_INVALID_ARGUMENT;522}523if (width > MAX_CANVAS_SIZE || height > MAX_CANVAS_SIZE) {524return WEBP_MUX_INVALID_ARGUMENT;525}526527if (mux->canvas_width != 0 || mux->canvas_height != 0) {528if (width > mux->canvas_width || height > mux->canvas_height) {529return WEBP_MUX_INVALID_ARGUMENT;530}531width = mux->canvas_width;532height = mux->canvas_height;533}534535if (flags == 0 && mux->unknown == NULL) {536// For simple file format, VP8X chunk should not be added.537return WEBP_MUX_OK;538}539540if (MuxHasAlpha(images)) {541// This means some frames explicitly/implicitly contain alpha.542// Note: This 'flags' update must NOT be done for a lossless image543// without a VP8X chunk!544flags |= ALPHA_FLAG;545}546547PutLE32(data + 0, flags); // VP8X chunk flags.548PutLE24(data + 4, width - 1); // canvas width.549PutLE24(data + 7, height - 1); // canvas height.550551return MuxSet(mux, kChunks[IDX_VP8X].tag, &vp8x, 1);552}553554// Cleans up 'mux' by removing any unnecessary chunks.555static WebPMuxError MuxCleanup(WebPMux* const mux) {556int num_frames;557int num_anim_chunks;558559// If we have an image with a single frame, and its rectangle560// covers the whole canvas, convert it to a non-animated image561// (to avoid writing ANMF chunk unnecessarily).562WebPMuxError err = WebPMuxNumChunks(mux, kChunks[IDX_ANMF].id, &num_frames);563if (err != WEBP_MUX_OK) return err;564if (num_frames == 1) {565WebPMuxImage* frame = NULL;566err = MuxImageGetNth((const WebPMuxImage**)&mux->images, 1, &frame);567if (err != WEBP_MUX_OK) return err;568// We know that one frame does exist.569assert(frame != NULL);570if (frame->header != NULL &&571((mux->canvas_width == 0 && mux->canvas_height == 0) ||572(frame->width == mux->canvas_width &&573frame->height == mux->canvas_height))) {574assert(frame->header->tag == kChunks[IDX_ANMF].tag);575ChunkDelete(frame->header); // Removes ANMF chunk.576frame->header = NULL;577num_frames = 0;578}579}580// Remove ANIM chunk if this is a non-animated image.581err = WebPMuxNumChunks(mux, kChunks[IDX_ANIM].id, &num_anim_chunks);582if (err != WEBP_MUX_OK) return err;583if (num_anim_chunks >= 1 && num_frames == 0) {584err = MuxDeleteAllNamedData(mux, kChunks[IDX_ANIM].tag);585if (err != WEBP_MUX_OK) return err;586}587return WEBP_MUX_OK;588}589590// Total size of a list of images.591static size_t ImageListDiskSize(const WebPMuxImage* wpi_list) {592size_t size = 0;593while (wpi_list != NULL) {594size += MuxImageDiskSize(wpi_list);595wpi_list = wpi_list->next;596}597return size;598}599600// Write out the given list of images into 'dst'.601static uint8_t* ImageListEmit(const WebPMuxImage* wpi_list, uint8_t* dst) {602while (wpi_list != NULL) {603dst = MuxImageEmit(wpi_list, dst);604wpi_list = wpi_list->next;605}606return dst;607}608609WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {610size_t size = 0;611uint8_t* data = NULL;612uint8_t* dst = NULL;613WebPMuxError err;614615if (assembled_data == NULL) {616return WEBP_MUX_INVALID_ARGUMENT;617}618// Clean up returned data, in case something goes wrong.619memset(assembled_data, 0, sizeof(*assembled_data));620621if (mux == NULL) {622return WEBP_MUX_INVALID_ARGUMENT;623}624625// Finalize mux.626err = MuxCleanup(mux);627if (err != WEBP_MUX_OK) return err;628err = CreateVP8XChunk(mux);629if (err != WEBP_MUX_OK) return err;630631// Allocate data.632size = ChunkListDiskSize(mux->vp8x) + ChunkListDiskSize(mux->iccp)633+ ChunkListDiskSize(mux->anim) + ImageListDiskSize(mux->images)634+ ChunkListDiskSize(mux->exif) + ChunkListDiskSize(mux->xmp)635+ ChunkListDiskSize(mux->unknown) + RIFF_HEADER_SIZE;636637data = (uint8_t*)WebPSafeMalloc(1ULL, size);638if (data == NULL) return WEBP_MUX_MEMORY_ERROR;639640// Emit header & chunks.641dst = MuxEmitRiffHeader(data, size);642dst = ChunkListEmit(mux->vp8x, dst);643dst = ChunkListEmit(mux->iccp, dst);644dst = ChunkListEmit(mux->anim, dst);645dst = ImageListEmit(mux->images, dst);646dst = ChunkListEmit(mux->exif, dst);647dst = ChunkListEmit(mux->xmp, dst);648dst = ChunkListEmit(mux->unknown, dst);649assert(dst == data + size);650651// Validate mux.652err = MuxValidate(mux);653if (err != WEBP_MUX_OK) {654WebPSafeFree(data);655data = NULL;656size = 0;657}658659// Finalize data.660assembled_data->bytes = data;661assembled_data->size = size;662663return err;664}665666//------------------------------------------------------------------------------667668669