mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 04:18:26 +01:00
Merge "ReadWebP: avoid conversion to ARGB if final format is YUVA"
This commit is contained in:
commit
77cad88589
@ -50,13 +50,12 @@ static int verbose = 0;
|
|||||||
|
|
||||||
static int ReadYUV(const uint8_t* const data, size_t data_size,
|
static int ReadYUV(const uint8_t* const data, size_t data_size,
|
||||||
WebPPicture* const pic) {
|
WebPPicture* const pic) {
|
||||||
int y;
|
|
||||||
const int use_argb = pic->use_argb;
|
const int use_argb = pic->use_argb;
|
||||||
const int uv_width = (pic->width + 1) / 2;
|
const int uv_width = (pic->width + 1) / 2;
|
||||||
const int uv_height = (pic->height + 1) / 2;
|
const int uv_height = (pic->height + 1) / 2;
|
||||||
|
const int y_plane_size = pic->width * pic->height;
|
||||||
const int uv_plane_size = uv_width * uv_height;
|
const int uv_plane_size = uv_width * uv_height;
|
||||||
const size_t expected_data_size =
|
const size_t expected_data_size = y_plane_size + 2 * uv_plane_size;
|
||||||
pic->width * pic->height + 2 * uv_plane_size;
|
|
||||||
|
|
||||||
if (data_size != expected_data_size) {
|
if (data_size != expected_data_size) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -67,18 +66,12 @@ static int ReadYUV(const uint8_t* const data, size_t data_size,
|
|||||||
|
|
||||||
pic->use_argb = 0;
|
pic->use_argb = 0;
|
||||||
if (!WebPPictureAlloc(pic)) return 0;
|
if (!WebPPictureAlloc(pic)) return 0;
|
||||||
|
ExUtilCopyPlane(data, pic->width, pic->y, pic->y_stride,
|
||||||
for (y = 0; y < pic->height; ++y) {
|
pic->width, pic->height);
|
||||||
memcpy(pic->y + y * pic->y_stride, data + y * pic->width,
|
ExUtilCopyPlane(data + y_plane_size, uv_width,
|
||||||
pic->width * sizeof(*pic->y));
|
pic->u, pic->uv_stride, uv_width, uv_height);
|
||||||
}
|
ExUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width,
|
||||||
for (y = 0; y < uv_height; ++y) {
|
pic->v, pic->uv_stride, uv_width, uv_height);
|
||||||
const uint8_t* const uv_data = data + pic->height * pic->y_stride;
|
|
||||||
memcpy(pic->u + y * pic->uv_stride, uv_data + y * uv_width,
|
|
||||||
uv_width * sizeof(*uv_data));
|
|
||||||
memcpy(pic->v + y * pic->uv_stride, uv_data + y * uv_width + uv_plane_size,
|
|
||||||
uv_width * sizeof(*uv_data));
|
|
||||||
}
|
|
||||||
return use_argb ? WebPPictureYUVAToARGB(pic) : 1;
|
return use_argb ? WebPPictureYUVAToARGB(pic) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,3 +268,14 @@ VP8StatusCode ExUtilDecodeWebPIncremental(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void ExUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||||
|
uint8_t* dst, int dst_stride, int width, int height) {
|
||||||
|
while (height-- > 0) {
|
||||||
|
memcpy(dst, src, width * sizeof(*dst));
|
||||||
|
src += src_stride;
|
||||||
|
dst += dst_stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -53,6 +53,12 @@ int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
|
|||||||
int ExUtilWriteFile(const char* const file_name,
|
int ExUtilWriteFile(const char* const file_name,
|
||||||
const uint8_t* data, size_t data_size);
|
const uint8_t* data, size_t data_size);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Copy width x height pixels from 'src' to 'dst' honoring the strides.
|
||||||
|
void ExUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||||
|
uint8_t* dst, int dst_stride, int width, int height);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// WebP decoding
|
// WebP decoding
|
||||||
|
|
||||||
|
@ -45,18 +45,42 @@ int ReadWebP(const uint8_t* const data, size_t data_size,
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
const int has_alpha = keep_alpha && bitstream->has_alpha;
|
const int has_alpha = keep_alpha && bitstream->has_alpha;
|
||||||
// TODO(skal): use MODE_YUV(A), depending on the expected
|
if (pic->use_argb) {
|
||||||
// input pic->use_argb. This would save some conversion steps.
|
|
||||||
output_buffer->colorspace = has_alpha ? MODE_RGBA : MODE_RGB;
|
output_buffer->colorspace = has_alpha ? MODE_RGBA : MODE_RGB;
|
||||||
|
} else {
|
||||||
|
output_buffer->colorspace = has_alpha ? MODE_YUVA : MODE_YUV;
|
||||||
|
}
|
||||||
|
|
||||||
status = ExUtilDecodeWebP(data, data_size, 0, &config);
|
status = ExUtilDecodeWebP(data, data_size, 0, &config);
|
||||||
if (status == VP8_STATUS_OK) {
|
if (status == VP8_STATUS_OK) {
|
||||||
const uint8_t* const rgba = output_buffer->u.RGBA.rgba;
|
|
||||||
const int stride = output_buffer->u.RGBA.stride;
|
|
||||||
pic->width = output_buffer->width;
|
pic->width = output_buffer->width;
|
||||||
pic->height = output_buffer->height;
|
pic->height = output_buffer->height;
|
||||||
|
if (pic->use_argb) {
|
||||||
|
const uint8_t* const rgba = output_buffer->u.RGBA.rgba;
|
||||||
|
const int stride = output_buffer->u.RGBA.stride;
|
||||||
ok = has_alpha ? WebPPictureImportRGBA(pic, rgba, stride)
|
ok = has_alpha ? WebPPictureImportRGBA(pic, rgba, stride)
|
||||||
: WebPPictureImportRGB(pic, rgba, stride);
|
: WebPPictureImportRGB(pic, rgba, stride);
|
||||||
|
} else {
|
||||||
|
pic->colorspace = has_alpha ? WEBP_YUV420A : WEBP_YUV420;
|
||||||
|
ok = WebPPictureAlloc(pic);
|
||||||
|
if (!ok) {
|
||||||
|
status = VP8_STATUS_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
const WebPYUVABuffer* const yuva = &output_buffer->u.YUVA;
|
||||||
|
const int uv_width = (pic->width + 1) >> 1;
|
||||||
|
const int uv_height = (pic->height + 1) >> 1;
|
||||||
|
ExUtilCopyPlane(yuva->y, yuva->y_stride,
|
||||||
|
pic->y, pic->y_stride, pic->width, pic->height);
|
||||||
|
ExUtilCopyPlane(yuva->u, yuva->u_stride,
|
||||||
|
pic->u, pic->uv_stride, uv_width, uv_height);
|
||||||
|
ExUtilCopyPlane(yuva->v, yuva->v_stride,
|
||||||
|
pic->v, pic->uv_stride, uv_width, uv_height);
|
||||||
|
if (has_alpha) {
|
||||||
|
ExUtilCopyPlane(yuva->a, yuva->a_stride,
|
||||||
|
pic->a, pic->a_stride, pic->width, pic->height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user