mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
Update mux code to match the spec wrt animation
- Allow a duration of 0 - Rename LOOP chunk to ANIM and add the background color field to it. - Add a disposal method field for each animation frame. - Modify webpmux.c binary interface to allow the input of background color and disposal methods. Also make '-loop' and '-bgcolor' arguments optional with some default values. Change-Id: I807372a61cdb8a0d3080ae3552caf2848070bf4d
This commit is contained in:
@ -39,6 +39,7 @@ typedef struct Frame {
|
||||
int x_offset_, y_offset_;
|
||||
int width_, height_;
|
||||
int duration_;
|
||||
WebPMuxAnimDispose dispose_method_;
|
||||
int is_fragment_; // this is a frame fragment (and not a full frame).
|
||||
int frame_num_; // the referent frame number for use in assembling fragments.
|
||||
int complete_; // img_components_ contains a full image.
|
||||
@ -58,6 +59,7 @@ struct WebPDemuxer {
|
||||
uint32_t feature_flags_;
|
||||
int canvas_width_, canvas_height_;
|
||||
int loop_count_;
|
||||
uint32_t bgcolor_;
|
||||
int num_frames_;
|
||||
Frame* frames_;
|
||||
Chunk* chunks_; // non-image chunks
|
||||
@ -290,9 +292,7 @@ static ParseStatus NewFrame(const MemBuffer* const mem,
|
||||
static ParseStatus ParseFrame(
|
||||
WebPDemuxer* const dmux, uint32_t frame_chunk_size) {
|
||||
const int has_frames = !!(dmux->feature_flags_ & ANIMATION_FLAG);
|
||||
const uint32_t padding = (ANMF_CHUNK_SIZE & 1);
|
||||
const uint32_t anmf_payload_size =
|
||||
frame_chunk_size - (ANMF_CHUNK_SIZE + padding);
|
||||
const uint32_t anmf_payload_size = frame_chunk_size - ANMF_CHUNK_SIZE;
|
||||
int added_frame = 0;
|
||||
MemBuffer* const mem = &dmux->mem_;
|
||||
Frame* frame;
|
||||
@ -300,12 +300,12 @@ static ParseStatus ParseFrame(
|
||||
NewFrame(mem, ANMF_CHUNK_SIZE, frame_chunk_size, &frame);
|
||||
if (status != PARSE_OK) return status;
|
||||
|
||||
frame->x_offset_ = 2 * GetLE24s(mem);
|
||||
frame->y_offset_ = 2 * GetLE24s(mem);
|
||||
frame->width_ = 1 + GetLE24s(mem);
|
||||
frame->height_ = 1 + GetLE24s(mem);
|
||||
frame->duration_ = 1 + GetLE24s(mem);
|
||||
Skip(mem, padding);
|
||||
frame->x_offset_ = 2 * GetLE24s(mem);
|
||||
frame->y_offset_ = 2 * GetLE24s(mem);
|
||||
frame->width_ = 1 + GetLE24s(mem);
|
||||
frame->height_ = 1 + GetLE24s(mem);
|
||||
frame->duration_ = GetLE24s(mem);
|
||||
frame->dispose_method_ = (WebPMuxAnimDispose)(GetByte(mem) & 1);
|
||||
if (frame->width_ * (uint64_t)frame->height_ >= MAX_IMAGE_AREA) {
|
||||
return PARSE_ERROR;
|
||||
}
|
||||
@ -331,9 +331,7 @@ static ParseStatus ParseFrame(
|
||||
static ParseStatus ParseFragment(WebPDemuxer* const dmux,
|
||||
uint32_t fragment_chunk_size) {
|
||||
const int has_fragments = !!(dmux->feature_flags_ & FRAGMENTS_FLAG);
|
||||
const uint32_t padding = (FRGM_CHUNK_SIZE & 1);
|
||||
const uint32_t frgm_payload_size =
|
||||
fragment_chunk_size - (FRGM_CHUNK_SIZE + padding);
|
||||
const uint32_t frgm_payload_size = fragment_chunk_size - FRGM_CHUNK_SIZE;
|
||||
int added_fragment = 0;
|
||||
MemBuffer* const mem = &dmux->mem_;
|
||||
Frame* frame;
|
||||
@ -344,7 +342,6 @@ static ParseStatus ParseFragment(WebPDemuxer* const dmux,
|
||||
frame->is_fragment_ = 1;
|
||||
frame->x_offset_ = 2 * GetLE24s(mem);
|
||||
frame->y_offset_ = 2 * GetLE24s(mem);
|
||||
Skip(mem, padding);
|
||||
|
||||
// Store a fragment only if the fragments flag is set and all data for this
|
||||
// fragment is available.
|
||||
@ -444,7 +441,7 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) {
|
||||
|
||||
static ParseStatus ParseVP8X(WebPDemuxer* const dmux) {
|
||||
MemBuffer* const mem = &dmux->mem_;
|
||||
int loop_chunks = 0;
|
||||
int anim_chunks = 0;
|
||||
uint32_t vp8x_size;
|
||||
ParseStatus status = PARSE_OK;
|
||||
|
||||
@ -493,15 +490,16 @@ static ParseStatus ParseVP8X(WebPDemuxer* const dmux) {
|
||||
status = ParseSingleImage(dmux);
|
||||
break;
|
||||
}
|
||||
case MKFOURCC('L', 'O', 'O', 'P'): {
|
||||
if (chunk_size_padded < LOOP_CHUNK_SIZE) return PARSE_ERROR;
|
||||
case MKFOURCC('A', 'N', 'I', 'M'): {
|
||||
if (chunk_size_padded < ANIM_CHUNK_SIZE) return PARSE_ERROR;
|
||||
|
||||
if (MemDataSize(mem) < chunk_size_padded) {
|
||||
status = PARSE_NEED_MORE_DATA;
|
||||
} else if (loop_chunks == 0) {
|
||||
++loop_chunks;
|
||||
} else if (anim_chunks == 0) {
|
||||
++anim_chunks;
|
||||
dmux->bgcolor_ = GetLE32(mem);
|
||||
dmux->loop_count_ = GetLE16s(mem);
|
||||
Skip(mem, chunk_size_padded - LOOP_CHUNK_SIZE);
|
||||
Skip(mem, chunk_size_padded - ANIM_CHUNK_SIZE);
|
||||
} else {
|
||||
store_chunk = 0;
|
||||
goto Skip;
|
||||
@ -629,6 +627,7 @@ static int IsValidExtendedFormat(const WebPDemuxer* const dmux) {
|
||||
static void InitDemux(WebPDemuxer* const dmux, const MemBuffer* const mem) {
|
||||
dmux->state_ = WEBP_DEMUX_PARSING_HEADER;
|
||||
dmux->loop_count_ = 1;
|
||||
dmux->bgcolor_ = 0xFFFFFFFF; // White background by default.
|
||||
dmux->canvas_width_ = -1;
|
||||
dmux->canvas_height_ = -1;
|
||||
dmux->mem_ = *mem;
|
||||
@ -696,10 +695,11 @@ uint32_t WebPDemuxGetI(const WebPDemuxer* dmux, WebPFormatFeature feature) {
|
||||
if (dmux == NULL) return 0;
|
||||
|
||||
switch (feature) {
|
||||
case WEBP_FF_FORMAT_FLAGS: return dmux->feature_flags_;
|
||||
case WEBP_FF_CANVAS_WIDTH: return (uint32_t)dmux->canvas_width_;
|
||||
case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_;
|
||||
case WEBP_FF_LOOP_COUNT: return (uint32_t)dmux->loop_count_;
|
||||
case WEBP_FF_FORMAT_FLAGS: return dmux->feature_flags_;
|
||||
case WEBP_FF_CANVAS_WIDTH: return (uint32_t)dmux->canvas_width_;
|
||||
case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_;
|
||||
case WEBP_FF_LOOP_COUNT: return (uint32_t)dmux->loop_count_;
|
||||
case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -778,6 +778,7 @@ static int SynthesizeFrame(const WebPDemuxer* const dmux,
|
||||
iter->width = fragment->width_;
|
||||
iter->height = fragment->height_;
|
||||
iter->duration = fragment->duration_;
|
||||
iter->dispose_method = fragment->dispose_method_;
|
||||
iter->complete = fragment->complete_;
|
||||
iter->fragment.bytes = payload;
|
||||
iter->fragment.size = payload_size;
|
||||
|
@ -47,7 +47,7 @@ static void MuxRelease(WebPMux* const mux) {
|
||||
MuxImageDeleteAll(&mux->images_);
|
||||
DeleteAllChunks(&mux->vp8x_);
|
||||
DeleteAllChunks(&mux->iccp_);
|
||||
DeleteAllChunks(&mux->loop_);
|
||||
DeleteAllChunks(&mux->anim_);
|
||||
DeleteAllChunks(&mux->exif_);
|
||||
DeleteAllChunks(&mux->xmp_);
|
||||
DeleteAllChunks(&mux->unknown_);
|
||||
@ -82,7 +82,7 @@ static WebPMuxError MuxSet(WebPMux* const mux, CHUNK_INDEX idx, uint32_t nth,
|
||||
ChunkInit(&chunk);
|
||||
SWITCH_ID_LIST(IDX_VP8X, &mux->vp8x_);
|
||||
SWITCH_ID_LIST(IDX_ICCP, &mux->iccp_);
|
||||
SWITCH_ID_LIST(IDX_LOOP, &mux->loop_);
|
||||
SWITCH_ID_LIST(IDX_ANIM, &mux->anim_);
|
||||
SWITCH_ID_LIST(IDX_EXIF, &mux->exif_);
|
||||
SWITCH_ID_LIST(IDX_XMP, &mux->xmp_);
|
||||
if (idx == IDX_UNKNOWN && data->size > TAG_SIZE) {
|
||||
@ -109,11 +109,10 @@ static WebPMuxError MuxAddChunk(WebPMux* const mux, uint32_t nth, uint32_t tag,
|
||||
}
|
||||
|
||||
// Create data for frame/tile given image data, offsets and duration.
|
||||
static WebPMuxError CreateFrameFragmentData(const WebPData* const image,
|
||||
int x_offset, int y_offset,
|
||||
int duration, int is_lossless,
|
||||
int is_frame,
|
||||
WebPData* const frame_frgm) {
|
||||
static WebPMuxError CreateFrameFragmentData(
|
||||
const WebPData* const image, int x_offset, int y_offset, int duration,
|
||||
WebPMuxAnimDispose dispose_method, int is_lossless, int is_frame,
|
||||
WebPData* const frame_frgm) {
|
||||
int width;
|
||||
int height;
|
||||
uint8_t* frame_frgm_bytes;
|
||||
@ -124,7 +123,8 @@ static WebPMuxError CreateFrameFragmentData(const WebPData* const image,
|
||||
VP8GetInfo(image->bytes, image->size, image->size, &width, &height);
|
||||
if (!ok) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
||||
assert(width > 0 && height > 0 && duration > 0);
|
||||
assert(width > 0 && height > 0 && duration >= 0);
|
||||
assert(dispose_method == (dispose_method & 1));
|
||||
// Note: assertion on upper bounds is done in PutLE24().
|
||||
|
||||
frame_frgm_bytes = (uint8_t*)malloc(frame_frgm_size);
|
||||
@ -136,7 +136,8 @@ static WebPMuxError CreateFrameFragmentData(const WebPData* const image,
|
||||
if (is_frame) {
|
||||
PutLE24(frame_frgm_bytes + 6, width - 1);
|
||||
PutLE24(frame_frgm_bytes + 9, height - 1);
|
||||
PutLE24(frame_frgm_bytes + 12, duration - 1);
|
||||
PutLE24(frame_frgm_bytes + 12, duration);
|
||||
frame_frgm_bytes[15] = (dispose_method & 1);
|
||||
}
|
||||
|
||||
frame_frgm->bytes = frame_frgm_bytes;
|
||||
@ -200,11 +201,6 @@ static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux, uint32_t tag) {
|
||||
return DeleteChunks(chunk_list, tag);
|
||||
}
|
||||
|
||||
static WebPMuxError DeleteLoopCount(WebPMux* const mux) {
|
||||
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
return MuxDeleteAllNamedData(mux, kChunks[IDX_LOOP].tag);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Set API(s).
|
||||
|
||||
@ -333,16 +329,20 @@ WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* frame,
|
||||
const int x_offset = frame->x_offset & ~1; // Snap offsets to even.
|
||||
const int y_offset = frame->y_offset & ~1;
|
||||
const int duration = is_frame ? frame->duration : 1 /* unused */;
|
||||
const WebPMuxAnimDispose dispose_method =
|
||||
is_frame ? frame->dispose_method : 0 /* unused */;
|
||||
const uint32_t tag = kChunks[is_frame ? IDX_ANMF : IDX_FRGM].tag;
|
||||
WebPData frame_frgm;
|
||||
if (x_offset < 0 || x_offset >= MAX_POSITION_OFFSET ||
|
||||
y_offset < 0 || y_offset >= MAX_POSITION_OFFSET ||
|
||||
(duration <= 0 || duration > MAX_DURATION)) {
|
||||
(duration < 0 || duration >= MAX_DURATION) ||
|
||||
dispose_method != (dispose_method & 1)) {
|
||||
err = WEBP_MUX_INVALID_ARGUMENT;
|
||||
goto Err;
|
||||
}
|
||||
err = CreateFrameFragmentData(&wpi.img_->data_, x_offset, y_offset,
|
||||
duration, is_lossless, is_frame, &frame_frgm);
|
||||
duration, dispose_method, is_lossless,
|
||||
is_frame, &frame_frgm);
|
||||
if (err != WEBP_MUX_OK) goto Err;
|
||||
// Add frame/fragment chunk (with copy_data = 1).
|
||||
err = AddDataToChunkList(&frame_frgm, 1, tag, &wpi.header_);
|
||||
@ -362,20 +362,24 @@ WebPMuxError WebPMuxPushFrame(WebPMux* mux, const WebPMuxFrameInfo* frame,
|
||||
return err;
|
||||
}
|
||||
|
||||
WebPMuxError WebPMuxSetLoopCount(WebPMux* mux, int loop_count) {
|
||||
WebPMuxError WebPMuxSetAnimationParams(WebPMux* mux,
|
||||
const WebPMuxAnimParams* params) {
|
||||
WebPMuxError err;
|
||||
uint8_t data[LOOP_CHUNK_SIZE];
|
||||
uint8_t data[ANIM_CHUNK_SIZE];
|
||||
|
||||
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
if (loop_count >= MAX_LOOP_COUNT) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
if (mux == NULL || params == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
if (params->loop_count < 0 || params->loop_count >= MAX_LOOP_COUNT) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Delete the existing LOOP chunk(s).
|
||||
err = DeleteLoopCount(mux);
|
||||
// Delete any existing ANIM chunk(s).
|
||||
err = MuxDeleteAllNamedData(mux, kChunks[IDX_ANIM].tag);
|
||||
if (err != WEBP_MUX_OK && err != WEBP_MUX_NOT_FOUND) return err;
|
||||
|
||||
// Add the given loop count.
|
||||
PutLE16(data, loop_count);
|
||||
return MuxAddChunk(mux, 1, kChunks[IDX_LOOP].tag, data, sizeof(data), 1);
|
||||
// Set the animation parameters.
|
||||
PutLE32(data, params->bgcolor);
|
||||
PutLE16(data + 4, params->loop_count);
|
||||
return MuxAddChunk(mux, 1, kChunks[IDX_ANIM].tag, data, sizeof(data), 1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -408,7 +412,7 @@ static WebPMuxError GetFrameFragmentInfo(
|
||||
|
||||
*x_offset = 2 * GetLE24(data->bytes + 0);
|
||||
*y_offset = 2 * GetLE24(data->bytes + 3);
|
||||
if (is_frame) *duration = 1 + GetLE24(data->bytes + 12);
|
||||
if (is_frame) *duration = GetLE24(data->bytes + 12);
|
||||
return WEBP_MUX_OK;
|
||||
}
|
||||
|
||||
@ -586,21 +590,21 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {
|
||||
uint8_t* data = NULL;
|
||||
uint8_t* dst = NULL;
|
||||
int num_frames;
|
||||
int num_loop_chunks;
|
||||
int num_anim_chunks;
|
||||
WebPMuxError err;
|
||||
|
||||
if (mux == NULL || assembled_data == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Remove LOOP chunk if unnecessary.
|
||||
err = WebPMuxNumChunks(mux, kChunks[IDX_LOOP].id, &num_loop_chunks);
|
||||
// Remove ANIM chunk if unnecessary.
|
||||
err = WebPMuxNumChunks(mux, kChunks[IDX_ANIM].id, &num_anim_chunks);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
if (num_loop_chunks >= 1) {
|
||||
if (num_anim_chunks >= 1) {
|
||||
err = WebPMuxNumChunks(mux, kChunks[IDX_ANMF].id, &num_frames);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
if (num_frames == 0) {
|
||||
err = DeleteLoopCount(mux);
|
||||
err = MuxDeleteAllNamedData(mux, kChunks[IDX_ANIM].tag);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
}
|
||||
}
|
||||
@ -611,7 +615,7 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {
|
||||
|
||||
// Allocate data.
|
||||
size = ChunksListDiskSize(mux->vp8x_) + ChunksListDiskSize(mux->iccp_)
|
||||
+ ChunksListDiskSize(mux->loop_) + MuxImageListDiskSize(mux->images_)
|
||||
+ ChunksListDiskSize(mux->anim_) + MuxImageListDiskSize(mux->images_)
|
||||
+ ChunksListDiskSize(mux->exif_) + ChunksListDiskSize(mux->xmp_)
|
||||
+ ChunksListDiskSize(mux->unknown_) + RIFF_HEADER_SIZE;
|
||||
|
||||
@ -622,7 +626,7 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {
|
||||
dst = MuxEmitRiffHeader(data, size);
|
||||
dst = ChunkListEmit(mux->vp8x_, dst);
|
||||
dst = ChunkListEmit(mux->iccp_, dst);
|
||||
dst = ChunkListEmit(mux->loop_, dst);
|
||||
dst = ChunkListEmit(mux->anim_, dst);
|
||||
dst = MuxImageListEmit(mux->images_, dst);
|
||||
dst = ChunkListEmit(mux->exif_, dst);
|
||||
dst = ChunkListEmit(mux->xmp_, dst);
|
||||
|
@ -30,7 +30,7 @@ typedef struct WebPChunk WebPChunk;
|
||||
struct WebPChunk {
|
||||
uint32_t tag_;
|
||||
int owner_; // True if *data_ memory is owned internally.
|
||||
// VP8X, Loop, and other internally created chunks
|
||||
// VP8X, ANIM, and other internally created chunks
|
||||
// like ANMF/FRGM are always owned.
|
||||
WebPData data_;
|
||||
WebPChunk* next_;
|
||||
@ -53,7 +53,7 @@ struct WebPMux {
|
||||
WebPChunk* iccp_;
|
||||
WebPChunk* exif_;
|
||||
WebPChunk* xmp_;
|
||||
WebPChunk* loop_;
|
||||
WebPChunk* anim_;
|
||||
WebPChunk* vp8x_;
|
||||
|
||||
WebPChunk* unknown_;
|
||||
@ -66,7 +66,7 @@ struct WebPMux {
|
||||
typedef enum {
|
||||
IDX_VP8X = 0,
|
||||
IDX_ICCP,
|
||||
IDX_LOOP,
|
||||
IDX_ANIM,
|
||||
IDX_ANMF,
|
||||
IDX_FRGM,
|
||||
IDX_ALPHA,
|
||||
|
@ -22,7 +22,7 @@ extern "C" {
|
||||
const ChunkInfo kChunks[] = {
|
||||
{ MKFOURCC('V', 'P', '8', 'X'), WEBP_CHUNK_VP8X, VP8X_CHUNK_SIZE },
|
||||
{ MKFOURCC('I', 'C', 'C', 'P'), WEBP_CHUNK_ICCP, UNDEFINED_CHUNK_SIZE },
|
||||
{ MKFOURCC('L', 'O', 'O', 'P'), WEBP_CHUNK_LOOP, LOOP_CHUNK_SIZE },
|
||||
{ MKFOURCC('A', 'N', 'I', 'M'), WEBP_CHUNK_ANIM, ANIM_CHUNK_SIZE },
|
||||
{ MKFOURCC('A', 'N', 'M', 'F'), WEBP_CHUNK_ANMF, ANMF_CHUNK_SIZE },
|
||||
{ MKFOURCC('F', 'R', 'G', 'M'), WEBP_CHUNK_FRGM, FRGM_CHUNK_SIZE },
|
||||
{ MKFOURCC('A', 'L', 'P', 'H'), WEBP_CHUNK_ALPHA, UNDEFINED_CHUNK_SIZE },
|
||||
@ -135,7 +135,7 @@ static int ChunkSearchListToSet(WebPChunk** chunk_list, uint32_t nth,
|
||||
WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data,
|
||||
int copy_data, uint32_t tag) {
|
||||
// For internally allocated chunks, always copy data & make it owner of data.
|
||||
if (tag == kChunks[IDX_VP8X].tag || tag == kChunks[IDX_LOOP].tag) {
|
||||
if (tag == kChunks[IDX_VP8X].tag || tag == kChunks[IDX_ANIM].tag) {
|
||||
copy_data = 1;
|
||||
}
|
||||
|
||||
@ -462,10 +462,10 @@ uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size) {
|
||||
|
||||
WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id) {
|
||||
assert(mux != NULL);
|
||||
switch(id) {
|
||||
switch (id) {
|
||||
case WEBP_CHUNK_VP8X: return (WebPChunk**)&mux->vp8x_;
|
||||
case WEBP_CHUNK_ICCP: return (WebPChunk**)&mux->iccp_;
|
||||
case WEBP_CHUNK_LOOP: return (WebPChunk**)&mux->loop_;
|
||||
case WEBP_CHUNK_ANIM: return (WebPChunk**)&mux->anim_;
|
||||
case WEBP_CHUNK_EXIF: return (WebPChunk**)&mux->exif_;
|
||||
case WEBP_CHUNK_XMP: return (WebPChunk**)&mux->xmp_;
|
||||
case WEBP_CHUNK_UNKNOWN: return (WebPChunk**)&mux->unknown_;
|
||||
@ -518,7 +518,7 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
||||
int num_iccp;
|
||||
int num_exif;
|
||||
int num_xmp;
|
||||
int num_loop_chunks;
|
||||
int num_anim;
|
||||
int num_frames;
|
||||
int num_fragments;
|
||||
int num_vp8x;
|
||||
@ -548,19 +548,19 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
||||
err = ValidateChunk(mux, IDX_XMP, XMP_FLAG, flags, 1, &num_xmp);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
|
||||
// Animation: ANIMATION_FLAG, loop chunk and frame chunk(s) are consistent.
|
||||
// At most one loop chunk.
|
||||
err = ValidateChunk(mux, IDX_LOOP, NO_FLAG, flags, 1, &num_loop_chunks);
|
||||
// Animation: ANIMATION_FLAG, ANIM chunk and ANMF chunk(s) are consistent.
|
||||
// At most one ANIM chunk.
|
||||
err = ValidateChunk(mux, IDX_ANIM, NO_FLAG, flags, 1, &num_anim);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
err = ValidateChunk(mux, IDX_ANMF, NO_FLAG, flags, -1, &num_frames);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
|
||||
{
|
||||
const int has_animation = !!(flags & ANIMATION_FLAG);
|
||||
if (has_animation && (num_loop_chunks == 0 || num_frames == 0)) {
|
||||
if (has_animation && (num_anim == 0 || num_frames == 0)) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
if (!has_animation && (num_loop_chunks == 1 || num_frames > 0)) {
|
||||
if (!has_animation && (num_anim == 1 || num_frames > 0)) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ static WebPMuxError MuxGet(const WebPMux* const mux, CHUNK_INDEX idx,
|
||||
|
||||
SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_);
|
||||
SWITCH_ID_LIST(IDX_ICCP, mux->iccp_);
|
||||
SWITCH_ID_LIST(IDX_LOOP, mux->loop_);
|
||||
SWITCH_ID_LIST(IDX_ANIM, mux->anim_);
|
||||
SWITCH_ID_LIST(IDX_EXIF, mux->exif_);
|
||||
SWITCH_ID_LIST(IDX_XMP, mux->xmp_);
|
||||
SWITCH_ID_LIST(IDX_UNKNOWN, mux->unknown_);
|
||||
@ -376,7 +376,10 @@ static WebPMuxError MuxGetFrameFragmentInternal(const WebPMuxImage* const wpi,
|
||||
// Extract info.
|
||||
frame->x_offset = 2 * GetLE24(frame_frgm_data->bytes + 0);
|
||||
frame->y_offset = 2 * GetLE24(frame_frgm_data->bytes + 3);
|
||||
frame->duration = is_frame ? 1 + GetLE24(frame_frgm_data->bytes + 12) : 1;
|
||||
frame->duration = is_frame ? GetLE24(frame_frgm_data->bytes + 12) : 1;
|
||||
frame->dispose_method =
|
||||
is_frame ? (WebPMuxAnimDispose)(frame_frgm_data->bytes[15] & 1)
|
||||
: WEBP_MUX_DISPOSE_NONE;
|
||||
frame->id = ChunkGetIdFromTag(wpi->header_->tag_);
|
||||
return SynthesizeBitstream(wpi, &frame->bitstream);
|
||||
}
|
||||
@ -403,16 +406,18 @@ WebPMuxError WebPMuxGetFrame(
|
||||
}
|
||||
}
|
||||
|
||||
WebPMuxError WebPMuxGetLoopCount(const WebPMux* mux, int* loop_count) {
|
||||
WebPData image;
|
||||
WebPMuxError WebPMuxGetAnimationParams(const WebPMux* mux,
|
||||
WebPMuxAnimParams* params) {
|
||||
WebPData anim;
|
||||
WebPMuxError err;
|
||||
|
||||
if (mux == NULL || loop_count == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
if (mux == NULL || params == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
||||
err = MuxGet(mux, IDX_LOOP, 1, &image);
|
||||
err = MuxGet(mux, IDX_ANIM, 1, &anim);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
if (image.size < kChunks[WEBP_CHUNK_LOOP].size) return WEBP_MUX_BAD_DATA;
|
||||
*loop_count = GetLE16(image.bytes);
|
||||
if (anim.size < kChunks[WEBP_CHUNK_ANIM].size) return WEBP_MUX_BAD_DATA;
|
||||
params->bgcolor = GetLE32(anim.bytes);
|
||||
params->loop_count = GetLE16(anim.bytes + 4);
|
||||
|
||||
return WEBP_MUX_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user