mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-28 14:38:21 +01:00
Demux: Add option to get frame count using GetI()
Also tweak the code for single image and fragmented image cases, so that dmux->num_frames_ is always correct. Change-Id: I31e6904222e4d96a54a0d8c8aa73d43b7a9094e7
This commit is contained in:
parent
988b8f56b3
commit
068eba8d58
@ -337,6 +337,7 @@ static ParseStatus ParseFrame(
|
|||||||
// 'fragment_chunk_size' is the previously validated, padded chunk size.
|
// 'fragment_chunk_size' is the previously validated, padded chunk size.
|
||||||
static ParseStatus ParseFragment(WebPDemuxer* const dmux,
|
static ParseStatus ParseFragment(WebPDemuxer* const dmux,
|
||||||
uint32_t fragment_chunk_size) {
|
uint32_t fragment_chunk_size) {
|
||||||
|
const int frame_num = 1; // All fragments belong to the 1st (and only) frame.
|
||||||
const int has_fragments = !!(dmux->feature_flags_ & FRAGMENTS_FLAG);
|
const int has_fragments = !!(dmux->feature_flags_ & FRAGMENTS_FLAG);
|
||||||
const uint32_t frgm_payload_size = fragment_chunk_size - FRGM_CHUNK_SIZE;
|
const uint32_t frgm_payload_size = fragment_chunk_size - FRGM_CHUNK_SIZE;
|
||||||
int added_fragment = 0;
|
int added_fragment = 0;
|
||||||
@ -352,12 +353,14 @@ static ParseStatus ParseFragment(WebPDemuxer* const dmux,
|
|||||||
|
|
||||||
// Store a fragment only if the fragments flag is set and all data for this
|
// Store a fragment only if the fragments flag is set and all data for this
|
||||||
// fragment is available.
|
// fragment is available.
|
||||||
status = StoreFrame(dmux->num_frames_, frgm_payload_size, mem, frame, NULL);
|
status = StoreFrame(frame_num, frgm_payload_size, mem, frame, NULL);
|
||||||
if (status != PARSE_ERROR && has_fragments && frame->frame_num_ > 0) {
|
if (status != PARSE_ERROR && has_fragments && frame->frame_num_ > 0) {
|
||||||
// Note num_frames_ is incremented only when all fragments have been
|
|
||||||
// consumed.
|
|
||||||
added_fragment = AddFrame(dmux, frame);
|
added_fragment = AddFrame(dmux, frame);
|
||||||
if (!added_fragment) status = PARSE_ERROR;
|
if (!added_fragment) {
|
||||||
|
status = PARSE_ERROR;
|
||||||
|
} else {
|
||||||
|
dmux->num_frames_ = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!added_fragment) free(frame);
|
if (!added_fragment) free(frame);
|
||||||
@ -522,7 +525,6 @@ static ParseStatus ParseVP8X(WebPDemuxer* const dmux) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MKFOURCC('F', 'R', 'G', 'M'): {
|
case MKFOURCC('F', 'R', 'G', 'M'): {
|
||||||
if (dmux->num_frames_ == 0) dmux->num_frames_ = 1;
|
|
||||||
status = ParseFragment(dmux, chunk_size_padded);
|
status = ParseFragment(dmux, chunk_size_padded);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -712,6 +714,7 @@ uint32_t WebPDemuxGetI(const WebPDemuxer* dmux, WebPFormatFeature feature) {
|
|||||||
case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_;
|
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_LOOP_COUNT: return (uint32_t)dmux->loop_count_;
|
||||||
case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_;
|
case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_;
|
||||||
|
case WEBP_FF_FRAME_COUNT: return (uint32_t)dmux->num_frames_;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,11 @@ enum WebPFormatFeature {
|
|||||||
WEBP_FF_CANVAS_WIDTH,
|
WEBP_FF_CANVAS_WIDTH,
|
||||||
WEBP_FF_CANVAS_HEIGHT,
|
WEBP_FF_CANVAS_HEIGHT,
|
||||||
WEBP_FF_LOOP_COUNT,
|
WEBP_FF_LOOP_COUNT,
|
||||||
WEBP_FF_BACKGROUND_COLOR
|
WEBP_FF_BACKGROUND_COLOR,
|
||||||
|
WEBP_FF_FRAME_COUNT // Number of frames present in the demux object.
|
||||||
|
// In case of a partial demux, this is the number of
|
||||||
|
// frames seen so far, with the last frame possibly
|
||||||
|
// being partial.
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the 'feature' value from the 'dmux'.
|
// Get the 'feature' value from the 'dmux'.
|
||||||
@ -121,7 +125,7 @@ WEBP_EXTERN(uint32_t) WebPDemuxGetI(
|
|||||||
|
|
||||||
struct WebPIterator {
|
struct WebPIterator {
|
||||||
int frame_num;
|
int frame_num;
|
||||||
int num_frames;
|
int num_frames; // equivalent to WEBP_FF_FRAME_COUNT.
|
||||||
int fragment_num;
|
int fragment_num;
|
||||||
int num_fragments;
|
int num_fragments;
|
||||||
int x_offset, y_offset; // offset relative to the canvas.
|
int x_offset, y_offset; // offset relative to the canvas.
|
||||||
|
Loading…
Reference in New Issue
Block a user