mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
Merge "decode.h: use size_t consistently"
This commit is contained in:
@ -40,10 +40,10 @@ static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
|
||||
ok = 0;
|
||||
} else if (mode >= MODE_YUV) { // YUV checks
|
||||
const WebPYUVABuffer* const buf = &buffer->u.YUVA;
|
||||
const int size = buf->y_stride * height;
|
||||
const int u_size = buf->u_stride * ((height + 1) / 2);
|
||||
const int v_size = buf->v_stride * ((height + 1) / 2);
|
||||
const int a_size = buf->a_stride * height;
|
||||
const size_t size = buf->y_stride * height;
|
||||
const size_t u_size = buf->u_stride * ((height + 1) / 2);
|
||||
const size_t v_size = buf->v_stride * ((height + 1) / 2);
|
||||
const size_t a_size = buf->a_stride * height;
|
||||
ok &= (size <= buf->y_size);
|
||||
ok &= (u_size <= buf->u_size);
|
||||
ok &= (v_size <= buf->v_size);
|
||||
@ -56,7 +56,8 @@ static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
|
||||
}
|
||||
} else { // RGB checks
|
||||
const WebPRGBABuffer* const buf = &buffer->u.RGBA;
|
||||
ok &= (buf->stride * height <= buf->size);
|
||||
const size_t size = buf->stride * height;
|
||||
ok &= (size <= buf->size);
|
||||
ok &= (buf->stride >= width * kModeBpp[mode]);
|
||||
}
|
||||
return ok ? VP8_STATUS_OK : VP8_STATUS_INVALID_PARAM;
|
||||
|
@ -548,7 +548,7 @@ WebPIDecoder* WebPINewDecoder(WebPDecBuffer* const output_buffer) {
|
||||
return idec;
|
||||
}
|
||||
|
||||
WebPIDecoder* WebPIDecode(const uint8_t* data, uint32_t data_size,
|
||||
WebPIDecoder* WebPIDecode(const uint8_t* data, size_t data_size,
|
||||
WebPDecoderConfig* const config) {
|
||||
WebPIDecoder* idec;
|
||||
|
||||
@ -595,7 +595,7 @@ WebPIDecoder* WebPINew(WEBP_CSP_MODE mode) {
|
||||
}
|
||||
|
||||
WebPIDecoder* WebPINewRGB(WEBP_CSP_MODE mode, uint8_t* output_buffer,
|
||||
int output_buffer_size, int output_stride) {
|
||||
size_t output_buffer_size, int output_stride) {
|
||||
WebPIDecoder* idec;
|
||||
if (mode >= MODE_YUV) return NULL;
|
||||
idec = WebPINewDecoder(NULL);
|
||||
@ -608,9 +608,9 @@ WebPIDecoder* WebPINewRGB(WEBP_CSP_MODE mode, uint8_t* output_buffer,
|
||||
return idec;
|
||||
}
|
||||
|
||||
WebPIDecoder* WebPINewYUV(uint8_t* luma, int luma_size, int luma_stride,
|
||||
uint8_t* u, int u_size, int u_stride,
|
||||
uint8_t* v, int v_size, int v_stride) {
|
||||
WebPIDecoder* WebPINewYUV(uint8_t* luma, size_t luma_size, int luma_stride,
|
||||
uint8_t* u, size_t u_size, int u_stride,
|
||||
uint8_t* v, size_t v_size, int v_stride) {
|
||||
WebPIDecoder* const idec = WebPINewDecoder(NULL);
|
||||
if (!idec) return NULL;
|
||||
idec->output_.colorspace = MODE_YUV;
|
||||
@ -641,7 +641,7 @@ static VP8StatusCode IDecCheckStatus(const WebPIDecoder* const idec) {
|
||||
}
|
||||
|
||||
VP8StatusCode WebPIAppend(WebPIDecoder* const idec,
|
||||
const uint8_t* const data, uint32_t data_size) {
|
||||
const uint8_t* const data, size_t data_size) {
|
||||
VP8StatusCode status;
|
||||
if (idec == NULL || data == NULL) {
|
||||
return VP8_STATUS_INVALID_PARAM;
|
||||
@ -662,7 +662,7 @@ VP8StatusCode WebPIAppend(WebPIDecoder* const idec,
|
||||
}
|
||||
|
||||
VP8StatusCode WebPIUpdate(WebPIDecoder* const idec,
|
||||
const uint8_t* const data, uint32_t data_size) {
|
||||
const uint8_t* const data, size_t data_size) {
|
||||
VP8StatusCode status;
|
||||
if (idec == NULL || data == NULL) {
|
||||
return VP8_STATUS_INVALID_PARAM;
|
||||
|
@ -275,7 +275,7 @@ struct VP8Decoder {
|
||||
|
||||
// extensions
|
||||
const uint8_t* alpha_data_; // compressed alpha data (if present)
|
||||
uint32_t alpha_data_size_;
|
||||
size_t alpha_data_size_;
|
||||
uint8_t* alpha_plane_; // output
|
||||
|
||||
int layer_colorspace_;
|
||||
|
@ -20,7 +20,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static const int kHeaderBytes = 5;
|
||||
static const size_t kHeaderBytes = 5;
|
||||
static const uint32_t kImageSizeBits = 14;
|
||||
|
||||
static const int kCodeLengthLiterals = 16;
|
||||
@ -94,7 +94,7 @@ static int ReadImageSize(VP8LBitReader* const br,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int VP8LGetInfo(const uint8_t* data, int data_size,
|
||||
int VP8LGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
if (data_size < kHeaderBytes) {
|
||||
return 0; // not enough data
|
||||
|
@ -102,7 +102,7 @@ typedef struct {
|
||||
// width and height. Returns 0 in case of formatting error. width/height
|
||||
// can be passed NULL.
|
||||
int VP8LGetInfo(const uint8_t* data,
|
||||
int data_size, // data available so far
|
||||
size_t data_size, // data available so far
|
||||
int *width, int *height);
|
||||
|
||||
// Allocates and initialize a new lossless decoder instance.
|
||||
|
@ -56,7 +56,7 @@ static WEBP_INLINE uint32_t get_le32(const uint8_t* const data) {
|
||||
// VP8_STATUS_OK otherwise.
|
||||
// In case there are not enough bytes (partial RIFF container), return 0 for
|
||||
// riff_size. Else return the riff_size extracted from the header.
|
||||
static VP8StatusCode ParseRIFF(const uint8_t** data, uint32_t* data_size,
|
||||
static VP8StatusCode ParseRIFF(const uint8_t** data, size_t* data_size,
|
||||
size_t* riff_size) {
|
||||
assert(data);
|
||||
assert(data_size);
|
||||
@ -87,7 +87,7 @@ static VP8StatusCode ParseRIFF(const uint8_t** data, uint32_t* data_size,
|
||||
// VP8_STATUS_OK otherwise.
|
||||
// If a VP8X chunk is found, found_vp8x is set to true and *width, *height and
|
||||
// *flags are set to the corresponding values extracted from the VP8X chunk.
|
||||
static VP8StatusCode ParseVP8X(const uint8_t** data, uint32_t* data_size,
|
||||
static VP8StatusCode ParseVP8X(const uint8_t** data, size_t* data_size,
|
||||
int* found_vp8x,
|
||||
int* width, int* height, uint32_t* flags) {
|
||||
const uint32_t vp8x_size = CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE;
|
||||
@ -130,12 +130,12 @@ static VP8StatusCode ParseVP8X(const uint8_t** data, uint32_t* data_size,
|
||||
// VP8_STATUS_OK otherwise.
|
||||
// If an alpha chunk is found, alpha_data and alpha_size are set appropriately.
|
||||
static VP8StatusCode ParseOptionalChunks(const uint8_t** data,
|
||||
uint32_t* data_size,
|
||||
uint32_t riff_size,
|
||||
size_t* data_size,
|
||||
size_t riff_size,
|
||||
const uint8_t** alpha_data,
|
||||
uint32_t* alpha_size) {
|
||||
size_t* alpha_size) {
|
||||
const uint8_t* buf;
|
||||
uint32_t buf_size;
|
||||
size_t buf_size;
|
||||
uint32_t total_size = TAG_SIZE + // "WEBP".
|
||||
CHUNK_HEADER_SIZE + // "VP8Xnnnn".
|
||||
VP8X_CHUNK_SIZE; // data.
|
||||
@ -195,7 +195,7 @@ static VP8StatusCode ParseOptionalChunks(const uint8_t** data,
|
||||
// If a VP8/VP8L chunk is found, chunk_size is set to the total number of bytes
|
||||
// extracted from the VP8/VP8L chunk header.
|
||||
// The flag 'is_lossless' is set to 1 in case of VP8L chunk.
|
||||
static VP8StatusCode ParseVP8Header(const uint8_t** data, uint32_t* data_size,
|
||||
static VP8StatusCode ParseVP8Header(const uint8_t** data, size_t* data_size,
|
||||
size_t riff_size,
|
||||
size_t* chunk_size, int* is_lossless) {
|
||||
const int is_vp8 = !memcmp(*data, "VP8 ", TAG_SIZE);
|
||||
@ -231,7 +231,7 @@ static VP8StatusCode ParseVP8Header(const uint8_t** data, uint32_t* data_size,
|
||||
|
||||
VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers) {
|
||||
const uint8_t* buf;
|
||||
uint32_t buf_size;
|
||||
size_t buf_size;
|
||||
int found_vp8x;
|
||||
VP8StatusCode status;
|
||||
|
||||
@ -296,7 +296,7 @@ void WebPResetDecParams(WebPDecParams* const params) {
|
||||
// "Into" decoding variants
|
||||
|
||||
// Main flow
|
||||
static VP8StatusCode DecodeInto(const uint8_t* data, uint32_t data_size,
|
||||
static VP8StatusCode DecodeInto(const uint8_t* data, size_t data_size,
|
||||
WebPDecParams* const params) {
|
||||
VP8StatusCode status;
|
||||
VP8Io io;
|
||||
@ -370,8 +370,8 @@ static VP8StatusCode DecodeInto(const uint8_t* data, uint32_t data_size,
|
||||
|
||||
// Helpers
|
||||
static uint8_t* DecodeIntoRGBABuffer(WEBP_CSP_MODE colorspace,
|
||||
const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* rgba, int stride, int size) {
|
||||
const uint8_t* data, size_t data_size,
|
||||
uint8_t* rgba, int stride, size_t size) {
|
||||
WebPDecParams params;
|
||||
WebPDecBuffer buf;
|
||||
if (rgba == NULL) {
|
||||
@ -391,35 +391,35 @@ static uint8_t* DecodeIntoRGBABuffer(WEBP_CSP_MODE colorspace,
|
||||
return rgba;
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeRGBInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output, int size, int stride) {
|
||||
uint8_t* WebPDecodeRGBInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* output, size_t size, int stride) {
|
||||
return DecodeIntoRGBABuffer(MODE_RGB, data, data_size, output, stride, size);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeRGBAInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output, int size, int stride) {
|
||||
uint8_t* WebPDecodeRGBAInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* output, size_t size, int stride) {
|
||||
return DecodeIntoRGBABuffer(MODE_RGBA, data, data_size, output, stride, size);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeARGBInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output, int size, int stride) {
|
||||
uint8_t* WebPDecodeARGBInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* output, size_t size, int stride) {
|
||||
return DecodeIntoRGBABuffer(MODE_ARGB, data, data_size, output, stride, size);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeBGRInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output, int size, int stride) {
|
||||
uint8_t* WebPDecodeBGRInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* output, size_t size, int stride) {
|
||||
return DecodeIntoRGBABuffer(MODE_BGR, data, data_size, output, stride, size);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeBGRAInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* output, int size, int stride) {
|
||||
uint8_t* WebPDecodeBGRAInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* output, size_t size, int stride) {
|
||||
return DecodeIntoRGBABuffer(MODE_BGRA, data, data_size, output, stride, size);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeYUVInto(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* luma, int luma_size, int luma_stride,
|
||||
uint8_t* u, int u_size, int u_stride,
|
||||
uint8_t* v, int v_size, int v_stride) {
|
||||
uint8_t* WebPDecodeYUVInto(const uint8_t* data, size_t data_size,
|
||||
uint8_t* luma, size_t luma_size, int luma_stride,
|
||||
uint8_t* u, size_t u_size, int u_stride,
|
||||
uint8_t* v, size_t v_size, int v_stride) {
|
||||
WebPDecParams params;
|
||||
WebPDecBuffer output;
|
||||
if (luma == NULL) return NULL;
|
||||
@ -446,7 +446,7 @@ uint8_t* WebPDecodeYUVInto(const uint8_t* data, uint32_t data_size,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static uint8_t* Decode(WEBP_CSP_MODE mode, const uint8_t* data,
|
||||
uint32_t data_size, int* width, int* height,
|
||||
size_t data_size, int* width, int* height,
|
||||
WebPDecBuffer* keep_info) {
|
||||
WebPDecParams params;
|
||||
WebPDecBuffer output;
|
||||
@ -474,32 +474,32 @@ static uint8_t* Decode(WEBP_CSP_MODE mode, const uint8_t* data,
|
||||
return (mode >= MODE_YUV) ? output.u.YUVA.y : output.u.RGBA.rgba;
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeRGB(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
return Decode(MODE_RGB, data, data_size, width, height, NULL);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeRGBA(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
return Decode(MODE_RGBA, data, data_size, width, height, NULL);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeARGB(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
return Decode(MODE_ARGB, data, data_size, width, height, NULL);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeBGR(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
return Decode(MODE_BGR, data, data_size, width, height, NULL);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeBGRA(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
return Decode(MODE_BGRA, data, data_size, width, height, NULL);
|
||||
}
|
||||
|
||||
uint8_t* WebPDecodeYUV(const uint8_t* data, uint32_t data_size,
|
||||
uint8_t* WebPDecodeYUV(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height, uint8_t** u, uint8_t** v,
|
||||
int* stride, int* uv_stride) {
|
||||
WebPDecBuffer output; // only to preserve the side-infos
|
||||
@ -523,7 +523,7 @@ static void DefaultFeatures(WebPBitstreamFeatures* const features) {
|
||||
features->bitstream_version = 0;
|
||||
}
|
||||
|
||||
static VP8StatusCode GetFeatures(const uint8_t* data, uint32_t data_size,
|
||||
static VP8StatusCode GetFeatures(const uint8_t* data, size_t data_size,
|
||||
WebPBitstreamFeatures* const features) {
|
||||
size_t chunk_size = 0;
|
||||
size_t riff_size = 0;
|
||||
@ -584,7 +584,7 @@ static VP8StatusCode GetFeatures(const uint8_t* data, uint32_t data_size,
|
||||
//------------------------------------------------------------------------------
|
||||
// WebPGetInfo()
|
||||
|
||||
int WebPGetInfo(const uint8_t* data, uint32_t data_size,
|
||||
int WebPGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height) {
|
||||
WebPBitstreamFeatures features;
|
||||
|
||||
@ -619,7 +619,7 @@ int WebPInitDecoderConfigInternal(WebPDecoderConfig* const config,
|
||||
return 1;
|
||||
}
|
||||
|
||||
VP8StatusCode WebPGetFeaturesInternal(const uint8_t* data, uint32_t data_size,
|
||||
VP8StatusCode WebPGetFeaturesInternal(const uint8_t* data, size_t data_size,
|
||||
WebPBitstreamFeatures* const features,
|
||||
int version) {
|
||||
VP8StatusCode status;
|
||||
@ -637,7 +637,7 @@ VP8StatusCode WebPGetFeaturesInternal(const uint8_t* data, uint32_t data_size,
|
||||
return status;
|
||||
}
|
||||
|
||||
VP8StatusCode WebPDecode(const uint8_t* data, uint32_t data_size,
|
||||
VP8StatusCode WebPDecode(const uint8_t* data, size_t data_size,
|
||||
WebPDecoderConfig* const config) {
|
||||
WebPDecParams params;
|
||||
VP8StatusCode status;
|
||||
|
@ -60,7 +60,7 @@ typedef struct {
|
||||
size_t data_size; // input buffer size
|
||||
size_t offset; // offset to main data chunk (VP8 or VP8L)
|
||||
const uint8_t* alpha_data; // points to alpha chunk (if present)
|
||||
uint32_t alpha_data_size; // alpha chunk size
|
||||
size_t alpha_data_size; // alpha chunk size
|
||||
size_t compressed_size; // VP8/VP8L compressed data size
|
||||
size_t riff_size; // size of the riff payload (or 0 if absent)
|
||||
int is_lossless; // true if a VP8L chunk is present
|
||||
|
Reference in New Issue
Block a user