mirror of
https://github.com/webmproject/libwebp.git
synced 2025-01-27 15:12:54 +01:00
remove experimental YUV444 YUV422 and YUV400 code
(never used) Change-Id: I12a886703592133939607df05132e9b498f916c1
This commit is contained in:
parent
380cca4f2c
commit
257adfb0be
@ -597,9 +597,6 @@ static void HelpLong(void) {
|
|||||||
printf(" -resize <w> <h> ........ resize picture (after any cropping)\n");
|
printf(" -resize <w> <h> ........ resize picture (after any cropping)\n");
|
||||||
printf(" -mt .................... use multi-threading if available\n");
|
printf(" -mt .................... use multi-threading if available\n");
|
||||||
printf(" -low_memory ............ reduce memory usage (slower encoding)\n");
|
printf(" -low_memory ............ reduce memory usage (slower encoding)\n");
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
printf(" -444 / -422 / -gray .... change colorspace\n");
|
|
||||||
#endif
|
|
||||||
printf(" -map <int> ............. print map of extra info\n");
|
printf(" -map <int> ............. print map of extra info\n");
|
||||||
printf(" -print_psnr ............ prints averaged PSNR distortion\n");
|
printf(" -print_psnr ............ prints averaged PSNR distortion\n");
|
||||||
printf(" -print_ssim ............ prints averaged SSIM distortion\n");
|
printf(" -print_ssim ............ prints averaged SSIM distortion\n");
|
||||||
@ -812,14 +809,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
config.partition_limit = strtol(argv[++c], NULL, 0);
|
config.partition_limit = strtol(argv[++c], NULL, 0);
|
||||||
} else if (!strcmp(argv[c], "-map") && c < argc - 1) {
|
} else if (!strcmp(argv[c], "-map") && c < argc - 1) {
|
||||||
picture.extra_info_type = strtol(argv[++c], NULL, 0);
|
picture.extra_info_type = strtol(argv[++c], NULL, 0);
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
} else if (!strcmp(argv[c], "-444")) {
|
|
||||||
picture.colorspace = WEBP_YUV444;
|
|
||||||
} else if (!strcmp(argv[c], "-422")) {
|
|
||||||
picture.colorspace = WEBP_YUV422;
|
|
||||||
} else if (!strcmp(argv[c], "-gray")) {
|
|
||||||
picture.colorspace = WEBP_YUV400;
|
|
||||||
#endif
|
|
||||||
} else if (!strcmp(argv[c], "-crop") && c < argc - 4) {
|
} else if (!strcmp(argv[c], "-crop") && c < argc - 4) {
|
||||||
crop = 1;
|
crop = 1;
|
||||||
crop_x = strtol(argv[++c], NULL, 0);
|
crop_x = strtol(argv[++c], NULL, 0);
|
||||||
|
@ -788,9 +788,9 @@ int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
|||||||
h = options->crop_height;
|
h = options->crop_height;
|
||||||
x = options->crop_left;
|
x = options->crop_left;
|
||||||
y = options->crop_top;
|
y = options->crop_top;
|
||||||
if (!WebPIsRGBMode(src_colorspace)) { // only snap for YUV420 or YUV422
|
if (!WebPIsRGBMode(src_colorspace)) { // only snap for YUV420
|
||||||
x &= ~1;
|
x &= ~1;
|
||||||
y &= ~1; // TODO(later): only for YUV420, not YUV422.
|
y &= ~1;
|
||||||
}
|
}
|
||||||
if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) {
|
if (x < 0 || y < 0 || w <= 0 || h <= 0 || x + w > W || y + h > H) {
|
||||||
return 0; // out of frame boundary error
|
return 0; // out of frame boundary error
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#define USE_GAMMA_COMPRESSION
|
#define USE_GAMMA_COMPRESSION
|
||||||
|
|
||||||
#define HALVE(x) (((x) + 1) >> 1)
|
#define HALVE(x) (((x) + 1) >> 1)
|
||||||
#define IS_YUV_CSP(csp, YUV_CSP) (((csp) & WEBP_CSP_UV_MASK) == (YUV_CSP))
|
|
||||||
|
|
||||||
static const union {
|
static const union {
|
||||||
uint32_t argb;
|
uint32_t argb;
|
||||||
@ -54,29 +53,17 @@ int WebPPictureAlloc(WebPPicture* picture) {
|
|||||||
const int uv_width = HALVE(width);
|
const int uv_width = HALVE(width);
|
||||||
const int uv_height = HALVE(height);
|
const int uv_height = HALVE(height);
|
||||||
const int uv_stride = uv_width;
|
const int uv_stride = uv_width;
|
||||||
int uv0_stride = 0;
|
|
||||||
int a_width, a_stride;
|
int a_width, a_stride;
|
||||||
uint64_t y_size, uv_size, uv0_size, a_size, total_size;
|
uint64_t y_size, uv_size, a_size, total_size;
|
||||||
uint8_t* mem;
|
uint8_t* mem;
|
||||||
|
|
||||||
// U/V
|
// U/V
|
||||||
switch (uv_csp) {
|
switch (uv_csp) {
|
||||||
case WEBP_YUV420:
|
case WEBP_YUV420:
|
||||||
break;
|
break;
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
case WEBP_YUV400: // for now, we'll just reset the U/V samples
|
|
||||||
break;
|
|
||||||
case WEBP_YUV422:
|
|
||||||
uv0_stride = uv_width;
|
|
||||||
break;
|
|
||||||
case WEBP_YUV444:
|
|
||||||
uv0_stride = width;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uv0_size = height * uv0_stride;
|
|
||||||
|
|
||||||
// alpha
|
// alpha
|
||||||
a_width = has_alpha ? width : 0;
|
a_width = has_alpha ? width : 0;
|
||||||
@ -85,7 +72,7 @@ int WebPPictureAlloc(WebPPicture* picture) {
|
|||||||
uv_size = (uint64_t)uv_stride * uv_height;
|
uv_size = (uint64_t)uv_stride * uv_height;
|
||||||
a_size = (uint64_t)a_stride * height;
|
a_size = (uint64_t)a_stride * height;
|
||||||
|
|
||||||
total_size = y_size + a_size + 2 * uv_size + 2 * uv0_size;
|
total_size = y_size + a_size + 2 * uv_size;
|
||||||
|
|
||||||
// Security and validation checks
|
// Security and validation checks
|
||||||
if (width <= 0 || height <= 0 || // luma/alpha param error
|
if (width <= 0 || height <= 0 || // luma/alpha param error
|
||||||
@ -102,7 +89,7 @@ int WebPPictureAlloc(WebPPicture* picture) {
|
|||||||
picture->y_stride = y_stride;
|
picture->y_stride = y_stride;
|
||||||
picture->uv_stride = uv_stride;
|
picture->uv_stride = uv_stride;
|
||||||
picture->a_stride = a_stride;
|
picture->a_stride = a_stride;
|
||||||
picture->uv0_stride = uv0_stride;
|
|
||||||
// TODO(skal): we could align the y/u/v planes and adjust stride.
|
// TODO(skal): we could align the y/u/v planes and adjust stride.
|
||||||
picture->y = mem;
|
picture->y = mem;
|
||||||
mem += y_size;
|
mem += y_size;
|
||||||
@ -112,16 +99,10 @@ int WebPPictureAlloc(WebPPicture* picture) {
|
|||||||
picture->v = mem;
|
picture->v = mem;
|
||||||
mem += uv_size;
|
mem += uv_size;
|
||||||
|
|
||||||
if (a_size) {
|
if (a_size > 0) {
|
||||||
picture->a = mem;
|
picture->a = mem;
|
||||||
mem += a_size;
|
mem += a_size;
|
||||||
}
|
}
|
||||||
if (uv0_size) {
|
|
||||||
picture->u0 = mem;
|
|
||||||
mem += uv0_size;
|
|
||||||
picture->v0 = mem;
|
|
||||||
mem += uv0_size;
|
|
||||||
}
|
|
||||||
(void)mem; // makes the static analyzer happy
|
(void)mem; // makes the static analyzer happy
|
||||||
} else {
|
} else {
|
||||||
void* memory;
|
void* memory;
|
||||||
@ -154,10 +135,8 @@ static void PictureResetARGB(WebPPicture* const picture) {
|
|||||||
static void PictureResetYUVA(WebPPicture* const picture) {
|
static void PictureResetYUVA(WebPPicture* const picture) {
|
||||||
picture->memory_ = NULL;
|
picture->memory_ = NULL;
|
||||||
picture->y = picture->u = picture->v = picture->a = NULL;
|
picture->y = picture->u = picture->v = picture->a = NULL;
|
||||||
picture->u0 = picture->v0 = NULL;
|
|
||||||
picture->y_stride = picture->uv_stride = 0;
|
picture->y_stride = picture->uv_stride = 0;
|
||||||
picture->a_stride = 0;
|
picture->a_stride = 0;
|
||||||
picture->uv0_stride = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
|
// Grab the 'specs' (writer, *opaque, width, height...) from 'src' and copy them
|
||||||
@ -214,11 +193,8 @@ static void CopyPlane(const uint8_t* src, int src_stride,
|
|||||||
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) {
|
if (!pic->use_argb) {
|
||||||
const int is_yuv422 = IS_YUV_CSP(pic->colorspace, WEBP_YUV422);
|
*left &= ~1;
|
||||||
if (IS_YUV_CSP(pic->colorspace, WEBP_YUV420) || is_yuv422) {
|
*top &= ~1;
|
||||||
*left &= ~1;
|
|
||||||
if (!is_yuv422) *top &= ~1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,18 +228,6 @@ int WebPPictureCopy(const WebPPicture* src, WebPPicture* dst) {
|
|||||||
CopyPlane(src->a, src->a_stride,
|
CopyPlane(src->a, src->a_stride,
|
||||||
dst->a, dst->a_stride, dst->width, dst->height);
|
dst->a, dst->a_stride, dst->width, dst->height);
|
||||||
}
|
}
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
if (dst->u0 != NULL) {
|
|
||||||
int uv0_width = src->width;
|
|
||||||
if (IS_YUV_CSP(dst->colorspace, WEBP_YUV422)) {
|
|
||||||
uv0_width = HALVE(uv0_width);
|
|
||||||
}
|
|
||||||
CopyPlane(src->u0, src->uv0_stride,
|
|
||||||
dst->u0, dst->uv0_stride, uv0_width, dst->height);
|
|
||||||
CopyPlane(src->v0, src->uv0_stride,
|
|
||||||
dst->v0, dst->uv0_stride, uv0_width, dst->height);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
CopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride,
|
CopyPlane((const uint8_t*)src->argb, 4 * src->argb_stride,
|
||||||
(uint8_t*)dst->argb, 4 * dst->argb_stride,
|
(uint8_t*)dst->argb, 4 * dst->argb_stride,
|
||||||
@ -303,15 +267,6 @@ int WebPPictureView(const WebPPicture* src,
|
|||||||
dst->a = src->a + top * src->a_stride + left;
|
dst->a = src->a + top * src->a_stride + left;
|
||||||
dst->a_stride = src->a_stride;
|
dst->a_stride = src->a_stride;
|
||||||
}
|
}
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
if (src->u0 != NULL) {
|
|
||||||
const int left_pos =
|
|
||||||
IS_YUV_CSP(dst->colorspace, WEBP_YUV422) ? (left >> 1) : left;
|
|
||||||
dst->u0 = src->u0 + top * src->uv0_stride + left_pos;
|
|
||||||
dst->v0 = src->v0 + top * src->uv0_stride + left_pos;
|
|
||||||
dst->uv0_stride = src->uv0_stride;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
dst->argb = src->argb + top * src->argb_stride + left;
|
dst->argb = src->argb + top * src->argb_stride + left;
|
||||||
dst->argb_stride = src->argb_stride;
|
dst->argb_stride = src->argb_stride;
|
||||||
@ -349,20 +304,6 @@ int WebPPictureCrop(WebPPicture* pic,
|
|||||||
CopyPlane(pic->a + a_offset, pic->a_stride,
|
CopyPlane(pic->a + a_offset, pic->a_stride,
|
||||||
tmp.a, tmp.a_stride, width, height);
|
tmp.a, tmp.a_stride, width, height);
|
||||||
}
|
}
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
if (tmp.u0 != NULL) {
|
|
||||||
int w = width;
|
|
||||||
int left_pos = left;
|
|
||||||
if (IS_YUV_CSP(tmp.colorspace, WEBP_YUV422)) {
|
|
||||||
w = HALVE(w);
|
|
||||||
left_pos = HALVE(left_pos);
|
|
||||||
}
|
|
||||||
CopyPlane(pic->u0 + top * pic->uv0_stride + left_pos, pic->uv0_stride,
|
|
||||||
tmp.u0, tmp.uv0_stride, w, height);
|
|
||||||
CopyPlane(pic->v0 + top * pic->uv0_stride + left_pos, pic->uv0_stride,
|
|
||||||
tmp.v0, tmp.uv0_stride, w, height);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
const uint8_t* const src =
|
const uint8_t* const src =
|
||||||
(const uint8_t*)(pic->argb + top * pic->argb_stride + left);
|
(const uint8_t*)(pic->argb + top * pic->argb_stride + left);
|
||||||
@ -465,18 +406,6 @@ int WebPPictureRescale(WebPPicture* pic, int width, int height) {
|
|||||||
HALVE(prev_width), HALVE(prev_height), pic->uv_stride,
|
HALVE(prev_width), HALVE(prev_height), pic->uv_stride,
|
||||||
tmp.v,
|
tmp.v,
|
||||||
HALVE(width), HALVE(height), tmp.uv_stride, work, 1);
|
HALVE(width), HALVE(height), tmp.uv_stride, work, 1);
|
||||||
|
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
|
||||||
if (tmp.u0 != NULL) {
|
|
||||||
const int s = IS_YUV_CSP(tmp.colorspace, WEBP_YUV422) ? 2 : 1;
|
|
||||||
RescalePlane(
|
|
||||||
pic->u0, (prev_width + s / 2) / s, prev_height, pic->uv0_stride,
|
|
||||||
tmp.u0, (width + s / 2) / s, height, tmp.uv0_stride, work, 1);
|
|
||||||
RescalePlane(
|
|
||||||
pic->v0, (prev_width + s / 2) / s, prev_height, pic->uv0_stride,
|
|
||||||
tmp.v0, (width + s / 2) / s, height, tmp.uv0_stride, work, 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
work = (int32_t*)WebPSafeMalloc(2ULL * width * 4, sizeof(*work));
|
work = (int32_t*)WebPSafeMalloc(2ULL * width * 4, sizeof(*work));
|
||||||
if (work == NULL) {
|
if (work == NULL) {
|
||||||
@ -687,26 +616,6 @@ static WEBP_INLINE int LinearToGamma(uint32_t base_value, int shift) {
|
|||||||
picture->v[dst] = RGBToV(r, g, b, &rg); \
|
picture->v[dst] = RGBToV(r, g, b, &rg); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RGB_TO_UV0(x_in, x_out, y, SUM) { \
|
|
||||||
const int src = (step * (x_in) + (y) * rgb_stride); \
|
|
||||||
const int dst = (x_out) + (y) * picture->uv0_stride; \
|
|
||||||
const int r = SUM(r_ptr + src); \
|
|
||||||
const int g = SUM(g_ptr + src); \
|
|
||||||
const int b = SUM(b_ptr + src); \
|
|
||||||
picture->u0[dst] = RGBToU(r, g, b, &rg); \
|
|
||||||
picture->v0[dst] = RGBToV(r, g, b, &rg); \
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MakeGray(WebPPicture* const picture) {
|
|
||||||
int y;
|
|
||||||
const int uv_width = HALVE(picture->width);
|
|
||||||
const int uv_height = HALVE(picture->height);
|
|
||||||
for (y = 0; y < uv_height; ++y) {
|
|
||||||
memset(picture->u + y * picture->uv_stride, 128, uv_width);
|
|
||||||
memset(picture->v + y * picture->uv_stride, 128, uv_width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ImportYUVAFromRGBA(const uint8_t* const r_ptr,
|
static int ImportYUVAFromRGBA(const uint8_t* const r_ptr,
|
||||||
const uint8_t* const g_ptr,
|
const uint8_t* const g_ptr,
|
||||||
const uint8_t* const b_ptr,
|
const uint8_t* const b_ptr,
|
||||||
@ -742,45 +651,21 @@ static int ImportYUVAFromRGBA(const uint8_t* const r_ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Downsample U/V plane
|
// Downsample U/V plane
|
||||||
if (uv_csp != WEBP_YUV400) {
|
for (y = 0; y < (height >> 1); ++y) {
|
||||||
for (y = 0; y < (height >> 1); ++y) {
|
for (x = 0; x < (width >> 1); ++x) {
|
||||||
for (x = 0; x < (width >> 1); ++x) {
|
RGB_TO_UV(x, y, SUM4);
|
||||||
RGB_TO_UV(x, y, SUM4);
|
|
||||||
}
|
|
||||||
if (width & 1) {
|
|
||||||
RGB_TO_UV(x, y, SUM2V);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (height & 1) {
|
if (width & 1) {
|
||||||
for (x = 0; x < (width >> 1); ++x) {
|
RGB_TO_UV(x, y, SUM2V);
|
||||||
RGB_TO_UV(x, y, SUM2H);
|
|
||||||
}
|
|
||||||
if (width & 1) {
|
|
||||||
RGB_TO_UV(x, y, SUM1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
if (height & 1) {
|
||||||
// Store original U/V samples too
|
for (x = 0; x < (width >> 1); ++x) {
|
||||||
if (uv_csp == WEBP_YUV422) {
|
RGB_TO_UV(x, y, SUM2H);
|
||||||
for (y = 0; y < height; ++y) {
|
}
|
||||||
for (x = 0; x < (width >> 1); ++x) {
|
if (width & 1) {
|
||||||
RGB_TO_UV0(2 * x, x, y, SUM2H);
|
RGB_TO_UV(x, y, SUM1);
|
||||||
}
|
|
||||||
if (width & 1) {
|
|
||||||
RGB_TO_UV0(2 * x, x, y, SUM1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (uv_csp == WEBP_YUV444) {
|
|
||||||
for (y = 0; y < height; ++y) {
|
|
||||||
for (x = 0; x < width; ++x) {
|
|
||||||
RGB_TO_UV0(x, x, y, SUM1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
MakeGray(picture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_alpha) {
|
if (has_alpha) {
|
||||||
|
@ -246,16 +246,9 @@ typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture);
|
|||||||
// Color spaces.
|
// Color spaces.
|
||||||
typedef enum WebPEncCSP {
|
typedef enum WebPEncCSP {
|
||||||
// chroma sampling
|
// chroma sampling
|
||||||
WEBP_YUV420 = 0, // 4:2:0
|
WEBP_YUV420 = 0, // 4:2:0
|
||||||
WEBP_YUV422 = 1, // 4:2:2
|
WEBP_YUV420A = 4, // alpha channel variant
|
||||||
WEBP_YUV444 = 2, // 4:4:4
|
WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors
|
||||||
WEBP_YUV400 = 3, // grayscale
|
|
||||||
WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors
|
|
||||||
// alpha channel variants
|
|
||||||
WEBP_YUV420A = 4,
|
|
||||||
WEBP_YUV422A = 5,
|
|
||||||
WEBP_YUV444A = 6,
|
|
||||||
WEBP_YUV400A = 7, // grayscale + alpha
|
|
||||||
WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present
|
WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present
|
||||||
} WebPEncCSP;
|
} WebPEncCSP;
|
||||||
|
|
||||||
@ -334,17 +327,15 @@ struct WebPPicture {
|
|||||||
|
|
||||||
uint32_t pad3[3]; // padding for later use
|
uint32_t pad3[3]; // padding for later use
|
||||||
|
|
||||||
// Unused for now: original samples (for non-YUV420 modes)
|
// Unused for now
|
||||||
uint8_t *u0, *v0;
|
uint8_t *pad4, *pad5;
|
||||||
int uv0_stride;
|
uint32_t pad6[8]; // padding for later use
|
||||||
|
|
||||||
uint32_t pad4[7]; // padding for later use
|
|
||||||
|
|
||||||
// PRIVATE FIELDS
|
// PRIVATE FIELDS
|
||||||
////////////////////
|
////////////////////
|
||||||
void* memory_; // row chunk of memory for yuva planes
|
void* memory_; // row chunk of memory for yuva planes
|
||||||
void* memory_argb_; // and for argb too.
|
void* memory_argb_; // and for argb too.
|
||||||
void* pad5[2]; // padding for later use
|
void* pad7[2]; // padding for later use
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal, version-checked, entry point
|
// Internal, version-checked, entry point
|
||||||
|
Loading…
x
Reference in New Issue
Block a user