mux: use size_t consistently

remove mixed use of uint32_t

Change-Id: I57f701a0d9fce255c4dd83c01e523079976ef5b5
This commit is contained in:
James Zern 2012-04-18 17:13:34 -07:00
parent dceb8b4d9a
commit 95667b8d86
6 changed files with 59 additions and 57 deletions

View File

@ -215,9 +215,9 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
err = WebPMuxGetFrame(mux, i, &image, &alpha,
&x_offset, &y_offset, &duration);
RETURN_IF_ERROR2("Failed to retrieve frame#%d\n", i);
printf("%3d: %8d %8d %8d %10u",
printf("%3d: %8d %8d %8d %10zu",
i, x_offset, y_offset, duration, image.size_);
if (flag & ALPHA_FLAG) printf(" %10u", alpha.size_);
if (flag & ALPHA_FLAG) printf(" %10zu", alpha.size_);
printf("\n");
}
}
@ -239,9 +239,9 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
WebPData image, alpha;
err = WebPMuxGetTile(mux, i, &image, &alpha, &x_offset, &y_offset);
RETURN_IF_ERROR2("Failed to retrieve tile#%d\n", i);
printf("%3d: %8d %8d %10u",
printf("%3d: %8d %8d %10zu",
i, x_offset, y_offset, image.size_);
if (flag & ALPHA_FLAG) printf(" %10u", alpha.size_);
if (flag & ALPHA_FLAG) printf(" %10zu", alpha.size_);
printf("\n");
}
}
@ -251,21 +251,21 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
WebPData icc_profile;
err = WebPMuxGetColorProfile(mux, &icc_profile);
RETURN_IF_ERROR("Failed to retrieve the color profile\n");
printf("Size of the color profile data: %u\n", icc_profile.size_);
printf("Size of the color profile data: %zu\n", icc_profile.size_);
}
if (flag & META_FLAG) {
WebPData metadata;
err = WebPMuxGetMetadata(mux, &metadata);
RETURN_IF_ERROR("Failed to retrieve the XMP metadata\n");
printf("Size of the XMP metadata: %u\n", metadata.size_);
printf("Size of the XMP metadata: %zu\n", metadata.size_);
}
if ((flag & ALPHA_FLAG) && !(flag & (ANIMATION_FLAG | TILE_FLAG))) {
WebPData image, alpha;
err = WebPMuxGetImage(mux, &image, &alpha);
RETURN_IF_ERROR("Failed to retrieve the image\n");
printf("Size of the alpha data: %u\n", alpha.size_);
printf("Size of the alpha data: %zu\n", alpha.size_);
}
return WEBP_MUX_OK;
@ -411,8 +411,8 @@ static int ReadImage(const char* filename,
ok &= WebPDataCopy(&image, image_ptr);
ok &= WebPDataCopy(&alpha, alpha_ptr);
if (!ok) {
fprintf(stderr, "Error allocating storage for image (%u bytes) "
"and alpha (%u bytes) data\n", image.size_, alpha.size_);
fprintf(stderr, "Error allocating storage for image (%zu bytes) "
"and alpha (%zu bytes) data\n", image.size_, alpha.size_);
WebPDataFree(image_ptr);
WebPDataFree(alpha_ptr);
}
@ -434,7 +434,7 @@ static int WriteData(const char* filename, const WebPData* const webpdata) {
if (fwrite(webpdata->bytes_, webpdata->size_, 1, fout) != 1) {
fprintf(stderr, "Error writing file %s!\n", filename);
} else {
fprintf(stderr, "Saved file %s (%d bytes)\n", filename, webpdata->size_);
fprintf(stderr, "Saved file %s (%zu bytes)\n", filename, webpdata->size_);
ok = 1;
}
if (fout != stdout) fclose(fout);

View File

@ -70,7 +70,7 @@ void WebPMuxDelete(WebPMux* const mux) {
}
static WebPMuxError MuxSet(WebPMux* const mux, TAG_ID id, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* data, size_t size,
WebPImageInfo* image_info, int copy_data) {
WebPChunk chunk;
WebPMuxError err = WEBP_MUX_NOT_FOUND;
@ -114,7 +114,7 @@ static void InitImageInfo(WebPImageInfo* const image_info) {
// Dimensions calculated from passed VP8 image data.
static WebPImageInfo* CreateImageInfo(uint32_t x_offset, uint32_t y_offset,
uint32_t duration,
const uint8_t* data, uint32_t size) {
const uint8_t* data, size_t size) {
int width;
int height;
WebPImageInfo* image_info = NULL;
@ -161,7 +161,7 @@ static WebPMuxError CreateDataFromImageInfo(const WebPImageInfo* image_info,
}
// Outputs image data given data from a webp file (including RIFF header).
static WebPMuxError GetImageData(const uint8_t* data, uint32_t size,
static WebPMuxError GetImageData(const uint8_t* data, size_t size,
WebPData* const image, WebPData* const alpha) {
if (size < TAG_SIZE || memcmp(data, "RIFF", TAG_SIZE)) {
// It is NOT webp file data. Return input data as is.
@ -220,8 +220,8 @@ static WebPMuxError DeleteLoopCount(WebPMux* const mux) {
// Set API(s).
WebPMuxError WebPMuxSetImage(WebPMux* const mux,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
int copy_data) {
WebPMuxError err;
WebPChunk chunk;
@ -264,7 +264,7 @@ WebPMuxError WebPMuxSetImage(WebPMux* const mux,
}
WebPMuxError WebPMuxSetMetadata(WebPMux* const mux,
const uint8_t* data, uint32_t size,
const uint8_t* data, size_t size,
int copy_data) {
WebPMuxError err;
@ -281,7 +281,7 @@ WebPMuxError WebPMuxSetMetadata(WebPMux* const mux,
}
WebPMuxError WebPMuxSetColorProfile(WebPMux* const mux,
const uint8_t* data, uint32_t size,
const uint8_t* data, size_t size,
int copy_data) {
WebPMuxError err;
@ -320,8 +320,8 @@ WebPMuxError WebPMuxSetLoopCount(WebPMux* const mux, uint32_t loop_count) {
static WebPMuxError MuxAddFrameTileInternal(
WebPMux* const mux, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
uint32_t x_offset, uint32_t y_offset, uint32_t duration,
int copy_data, uint32_t tag) {
WebPChunk chunk;
@ -405,8 +405,8 @@ static WebPMuxError MuxAddFrameTileInternal(
// TODO(urvang): Think about whether we need 'nth' while adding a frame or tile.
WebPMuxError WebPMuxAddFrame(WebPMux* const mux, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
uint32_t x_offset, uint32_t y_offset,
uint32_t duration, int copy_data) {
return MuxAddFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size,
@ -415,8 +415,8 @@ WebPMuxError WebPMuxAddFrame(WebPMux* const mux, uint32_t nth,
}
WebPMuxError WebPMuxAddTile(WebPMux* const mux, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
uint32_t x_offset, uint32_t y_offset,
int copy_data) {
return MuxAddFrameTileInternal(mux, nth, data, size, alpha_data, alpha_size,
@ -594,8 +594,8 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {
}
WebPMuxError WebPMuxAssemble(WebPMux* const mux,
uint8_t** output_data, uint32_t* output_size) {
uint32_t size = 0;
uint8_t** output_data, size_t* output_size) {
size_t size = 0;
uint8_t* data = NULL;
uint8_t* dst = NULL;
int num_frames;
@ -641,7 +641,8 @@ WebPMuxError WebPMuxAssemble(WebPMux* const mux,
// Main RIFF header.
PutLE32(data + 0, mktag('R', 'I', 'F', 'F'));
PutLE32(data + 4, size - CHUNK_HEADER_SIZE);
PutLE32(data + 4, (uint32_t)size - CHUNK_HEADER_SIZE);
assert(size == (uint32_t)size);
PutLE32(data + 8, mktag('W', 'E', 'B', 'P'));
// Chunks.

View File

@ -37,7 +37,7 @@ typedef struct {
typedef struct WebPChunk WebPChunk;
struct WebPChunk {
uint32_t tag_;
uint32_t payload_size_;
size_t payload_size_;
WebPImageInfo* image_info_;
int owner_; // True if *data_ memory is owned internally.
// VP8X, Loop, and other internally created chunks
@ -122,7 +122,7 @@ static WEBP_INLINE void PutLE32(uint8_t* const data, uint32_t val) {
PutLE16(data + 2, val >> 16);
}
static WEBP_INLINE uint32_t SizeWithPadding(uint32_t chunk_size) {
static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) {
return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U);
}
@ -144,7 +144,7 @@ WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag);
// Fill the chunk with the given data & image_info.
WebPMuxError ChunkAssignDataImageInfo(WebPChunk* chunk,
const uint8_t* data, uint32_t data_size,
const uint8_t* data, size_t data_size,
WebPImageInfo* image_info,
int copy_data, uint32_t tag);
@ -160,13 +160,13 @@ WebPChunk* ChunkRelease(WebPChunk* const chunk);
WebPChunk* ChunkDelete(WebPChunk* const chunk);
// Size of a chunk including header and padding.
static WEBP_INLINE uint32_t ChunkDiskSize(const WebPChunk* chunk) {
static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) {
assert(chunk->payload_size_ < MAX_CHUNK_PAYLOAD);
return SizeWithPadding(chunk->payload_size_);
}
// Total size of a list of chunks.
uint32_t ChunksListDiskSize(const WebPChunk* chunk_list);
size_t ChunksListDiskSize(const WebPChunk* chunk_list);
// Write out the given list of chunks into 'dst'.
uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst);
@ -229,7 +229,7 @@ WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth,
TAG_ID id, WebPMuxImage** wpi);
// Total size of a list of images.
uint32_t MuxImageListDiskSize(const WebPMuxImage* wpi_list);
size_t MuxImageListDiskSize(const WebPMuxImage* wpi_list);
// Write out the given list of images into 'dst'.
uint8_t* MuxImageListEmit(const WebPMuxImage* wpi_list, uint8_t* dst);

View File

@ -124,7 +124,7 @@ static int ChunkSearchListToSet(WebPChunk** chunk_list, uint32_t nth,
// Chunk writer methods.
WebPMuxError ChunkAssignDataImageInfo(WebPChunk* chunk,
const uint8_t* data, uint32_t data_size,
const uint8_t* data, size_t data_size,
WebPImageInfo* image_info,
int copy_data, uint32_t tag) {
// For internally allocated chunks, always copy data & make it owner of data.
@ -193,8 +193,8 @@ WebPChunk* ChunkDelete(WebPChunk* const chunk) {
//------------------------------------------------------------------------------
// Chunk serialization methods.
uint32_t ChunksListDiskSize(const WebPChunk* chunk_list) {
uint32_t size = 0;
size_t ChunksListDiskSize(const WebPChunk* chunk_list) {
size_t size = 0;
while (chunk_list) {
size += ChunkDiskSize(chunk_list);
chunk_list = chunk_list->next_;
@ -206,7 +206,8 @@ static uint8_t* ChunkEmit(const WebPChunk* const chunk, uint8_t* dst) {
assert(chunk);
assert(chunk->tag_ != NIL_TAG);
PutLE32(dst + 0, chunk->tag_);
PutLE32(dst + TAG_SIZE, chunk->payload_size_);
PutLE32(dst + TAG_SIZE, (uint32_t)chunk->payload_size_);
assert(chunk->payload_size_ == (uint32_t)chunk->payload_size_);
memcpy(dst + CHUNK_HEADER_SIZE, chunk->data_, chunk->payload_size_);
if (chunk->payload_size_ & 1)
dst[CHUNK_HEADER_SIZE + chunk->payload_size_] = 0; // Add padding.
@ -376,16 +377,16 @@ WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth,
// MuxImage serialization methods.
// Size of an image.
static uint32_t MuxImageDiskSize(const WebPMuxImage* wpi) {
uint32_t size = 0;
static size_t MuxImageDiskSize(const WebPMuxImage* wpi) {
size_t size = 0;
if (wpi->header_ != NULL) size += ChunkDiskSize(wpi->header_);
if (wpi->alpha_ != NULL) size += ChunkDiskSize(wpi->alpha_);
if (wpi->vp8_ != NULL) size += ChunkDiskSize(wpi->vp8_);
return size;
}
uint32_t MuxImageListDiskSize(const WebPMuxImage* wpi_list) {
uint32_t size = 0;
size_t MuxImageListDiskSize(const WebPMuxImage* wpi_list) {
size_t size = 0;
while (wpi_list) {
size += MuxImageDiskSize(wpi_list);
wpi_list = wpi_list->next_;

View File

@ -52,7 +52,7 @@ static WebPMuxError MuxGet(const WebPMux* const mux, TAG_ID id, uint32_t nth,
// Fill the chunk with the given data, after verifying that the data size
// doesn't exceed 'max_size'.
static WebPMuxError ChunkAssignData(WebPChunk* chunk, const uint8_t* data,
uint32_t data_size, uint32_t riff_size,
size_t data_size, size_t riff_size,
int copy_data) {
uint32_t chunk_size;
@ -61,7 +61,7 @@ static WebPMuxError ChunkAssignData(WebPChunk* chunk, const uint8_t* data,
chunk_size = GetLE32(data + TAG_SIZE);
{
const uint32_t chunk_disk_size = SizeWithPadding(chunk_size);
const size_t chunk_disk_size = SizeWithPadding(chunk_size);
if (chunk_disk_size > riff_size) return WEBP_MUX_BAD_DATA;
if (chunk_disk_size > data_size) return WEBP_MUX_NOT_ENOUGH_DATA;
}
@ -74,9 +74,9 @@ static WebPMuxError ChunkAssignData(WebPChunk* chunk, const uint8_t* data,
//------------------------------------------------------------------------------
// Create a mux object from WebP-RIFF data.
WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data,
WebPMux* WebPMuxCreate(const uint8_t* data, size_t size, int copy_data,
WebPMuxState* const mux_state) {
uint32_t riff_size;
size_t riff_size;
uint32_t tag;
const uint8_t* end;
WebPMux* mux = NULL;
@ -170,7 +170,7 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data,
}
{
const uint32_t data_size = ChunkDiskSize(&chunk);
const size_t data_size = ChunkDiskSize(&chunk);
data += data_size;
size -= data_size;
}
@ -292,7 +292,7 @@ static WebPMuxError MuxGetFrameTileInternal(
WebPData* const image, WebPData* const alpha,
uint32_t* x_offset, uint32_t* y_offset, uint32_t* duration, uint32_t tag) {
const uint8_t* frame_tile_data;
uint32_t frame_tile_size;
size_t frame_tile_size;
WebPMuxError err;
WebPMuxImage* wpi;

View File

@ -84,7 +84,7 @@ typedef struct WebPMux WebPMux; // main opaque object.
// (ICC profile, metadata) and WebP compressed image data.
typedef struct {
const uint8_t* bytes_;
uint32_t size_;
size_t size_;
} WebPData;
//------------------------------------------------------------------------------
@ -114,7 +114,7 @@ WEBP_EXTERN(void) WebPMuxDelete(WebPMux* const mux);
// Returns:
// A pointer to the mux object created from given data - on success.
// NULL - In case of invalid data or memory error.
WEBP_EXTERN(WebPMux*) WebPMuxCreate(const uint8_t* data, uint32_t size,
WEBP_EXTERN(WebPMux*) WebPMuxCreate(const uint8_t* data, size_t size,
int copy_data,
WebPMuxState* const mux_state);
@ -138,8 +138,8 @@ WEBP_EXTERN(WebPMux*) WebPMuxCreate(const uint8_t* data, uint32_t size,
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxSetImage(
WebPMux* const mux,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
int copy_data);
// Gets a reference to the image in the mux object.
@ -183,7 +183,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteImage(WebPMux* const mux);
// WEBP_MUX_MEMORY_ERROR - on memory allocation error.
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxSetMetadata(
WebPMux* const mux, const uint8_t* data, uint32_t size, int copy_data);
WebPMux* const mux, const uint8_t* data, size_t size, int copy_data);
// Gets a reference to the XMP metadata in the mux object.
// The caller should NOT free the returned data.
@ -222,7 +222,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteMetadata(WebPMux* const mux);
// WEBP_MUX_MEMORY_ERROR - on memory allocation error
// WEBP_MUX_OK - on success
WEBP_EXTERN(WebPMuxError) WebPMuxSetColorProfile(
WebPMux* const mux, const uint8_t* data, uint32_t size, int copy_data);
WebPMux* const mux, const uint8_t* data, size_t size, int copy_data);
// Gets a reference to the color profile in the mux object.
// The caller should NOT free the returned data.
@ -271,8 +271,8 @@ WEBP_EXTERN(WebPMuxError) WebPMuxDeleteColorProfile(WebPMux* const mux);
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxAddFrame(
WebPMux* const mux, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
uint32_t x_offset, uint32_t y_offset, uint32_t duration,
int copy_data);
@ -370,8 +370,8 @@ WEBP_EXTERN(WebPMuxError) WebPMuxGetLoopCount(const WebPMux* const mux,
// WEBP_MUX_OK - on success.
WEBP_EXTERN(WebPMuxError) WebPMuxAddTile(
WebPMux* const mux, uint32_t nth,
const uint8_t* data, uint32_t size,
const uint8_t* alpha_data, uint32_t alpha_size,
const uint8_t* data, size_t size,
const uint8_t* alpha_data, size_t alpha_size,
uint32_t x_offset, uint32_t y_offset,
int copy_data);
@ -454,7 +454,7 @@ WEBP_EXTERN(WebPMuxError) WebPMuxNumNamedElements(const WebPMux* const mux,
// WEBP_MUX_OK - on success
WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* const mux,
uint8_t** output_data,
uint32_t* output_size);
size_t* output_size);
//------------------------------------------------------------------------------