mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 12:28:26 +01:00
Mux: Add WebPDataInit() and remove WebPImageInfo
Change-Id: If661f7d198e284a103a53a451e9f74805119fcf9
This commit is contained in:
parent
8130c4cc64
commit
857650c8fc
@ -17,15 +17,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Object to store metadata about images.
|
|
||||||
typedef struct {
|
|
||||||
int x_offset_;
|
|
||||||
int y_offset_;
|
|
||||||
int duration_;
|
|
||||||
int width_;
|
|
||||||
int height_;
|
|
||||||
} WebPImageInfo;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Life of a mux object.
|
// Life of a mux object.
|
||||||
|
|
||||||
@ -155,7 +146,7 @@ static WebPMuxError CreateFrameTileData(const WebPData* const image,
|
|||||||
static WebPMuxError GetImageData(const WebPData* const bitstream,
|
static WebPMuxError GetImageData(const WebPData* const bitstream,
|
||||||
WebPData* const image, WebPData* const alpha,
|
WebPData* const image, WebPData* const alpha,
|
||||||
int* const is_lossless) {
|
int* const is_lossless) {
|
||||||
memset(alpha, 0, sizeof(*alpha)); // Default: no alpha.
|
WebPDataInit(alpha); // Default: no alpha.
|
||||||
if (bitstream->size_ < TAG_SIZE ||
|
if (bitstream->size_ < TAG_SIZE ||
|
||||||
memcmp(bitstream->bytes_, "RIFF", TAG_SIZE)) {
|
memcmp(bitstream->bytes_, "RIFF", TAG_SIZE)) {
|
||||||
// It is NOT webp file data. Return input data as is.
|
// It is NOT webp file data. Return input data as is.
|
||||||
@ -359,7 +350,7 @@ static WebPMuxError MuxPushFrameTileInternal(
|
|||||||
if (err != WEBP_MUX_OK) return err;
|
if (err != WEBP_MUX_OK) return err;
|
||||||
image_tag = is_lossless ? kChunks[IDX_VP8L].tag : kChunks[IDX_VP8].tag;
|
image_tag = is_lossless ? kChunks[IDX_VP8L].tag : kChunks[IDX_VP8].tag;
|
||||||
|
|
||||||
memset(&frame_tile, 0, sizeof(frame_tile));
|
WebPDataInit(&frame_tile);
|
||||||
ChunkInit(&chunk);
|
ChunkInit(&chunk);
|
||||||
MuxImageInit(&wpi);
|
MuxImageInit(&wpi);
|
||||||
|
|
||||||
@ -506,30 +497,19 @@ WebPMuxError MuxGetImageWidthHeight(const WebPChunk* const image_chunk,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi,
|
static WebPMuxError GetImageInfo(const WebPMuxImage* const wpi,
|
||||||
WebPImageInfo* const image_info) {
|
int* const x_offset, int* const y_offset,
|
||||||
|
int* const duration,
|
||||||
|
int* const width, int* const height) {
|
||||||
const WebPChunk* const image_chunk = wpi->img_;
|
const WebPChunk* const image_chunk = wpi->img_;
|
||||||
const WebPChunk* const frame_tile_chunk = wpi->header_;
|
const WebPChunk* const frame_tile_chunk = wpi->header_;
|
||||||
WebPMuxError err;
|
|
||||||
int x_offset, y_offset, duration;
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
memset(image_info, 0, sizeof(*image_info));
|
|
||||||
|
|
||||||
// Get offsets and duration from FRM/TILE chunk.
|
// Get offsets and duration from FRM/TILE chunk.
|
||||||
err = GetFrameTileInfo(frame_tile_chunk, &x_offset, &y_offset, &duration);
|
const WebPMuxError err =
|
||||||
|
GetFrameTileInfo(frame_tile_chunk, x_offset, y_offset, duration);
|
||||||
if (err != WEBP_MUX_OK) return err;
|
if (err != WEBP_MUX_OK) return err;
|
||||||
|
|
||||||
// Get width and height from VP8/VP8L chunk.
|
// Get width and height from VP8/VP8L chunk.
|
||||||
err = MuxGetImageWidthHeight(image_chunk, &width, &height);
|
return MuxGetImageWidthHeight(image_chunk, width, height);
|
||||||
if (err != WEBP_MUX_OK) return err;
|
|
||||||
|
|
||||||
// All OK: fill up image_info.
|
|
||||||
image_info->x_offset_ = x_offset;
|
|
||||||
image_info->y_offset_ = y_offset;
|
|
||||||
image_info->duration_ = duration;
|
|
||||||
image_info->width_ = width;
|
|
||||||
image_info->height_ = height;
|
|
||||||
return WEBP_MUX_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static WebPMuxError GetImageCanvasWidthHeight(
|
static WebPMuxError GetImageCanvasWidthHeight(
|
||||||
@ -537,7 +517,7 @@ static WebPMuxError GetImageCanvasWidthHeight(
|
|||||||
int* const width, int* const height) {
|
int* const width, int* const height) {
|
||||||
WebPMuxImage* wpi = NULL;
|
WebPMuxImage* wpi = NULL;
|
||||||
assert(mux != NULL);
|
assert(mux != NULL);
|
||||||
assert(width && height);
|
assert(width != NULL && height != NULL);
|
||||||
|
|
||||||
wpi = mux->images_;
|
wpi = mux->images_;
|
||||||
assert(wpi != NULL);
|
assert(wpi != NULL);
|
||||||
@ -549,17 +529,18 @@ static WebPMuxError GetImageCanvasWidthHeight(
|
|||||||
int64_t image_area = 0;
|
int64_t image_area = 0;
|
||||||
// Aggregate the bounding box for animation frames & tiled images.
|
// Aggregate the bounding box for animation frames & tiled images.
|
||||||
for (; wpi != NULL; wpi = wpi->next_) {
|
for (; wpi != NULL; wpi = wpi->next_) {
|
||||||
WebPImageInfo image_info;
|
int x_offset, y_offset, duration, w, h;
|
||||||
const WebPMuxError err = GetImageInfo(wpi, &image_info);
|
const WebPMuxError err = GetImageInfo(wpi, &x_offset, &y_offset,
|
||||||
const int max_x_pos = image_info.x_offset_ + image_info.width_;
|
&duration, &w, &h);
|
||||||
const int max_y_pos = image_info.y_offset_ + image_info.height_;
|
const int max_x_pos = x_offset + w;
|
||||||
|
const int max_y_pos = y_offset + h;
|
||||||
if (err != WEBP_MUX_OK) return err;
|
if (err != WEBP_MUX_OK) return err;
|
||||||
assert(image_info.x_offset_ < MAX_POSITION_OFFSET);
|
assert(x_offset < MAX_POSITION_OFFSET);
|
||||||
assert(image_info.y_offset_ < MAX_POSITION_OFFSET);
|
assert(y_offset < MAX_POSITION_OFFSET);
|
||||||
|
|
||||||
if (max_x_pos > max_x) max_x = max_x_pos;
|
if (max_x_pos > max_x) max_x = max_x_pos;
|
||||||
if (max_y_pos > max_y) max_y = max_y_pos;
|
if (max_y_pos > max_y) max_y = max_y_pos;
|
||||||
image_area += (image_info.width_ * image_info.height_);
|
image_area += w * h;
|
||||||
}
|
}
|
||||||
*width = max_x;
|
*width = max_x;
|
||||||
*height = max_y;
|
*height = max_y;
|
||||||
|
@ -212,17 +212,23 @@ uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Manipulation of a WebPData object.
|
// Manipulation of a WebPData object.
|
||||||
|
|
||||||
|
void WebPDataInit(WebPData* const webp_data) {
|
||||||
|
if (webp_data != NULL) {
|
||||||
|
memset(webp_data, 0, sizeof(*webp_data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebPDataClear(WebPData* const webp_data) {
|
void WebPDataClear(WebPData* const webp_data) {
|
||||||
if (webp_data != NULL) {
|
if (webp_data != NULL) {
|
||||||
free((void*)webp_data->bytes_);
|
free((void*)webp_data->bytes_);
|
||||||
memset(webp_data, 0, sizeof(*webp_data));
|
WebPDataInit(webp_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebPDataCopy(const WebPData* const src, WebPData* const dst) {
|
int WebPDataCopy(const WebPData* const src, WebPData* const dst) {
|
||||||
if (src == NULL || dst == NULL) return 0;
|
if (src == NULL || dst == NULL) return 0;
|
||||||
|
|
||||||
memset(dst, 0, sizeof(*dst));
|
WebPDataInit(dst);
|
||||||
if (src->bytes_ != NULL && src->size_ != 0) {
|
if (src->bytes_ != NULL && src->size_ != 0) {
|
||||||
dst->bytes_ = (uint8_t*)malloc(src->size_);
|
dst->bytes_ = (uint8_t*)malloc(src->size_);
|
||||||
if (dst->bytes_ == NULL) return 0;
|
if (dst->bytes_ == NULL) return 0;
|
||||||
|
@ -37,7 +37,7 @@ static WebPMuxError MuxGet(const WebPMux* const mux, CHUNK_INDEX idx,
|
|||||||
uint32_t nth, WebPData* const data) {
|
uint32_t nth, WebPData* const data) {
|
||||||
assert(mux != NULL);
|
assert(mux != NULL);
|
||||||
assert(!IsWPI(kChunks[idx].id));
|
assert(!IsWPI(kChunks[idx].id));
|
||||||
memset(data, 0, sizeof(*data));
|
WebPDataInit(data);
|
||||||
|
|
||||||
SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_);
|
SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_);
|
||||||
SWITCH_ID_LIST(IDX_ICCP, mux->iccp_);
|
SWITCH_ID_LIST(IDX_ICCP, mux->iccp_);
|
||||||
|
@ -100,6 +100,9 @@ typedef struct {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Manipulation of a WebPData object.
|
// Manipulation of a WebPData object.
|
||||||
|
|
||||||
|
// Initializes the contents of the 'webp_data' object with default values.
|
||||||
|
WEBP_EXTERN(void) WebPDataInit(WebPData* const webp_data);
|
||||||
|
|
||||||
// Clears the contents of the 'webp_data' object by calling free(). Does not
|
// Clears the contents of the 'webp_data' object by calling free(). Does not
|
||||||
// deallocate the object itself.
|
// deallocate the object itself.
|
||||||
WEBP_EXTERN(void) WebPDataClear(WebPData* const webp_data);
|
WEBP_EXTERN(void) WebPDataClear(WebPData* const webp_data);
|
||||||
|
Loading…
Reference in New Issue
Block a user