mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Mux: only allow adding frame/tiles at the end.
Change-Id: I5d685628da8c8ac85144cee2e5808b30ec79fef9
This commit is contained in:
parent
2c341b0eed
commit
b494ad5096
@ -797,7 +797,7 @@ static int Process(const WebPMuxConfig* config) {
|
|||||||
WebPDataClear(&webpdata);
|
WebPDataClear(&webpdata);
|
||||||
ERROR_GOTO1("ERROR: Could not parse frame properties.\n", Err2);
|
ERROR_GOTO1("ERROR: Could not parse frame properties.\n", Err2);
|
||||||
}
|
}
|
||||||
err = WebPMuxSetFrame(mux, 0, &webpdata, x_offset, y_offset,
|
err = WebPMuxPushFrame(mux, &webpdata, x_offset, y_offset,
|
||||||
duration, 1);
|
duration, 1);
|
||||||
WebPDataClear(&webpdata);
|
WebPDataClear(&webpdata);
|
||||||
if (err != WEBP_MUX_OK) {
|
if (err != WEBP_MUX_OK) {
|
||||||
@ -825,7 +825,7 @@ static int Process(const WebPMuxConfig* config) {
|
|||||||
WebPDataClear(&webpdata);
|
WebPDataClear(&webpdata);
|
||||||
ERROR_GOTO1("ERROR: Could not parse tile properties.\n", Err2);
|
ERROR_GOTO1("ERROR: Could not parse tile properties.\n", Err2);
|
||||||
}
|
}
|
||||||
err = WebPMuxSetTile(mux, 0, &webpdata, x_offset, y_offset, 1);
|
err = WebPMuxPushTile(mux, &webpdata, x_offset, y_offset, 1);
|
||||||
WebPDataClear(&webpdata);
|
WebPDataClear(&webpdata);
|
||||||
if (err != WEBP_MUX_OK) {
|
if (err != WEBP_MUX_OK) {
|
||||||
ERROR_GOTO3("ERROR#%d: Could not add a tile at index %d.\n",
|
ERROR_GOTO3("ERROR#%d: Could not add a tile at index %d.\n",
|
||||||
|
@ -273,7 +273,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux,
|
|||||||
if (err != WEBP_MUX_OK) goto Err;
|
if (err != WEBP_MUX_OK) goto Err;
|
||||||
|
|
||||||
// Add this image to mux.
|
// Add this image to mux.
|
||||||
err = MuxImageSetNth(&wpi, &mux->images_, 1);
|
err = MuxImagePush(&wpi, &mux->images_);
|
||||||
if (err != WEBP_MUX_OK) goto Err;
|
if (err != WEBP_MUX_OK) goto Err;
|
||||||
|
|
||||||
// All OK.
|
// All OK.
|
||||||
@ -343,10 +343,9 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* const mux, uint32_t loop_count) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WebPMuxError MuxSetFrameTileInternal(
|
static WebPMuxError MuxPushFrameTileInternal(
|
||||||
WebPMux* const mux, uint32_t nth, const WebPData* const bitstream,
|
WebPMux* const mux, const WebPData* const bitstream, uint32_t x_offset,
|
||||||
uint32_t x_offset, uint32_t y_offset, uint32_t duration,
|
uint32_t y_offset, uint32_t duration, int copy_data, uint32_t tag) {
|
||||||
int copy_data, uint32_t tag) {
|
|
||||||
WebPChunk chunk;
|
WebPChunk chunk;
|
||||||
WebPData image;
|
WebPData image;
|
||||||
WebPData alpha;
|
WebPData alpha;
|
||||||
@ -418,7 +417,7 @@ static WebPMuxError MuxSetFrameTileInternal(
|
|||||||
ChunkInit(&chunk); // chunk owned by wpi.header_ now.
|
ChunkInit(&chunk); // chunk owned by wpi.header_ now.
|
||||||
|
|
||||||
// Add this WebPMuxImage to mux.
|
// Add this WebPMuxImage to mux.
|
||||||
err = MuxImageSetNth(&wpi, &mux->images_, nth);
|
err = MuxImagePush(&wpi, &mux->images_);
|
||||||
if (err != WEBP_MUX_OK) goto Err;
|
if (err != WEBP_MUX_OK) goto Err;
|
||||||
|
|
||||||
// All is well.
|
// All is well.
|
||||||
@ -432,21 +431,19 @@ static WebPMuxError MuxSetFrameTileInternal(
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(urvang): Think about whether we need 'nth' while adding a frame or tile.
|
WebPMuxError WebPMuxPushFrame(WebPMux* const mux,
|
||||||
|
|
||||||
WebPMuxError WebPMuxSetFrame(WebPMux* const mux, uint32_t nth,
|
|
||||||
const WebPData* const bitstream,
|
const WebPData* const bitstream,
|
||||||
uint32_t x_offset, uint32_t y_offset,
|
uint32_t x_offset, uint32_t y_offset,
|
||||||
uint32_t duration, int copy_data) {
|
uint32_t duration, int copy_data) {
|
||||||
return MuxSetFrameTileInternal(mux, nth, bitstream, x_offset, y_offset,
|
return MuxPushFrameTileInternal(mux, bitstream, x_offset, y_offset,
|
||||||
duration, copy_data, kChunks[IDX_FRAME].tag);
|
duration, copy_data, kChunks[IDX_FRAME].tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebPMuxError WebPMuxSetTile(WebPMux* const mux, uint32_t nth,
|
WebPMuxError WebPMuxPushTile(WebPMux* const mux,
|
||||||
const WebPData* const bitstream,
|
const WebPData* const bitstream,
|
||||||
uint32_t x_offset, uint32_t y_offset,
|
uint32_t x_offset, uint32_t y_offset,
|
||||||
int copy_data) {
|
int copy_data) {
|
||||||
return MuxSetFrameTileInternal(mux, nth, bitstream, x_offset, y_offset,
|
return MuxPushFrameTileInternal(mux, bitstream, x_offset, y_offset,
|
||||||
1 /* unused duration*/, copy_data,
|
1 /* unused duration*/, copy_data,
|
||||||
kChunks[IDX_TILE].tag);
|
kChunks[IDX_TILE].tag);
|
||||||
}
|
}
|
||||||
|
@ -215,10 +215,8 @@ static WEBP_INLINE WebPChunk** MuxImageGetListFromId(WebPMuxImage* wpi,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets 'wpi' at nth position in the 'wpi_list'.
|
// Pushes 'wpi' at the end of 'wpi_list'.
|
||||||
// nth = 0 has the special meaning "last of the list".
|
WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list);
|
||||||
WebPMuxError MuxImageSetNth(const WebPMuxImage* wpi, WebPMuxImage** wpi_list,
|
|
||||||
uint32_t nth);
|
|
||||||
|
|
||||||
// Delete nth image in the image list with given tag id.
|
// Delete nth image in the image list with given tag id.
|
||||||
WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth,
|
WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth,
|
||||||
|
@ -275,27 +275,6 @@ int MuxImageCount(WebPMuxImage* const wpi_list, WebPChunkId id) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs a pointer to 'prev_wpi->next_',
|
|
||||||
// where 'prev_wpi' is the pointer to the image at position (nth - 1).
|
|
||||||
// Returns 1 if nth image was found, 0 otherwise.
|
|
||||||
static int SearchImageToSet(WebPMuxImage** wpi_list, uint32_t nth,
|
|
||||||
WebPMuxImage*** const location) {
|
|
||||||
uint32_t count = 0;
|
|
||||||
assert(wpi_list);
|
|
||||||
*location = wpi_list;
|
|
||||||
|
|
||||||
while (*wpi_list) {
|
|
||||||
WebPMuxImage* const cur_wpi = *wpi_list;
|
|
||||||
++count;
|
|
||||||
if (count == nth) return 1; // Found.
|
|
||||||
wpi_list = &cur_wpi->next_;
|
|
||||||
*location = wpi_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// *chunk_list is ok to be NULL if adding at last location.
|
|
||||||
return (nth == 0 || (count == nth - 1)) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Outputs a pointer to 'prev_wpi->next_',
|
// Outputs a pointer to 'prev_wpi->next_',
|
||||||
// where 'prev_wpi' is the pointer to the image at position (nth - 1).
|
// where 'prev_wpi' is the pointer to the image at position (nth - 1).
|
||||||
// Returns 1 if nth image with given id was found, 0 otherwise.
|
// Returns 1 if nth image with given id was found, 0 otherwise.
|
||||||
@ -335,19 +314,25 @@ static int SearchImageToGetOrDelete(WebPMuxImage** wpi_list, uint32_t nth,
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// MuxImage writer methods.
|
// MuxImage writer methods.
|
||||||
|
|
||||||
WebPMuxError MuxImageSetNth(const WebPMuxImage* wpi, WebPMuxImage** wpi_list,
|
WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list) {
|
||||||
uint32_t nth) {
|
|
||||||
WebPMuxImage* new_wpi;
|
WebPMuxImage* new_wpi;
|
||||||
|
|
||||||
if (!SearchImageToSet(wpi_list, nth, &wpi_list)) {
|
while (*wpi_list != NULL) {
|
||||||
return WEBP_MUX_NOT_FOUND;
|
WebPMuxImage* const cur_wpi = *wpi_list;
|
||||||
|
if (cur_wpi->next_ == NULL) break;
|
||||||
|
wpi_list = &cur_wpi->next_;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_wpi = (WebPMuxImage*)malloc(sizeof(*new_wpi));
|
new_wpi = (WebPMuxImage*)malloc(sizeof(*new_wpi));
|
||||||
if (new_wpi == NULL) return WEBP_MUX_MEMORY_ERROR;
|
if (new_wpi == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||||
*new_wpi = *wpi;
|
*new_wpi = *wpi;
|
||||||
new_wpi->next_ = *wpi_list;
|
new_wpi->next_ = NULL;
|
||||||
|
|
||||||
|
if (*wpi_list != NULL) {
|
||||||
|
(*wpi_list)->next_ = new_wpi;
|
||||||
|
} else {
|
||||||
*wpi_list = new_wpi;
|
*wpi_list = new_wpi;
|
||||||
|
}
|
||||||
return WEBP_MUX_OK;
|
return WEBP_MUX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
|
|||||||
if (id == WEBP_CHUNK_IMAGE) {
|
if (id == WEBP_CHUNK_IMAGE) {
|
||||||
wpi->is_partial_ = 0; // wpi is completely filled.
|
wpi->is_partial_ = 0; // wpi is completely filled.
|
||||||
// Add this to mux->images_ list.
|
// Add this to mux->images_ list.
|
||||||
if (MuxImageSetNth(wpi, &mux->images_, 0) != WEBP_MUX_OK) goto Err;
|
if (MuxImagePush(wpi, &mux->images_) != WEBP_MUX_OK) goto Err;
|
||||||
MuxImageInit(wpi); // Reset for reading next image.
|
MuxImageInit(wpi); // Reset for reading next image.
|
||||||
} else {
|
} else {
|
||||||
wpi->is_partial_ = 1; // wpi is only partially filled.
|
wpi->is_partial_ = 1; // wpi is only partially filled.
|
||||||
|
@ -267,11 +267,9 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteColorProfile(WebPMux* const mux);
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Animation.
|
// Animation.
|
||||||
|
|
||||||
// Adds an animation frame to the mux object.
|
// Adds an animation frame at the end of the mux object.
|
||||||
// nth=0 has a special meaning - last position.
|
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// mux - (in/out) object to which an animation frame is to be added
|
// mux - (in/out) object to which an animation frame is to be added
|
||||||
// nth - (in) The position at which the frame is to be added.
|
|
||||||
// bitstream - (in) the image data corresponding to the frame. It can either
|
// bitstream - (in) the image data corresponding to the frame. It can either
|
||||||
// be a raw VP8/VP8L bitstream or a single-image WebP file
|
// be a raw VP8/VP8L bitstream or a single-image WebP file
|
||||||
// (non-animated and non-tiled)
|
// (non-animated and non-tiled)
|
||||||
@ -282,17 +280,15 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteColorProfile(WebPMux* const mux);
|
|||||||
// value 0 indicates data will NOT be copied.
|
// value 0 indicates data will NOT be copied.
|
||||||
// Returns:
|
// Returns:
|
||||||
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL
|
||||||
// WEBP_MUX_NOT_FOUND - If we have less than (nth-1) frames before adding.
|
|
||||||
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
// WEBP_MUX_OK - on success.
|
// WEBP_MUX_OK - on success.
|
||||||
WEBP_EXTERN(WebPMuxError) WebPMuxSetFrame(
|
WEBP_EXTERN(WebPMuxError) WebPMuxPushFrame(
|
||||||
WebPMux* const mux, uint32_t nth, const WebPData* const bitstream,
|
WebPMux* const mux, const WebPData* const bitstream,
|
||||||
uint32_t x_offset, uint32_t y_offset, uint32_t duration,
|
uint32_t x_offset, uint32_t y_offset, uint32_t duration,
|
||||||
int copy_data);
|
int copy_data);
|
||||||
|
|
||||||
// TODO(urvang): Create a struct as follows to reduce argument list size:
|
// TODO(urvang): Create a struct as follows to reduce argument list size:
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
// int nth;
|
|
||||||
// WebPData image;
|
// WebPData image;
|
||||||
// WebPData alpha;
|
// WebPData alpha;
|
||||||
// uint32_t x_offset, y_offset;
|
// uint32_t x_offset, y_offset;
|
||||||
@ -360,11 +356,9 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* const mux,
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Tiling.
|
// Tiling.
|
||||||
|
|
||||||
// Adds a tile to the mux object.
|
// Adds a tile at the end of the mux object.
|
||||||
// nth=0 has a special meaning - last position.
|
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// mux - (in/out) object to which a tile is to be added
|
// mux - (in/out) object to which a tile is to be added.
|
||||||
// nth - (in) The position at which the tile is to be added.
|
|
||||||
// bitstream - (in) the image data corresponding to the frame. It can either
|
// bitstream - (in) the image data corresponding to the frame. It can either
|
||||||
// be a raw VP8/VP8L bitstream or a single-image WebP file
|
// be a raw VP8/VP8L bitstream or a single-image WebP file
|
||||||
// (non-animated and non-tiled)
|
// (non-animated and non-tiled)
|
||||||
@ -374,11 +368,10 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* const mux,
|
|||||||
// value 0 indicates data will NOT be copied.
|
// value 0 indicates data will NOT be copied.
|
||||||
// Returns:
|
// Returns:
|
||||||
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL
|
// WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL
|
||||||
// WEBP_MUX_NOT_FOUND - If we have less than (nth-1) tiles before adding.
|
|
||||||
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
|
||||||
// WEBP_MUX_OK - on success.
|
// WEBP_MUX_OK - on success.
|
||||||
WEBP_EXTERN(WebPMuxError) WebPMuxSetTile(
|
WEBP_EXTERN(WebPMuxError) WebPMuxPushTile(
|
||||||
WebPMux* const mux, uint32_t nth, const WebPData* const bitstream,
|
WebPMux* const mux, const WebPData* const bitstream,
|
||||||
uint32_t x_offset, uint32_t y_offset, int copy_data);
|
uint32_t x_offset, uint32_t y_offset, int copy_data);
|
||||||
|
|
||||||
// Gets the nth tile from the mux object.
|
// Gets the nth tile from the mux object.
|
||||||
|
Loading…
Reference in New Issue
Block a user