mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-12 20:00:09 +00:00
Merge branch 'matthiasc/for-main' into 'main'
colorstate: Consistent naming See merge request GNOME/gtk!7448
This commit is contained in:
commit
6d71dd0025
35
NEWS
35
NEWS
@ -1,6 +1,41 @@
|
||||
Overview of Changes in 4.15.4, xx-xx-xxxx
|
||||
=========================================
|
||||
|
||||
* GtkPopover:
|
||||
- Fix size allocation with wrapping labels
|
||||
|
||||
* CSS:
|
||||
- Fix fallout from recent changes
|
||||
- Make implementation of currentcolor inheritance match browsers
|
||||
|
||||
* Gdk:
|
||||
- Introduce GdkColorState for encoding color space information
|
||||
|
||||
* Gsk:
|
||||
- Improve caching of glyphs and textures
|
||||
- Remove the uber shader
|
||||
- Numerous bug fixes
|
||||
- Fix corner cases in offload handling
|
||||
- Implement occlusion culling for opaque content
|
||||
- Allow offloading (some) transformed textures
|
||||
- Take colorstate into account when compositing
|
||||
- Add GDK_DEBUG=linear to opt into linear compositing
|
||||
- Implement tiling for large textures
|
||||
|
||||
* Wayland:
|
||||
- Allow offloading GL textures via dmabuf export
|
||||
|
||||
* Deprecations:
|
||||
- GskGLShader and the render node
|
||||
|
||||
* Tools:
|
||||
- Improve the rendernode tool extract command
|
||||
|
||||
* Translation updates
|
||||
Georgian
|
||||
Hindi
|
||||
|
||||
|
||||
Overview of Changes in 4.15.3, 29-06-2024
|
||||
=========================================
|
||||
|
||||
|
@ -131,6 +131,7 @@ gboolean
|
||||
|
||||
/* }}} */
|
||||
/* {{{ Default implementation */
|
||||
/* {{{ Vfuncs */
|
||||
|
||||
static gboolean
|
||||
gdk_default_color_state_equal (GdkColorState *self,
|
||||
@ -155,6 +156,35 @@ gdk_default_color_state_get_no_srgb_tf (GdkColorState *color_state)
|
||||
return self->no_srgb;
|
||||
}
|
||||
|
||||
static GdkFloatColorConvert
|
||||
gdk_default_color_state_get_convert_to (GdkColorState *color_state,
|
||||
GdkColorState *target)
|
||||
{
|
||||
GdkDefaultColorState *self = (GdkDefaultColorState *) color_state;
|
||||
|
||||
if (!GDK_IS_DEFAULT_COLOR_STATE (target))
|
||||
return NULL;
|
||||
|
||||
return self->convert_to[GDK_DEFAULT_COLOR_STATE_ID (target)];
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* {{{ Conversion functions */
|
||||
|
||||
#define COORDINATE_TRANSFORM(name, tf) \
|
||||
static void \
|
||||
name(GdkColorState *self, \
|
||||
float (*values)[4], \
|
||||
gsize n_values) \
|
||||
{ \
|
||||
for (gsize i = 0; i < n_values; i++) \
|
||||
{ \
|
||||
values[i][0] = tf (values[i][0]); \
|
||||
values[i][1] = tf (values[i][1]); \
|
||||
values[i][2] = tf (values[i][2]); \
|
||||
} \
|
||||
}
|
||||
|
||||
static inline float
|
||||
srgb_oetf (float v)
|
||||
{
|
||||
@ -173,47 +203,10 @@ srgb_eotf (float v)
|
||||
return v / 12.92f;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_default_srgb_to_linear_srgb (GdkColorState *self,
|
||||
float (*values)[4],
|
||||
gsize n_values)
|
||||
{
|
||||
gsize i;
|
||||
COORDINATE_TRANSFORM(gdk_default_srgb_to_srgb_linear, srgb_eotf)
|
||||
COORDINATE_TRANSFORM(gdk_default_srgb_linear_to_srgb, srgb_oetf)
|
||||
|
||||
for (i = 0; i < n_values; i++)
|
||||
{
|
||||
values[i][0] = srgb_eotf (values[i][0]);
|
||||
values[i][1] = srgb_eotf (values[i][1]);
|
||||
values[i][2] = srgb_eotf (values[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_default_srgb_linear_to_srgb (GdkColorState *self,
|
||||
float (*values)[4],
|
||||
gsize n_values)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
for (i = 0; i < n_values; i++)
|
||||
{
|
||||
values[i][0] = srgb_oetf (values[i][0]);
|
||||
values[i][1] = srgb_oetf (values[i][1]);
|
||||
values[i][2] = srgb_oetf (values[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
static GdkFloatColorConvert
|
||||
gdk_default_color_state_get_convert_to (GdkColorState *color_state,
|
||||
GdkColorState *target)
|
||||
{
|
||||
GdkDefaultColorState *self = (GdkDefaultColorState *) color_state;
|
||||
|
||||
if (!GDK_IS_DEFAULT_COLOR_STATE (target))
|
||||
return NULL;
|
||||
|
||||
return self->convert_to[GDK_DEFAULT_COLOR_STATE_ID (target)];
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static const
|
||||
GdkColorStateClass GDK_DEFAULT_COLOR_STATE_CLASS = {
|
||||
@ -235,7 +228,7 @@ GdkDefaultColorState gdk_default_color_states[] = {
|
||||
.name = "srgb",
|
||||
.no_srgb = GDK_COLOR_STATE_SRGB_LINEAR,
|
||||
.convert_to = {
|
||||
[GDK_COLOR_STATE_ID_SRGB_LINEAR] = gdk_default_srgb_to_linear_srgb,
|
||||
[GDK_COLOR_STATE_ID_SRGB_LINEAR] = gdk_default_srgb_to_srgb_linear,
|
||||
},
|
||||
},
|
||||
[GDK_COLOR_STATE_ID_SRGB_LINEAR] = {
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkcolorstateprivate.h>
|
||||
#include <gdk/gdkmemoryformatprivate.h>
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
test_srgb (void)
|
||||
@ -14,12 +17,100 @@ test_srgb (void)
|
||||
g_assert_false (gdk_color_state_equal (srgb, srgb_linear));
|
||||
}
|
||||
|
||||
static float
|
||||
image_distance (const guchar *data,
|
||||
const guchar *data2,
|
||||
gsize width,
|
||||
gsize height,
|
||||
gsize stride)
|
||||
{
|
||||
float dist = 0;
|
||||
|
||||
for (gsize i = 0; i < height; i++)
|
||||
{
|
||||
const float *p = (const float *) (data + i * stride);
|
||||
const float *p2 = (const float *) (data2 + i * stride);
|
||||
|
||||
for (gsize j = 0; j < width; j++)
|
||||
{
|
||||
float dr, dg, db, da;
|
||||
|
||||
dr = p[4 * j + 0] - p2[4 * j + 0];
|
||||
dg = p[4 * j + 1] - p2[4 * j + 1];
|
||||
db = p[4 * j + 2] - p2[4 * j + 2];
|
||||
da = p[4 * j + 3] - p2[4 * j + 3];
|
||||
|
||||
dist = MAX (dist, dr * dr + dg * dg + db * db + da * da);
|
||||
}
|
||||
}
|
||||
|
||||
return sqrt (dist);
|
||||
}
|
||||
|
||||
static void
|
||||
test_convert (gconstpointer testdata)
|
||||
{
|
||||
GdkColorState *cs;
|
||||
char *path;
|
||||
GdkTexture *texture;
|
||||
GdkTextureDownloader *downloader;
|
||||
GError *error = NULL;
|
||||
GBytes *bytes;
|
||||
const guchar *data;
|
||||
guchar *data2;
|
||||
gsize width, height;
|
||||
gsize size;
|
||||
gsize stride;
|
||||
|
||||
cs = gdk_color_state_get_by_id ((GdkColorStateId) GPOINTER_TO_UINT (testdata));
|
||||
|
||||
path = g_test_build_filename (G_TEST_DIST, "image-data", "image.png", NULL);
|
||||
|
||||
texture = gdk_texture_new_from_filename (path, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
width = gdk_texture_get_width (texture);
|
||||
height = gdk_texture_get_height (texture);
|
||||
|
||||
downloader = gdk_texture_downloader_new (texture);
|
||||
gdk_texture_downloader_set_format (downloader, GDK_MEMORY_R32G32B32A32_FLOAT);
|
||||
|
||||
bytes = gdk_texture_downloader_download_bytes (downloader, &stride);
|
||||
data = g_bytes_get_data (bytes, &size);
|
||||
data2 = g_memdup2 (data, size);
|
||||
|
||||
gdk_memory_convert_color_state (data2,
|
||||
stride,
|
||||
GDK_MEMORY_R32G32B32A32_FLOAT,
|
||||
gdk_texture_get_color_state (texture),
|
||||
cs,
|
||||
width,
|
||||
height);
|
||||
|
||||
gdk_memory_convert_color_state (data2,
|
||||
stride,
|
||||
GDK_MEMORY_R32G32B32A32_FLOAT,
|
||||
cs,
|
||||
gdk_texture_get_color_state (texture),
|
||||
width,
|
||||
height);
|
||||
|
||||
g_assert_true (image_distance (data, data2, width, height, stride) < 0.001);
|
||||
|
||||
g_free (data2);
|
||||
g_bytes_unref (bytes);
|
||||
gdk_texture_downloader_free (downloader);
|
||||
g_object_unref (texture);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
(g_test_init) (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/colorstate/srgb", test_srgb);
|
||||
g_test_add_data_func ("/colorstate/convert/srgb<->srgb-linear", GUINT_TO_POINTER (GDK_COLOR_STATE_ID_SRGB_LINEAR), test_convert);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user