summaryrefslogtreecommitdiffstats
path: root/contrib/libs/libwebp/src/mux/muxread.c
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-07-24 10:07:25 +0300
committerrobot-piglet <[email protected]>2025-07-24 10:16:27 +0300
commit1c295121fa6a70a55c0ed79beb993761eac1fadc (patch)
tree0a3af4cf839ddc14d3d2829c3b224c1da409d80c /contrib/libs/libwebp/src/mux/muxread.c
parent026ffc40392187f03308f5ae7445365ad4a1ef7f (diff)
Intermediate changes
commit_hash:9e9c04347de10235f77fcdaf62119e9b89e8bc59
Diffstat (limited to 'contrib/libs/libwebp/src/mux/muxread.c')
-rw-r--r--contrib/libs/libwebp/src/mux/muxread.c155
1 files changed, 81 insertions, 74 deletions
diff --git a/contrib/libs/libwebp/src/mux/muxread.c b/contrib/libs/libwebp/src/mux/muxread.c
index aa406c1a6df..b778070f701 100644
--- a/contrib/libs/libwebp/src/mux/muxread.c
+++ b/contrib/libs/libwebp/src/mux/muxread.c
@@ -13,8 +13,15 @@
// Vikas ([email protected])
#include <assert.h>
+#include <stddef.h>
+
+#include "src/dec/vp8_dec.h"
#include "src/mux/muxi.h"
#include "src/utils/utils.h"
+#include "src/webp/format_constants.h"
+#include "src/webp/mux.h"
+#include "src/webp/mux_types.h"
+#include "src/webp/types.h"
//------------------------------------------------------------------------------
// Helper method(s).
@@ -26,7 +33,7 @@
const WebPChunk* const chunk = ChunkSearchList((LIST), nth, \
kChunks[(INDEX)].tag); \
if (chunk) { \
- *data = chunk->data_; \
+ *data = chunk->data; \
return WEBP_MUX_OK; \
} else { \
return WEBP_MUX_NOT_FOUND; \
@@ -41,11 +48,11 @@ static WebPMuxError MuxGet(const WebPMux* const mux, CHUNK_INDEX idx,
assert(!IsWPI(kChunks[idx].id));
WebPDataInit(data);
- SWITCH_ID_LIST(IDX_VP8X, mux->vp8x_);
- SWITCH_ID_LIST(IDX_ICCP, mux->iccp_);
- SWITCH_ID_LIST(IDX_ANIM, mux->anim_);
- SWITCH_ID_LIST(IDX_EXIF, mux->exif_);
- SWITCH_ID_LIST(IDX_XMP, mux->xmp_);
+ SWITCH_ID_LIST(IDX_VP8X, mux->vp8x);
+ SWITCH_ID_LIST(IDX_ICCP, mux->iccp);
+ SWITCH_ID_LIST(IDX_ANIM, mux->anim);
+ SWITCH_ID_LIST(IDX_EXIF, mux->exif);
+ SWITCH_ID_LIST(IDX_XMP, mux->xmp);
assert(idx != IDX_UNKNOWN);
return WEBP_MUX_NOT_FOUND;
}
@@ -77,9 +84,9 @@ static WebPMuxError ChunkVerifyAndAssign(WebPChunk* chunk,
}
int MuxImageFinalize(WebPMuxImage* const wpi) {
- const WebPChunk* const img = wpi->img_;
- const WebPData* const image = &img->data_;
- const int is_lossless = (img->tag_ == kChunks[IDX_VP8L].tag);
+ const WebPChunk* const img = wpi->img;
+ const WebPData* const image = &img->data;
+ const int is_lossless = (img->tag == kChunks[IDX_VP8L].tag);
int w, h;
int vp8l_has_alpha = 0;
const int ok = is_lossless ?
@@ -88,29 +95,29 @@ int MuxImageFinalize(WebPMuxImage* const wpi) {
assert(img != NULL);
if (ok) {
// Ignore ALPH chunk accompanying VP8L.
- if (is_lossless && (wpi->alpha_ != NULL)) {
- ChunkDelete(wpi->alpha_);
- wpi->alpha_ = NULL;
+ if (is_lossless && (wpi->alpha != NULL)) {
+ ChunkDelete(wpi->alpha);
+ wpi->alpha = NULL;
}
- wpi->width_ = w;
- wpi->height_ = h;
- wpi->has_alpha_ = vp8l_has_alpha || (wpi->alpha_ != NULL);
+ wpi->width = w;
+ wpi->height = h;
+ wpi->has_alpha = vp8l_has_alpha || (wpi->alpha != NULL);
}
return ok;
}
static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
WebPMuxImage* const wpi) {
- const uint8_t* bytes = chunk->data_.bytes;
- size_t size = chunk->data_.size;
+ const uint8_t* bytes = chunk->data.bytes;
+ size_t size = chunk->data.size;
const uint8_t* const last = (bytes == NULL) ? NULL : bytes + size;
WebPChunk subchunk;
size_t subchunk_size;
- WebPChunk** unknown_chunk_list = &wpi->unknown_;
+ WebPChunk** unknown_chunk_list = &wpi->unknown;
ChunkInit(&subchunk);
- assert(chunk->tag_ == kChunks[IDX_ANMF].tag);
- assert(!wpi->is_partial_);
+ assert(chunk->tag == kChunks[IDX_ANMF].tag);
+ assert(!wpi->is_partial);
// ANMF.
{
@@ -120,12 +127,12 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
// be at least 'hdr_size'.
if (size < hdr_size) goto Fail;
if (ChunkAssignData(&subchunk, &temp, copy_data,
- chunk->tag_) != WEBP_MUX_OK) {
+ chunk->tag) != WEBP_MUX_OK) {
goto Fail;
}
}
- if (ChunkSetHead(&subchunk, &wpi->header_) != WEBP_MUX_OK) goto Fail;
- wpi->is_partial_ = 1; // Waiting for ALPH and/or VP8/VP8L chunks.
+ if (ChunkSetHead(&subchunk, &wpi->header) != WEBP_MUX_OK) goto Fail;
+ wpi->is_partial = 1; // Waiting for ALPH and/or VP8/VP8L chunks.
// Rest of the chunks.
subchunk_size = ChunkDiskSize(&subchunk) - CHUNK_HEADER_SIZE;
@@ -138,20 +145,20 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
copy_data) != WEBP_MUX_OK) {
goto Fail;
}
- switch (ChunkGetIdFromTag(subchunk.tag_)) {
+ switch (ChunkGetIdFromTag(subchunk.tag)) {
case WEBP_CHUNK_ALPHA:
- if (wpi->alpha_ != NULL) goto Fail; // Consecutive ALPH chunks.
- if (ChunkSetHead(&subchunk, &wpi->alpha_) != WEBP_MUX_OK) goto Fail;
- wpi->is_partial_ = 1; // Waiting for a VP8 chunk.
+ if (wpi->alpha != NULL) goto Fail; // Consecutive ALPH chunks.
+ if (ChunkSetHead(&subchunk, &wpi->alpha) != WEBP_MUX_OK) goto Fail;
+ wpi->is_partial = 1; // Waiting for a VP8 chunk.
break;
case WEBP_CHUNK_IMAGE:
- if (wpi->img_ != NULL) goto Fail; // Only 1 image chunk allowed.
- if (ChunkSetHead(&subchunk, &wpi->img_) != WEBP_MUX_OK) goto Fail;
+ if (wpi->img != NULL) goto Fail; // Only 1 image chunk allowed.
+ if (ChunkSetHead(&subchunk, &wpi->img) != WEBP_MUX_OK) goto Fail;
if (!MuxImageFinalize(wpi)) goto Fail;
- wpi->is_partial_ = 0; // wpi is completely filled.
+ wpi->is_partial = 0; // wpi is completely filled.
break;
case WEBP_CHUNK_UNKNOWN:
- if (wpi->is_partial_) {
+ if (wpi->is_partial) {
goto Fail; // Encountered an unknown chunk
// before some image chunks.
}
@@ -166,7 +173,7 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
bytes += subchunk_size;
size -= subchunk_size;
}
- if (wpi->is_partial_) goto Fail;
+ if (wpi->is_partial) goto Fail;
return 1;
Fail:
@@ -249,29 +256,29 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
goto Err;
}
data_size = ChunkDiskSize(&chunk);
- id = ChunkGetIdFromTag(chunk.tag_);
+ id = ChunkGetIdFromTag(chunk.tag);
switch (id) {
case WEBP_CHUNK_ALPHA:
- if (wpi->alpha_ != NULL) goto Err; // Consecutive ALPH chunks.
- if (ChunkSetHead(&chunk, &wpi->alpha_) != WEBP_MUX_OK) goto Err;
- wpi->is_partial_ = 1; // Waiting for a VP8 chunk.
+ if (wpi->alpha != NULL) goto Err; // Consecutive ALPH chunks.
+ if (ChunkSetHead(&chunk, &wpi->alpha) != WEBP_MUX_OK) goto Err;
+ wpi->is_partial = 1; // Waiting for a VP8 chunk.
break;
case WEBP_CHUNK_IMAGE:
- if (ChunkSetHead(&chunk, &wpi->img_) != WEBP_MUX_OK) goto Err;
+ if (ChunkSetHead(&chunk, &wpi->img) != WEBP_MUX_OK) goto Err;
if (!MuxImageFinalize(wpi)) goto Err;
- wpi->is_partial_ = 0; // wpi is completely filled.
+ wpi->is_partial = 0; // wpi is completely filled.
PushImage:
- // Add this to mux->images_ list.
- if (MuxImagePush(wpi, &mux->images_) != WEBP_MUX_OK) goto Err;
+ // Add this to mux->images list.
+ if (MuxImagePush(wpi, &mux->images) != WEBP_MUX_OK) goto Err;
MuxImageInit(wpi); // Reset for reading next image.
break;
case WEBP_CHUNK_ANMF:
- if (wpi->is_partial_) goto Err; // Previous wpi is still incomplete.
+ if (wpi->is_partial) goto Err; // Previous wpi is still incomplete.
if (!MuxImageParse(&chunk, copy_data, wpi)) goto Err;
ChunkRelease(&chunk);
goto PushImage;
default: // A non-image chunk.
- if (wpi->is_partial_) goto Err; // Encountered a non-image chunk before
+ if (wpi->is_partial) goto Err; // Encountered a non-image chunk before
// getting all chunks of an image.
if (chunk_list_ends[id] == NULL) {
chunk_list_ends[id] =
@@ -280,8 +287,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
if (ChunkAppend(&chunk, &chunk_list_ends[id]) != WEBP_MUX_OK) goto Err;
if (id == WEBP_CHUNK_VP8X) { // grab global specs
if (data_size < CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE) goto Err;
- mux->canvas_width_ = GetLE24(data + 12) + 1;
- mux->canvas_height_ = GetLE24(data + 15) + 1;
+ mux->canvas_width = GetLE24(data + 12) + 1;
+ mux->canvas_height = GetLE24(data + 15) + 1;
}
break;
}
@@ -291,7 +298,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
}
// Incomplete image.
- if (wpi->is_partial_) goto Err;
+ if (wpi->is_partial) goto Err;
// Validate mux if complete.
if (MuxValidate(mux) != WEBP_MUX_OK) goto Err;
@@ -311,8 +318,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
// Validates that the given mux has a single image.
static WebPMuxError ValidateForSingleImage(const WebPMux* const mux) {
- const int num_images = MuxImageCount(mux->images_, WEBP_CHUNK_IMAGE);
- const int num_frames = MuxImageCount(mux->images_, WEBP_CHUNK_ANMF);
+ const int num_images = MuxImageCount(mux->images, WEBP_CHUNK_IMAGE);
+ const int num_frames = MuxImageCount(mux->images, WEBP_CHUNK_ANMF);
if (num_images == 0) {
// No images in mux.
@@ -342,18 +349,18 @@ static WebPMuxError MuxGetCanvasInfo(const WebPMux* const mux,
w = GetLE24(data.bytes + 4) + 1;
h = GetLE24(data.bytes + 7) + 1;
} else {
- const WebPMuxImage* const wpi = mux->images_;
+ const WebPMuxImage* const wpi = mux->images;
// Grab user-forced canvas size as default.
- w = mux->canvas_width_;
- h = mux->canvas_height_;
+ 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_;
+ w = wpi->width;
+ h = wpi->height;
}
if (wpi != NULL) {
- if (wpi->has_alpha_) f |= ALPHA_FLAG;
+ if (wpi->has_alpha) f |= ALPHA_FLAG;
}
}
if (w * (uint64_t)h >= MAX_IMAGE_AREA) return WEBP_MUX_BAD_DATA;
@@ -396,29 +403,29 @@ static WebPMuxError SynthesizeBitstream(const WebPMuxImage* const wpi,
uint8_t* dst;
// Allocate data.
- const int need_vp8x = (wpi->alpha_ != NULL);
+ const int need_vp8x = (wpi->alpha != NULL);
const size_t vp8x_size = need_vp8x ? CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE : 0;
- const size_t alpha_size = need_vp8x ? ChunkDiskSize(wpi->alpha_) : 0;
+ const size_t alpha_size = need_vp8x ? ChunkDiskSize(wpi->alpha) : 0;
// Note: No need to output ANMF chunk for a single image.
const size_t size = RIFF_HEADER_SIZE + vp8x_size + alpha_size +
- ChunkDiskSize(wpi->img_);
+ ChunkDiskSize(wpi->img);
uint8_t* const data = (uint8_t*)WebPSafeMalloc(1ULL, size);
if (data == NULL) return WEBP_MUX_MEMORY_ERROR;
- // There should be at most one alpha_ chunk and exactly one img_ chunk.
- assert(wpi->alpha_ == NULL || wpi->alpha_->next_ == NULL);
- assert(wpi->img_ != NULL && wpi->img_->next_ == NULL);
+ // There should be at most one alpha chunk and exactly one img chunk.
+ assert(wpi->alpha == NULL || wpi->alpha->next == NULL);
+ assert(wpi->img != NULL && wpi->img->next == NULL);
// Main RIFF header.
dst = MuxEmitRiffHeader(data, size);
if (need_vp8x) {
- dst = EmitVP8XChunk(dst, wpi->width_, wpi->height_, ALPHA_FLAG); // VP8X.
- dst = ChunkListEmit(wpi->alpha_, dst); // ALPH.
+ dst = EmitVP8XChunk(dst, wpi->width, wpi->height, ALPHA_FLAG); // VP8X.
+ dst = ChunkListEmit(wpi->alpha, dst); // ALPH.
}
// Bitstream.
- dst = ChunkListEmit(wpi->img_, dst);
+ dst = ChunkListEmit(wpi->img, dst);
assert(dst == data + size);
// Output.
@@ -441,9 +448,9 @@ WebPMuxError WebPMuxGetChunk(const WebPMux* mux, const char fourcc[4],
return MuxGet(mux, idx, 1, chunk_data);
} else { // An unknown chunk type.
const WebPChunk* const chunk =
- ChunkSearchList(mux->unknown_, 1, ChunkGetTagFromFourCC(fourcc));
+ ChunkSearchList(mux->unknown, 1, ChunkGetTagFromFourCC(fourcc));
if (chunk == NULL) return WEBP_MUX_NOT_FOUND;
- *chunk_data = chunk->data_;
+ *chunk_data = chunk->data;
return WEBP_MUX_OK;
}
}
@@ -457,18 +464,18 @@ static WebPMuxError MuxGetImageInternal(const WebPMuxImage* const wpi,
info->dispose_method = WEBP_MUX_DISPOSE_NONE;
info->blend_method = WEBP_MUX_BLEND;
// Extract data for related fields.
- info->id = ChunkGetIdFromTag(wpi->img_->tag_);
+ info->id = ChunkGetIdFromTag(wpi->img->tag);
return SynthesizeBitstream(wpi, &info->bitstream);
}
static WebPMuxError MuxGetFrameInternal(const WebPMuxImage* const wpi,
WebPMuxFrameInfo* const frame) {
- const int is_frame = (wpi->header_->tag_ == kChunks[IDX_ANMF].tag);
+ const int is_frame = (wpi->header->tag == kChunks[IDX_ANMF].tag);
const WebPData* frame_data;
if (!is_frame) return WEBP_MUX_INVALID_ARGUMENT;
- assert(wpi->header_ != NULL); // Already checked by WebPMuxGetFrame().
+ assert(wpi->header != NULL); // Already checked by WebPMuxGetFrame().
// Get frame chunk.
- frame_data = &wpi->header_->data_;
+ frame_data = &wpi->header->data;
if (frame_data->size < kChunks[IDX_ANMF].size) return WEBP_MUX_BAD_DATA;
// Extract info.
frame->x_offset = 2 * GetLE24(frame_data->bytes + 0);
@@ -480,7 +487,7 @@ static WebPMuxError MuxGetFrameInternal(const WebPMuxImage* const wpi,
(bits & 1) ? WEBP_MUX_DISPOSE_BACKGROUND : WEBP_MUX_DISPOSE_NONE;
frame->blend_method = (bits & 2) ? WEBP_MUX_NO_BLEND : WEBP_MUX_BLEND;
}
- frame->id = ChunkGetIdFromTag(wpi->header_->tag_);
+ frame->id = ChunkGetIdFromTag(wpi->header->tag);
return SynthesizeBitstream(wpi, &frame->bitstream);
}
@@ -494,11 +501,11 @@ WebPMuxError WebPMuxGetFrame(
}
// Get the nth WebPMuxImage.
- err = MuxImageGetNth((const WebPMuxImage**)&mux->images_, nth, &wpi);
+ err = MuxImageGetNth((const WebPMuxImage**)&mux->images, nth, &wpi);
if (err != WEBP_MUX_OK) return err;
// Get frame info.
- if (wpi->header_ == NULL) {
+ if (wpi->header == NULL) {
return MuxGetImageInternal(wpi, frame);
} else {
return MuxGetFrameInternal(wpi, frame);
@@ -535,8 +542,8 @@ static CHUNK_INDEX ChunkGetIndexFromId(WebPChunkId id) {
static int CountChunks(const WebPChunk* const chunk_list, uint32_t tag) {
int count = 0;
const WebPChunk* current;
- for (current = chunk_list; current != NULL; current = current->next_) {
- if (tag == NIL_TAG || current->tag_ == tag) {
+ for (current = chunk_list; current != NULL; current = current->next) {
+ if (tag == NIL_TAG || current->tag == tag) {
count++; // Count chunks whose tags match.
}
}
@@ -550,7 +557,7 @@ WebPMuxError WebPMuxNumChunks(const WebPMux* mux,
}
if (IsWPI(id)) {
- *num_elements = MuxImageCount(mux->images_, id);
+ *num_elements = MuxImageCount(mux->images, id);
} else {
WebPChunk* const* chunk_list = MuxGetChunkListFromId(mux, id);
const CHUNK_INDEX idx = ChunkGetIndexFromId(id);