mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
Merge "rename 'use_argb_input' to 'use_argb'" into 0.2.0
This commit is contained in:
commit
3e5bbe1c2e
@ -64,13 +64,13 @@ extern void* VP8GetCPUInfo; // opaque forward declaration.
|
|||||||
static int verbose = 0;
|
static int verbose = 0;
|
||||||
|
|
||||||
static int ReadYUV(FILE* in_file, WebPPicture* const pic) {
|
static int ReadYUV(FILE* in_file, WebPPicture* const pic) {
|
||||||
const int use_argb_input = pic->use_argb_input;
|
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;
|
||||||
int y;
|
int y;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
pic->use_argb_input = 0;
|
pic->use_argb = 0;
|
||||||
if (!WebPPictureAlloc(pic)) return ok;
|
if (!WebPPictureAlloc(pic)) return ok;
|
||||||
|
|
||||||
for (y = 0; y < pic->height; ++y) {
|
for (y = 0; y < pic->height; ++y) {
|
||||||
@ -87,7 +87,7 @@ static int ReadYUV(FILE* in_file, WebPPicture* const pic) {
|
|||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
ok = 1;
|
ok = 1;
|
||||||
if (use_argb_input) ok = WebPPictureYUVAToARGB(pic);
|
if (use_argb) ok = WebPPictureYUVAToARGB(pic);
|
||||||
|
|
||||||
End:
|
End:
|
||||||
return ok;
|
return ok;
|
||||||
@ -943,7 +943,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
keep_alpha = 0;
|
keep_alpha = 0;
|
||||||
} else if (!strcmp(argv[c], "-lossless")) {
|
} else if (!strcmp(argv[c], "-lossless")) {
|
||||||
config.lossless = 1;
|
config.lossless = 1;
|
||||||
picture.use_argb_input = 1;
|
picture.use_argb = 1;
|
||||||
} else if (!strcmp(argv[c], "-hint") && c < argc - 1) {
|
} else if (!strcmp(argv[c], "-hint") && c < argc - 1) {
|
||||||
++c;
|
++c;
|
||||||
if (!strcmp(argv[c], "photo")) {
|
if (!strcmp(argv[c], "photo")) {
|
||||||
@ -1139,7 +1139,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
// Write info
|
// Write info
|
||||||
if (dump_file) {
|
if (dump_file) {
|
||||||
if (picture.use_argb_input) {
|
if (picture.use_argb) {
|
||||||
fprintf(stderr, "Warning: can't dump file (-d option) in lossless mode.");
|
fprintf(stderr, "Warning: can't dump file (-d option) in lossless mode.");
|
||||||
} else if (!DumpPicture(&picture, dump_file)) {
|
} else if (!DumpPicture(&picture, dump_file)) {
|
||||||
fprintf(stderr, "Warning, couldn't dump picture %s\n", dump_file);
|
fprintf(stderr, "Warning, couldn't dump picture %s\n", dump_file);
|
||||||
|
@ -62,7 +62,7 @@ static int EncodeLossless(const uint8_t* data, int width, int height,
|
|||||||
WebPPictureInit(&picture);
|
WebPPictureInit(&picture);
|
||||||
picture.width = width;
|
picture.width = width;
|
||||||
picture.height = height;
|
picture.height = height;
|
||||||
picture.use_argb_input = 1;
|
picture.use_argb = 1;
|
||||||
if (!WebPPictureAlloc(&picture)) return 0;
|
if (!WebPPictureAlloc(&picture)) return 0;
|
||||||
|
|
||||||
// Transfer the alpha values to the green channel.
|
// Transfer the alpha values to the green channel.
|
||||||
|
@ -41,7 +41,7 @@ int WebPPictureAlloc(WebPPicture* picture) {
|
|||||||
const int width = picture->width;
|
const int width = picture->width;
|
||||||
const int height = picture->height;
|
const int height = picture->height;
|
||||||
|
|
||||||
if (!picture->use_argb_input) {
|
if (!picture->use_argb) {
|
||||||
const int y_stride = width;
|
const int y_stride = width;
|
||||||
const int uv_width = HALVE(width);
|
const int uv_width = HALVE(width);
|
||||||
const int uv_height = HALVE(height);
|
const int uv_height = HALVE(height);
|
||||||
@ -172,7 +172,7 @@ static int PictureAllocARGB(WebPPicture* const picture) {
|
|||||||
WebPPicture tmp;
|
WebPPicture tmp;
|
||||||
free(picture->memory_argb_);
|
free(picture->memory_argb_);
|
||||||
PictureResetARGB(picture);
|
PictureResetARGB(picture);
|
||||||
picture->use_argb_input = 1;
|
picture->use_argb = 1;
|
||||||
WebPPictureGrabSpecs(picture, &tmp);
|
WebPPictureGrabSpecs(picture, &tmp);
|
||||||
if (!WebPPictureAlloc(&tmp)) {
|
if (!WebPPictureAlloc(&tmp)) {
|
||||||
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
@ -209,7 +209,7 @@ static void CopyPlane(const uint8_t* src, int src_stride,
|
|||||||
// Adjust top-left corner to chroma sample position.
|
// Adjust top-left corner to chroma sample position.
|
||||||
static void SnapTopLeftPosition(const WebPPicture* const pic,
|
static void SnapTopLeftPosition(const WebPPicture* const pic,
|
||||||
int* const left, int* const top) {
|
int* const left, int* const top) {
|
||||||
if (!pic->use_argb_input) {
|
if (!pic->use_argb) {
|
||||||
const int is_yuv422 = IS_YUV_CSP(pic->colorspace, WEBP_YUV422);
|
const int is_yuv422 = IS_YUV_CSP(pic->colorspace, WEBP_YUV422);
|
||||||
if (IS_YUV_CSP(pic->colorspace, WEBP_YUV420) || is_yuv422) {
|
if (IS_YUV_CSP(pic->colorspace, WEBP_YUV420) || is_yuv422) {
|
||||||
*left &= ~1;
|
*left &= ~1;
|
||||||
@ -237,7 +237,7 @@ int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) {
|
|||||||
WebPPictureGrabSpecs(src, dst);
|
WebPPictureGrabSpecs(src, dst);
|
||||||
if (!WebPPictureAlloc(dst)) return 0;
|
if (!WebPPictureAlloc(dst)) return 0;
|
||||||
|
|
||||||
if (!src->use_argb_input) {
|
if (!src->use_argb) {
|
||||||
CopyPlane(src->y, src->y_stride,
|
CopyPlane(src->y, src->y_stride,
|
||||||
dst->y, dst->y_stride, dst->width, dst->height);
|
dst->y, dst->y_stride, dst->width, dst->height);
|
||||||
CopyPlane(src->u, src->uv_stride,
|
CopyPlane(src->u, src->uv_stride,
|
||||||
@ -270,7 +270,7 @@ int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) {
|
|||||||
|
|
||||||
int WebPPictureIsView(const WebPPicture* picture) {
|
int WebPPictureIsView(const WebPPicture* picture) {
|
||||||
if (picture == NULL) return 0;
|
if (picture == NULL) return 0;
|
||||||
if (picture->use_argb_input) {
|
if (picture->use_argb) {
|
||||||
return (picture->memory_argb_ == NULL);
|
return (picture->memory_argb_ == NULL);
|
||||||
}
|
}
|
||||||
return (picture->memory_ == NULL);
|
return (picture->memory_ == NULL);
|
||||||
@ -289,7 +289,7 @@ int WebPPictureView(const WebPPicture* src,
|
|||||||
}
|
}
|
||||||
dst->width = width;
|
dst->width = width;
|
||||||
dst->height = height;
|
dst->height = height;
|
||||||
if (!src->use_argb_input) {
|
if (!src->use_argb) {
|
||||||
dst->y = src->y + top * src->y_stride + left;
|
dst->y = src->y + top * src->y_stride + left;
|
||||||
dst->u = src->u + (top >> 1) * src->uv_stride + (left >> 1);
|
dst->u = src->u + (top >> 1) * src->uv_stride + (left >> 1);
|
||||||
dst->v = src->v + (top >> 1) * src->uv_stride + (left >> 1);
|
dst->v = src->v + (top >> 1) * src->uv_stride + (left >> 1);
|
||||||
@ -325,7 +325,7 @@ int WebPPictureCrop(WebPPicture* pic,
|
|||||||
tmp.height = height;
|
tmp.height = height;
|
||||||
if (!WebPPictureAlloc(&tmp)) return 0;
|
if (!WebPPictureAlloc(&tmp)) return 0;
|
||||||
|
|
||||||
if (!pic->use_argb_input) {
|
if (!pic->use_argb) {
|
||||||
const int y_offset = top * pic->y_stride + left;
|
const int y_offset = top * pic->y_stride + left;
|
||||||
const int uv_offset = (top / 2) * pic->uv_stride + left / 2;
|
const int uv_offset = (top / 2) * pic->uv_stride + left / 2;
|
||||||
CopyPlane(pic->y + y_offset, pic->y_stride,
|
CopyPlane(pic->y + y_offset, pic->y_stride,
|
||||||
@ -415,7 +415,7 @@ int WebPPictureRescale(WebPPicture* pic, int width, int height) {
|
|||||||
tmp.height = height;
|
tmp.height = height;
|
||||||
if (!WebPPictureAlloc(&tmp)) return 0;
|
if (!WebPPictureAlloc(&tmp)) return 0;
|
||||||
|
|
||||||
if (!pic->use_argb_input) {
|
if (!pic->use_argb) {
|
||||||
work = (int32_t*)malloc(2 * width * sizeof(*work));
|
work = (int32_t*)malloc(2 * width * sizeof(*work));
|
||||||
if (work == NULL) {
|
if (work == NULL) {
|
||||||
WebPPictureFree(&tmp);
|
WebPPictureFree(&tmp);
|
||||||
@ -528,7 +528,7 @@ static int CheckNonOpaque(const uint8_t* alpha, int width, int height,
|
|||||||
// Checking for the presence of non-opaque alpha.
|
// Checking for the presence of non-opaque alpha.
|
||||||
int WebPPictureHasTransparency(const WebPPicture* picture) {
|
int WebPPictureHasTransparency(const WebPPicture* picture) {
|
||||||
if (picture == NULL) return 0;
|
if (picture == NULL) return 0;
|
||||||
if (!picture->use_argb_input) {
|
if (!picture->use_argb) {
|
||||||
return CheckNonOpaque(picture->a, picture->width, picture->height,
|
return CheckNonOpaque(picture->a, picture->width, picture->height,
|
||||||
1, picture->a_stride);
|
1, picture->a_stride);
|
||||||
} else {
|
} else {
|
||||||
@ -625,7 +625,7 @@ static int ImportYUVAFromRGBA(const uint8_t* const r_ptr,
|
|||||||
const int has_alpha = CheckNonOpaque(a_ptr, width, height, step, rgb_stride);
|
const int has_alpha = CheckNonOpaque(a_ptr, width, height, step, rgb_stride);
|
||||||
|
|
||||||
picture->colorspace = uv_csp;
|
picture->colorspace = uv_csp;
|
||||||
picture->use_argb_input = 0;
|
picture->use_argb = 0;
|
||||||
if (has_alpha) {
|
if (has_alpha) {
|
||||||
picture->colorspace |= WEBP_CSP_ALPHA_BIT;
|
picture->colorspace |= WEBP_CSP_ALPHA_BIT;
|
||||||
}
|
}
|
||||||
@ -704,7 +704,7 @@ static int Import(WebPPicture* const picture,
|
|||||||
const int width = picture->width;
|
const int width = picture->width;
|
||||||
const int height = picture->height;
|
const int height = picture->height;
|
||||||
|
|
||||||
if (!picture->use_argb_input) {
|
if (!picture->use_argb) {
|
||||||
return ImportYUVAFromRGBA(r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride,
|
return ImportYUVAFromRGBA(r_ptr, g_ptr, b_ptr, a_ptr, step, rgb_stride,
|
||||||
picture);
|
picture);
|
||||||
}
|
}
|
||||||
@ -856,7 +856,7 @@ int WebPPictureARGBToYUVA(WebPPicture* picture, WebPEncCSP colorspace) {
|
|||||||
// would be calling WebPPictureFree(picture) otherwise.
|
// would be calling WebPPictureFree(picture) otherwise.
|
||||||
WebPPicture tmp = *picture;
|
WebPPicture tmp = *picture;
|
||||||
PictureResetARGB(&tmp); // reset ARGB buffer so that it's not free()'d.
|
PictureResetARGB(&tmp); // reset ARGB buffer so that it's not free()'d.
|
||||||
tmp.use_argb_input = 0;
|
tmp.use_argb = 0;
|
||||||
tmp.colorspace = colorspace & WEBP_CSP_UV_MASK;
|
tmp.colorspace = colorspace & WEBP_CSP_UV_MASK;
|
||||||
if (!ImportYUVAFromRGBA(r, g, b, a, 4, 4 * picture->argb_stride, &tmp)) {
|
if (!ImportYUVAFromRGBA(r, g, b, a, 4, 4 * picture->argb_stride, &tmp)) {
|
||||||
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
@ -957,8 +957,7 @@ int WebPPictureDistortion(const WebPPicture* pic1, const WebPPicture* pic2,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// TODO(skal): provide distortion for ARGB too.
|
// TODO(skal): provide distortion for ARGB too.
|
||||||
if (pic1->use_argb_input == 1 ||
|
if (pic1->use_argb == 1 || pic1->use_argb != pic2->use_argb) {
|
||||||
pic1->use_argb_input != pic2->use_argb_input) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1020,7 +1019,7 @@ static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.lossless = !!lossless;
|
config.lossless = !!lossless;
|
||||||
pic.use_argb_input = !!lossless;
|
pic.use_argb = !!lossless;
|
||||||
pic.width = width;
|
pic.width = width;
|
||||||
pic.height = height;
|
pic.height = height;
|
||||||
pic.writer = WebPMemoryWrite;
|
pic.writer = WebPMemoryWrite;
|
||||||
|
@ -246,7 +246,7 @@ struct WebPPicture {
|
|||||||
// It is recommended to use ARGB input (*argb, argb_stride) for lossless
|
// It is recommended to use ARGB input (*argb, argb_stride) for lossless
|
||||||
// compression, and YUV input (*y, *u, *v, etc.) for lossy compression
|
// compression, and YUV input (*y, *u, *v, etc.) for lossy compression
|
||||||
// since these are the respective native colorspace for these formats.
|
// since these are the respective native colorspace for these formats.
|
||||||
int use_argb_input;
|
int use_argb;
|
||||||
|
|
||||||
// YUV input (mostly used for input to lossy compression)
|
// YUV input (mostly used for input to lossy compression)
|
||||||
WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr).
|
WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr).
|
||||||
@ -399,15 +399,15 @@ WEBP_EXTERN(int) WebPPictureImportBGRX(
|
|||||||
WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride);
|
WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride);
|
||||||
|
|
||||||
// Converts picture->argb data to the YUVA format specified by 'colorspace'.
|
// Converts picture->argb data to the YUVA format specified by 'colorspace'.
|
||||||
// Upon return, picture->use_argb_input is set to false. The presence of
|
// Upon return, picture->use_argb is set to false. The presence of real
|
||||||
// real non-opaque transparent values is detected, and 'colorspace' will be
|
// non-opaque transparent values is detected, and 'colorspace' will be
|
||||||
// adjusted accordingly. Note that this method is lossy.
|
// adjusted accordingly. Note that this method is lossy.
|
||||||
// Returns false in case of error.
|
// Returns false in case of error.
|
||||||
WEBP_EXTERN(int) WebPPictureARGBToYUVA(WebPPicture* picture,
|
WEBP_EXTERN(int) WebPPictureARGBToYUVA(WebPPicture* picture,
|
||||||
WebPEncCSP colorspace);
|
WebPEncCSP colorspace);
|
||||||
|
|
||||||
// Converts picture->yuv to picture->argb and sets picture->use_argb_input
|
// Converts picture->yuv to picture->argb and sets picture->use_argb to true.
|
||||||
// to true. The input format must be YUV_420 or YUV_420A.
|
// The input format must be YUV_420 or YUV_420A.
|
||||||
// Note that the use of this method is discouraged if one has access to the
|
// Note that the use of this method is discouraged if one has access to the
|
||||||
// raw ARGB samples, since using YUV420 is comparatively lossy. Also, the
|
// raw ARGB samples, since using YUV420 is comparatively lossy. Also, the
|
||||||
// conversion from YUV420 to ARGB incurs a small loss too.
|
// conversion from YUV420 to ARGB incurs a small loss too.
|
||||||
@ -433,8 +433,8 @@ WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* picture);
|
|||||||
// Returns false in case of error, true otherwise.
|
// Returns false in case of error, true otherwise.
|
||||||
// In case of error, picture->error_code is updated accordingly.
|
// In case of error, picture->error_code is updated accordingly.
|
||||||
// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
|
// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
|
||||||
// on the value of 'picture->use_argb_input'. It is highly recommended to
|
// on the value of 'picture->use_argb'. It is highly recommended to use
|
||||||
// use the former for lossy encoding, and the latter for lossless encoding
|
// the former for lossy encoding, and the latter for lossless encoding
|
||||||
// (when config.lossless is true). Automatic conversion from one format to
|
// (when config.lossless is true). Automatic conversion from one format to
|
||||||
// another is provided but they both incur some loss.
|
// another is provided but they both incur some loss.
|
||||||
WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture);
|
WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture);
|
||||||
|
Loading…
Reference in New Issue
Block a user