tests: refactoring alpha-blending
No functional change. Moved color processing functions into shared files which can be used between different tests. Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
This commit is contained in:
+16
-70
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020 Collabora, Ltd.
|
* Copyright 2020 Collabora, Ltd.
|
||||||
|
* Copyright 2021 Advanced Micro Devices, Inc.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
|
|
||||||
#include "weston-test-client-helper.h"
|
#include "weston-test-client-helper.h"
|
||||||
#include "weston-test-fixture-compositor.h"
|
#include "weston-test-fixture-compositor.h"
|
||||||
|
#include "color_util.h"
|
||||||
|
|
||||||
struct setup_args {
|
struct setup_args {
|
||||||
struct fixture_metadata meta;
|
struct fixture_metadata meta;
|
||||||
@@ -104,6 +106,20 @@ premult_color(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
unpremult_float(struct color_float *cf)
|
||||||
|
{
|
||||||
|
if (cf->a == 0.0f) {
|
||||||
|
cf->r = 0.0f;
|
||||||
|
cf->g = 0.0f;
|
||||||
|
cf->b = 0.0f;
|
||||||
|
} else {
|
||||||
|
cf->r /= cf->a;
|
||||||
|
cf->g /= cf->a;
|
||||||
|
cf->b /= cf->a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fill_alpha_pattern(struct buffer *buf)
|
fill_alpha_pattern(struct buffer *buf)
|
||||||
{
|
{
|
||||||
@@ -137,76 +153,6 @@ fill_alpha_pattern(struct buffer *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct color_float {
|
|
||||||
float r, g, b, a;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct color_float
|
|
||||||
a8r8g8b8_to_float(uint32_t v)
|
|
||||||
{
|
|
||||||
struct color_float cf;
|
|
||||||
|
|
||||||
cf.a = ((v >> 24) & 0xff) / 255.f;
|
|
||||||
cf.r = ((v >> 16) & 0xff) / 255.f;
|
|
||||||
cf.g = ((v >> 8) & 0xff) / 255.f;
|
|
||||||
cf.b = ((v >> 0) & 0xff) / 255.f;
|
|
||||||
|
|
||||||
return cf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
unpremult_float(struct color_float *cf)
|
|
||||||
{
|
|
||||||
if (cf->a == 0.0f) {
|
|
||||||
cf->r = 0.0f;
|
|
||||||
cf->g = 0.0f;
|
|
||||||
cf->b = 0.0f;
|
|
||||||
} else {
|
|
||||||
cf->r /= cf->a;
|
|
||||||
cf->g /= cf->a;
|
|
||||||
cf->b /= cf->a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static float
|
|
||||||
sRGB_EOTF(float e)
|
|
||||||
{
|
|
||||||
assert(e >= 0.0f);
|
|
||||||
assert(e <= 1.0f);
|
|
||||||
|
|
||||||
if (e <= 0.04045)
|
|
||||||
return e / 12.92;
|
|
||||||
else
|
|
||||||
return pow((e + 0.055) / 1.055, 2.4);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sRGB_linearize(struct color_float *cf)
|
|
||||||
{
|
|
||||||
cf->r = sRGB_EOTF(cf->r);
|
|
||||||
cf->g = sRGB_EOTF(cf->g);
|
|
||||||
cf->b = sRGB_EOTF(cf->b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float
|
|
||||||
sRGB_EOTF_inv(float o)
|
|
||||||
{
|
|
||||||
assert(o >= 0.0f);
|
|
||||||
assert(o <= 1.0f);
|
|
||||||
|
|
||||||
if (o <= 0.04045 / 12.92)
|
|
||||||
return o * 12.92;
|
|
||||||
else
|
|
||||||
return pow(o, 1.0 / 2.4) * 1.055 - 0.055;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sRGB_delinearize(struct color_float *cf)
|
|
||||||
{
|
|
||||||
cf->r = sRGB_EOTF_inv(cf->r);
|
|
||||||
cf->g = sRGB_EOTF_inv(cf->g);
|
|
||||||
cf->b = sRGB_EOTF_inv(cf->b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
compare_float(float ref, float dst, int x, const char *chan, float *max_diff)
|
compare_float(float ref, float dst, int x, const char *chan, float *max_diff)
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Collabora, Ltd.
|
||||||
|
* Copyright 2021 Advanced Micro Devices, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the
|
||||||
|
* next paragraph) shall be included in all copies or substantial
|
||||||
|
* portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include "color_util.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
static float
|
||||||
|
sRGB_EOTF(float e)
|
||||||
|
{
|
||||||
|
assert(e >= 0.0f);
|
||||||
|
assert(e <= 1.0f);
|
||||||
|
|
||||||
|
if (e <= 0.04045)
|
||||||
|
return e / 12.92;
|
||||||
|
else
|
||||||
|
return pow((e + 0.055) / 1.055, 2.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float
|
||||||
|
sRGB_EOTF_inv(float o)
|
||||||
|
{
|
||||||
|
assert(o >= 0.0f);
|
||||||
|
assert(o <= 1.0f);
|
||||||
|
|
||||||
|
if (o <= 0.04045 / 12.92)
|
||||||
|
return o * 12.92;
|
||||||
|
else
|
||||||
|
return pow(o, 1.0 / 2.4) * 1.055 - 0.055;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
sRGB_linearize(struct color_float *cf)
|
||||||
|
{
|
||||||
|
cf->r = sRGB_EOTF(cf->r);
|
||||||
|
cf->g = sRGB_EOTF(cf->g);
|
||||||
|
cf->b = sRGB_EOTF(cf->b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sRGB_delinearize(struct color_float *cf)
|
||||||
|
{
|
||||||
|
cf->r = sRGB_EOTF_inv(cf->r);
|
||||||
|
cf->g = sRGB_EOTF_inv(cf->g);
|
||||||
|
cf->b = sRGB_EOTF_inv(cf->b);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct color_float
|
||||||
|
a8r8g8b8_to_float(uint32_t v)
|
||||||
|
{
|
||||||
|
struct color_float cf;
|
||||||
|
|
||||||
|
cf.a = ((v >> 24) & 0xff) / 255.f;
|
||||||
|
cf.r = ((v >> 16) & 0xff) / 255.f;
|
||||||
|
cf.g = ((v >> 8) & 0xff) / 255.f;
|
||||||
|
cf.b = ((v >> 0) & 0xff) / 255.f;
|
||||||
|
|
||||||
|
return cf;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Collabora, Ltd.
|
||||||
|
* Copyright 2021 Advanced Micro Devices, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the
|
||||||
|
* next paragraph) shall be included in all copies or substantial
|
||||||
|
* portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct color_float {
|
||||||
|
float r, g, b, a;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
sRGB_linearize(struct color_float *cf);
|
||||||
|
|
||||||
|
void
|
||||||
|
sRGB_delinearize(struct color_float *cf);
|
||||||
|
|
||||||
|
|
||||||
|
struct color_float
|
||||||
|
a8r8g8b8_to_float(uint32_t v);
|
||||||
@@ -33,6 +33,8 @@ lib_test_client = static_library(
|
|||||||
weston_test_protocol_c,
|
weston_test_protocol_c,
|
||||||
viewporter_client_protocol_h,
|
viewporter_client_protocol_h,
|
||||||
viewporter_protocol_c,
|
viewporter_protocol_c,
|
||||||
|
'color_util.h',
|
||||||
|
'color_util.c',
|
||||||
],
|
],
|
||||||
include_directories: common_inc,
|
include_directories: common_inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
|
|||||||
Reference in New Issue
Block a user