mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-01-02 17:00:18 +01:00
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:
parent
4b23aa11ae
commit
15d7546b2d
4 changed files with 144 additions and 70 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* 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
|
||||
|
|
@ -29,6 +30,7 @@
|
|||
|
||||
#include "weston-test-client-helper.h"
|
||||
#include "weston-test-fixture-compositor.h"
|
||||
#include "color_util.h"
|
||||
|
||||
struct setup_args {
|
||||
struct fixture_metadata meta;
|
||||
|
|
@ -104,6 +106,20 @@ premult_color(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
|
|||
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
|
||||
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
|
||||
compare_float(float ref, float dst, int x, const char *chan, float *max_diff)
|
||||
|
|
|
|||
84
tests/color_util.c
Normal file
84
tests/color_util.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
42
tests/color_util.h
Normal file
42
tests/color_util.h
Normal file
|
|
@ -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,
|
||||
viewporter_client_protocol_h,
|
||||
viewporter_protocol_c,
|
||||
'color_util.h',
|
||||
'color_util.c',
|
||||
],
|
||||
include_directories: common_inc,
|
||||
dependencies: [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue