Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1890)

Unified Diff: third_party/libwebp/demux/demux.c

Issue 22802020: libwebp: upstream animation cherry-picks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libwebp/demux/demux.c
diff --git a/third_party/libwebp/demux/demux.c b/third_party/libwebp/demux/demux.c
index 8c2250d660e77ed879197712395d8bb8e556fdfc..1d765c74c210e38e30296896709e625facad01db 100644
--- a/third_party/libwebp/demux/demux.c
+++ b/third_party/libwebp/demux/demux.c
@@ -47,8 +47,10 @@ typedef struct {
typedef struct Frame {
int x_offset_, y_offset_;
int width_, height_;
+ int has_alpha_;
int duration_;
WebPMuxAnimDispose dispose_method_;
+ WebPMuxAnimBlend blend_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.
@@ -196,18 +198,13 @@ static int AddFrame(WebPDemuxer* const dmux, Frame* const frame) {
}
// Store image bearing chunks to 'frame'.
-// If 'has_vp8l_alpha' is not NULL, it will be set to true if the frame is a
-// lossless image with alpha.
static ParseStatus StoreFrame(int frame_num, uint32_t min_size,
- MemBuffer* const mem, Frame* const frame,
- int* const has_vp8l_alpha) {
+ MemBuffer* const mem, Frame* const frame) {
int alpha_chunks = 0;
int image_chunks = 0;
int done = (MemDataSize(mem) < min_size);
ParseStatus status = PARSE_OK;
- if (has_vp8l_alpha != NULL) *has_vp8l_alpha = 0; // Default.
-
if (done) return PARSE_NEED_MORE_DATA;
do {
@@ -229,6 +226,7 @@ static ParseStatus StoreFrame(int frame_num, uint32_t min_size,
++alpha_chunks;
frame->img_components_[1].offset_ = chunk_start_offset;
frame->img_components_[1].size_ = chunk_size;
+ frame->has_alpha_ = 1;
frame->frame_num_ = frame_num;
Skip(mem, payload_available);
} else {
@@ -258,7 +256,7 @@ static ParseStatus StoreFrame(int frame_num, uint32_t min_size,
frame->img_components_[0].size_ = chunk_size;
frame->width_ = features.width;
frame->height_ = features.height;
- if (has_vp8l_alpha != NULL) *has_vp8l_alpha = features.has_alpha;
+ frame->has_alpha_ |= features.has_alpha;
fbarchard 2013/08/21 02:00:13 if you dont check the pointer, to enable alpha, th
urvang (Google) 2013/08/21 02:16:51 Nope. StoreFrame() is a static method, so 'frame'
frame->frame_num_ = frame_num;
frame->complete_ = (status == PARSE_OK);
Skip(mem, payload_available);
@@ -306,6 +304,7 @@ static ParseStatus ParseAnimationFrame(
const int has_frames = !!(dmux->feature_flags_ & ANIMATION_FLAG);
const uint32_t anmf_payload_size = frame_chunk_size - ANMF_CHUNK_SIZE;
int added_frame = 0;
+ int bits;
MemBuffer* const mem = &dmux->mem_;
Frame* frame;
ParseStatus status =
@@ -317,7 +316,10 @@ static ParseStatus ParseAnimationFrame(
frame->width_ = 1 + ReadLE24s(mem);
frame->height_ = 1 + ReadLE24s(mem);
frame->duration_ = ReadLE24s(mem);
- frame->dispose_method_ = (WebPMuxAnimDispose)(ReadByte(mem) & 1);
+ bits = ReadByte(mem);
+ frame->dispose_method_ =
+ (bits & 1) ? WEBP_MUX_DISPOSE_BACKGROUND : WEBP_MUX_DISPOSE_NONE;
+ frame->blend_method_ = (bits & 2) ? WEBP_MUX_NO_BLEND : WEBP_MUX_BLEND;
if (frame->width_ * (uint64_t)frame->height_ >= MAX_IMAGE_AREA) {
free(frame);
return PARSE_ERROR;
@@ -325,8 +327,7 @@ static ParseStatus ParseAnimationFrame(
// Store a frame only if the animation flag is set there is some data for
// this frame is available.
- status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame,
- NULL);
+ status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame);
if (status != PARSE_ERROR && has_frames && frame->frame_num_ > 0) {
added_frame = AddFrame(dmux, frame);
if (added_frame) {
@@ -361,7 +362,7 @@ static ParseStatus ParseFragment(WebPDemuxer* const dmux,
// Store a fragment only if the fragments flag is set there is some data for
// this fragment is available.
- status = StoreFrame(frame_num, frgm_payload_size, mem, frame, NULL);
+ status = StoreFrame(frame_num, frgm_payload_size, mem, frame);
if (status != PARSE_ERROR && has_fragments && frame->frame_num_ > 0) {
added_fragment = AddFrame(dmux, frame);
if (!added_fragment) {
@@ -424,7 +425,6 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) {
MemBuffer* const mem = &dmux->mem_;
Frame* frame;
ParseStatus status;
- int has_vp8l_alpha = 0; // Frame contains a lossless image with alpha.
if (dmux->frames_ != NULL) return PARSE_ERROR;
if (SizeIsInvalid(mem, min_size)) return PARSE_ERROR;
@@ -435,14 +435,14 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) {
// For the single image case we allow parsing of a partial frame, but we need
// at least CHUNK_HEADER_SIZE for parsing.
- status = StoreFrame(1, CHUNK_HEADER_SIZE, &dmux->mem_, frame,
- &has_vp8l_alpha);
+ status = StoreFrame(1, CHUNK_HEADER_SIZE, &dmux->mem_, frame);
if (status != PARSE_ERROR) {
const int has_alpha = !!(dmux->feature_flags_ & ALPHA_FLAG);
// Clear any alpha when the alpha flag is missing.
if (!has_alpha && frame->img_components_[1].size_ > 0) {
frame->img_components_[1].offset_ = 0;
frame->img_components_[1].size_ = 0;
+ frame->has_alpha_ = 0;
}
// Use the frame width/height as the canvas values for non-vp8x files.
@@ -451,7 +451,7 @@ static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) {
dmux->state_ = WEBP_DEMUX_PARSED_HEADER;
dmux->canvas_width_ = frame->width_;
dmux->canvas_height_ = frame->height_;
- dmux->feature_flags_ |= has_vp8l_alpha ? ALPHA_FLAG : 0;
+ dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0;
}
AddFrame(dmux, frame);
dmux->num_frames_ = 1;
@@ -836,8 +836,10 @@ static int SynthesizeFrame(const WebPDemuxer* const dmux,
iter->y_offset = fragment->y_offset_;
iter->width = fragment->width_;
iter->height = fragment->height_;
+ iter->has_alpha = fragment->has_alpha_;
iter->duration = fragment->duration_;
iter->dispose_method = fragment->dispose_method_;
+ iter->blend_method = fragment->blend_method_;
iter->complete = fragment->complete_;
iter->fragment.bytes = payload;
iter->fragment.size = payload_size;

Powered by Google App Engine
This is Rietveld 408576698