mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Mux: make ValidateForSingleImage() method static
Change-Id: I96ac5e3be26b8e8ecd9f055501a5feb7710bc324
This commit is contained in:
parent
fffefd18c3
commit
1d530c9a7e
@ -233,9 +233,6 @@ uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size);
|
||||
// or if 'id' is not known.
|
||||
WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id);
|
||||
|
||||
// Validates that the given mux has a single image.
|
||||
WebPMuxError MuxValidateForImage(const WebPMux* const mux);
|
||||
|
||||
// Get the canvas width and height after validating that VP8X/VP8/VP8L chunk and
|
||||
// canvas size are valid. This method can be used for validation-only purposes
|
||||
// by passing 'width' and 'height' to be NULL.
|
||||
|
@ -443,23 +443,6 @@ WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id) {
|
||||
}
|
||||
}
|
||||
|
||||
WebPMuxError MuxValidateForImage(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_fragments = MuxImageCount(mux->images_, WEBP_CHUNK_FRGM);
|
||||
|
||||
if (num_images == 0) {
|
||||
// No images in mux.
|
||||
return WEBP_MUX_NOT_FOUND;
|
||||
} else if (num_images == 1 && num_frames == 0 && num_fragments == 0) {
|
||||
// Valid case (single image).
|
||||
return WEBP_MUX_OK;
|
||||
} else {
|
||||
// Frame/Fragment case OR an invalid mux.
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
static int IsNotCompatible(int feature, int num_items) {
|
||||
return (feature != 0) != (num_items > 0);
|
||||
}
|
||||
|
@ -260,6 +260,24 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
|
||||
//------------------------------------------------------------------------------
|
||||
// Get API(s).
|
||||
|
||||
// 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_fragments = MuxImageCount(mux->images_, WEBP_CHUNK_FRGM);
|
||||
|
||||
if (num_images == 0) {
|
||||
// No images in mux.
|
||||
return WEBP_MUX_NOT_FOUND;
|
||||
} else if (num_images == 1 && num_frames == 0 && num_fragments == 0) {
|
||||
// Valid case (single image).
|
||||
return WEBP_MUX_OK;
|
||||
} else {
|
||||
// Frame/Fragment case OR an invalid mux.
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
WebPMuxError MuxGetCanvasSize(const WebPMux* const mux, int* width,
|
||||
int* height) {
|
||||
int w, h;
|
||||
@ -272,7 +290,7 @@ WebPMuxError MuxGetCanvasSize(const WebPMux* const mux, int* width,
|
||||
w = GetLE24(data.bytes + 4) + 1;
|
||||
h = GetLE24(data.bytes + 7) + 1;
|
||||
} else { // Single image case.
|
||||
WebPMuxError err = MuxValidateForImage(mux);
|
||||
WebPMuxError err = ValidateForSingleImage(mux);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
err = MuxGetImageWidthHeight(mux->images_->img_, &w, &h);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
@ -291,7 +309,6 @@ WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, int* width, int* height) {
|
||||
return MuxGetCanvasSize(mux, width, height);
|
||||
}
|
||||
|
||||
|
||||
WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) {
|
||||
WebPData data;
|
||||
|
||||
@ -303,7 +320,7 @@ WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) {
|
||||
if (data.size < CHUNK_SIZE_BYTES) return WEBP_MUX_BAD_DATA;
|
||||
*flags = GetLE32(data.bytes); // All OK. Fill up flags.
|
||||
} else {
|
||||
WebPMuxError err = MuxValidateForImage(mux); // Check for single image.
|
||||
WebPMuxError err = ValidateForSingleImage(mux); // Check for single image.
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
if (MuxHasLosslessImages(mux->images_)) {
|
||||
const WebPData* const vp8l_data = &mux->images_->img_->data_;
|
||||
|
Loading…
Reference in New Issue
Block a user