testyuv: added --monochrome and --luminance options for interactive mode

This commit is contained in:
Sam Lantinga 2024-03-01 02:42:18 -08:00
parent 991ad27de8
commit 47be24d225
2 changed files with 14 additions and 5 deletions

View File

@ -261,6 +261,8 @@ int main(int argc, char **argv)
Uint32 rgb_format = SDL_PIXELFORMAT_RGBX8888;
SDL_PropertiesID props;
SDL_Colorspace colorspace;
SDL_bool monochrome = SDL_FALSE;
int luminance = 100;
int current = 0;
int pitch;
Uint8 *raw_yuv;
@ -338,6 +340,12 @@ int main(int argc, char **argv)
} else if (SDL_strcmp(argv[i], "--bgra") == 0) {
rgb_format = SDL_PIXELFORMAT_BGRA8888;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--monochrome") == 0) {
monochrome = SDL_TRUE;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--luminance") == 0 && argv[i+1]) {
luminance = SDL_atoi(argv[i+1]);
consumed = 2;
} else if (SDL_strcmp(argv[i], "--automated") == 0) {
should_run_automated_tests = SDL_TRUE;
consumed = 1;
@ -351,6 +359,7 @@ int main(int argc, char **argv)
"[--jpeg|--bt601|--bt709|--auto]",
"[--yv12|--iyuv|--yuy2|--uyvy|--yvyu|--nv12|--nv21]",
"[--rgb555|--rgb565|--rgb24|--argb|--abgr|--rgba|--bgra]",
"[--monochrome] [--luminance N%]",
"[--automated]",
"[sample.bmp]",
NULL,
@ -403,7 +412,7 @@ int main(int argc, char **argv)
colorspace = GetColorspaceForYUVConversionMode(yuv_mode);
raw_yuv = SDL_calloc(1, MAX_YUV_SURFACE_SIZE(original->w, original->h, 0));
ConvertRGBtoYUV(yuv_format, original->pixels, original->pitch, raw_yuv, original->w, original->h, yuv_mode, 0, 100);
ConvertRGBtoYUV(yuv_format, original->pixels, original->pitch, raw_yuv, original->w, original->h, yuv_mode, monochrome, luminance);
pitch = CalculateYUVPitch(yuv_format, original->w);
converted = SDL_CreateSurface(original->w, original->h, rgb_format);

View File

@ -129,9 +129,9 @@ static void RGBtoYUV(const Uint8 *rgb, int *yuv, YUV_CONVERSION_MODE mode, int m
U = clip3(0, SDL_powf(2.0f, M) - 1, SDL_floorf(SDL_powf(2.0f, (M - 8)) * (112.0f * (B - L) / ((1.0f - Kb) * S) + 128) + 0.5f));
V = clip3(0, SDL_powf(2.0f, M) - 1, SDL_floorf(SDL_powf(2.0f, (M - 8)) * (112.0f * (R - L) / ((1.0f - Kr) * S) + 128) + 0.5f));
yuv[0] = (Uint8)Y;
yuv[1] = (Uint8)U;
yuv[2] = (Uint8)V;
yuv[0] = (int)Y;
yuv[1] = (int)U;
yuv[2] = (int)V;
if (monochrome) {
yuv[1] = 128;
@ -139,7 +139,7 @@ static void RGBtoYUV(const Uint8 *rgb, int *yuv, YUV_CONVERSION_MODE mode, int m
}
if (luminance != 100) {
yuv[0] = (Uint8)SDL_roundf(yuv[0] * (luminance / 100.0f));
yuv[0] = (int)SDL_roundf(yuv[0] * (luminance / 100.0f));
if (yuv[0] > 255) {
yuv[0] = 255;
}