mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-13 15:32:53 +01:00
Merge "allow WebPINewRGB/YUVA to be passed a NULL output buffer."
This commit is contained in:
commit
60904aa629
4
NEWS
4
NEWS
@ -1,3 +1,7 @@
|
|||||||
|
- next version:
|
||||||
|
* WebPINewRGB/WebPINewYUVA accept being passed a NULL output buffer
|
||||||
|
and will perform auto-allocation.
|
||||||
|
|
||||||
- 10/30/12: version 0.2.1
|
- 10/30/12: version 0.2.1
|
||||||
* Various security related fixes
|
* Various security related fixes
|
||||||
* cwebp.exe: fix import errors on Windows XP
|
* cwebp.exe: fix import errors on Windows XP
|
||||||
|
@ -595,12 +595,22 @@ void WebPIDelete(WebPIDecoder* idec) {
|
|||||||
|
|
||||||
WebPIDecoder* WebPINewRGB(WEBP_CSP_MODE mode, uint8_t* output_buffer,
|
WebPIDecoder* WebPINewRGB(WEBP_CSP_MODE mode, uint8_t* output_buffer,
|
||||||
size_t output_buffer_size, int output_stride) {
|
size_t output_buffer_size, int output_stride) {
|
||||||
|
const int is_external_memory = (output_buffer != NULL);
|
||||||
WebPIDecoder* idec;
|
WebPIDecoder* idec;
|
||||||
|
|
||||||
if (mode >= MODE_YUV) return NULL;
|
if (mode >= MODE_YUV) return NULL;
|
||||||
|
if (!is_external_memory) { // Overwrite parameters to sane values.
|
||||||
|
output_buffer_size = 0;
|
||||||
|
output_stride = 0;
|
||||||
|
} else { // A buffer was passed. Validate the other params.
|
||||||
|
if (output_stride == 0 || output_buffer_size == 0) {
|
||||||
|
return NULL; // invalid parameter.
|
||||||
|
}
|
||||||
|
}
|
||||||
idec = WebPINewDecoder(NULL);
|
idec = WebPINewDecoder(NULL);
|
||||||
if (idec == NULL) return NULL;
|
if (idec == NULL) return NULL;
|
||||||
idec->output_.colorspace = mode;
|
idec->output_.colorspace = mode;
|
||||||
idec->output_.is_external_memory = 1;
|
idec->output_.is_external_memory = is_external_memory;
|
||||||
idec->output_.u.RGBA.rgba = output_buffer;
|
idec->output_.u.RGBA.rgba = output_buffer;
|
||||||
idec->output_.u.RGBA.stride = output_stride;
|
idec->output_.u.RGBA.stride = output_stride;
|
||||||
idec->output_.u.RGBA.size = output_buffer_size;
|
idec->output_.u.RGBA.size = output_buffer_size;
|
||||||
@ -611,10 +621,30 @@ WebPIDecoder* WebPINewYUVA(uint8_t* luma, size_t luma_size, int luma_stride,
|
|||||||
uint8_t* u, size_t u_size, int u_stride,
|
uint8_t* u, size_t u_size, int u_stride,
|
||||||
uint8_t* v, size_t v_size, int v_stride,
|
uint8_t* v, size_t v_size, int v_stride,
|
||||||
uint8_t* a, size_t a_size, int a_stride) {
|
uint8_t* a, size_t a_size, int a_stride) {
|
||||||
WebPIDecoder* const idec = WebPINewDecoder(NULL);
|
const int is_external_memory = (luma != NULL);
|
||||||
|
WebPIDecoder* idec;
|
||||||
|
WEBP_CSP_MODE colorspace;
|
||||||
|
|
||||||
|
if (!is_external_memory) { // Overwrite parameters to sane values.
|
||||||
|
luma_size = u_size = v_size = a_size = 0;
|
||||||
|
luma_stride = u_stride = v_stride = a_stride = 0;
|
||||||
|
u = v = a = NULL;
|
||||||
|
colorspace = MODE_YUVA;
|
||||||
|
} else { // A luma buffer was passed. Validate the other parameters.
|
||||||
|
if (u == NULL || v == NULL) return NULL;
|
||||||
|
if (luma_size == 0 || u_size == 0 || v_size == 0) return NULL;
|
||||||
|
if (luma_stride == 0 || u_stride == 0 || v_stride == 0) return NULL;
|
||||||
|
if (a != NULL) {
|
||||||
|
if (a_size == 0 || a_stride == 0) return NULL;
|
||||||
|
}
|
||||||
|
colorspace = (a == NULL) ? MODE_YUV : MODE_YUVA;
|
||||||
|
}
|
||||||
|
|
||||||
|
idec = WebPINewDecoder(NULL);
|
||||||
if (idec == NULL) return NULL;
|
if (idec == NULL) return NULL;
|
||||||
idec->output_.colorspace = (a == NULL) ? MODE_YUV : MODE_YUVA;
|
|
||||||
idec->output_.is_external_memory = 1;
|
idec->output_.colorspace = colorspace;
|
||||||
|
idec->output_.is_external_memory = is_external_memory;
|
||||||
idec->output_.u.YUVA.y = luma;
|
idec->output_.u.YUVA.y = luma;
|
||||||
idec->output_.u.YUVA.y_stride = luma_stride;
|
idec->output_.u.YUVA.y_stride = luma_stride;
|
||||||
idec->output_.u.YUVA.y_size = luma_size;
|
idec->output_.u.YUVA.y_size = luma_size;
|
||||||
|
@ -269,19 +269,27 @@ WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer);
|
|||||||
// will output the RGB/A samples specified by 'csp' into a preallocated
|
// will output the RGB/A samples specified by 'csp' into a preallocated
|
||||||
// buffer 'output_buffer'. The size of this buffer is at least
|
// buffer 'output_buffer'. The size of this buffer is at least
|
||||||
// 'output_buffer_size' and the stride (distance in bytes between two scanlines)
|
// 'output_buffer_size' and the stride (distance in bytes between two scanlines)
|
||||||
// is specified by 'output_stride'. Returns NULL if the allocation failed.
|
// is specified by 'output_stride'.
|
||||||
|
// Additionally, output_buffer can be passed NULL in which case the output
|
||||||
|
// buffer will be allocated automatically when the decoding starts. The
|
||||||
|
// colorspace 'csp' is taken into account for allocating this buffer. All other
|
||||||
|
// parameters are ignored.
|
||||||
|
// Returns NULL if the allocation failed, or if some parameters are invalid.
|
||||||
WEBP_EXTERN(WebPIDecoder*) WebPINewRGB(
|
WEBP_EXTERN(WebPIDecoder*) WebPINewRGB(
|
||||||
WEBP_CSP_MODE csp,
|
WEBP_CSP_MODE csp,
|
||||||
uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
|
uint8_t* output_buffer, size_t output_buffer_size, int output_stride);
|
||||||
|
|
||||||
// This function allocates and initializes an incremental-decoder object, which
|
// This function allocates and initializes an incremental-decoder object, which
|
||||||
// will output the raw luma/chroma samples into a preallocated planes. The luma
|
// will output the raw luma/chroma samples into a preallocated planes if
|
||||||
// plane is specified by its pointer 'luma', its size 'luma_size' and its stride
|
// supplied. The luma plane is specified by its pointer 'luma', its size
|
||||||
// 'luma_stride'. Similarly, the chroma-u plane is specified by the 'u',
|
// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane
|
||||||
// 'u_size' and 'u_stride' parameters, and the chroma-v plane by 'v'
|
// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v
|
||||||
// and 'v_size'. And same for the alpha-plane. The 'a' pointer can be pass
|
// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer
|
||||||
// NULL in case one is not interested in the transparency plane.
|
// can be pass NULL in case one is not interested in the transparency plane.
|
||||||
// Returns NULL if the allocation failed.
|
// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied.
|
||||||
|
// In this case, the output buffer will be automatically allocated (using
|
||||||
|
// MODE_YUVA) when decoding starts. All parameters are then ignored.
|
||||||
|
// Returns NULL if the allocation failed or if a parameter is invalid.
|
||||||
WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA(
|
WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA(
|
||||||
uint8_t* luma, size_t luma_size, int luma_stride,
|
uint8_t* luma, size_t luma_size, int luma_stride,
|
||||||
uint8_t* u, size_t u_size, int u_stride,
|
uint8_t* u, size_t u_size, int u_stride,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user