Mux: make ValidateForSingleImage() method static

Change-Id: I96ac5e3be26b8e8ecd9f055501a5feb7710bc324
This commit is contained in:
Urvang Joshi 2013-05-03 13:58:53 -07:00
parent fffefd18c3
commit 1d530c9a7e
3 changed files with 20 additions and 23 deletions

View File

@ -233,9 +233,6 @@ uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size);
// or if 'id' is not known. // or if 'id' is not known.
WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id); 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 // 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 // canvas size are valid. This method can be used for validation-only purposes
// by passing 'width' and 'height' to be NULL. // by passing 'width' and 'height' to be NULL.

View File

@ -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) { static int IsNotCompatible(int feature, int num_items) {
return (feature != 0) != (num_items > 0); return (feature != 0) != (num_items > 0);
} }

View File

@ -260,6 +260,24 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Get API(s). // 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, WebPMuxError MuxGetCanvasSize(const WebPMux* const mux, int* width,
int* height) { int* height) {
int w, h; int w, h;
@ -272,7 +290,7 @@ WebPMuxError MuxGetCanvasSize(const WebPMux* const mux, int* width,
w = GetLE24(data.bytes + 4) + 1; w = GetLE24(data.bytes + 4) + 1;
h = GetLE24(data.bytes + 7) + 1; h = GetLE24(data.bytes + 7) + 1;
} else { // Single image case. } else { // Single image case.
WebPMuxError err = MuxValidateForImage(mux); WebPMuxError err = ValidateForSingleImage(mux);
if (err != WEBP_MUX_OK) return err; if (err != WEBP_MUX_OK) return err;
err = MuxGetImageWidthHeight(mux->images_->img_, &w, &h); err = MuxGetImageWidthHeight(mux->images_->img_, &w, &h);
if (err != WEBP_MUX_OK) return err; 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); return MuxGetCanvasSize(mux, width, height);
} }
WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) { WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, uint32_t* flags) {
WebPData data; 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; if (data.size < CHUNK_SIZE_BYTES) return WEBP_MUX_BAD_DATA;
*flags = GetLE32(data.bytes); // All OK. Fill up flags. *flags = GetLE32(data.bytes); // All OK. Fill up flags.
} else { } 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 (err != WEBP_MUX_OK) return err;
if (MuxHasLosslessImages(mux->images_)) { if (MuxHasLosslessImages(mux->images_)) {
const WebPData* const vp8l_data = &mux->images_->img_->data_; const WebPData* const vp8l_data = &mux->images_->img_->data_;