mux: light cleanup
- const / move declarations closer to first use - remove unnecessary ()s - don't return int unnecessarily with internal Init/Release - compact some lines Change-Id: If7ab505e417221debc356f21f075506939110a84
This commit is contained in:
parent
5e96a5dbef
commit
14f6b9f606
@ -20,11 +20,10 @@ extern "C" {
|
||||
//------------------------------------------------------------------------------
|
||||
// Life of a mux object.
|
||||
|
||||
static int MuxInit(WebPMux* const mux) {
|
||||
if (mux == NULL) return 0;
|
||||
static void MuxInit(WebPMux* const mux) {
|
||||
if (mux == NULL) return;
|
||||
memset(mux, 0, sizeof(*mux));
|
||||
mux->state_ = WEBP_MUX_STATE_PARTIAL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
WebPMux* WebPMuxNew(void) {
|
||||
@ -39,22 +38,20 @@ static void DeleteAllChunks(WebPChunk** const chunk_list) {
|
||||
}
|
||||
}
|
||||
|
||||
static int MuxRelease(WebPMux* const mux) {
|
||||
if (mux == NULL) return 0;
|
||||
static void MuxRelease(WebPMux* const mux) {
|
||||
if (mux == NULL) return;
|
||||
MuxImageDeleteAll(&mux->images_);
|
||||
DeleteAllChunks(&mux->vp8x_);
|
||||
DeleteAllChunks(&mux->iccp_);
|
||||
DeleteAllChunks(&mux->loop_);
|
||||
DeleteAllChunks(&mux->meta_);
|
||||
DeleteAllChunks(&mux->unknown_);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void WebPMuxDelete(WebPMux* const mux) {
|
||||
if (mux) {
|
||||
MuxRelease(mux);
|
||||
free(mux);
|
||||
}
|
||||
// If mux is NULL MuxRelease is a noop.
|
||||
MuxRelease(mux);
|
||||
free(mux);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -100,13 +97,11 @@ static WebPMuxError MuxSet(WebPMux* const mux, TAG_ID id, uint32_t nth,
|
||||
static WebPMuxError MuxAddChunk(WebPMux* const mux, uint32_t nth, uint32_t tag,
|
||||
const uint8_t* data, uint32_t size,
|
||||
WebPImageInfo* image_info, int copy_data) {
|
||||
TAG_ID id;
|
||||
const TAG_ID id = ChunkGetIdFromTag(tag);
|
||||
assert(mux != NULL);
|
||||
assert(size <= MAX_CHUNK_PAYLOAD);
|
||||
|
||||
id = ChunkGetIdFromTag(tag);
|
||||
if (id == NIL_ID) return WEBP_MUX_INVALID_PARAMETER;
|
||||
|
||||
return MuxSet(mux, id, nth, data, size, image_info, copy_data);
|
||||
}
|
||||
|
||||
@ -205,12 +200,10 @@ static WebPMuxError DeleteChunks(WebPChunk** chunk_list, uint32_t tag) {
|
||||
|
||||
static WebPMuxError MuxDeleteAllNamedData(WebPMux* const mux,
|
||||
const char* const tag) {
|
||||
TAG_ID id;
|
||||
const TAG_ID id = ChunkGetIdFromName(tag);
|
||||
WebPChunk** chunk_list;
|
||||
|
||||
if (mux == NULL || tag == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
||||
id = ChunkGetIdFromName(tag);
|
||||
if (IsWPI(id)) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
||||
chunk_list = GetChunkListFromId(mux, id);
|
||||
@ -458,10 +451,9 @@ WebPMuxError WebPMuxDeleteColorProfile(WebPMux* const mux) {
|
||||
static WebPMuxError DeleteFrameTileInternal(WebPMux* const mux,
|
||||
uint32_t nth,
|
||||
const char* const tag) {
|
||||
TAG_ID id;
|
||||
const TAG_ID id = ChunkGetIdFromName(tag);
|
||||
if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
||||
id = ChunkGetIdFromName(tag);
|
||||
assert(id == FRAME_ID || id == TILE_ID);
|
||||
return MuxImageDeleteNth(&mux->images_, nth, id);
|
||||
}
|
||||
@ -481,11 +473,7 @@ static WebPMuxError GetImageCanvasHeightWidth(const WebPMux* const mux,
|
||||
uint32_t flags,
|
||||
uint32_t* width,
|
||||
uint32_t* height) {
|
||||
uint32_t max_x = 0;
|
||||
uint32_t max_y = 0;
|
||||
uint64_t image_area = 0;
|
||||
WebPMuxImage* wpi = NULL;
|
||||
|
||||
assert(mux != NULL);
|
||||
assert(width && height);
|
||||
|
||||
@ -494,6 +482,9 @@ static WebPMuxError GetImageCanvasHeightWidth(const WebPMux* const mux,
|
||||
assert(wpi->vp8_ != NULL);
|
||||
|
||||
if (wpi->next_) {
|
||||
uint32_t max_x = 0;
|
||||
uint32_t max_y = 0;
|
||||
uint64_t image_area = 0;
|
||||
// Aggregate the bounding box for animation frames & tiled images.
|
||||
for (; wpi != NULL; wpi = wpi->next_) {
|
||||
const WebPImageInfo* image_info = wpi->vp8_->image_info_;
|
||||
@ -551,9 +542,8 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {
|
||||
const uint32_t data_size = VP8X_CHUNK_SIZE;
|
||||
const WebPMuxImage* images = NULL;
|
||||
|
||||
images = mux->images_; // First image.
|
||||
|
||||
assert(mux != NULL);
|
||||
images = mux->images_; // First image.
|
||||
if (images == NULL || images->vp8_ == NULL || images->vp8_->data_ == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
@ -254,4 +254,4 @@ WebPMuxError WebPMuxValidate(const WebPMux* const mux);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_MUX_MUXI_H_ */
|
||||
#endif /* WEBP_MUX_MUXI_H_ */
|
||||
|
@ -132,8 +132,7 @@ WebPMuxError ChunkAssignDataImageInfo(WebPChunk* chunk,
|
||||
WebPImageInfo* image_info,
|
||||
int copy_data, uint32_t tag) {
|
||||
// For internally allocated chunks, always copy data & make it owner of data.
|
||||
if ((tag == kChunks[VP8X_ID].chunkTag) ||
|
||||
(tag == kChunks[LOOP_ID].chunkTag)) {
|
||||
if (tag == kChunks[VP8X_ID].chunkTag || tag == kChunks[LOOP_ID].chunkTag) {
|
||||
copy_data = 1;
|
||||
}
|
||||
|
||||
@ -510,10 +509,10 @@ WebPMuxError WebPMuxValidate(const WebPMux* const mux) {
|
||||
err = WebPMuxNumNamedElements(mux, kChunks[FRAME_ID].chunkName, &num_frames);
|
||||
if (err != WEBP_MUX_OK) return err;
|
||||
if ((flags & ANIMATION_FLAG) &&
|
||||
((num_loop_chunks == 0) || (num_frames == 0))) {
|
||||
(num_loop_chunks == 0 || num_frames == 0)) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
} else if (((num_loop_chunks == 1) || (num_frames > 0)) &&
|
||||
!(flags & ANIMATION_FLAG)) {
|
||||
} else if (!(flags & ANIMATION_FLAG) &&
|
||||
(num_loop_chunks == 1 || num_frames > 0)) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@ -533,7 +532,7 @@ WebPMuxError WebPMuxValidate(const WebPMux* const mux) {
|
||||
|
||||
if (num_vp8x > 1) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
} else if ((num_vp8x == 0) && (num_images != 1)) {
|
||||
} else if (num_vp8x == 0 && num_images != 1) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@ -545,7 +544,7 @@ WebPMuxError WebPMuxValidate(const WebPMux* const mux) {
|
||||
}
|
||||
|
||||
// num_images & num_alpha_chunks are consistent.
|
||||
if ((num_alpha > 0) && (num_alpha != num_images)) {
|
||||
if (num_alpha > 0 && num_alpha != num_images) {
|
||||
// Note that "num_alpha > 0" is the correct check but "flags && ALPHA_FLAG"
|
||||
// is NOT, because ALPHA_FLAG is based on first image only.
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
|
@ -37,8 +37,8 @@ extern "C" {
|
||||
static WebPMuxError MuxGet(const WebPMux* const mux, TAG_ID id, uint32_t nth,
|
||||
WebPData* const data) {
|
||||
assert(mux != NULL);
|
||||
memset(data, 0, sizeof(*data));
|
||||
assert(!IsWPI(id));
|
||||
memset(data, 0, sizeof(*data));
|
||||
|
||||
SWITCH_ID_LIST(VP8X_ID, mux->vp8x_);
|
||||
SWITCH_ID_LIST(ICCP_ID, mux->iccp_);
|
||||
@ -79,7 +79,6 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data,
|
||||
uint32_t riff_size;
|
||||
uint32_t tag;
|
||||
const uint8_t* end;
|
||||
TAG_ID id;
|
||||
WebPMux* mux = NULL;
|
||||
WebPMuxImage* wpi = NULL;
|
||||
|
||||
@ -129,6 +128,7 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data,
|
||||
|
||||
// Loop over chunks.
|
||||
while (data != end) {
|
||||
TAG_ID id;
|
||||
WebPChunk chunk;
|
||||
WebPMuxError err;
|
||||
|
||||
@ -146,8 +146,8 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data,
|
||||
id = ChunkGetIdFromTag(chunk.tag_);
|
||||
|
||||
if (IsWPI(id)) { // An image chunk (frame/tile/alpha/vp8).
|
||||
WebPChunk** wpi_chunk_ptr;
|
||||
wpi_chunk_ptr = MuxImageGetListFromId(wpi, id); // Image chunk to set.
|
||||
WebPChunk** wpi_chunk_ptr =
|
||||
MuxImageGetListFromId(wpi, id); // Image chunk to set.
|
||||
assert(wpi_chunk_ptr != NULL);
|
||||
if (*wpi_chunk_ptr != NULL) goto Err; // Consecutive alpha chunks or
|
||||
// consecutive frame/tile chunks.
|
||||
@ -230,10 +230,7 @@ WebPMuxError WebPMuxGetImage(const WebPMux* const mux,
|
||||
WebPMuxError err;
|
||||
WebPMuxImage* wpi = NULL;
|
||||
|
||||
if (mux == NULL || image == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (mux == NULL || image == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
memset(image, 0, sizeof(*image));
|
||||
|
||||
err = ValidateForImage(mux);
|
||||
@ -262,19 +259,13 @@ WebPMuxError WebPMuxGetImage(const WebPMux* const mux,
|
||||
|
||||
WebPMuxError WebPMuxGetMetadata(const WebPMux* const mux,
|
||||
WebPData* const metadata) {
|
||||
if (mux == NULL || metadata == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (mux == NULL || metadata == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
return MuxGet(mux, META_ID, 1, metadata);
|
||||
}
|
||||
|
||||
WebPMuxError WebPMuxGetColorProfile(const WebPMux* const mux,
|
||||
WebPData* const color_profile) {
|
||||
if (mux == NULL || color_profile == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (mux == NULL || color_profile == NULL) return WEBP_MUX_INVALID_ARGUMENT;
|
||||
return MuxGet(mux, ICCP_ID, 1, color_profile);
|
||||
}
|
||||
|
||||
@ -378,14 +369,13 @@ static int CountChunks(WebPChunk* const chunk_list, uint32_t tag) {
|
||||
|
||||
WebPMuxError WebPMuxNumNamedElements(const WebPMux* const mux, const char* tag,
|
||||
int* num_elements) {
|
||||
TAG_ID id;
|
||||
const TAG_ID id = ChunkGetIdFromName(tag);
|
||||
WebPChunk** chunk_list;
|
||||
|
||||
if (mux == NULL || tag == NULL || num_elements == NULL) {
|
||||
return WEBP_MUX_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
id = ChunkGetIdFromName(tag);
|
||||
if (IsWPI(id)) {
|
||||
*num_elements = MuxImageCount(mux->images_, id);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user