mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-18 23:09:52 +02:00
add WebPMuxSetCanvasSize() to the mux API
previously, the final canvas size was adjusted tightly from the animation frames. Now, it can be specified separately (to be larger, in particular). calling WebPMuxSetCanvasSize(mux, 0, 0) triggers the 'adjust tightly' behaviour. This can be useful after calling WebPMuxCreate() if further image addition is expected. -> Fixed gif2webp accordingly. also: made WebPMuxAssemble() more robust by systematically zero-ing WebPData. Change-Id: Ib4f7eac372cf9dbf6e25cd686a77960e386a0b7f
This commit is contained in:
@ -264,6 +264,10 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
|
||||
// getting all chunks of an image.
|
||||
chunk_list = MuxGetChunkListFromId(mux, id); // List to add this chunk.
|
||||
if (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err;
|
||||
if (id == WEBP_CHUNK_VP8X) { // grab global specs
|
||||
mux->canvas_width_ = GetLE24(data + 12) + 1;
|
||||
mux->canvas_height_ = GetLE24(data + 15) + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
data += data_size;
|
||||
@ -320,14 +324,20 @@ static WebPMuxError MuxGetCanvasInfo(const WebPMux* const mux,
|
||||
f = GetLE32(data.bytes + 0);
|
||||
w = GetLE24(data.bytes + 4) + 1;
|
||||
h = GetLE24(data.bytes + 7) + 1;
|
||||
} else { // Single image case.
|
||||
} else {
|
||||
const WebPMuxImage* const wpi = mux->images_;
|
||||
WebPMuxError err = ValidateForSingleImage(mux);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
assert(wpi != NULL);
|
||||
w = wpi->width_;
|
||||
h = wpi->height_;
|
||||
if (wpi->has_alpha_) f |= ALPHA_FLAG;
|
||||
// Grab user-forced canvas size as default.
|
||||
w = mux->canvas_width_;
|
||||
h = mux->canvas_height_;
|
||||
if (w == 0 && h == 0 && ValidateForSingleImage(mux) == WEBP_MUX_OK) {
|
||||
// single image and not forced canvas size => use dimension of first frame
|
||||
assert(wpi != NULL);
|
||||
w = wpi->width_;
|
||||
h = wpi->height_;
|
||||
}
|
||||
if (wpi != NULL) {
|
||||
if (wpi->has_alpha_) f |= ALPHA_FLAG;
|
||||
}
|
||||
}
|
||||
if (w * (uint64_t)h >= MAX_IMAGE_AREA) return WEBP_MUX_BAD_DATA;
|
||||
|
||||
@ -537,4 +547,3 @@ WebPMuxError WebPMuxNumChunks(const WebPMux* mux,
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user