Commit Graph

71303 Commits

Author SHA1 Message Date
Matthias Clasen
f80ef35dc0 ngl: Use stem darkening for glyphs
This involves tweaking a freetype driver property
directly, since cairo font options don't cover this.

So the code is a bit ugly, but it does make text
appear darker.
2021-10-06 00:06:10 -04:00
Matthias Clasen
fe5e81757d Linearize gl textures
GL textures are typically in non-linear sRGB,
and in that case, we need to linearize them.
2021-10-06 00:06:10 -04:00
Matthias Clasen
a532b3dca5 ngl: Linearize colors too
Convert all the GdkRGBA colors that we have
in render nodes to linear sRGB before using
them. This brings the rendering back in line
with what cairo produces, except for the video.
2021-10-06 00:06:10 -04:00
Matthias Clasen
a6f8367c0a ngl: Apply gamma to frames
Use a shader to go from linear sRGB to sRGB when
we are done with a frame.
2021-10-06 00:06:10 -04:00
Matthias Clasen
da21a87de8 ngl: Upload textures in linear sRGB
We want to do compositing in a linear colorspace,
so convert textures to linear sRGB before uploading.

Currently, this causes images to come out dark, since
we don't have a way to tell the compositor that our
framebuffer is linear, so it assumes a gamma that we
don't provide.
2021-10-06 00:06:10 -04:00
Matthias Clasen
97c11ffc23 ci: Update dependencies for msys
Add libpng, libjpeg-turbo, libtiff and lcms2.
2021-10-06 00:06:10 -04:00
Matthias Clasen
26dd0536f0 texture: Cosmetics
introspection complained
2021-10-06 00:04:53 -04:00
Matthias Clasen
33c739b0f9 memorytexture: Cosmetics
gi-docgen complained
2021-10-06 00:04:53 -04:00
Matthias Clasen
e4ba83ad4f colorprofile: Cosmetics
gi-docgen complained.
2021-10-05 23:00:53 -04:00
Benjamin Otte
17521e26f8 gdk: Add GDK_DEBUG=srgb
Disables gdk_surface_set_color_profile() for backends and forces
sRGB.

This does not change any GSK renderers, it just turns off any backends
trying to hand us color profiles.
2021-10-06 04:10:06 +02:00
Benjamin Otte
5a389874da FIXME: Add crude color management impl for cairo 2021-10-06 04:09:35 +02:00
Benjamin Otte
ce344b9267 x11: Implement support for color profiles
Stole the implementation from eog.

This doesn't yet update the profile when it changes though.
2021-10-06 04:09:35 +02:00
Benjamin Otte
66e6d6728f gdk: Introduce GdkColor
GdkColor represents a color in the real world, by combining a color
profile, an alpha valueand N component values.

gsk_render_node_draw() has been ported to use GdkColor when rendering,
which makes it so the rendering happens in a color-managed way when a
ColorProfile has been attached to the target.
2021-10-06 04:09:35 +02:00
Matthias Clasen
4670c90312 Add an lcms2 subproject
Since lcms2 is using autotools, this uses the
experimental 'external project' module of meson,
and adds a minimal meson.build file to lcms2.

It seems to work.
2021-10-06 04:09:35 +02:00
Matthias Clasen
b02cc7878a Support color profiles in pixbufs
When creating a GdkTexture from a GdkPixbuf,
see if it has an icc profile attached, and if
so, use it.
2021-10-06 04:09:35 +02:00
Matthias Clasen
5ada992ac9 Check profiles match memory formats
When creating a GdkMemoryTexture, the caller provides
a memory format and a color profile, both of which
encode expectations about the color components of
the pixel data. Check that they match.
2021-10-06 04:09:35 +02:00
Matthias Clasen
ba6c03e902 jpeg: Save color profile information
When writing a jpeg image, include the icc profile.
2021-10-06 04:09:35 +02:00
Matthias Clasen
9ae493c86e memorytexture: Cosmetics 2021-10-06 04:09:35 +02:00
Matthias Clasen
023ecbf028 tiff: Add color profile support
Apply an embedded icc profile when loading tiff
images, and save associated icc profile information
when saving tiff images.
2021-10-06 04:09:34 +02:00
Benjamin Otte
809c4d9ec1 widget-factory: Add tests for loading color profiles
I figured out how to generate them, yay:

  cmsHPROFILE lcms_profile;
  cmsToneCurve *curve[3];

  curve[0] = cmsBuildParametricToneCurve (NULL, 4, (double[5]) { 1.0, 0, 0, 0, 0 });
  curve[1] = cmsBuildParametricToneCurve (NULL, 4, (double[5]) { 2.4, 255.0 / 15 / 1.055, 0.055 / 1.055, 0, 15./255 });
  curve[2] = cmsBuildGamma (NULL, 2.4);
  lcms_profile = cmsCreateRGBProfile (&(cmsCIExyY) {
                                        0.3127, 0.3290, 1.0
                                      },
                                      &(cmsCIExyYTRIPLE) {
                                        { 0.6400, 0.3300, 1.0 },
                                        { 0.3000, 0.6000, 1.0 },
                                        { 0.1500, 0.0600, 1.0 }
                                      },
                                      curve);

  cmsSaveProfileToFile (lcms_profile, "foo.icc");

  cmsFreeToneCurveTriple (curve);
  cmsCloseProfile (lcms_profile);
2021-10-06 04:09:34 +02:00
Benjamin Otte
a6fd0d0487 png: Refactor png saving
Do all the memory format shenanigans in GTK now and support all the PNG
formats.
2021-10-06 04:09:34 +02:00
Benjamin Otte
afb755a148 png: Handle color profiles 2021-10-06 04:09:34 +02:00
Benjamin Otte
3f2d0dbb27 colorprofile: Implement a global transform cache
Speeds up things by a factor of 10x, so seems like a good idea.

The cache is never purges, we might want to fix that.
2021-10-06 04:09:34 +02:00
Benjamin Otte
b819b928ea memoryformat: Optimize more
Make the formats allow converting to an lcms-compatible format and
then use a cmsTransform to convert between them.

Note that mixing RGBA and non-RGBA formats doesn't seem to work, so we
force all our RGB-only formats to convert to a RGBA format.
2021-10-06 04:09:34 +02:00
Benjamin Otte
72b78d2da1 png: Add private formats for weird PNG stuff 2021-10-06 04:09:34 +02:00
Benjamin Otte
03ea3fd10b png: Do loader conversions in GDK
Not inside libpng.

We really want to do them in GL, but we don't have a premultiply step
yet.
2021-10-06 04:09:34 +02:00
Benjamin Otte
1b9243fed5 memoryformat: Do some gdk_memory_convert() massaging
* Add name support to the formats
* Add profiler mark to gdk_memory_convert()
* Split up the different branches of conversion
* Use memcpy for straight copies
2021-10-06 04:09:34 +02:00
Benjamin Otte
422340a1e3 ngl: Avoid cairo in icon upload
Use the new memory texture magic
2021-10-06 04:09:34 +02:00
Benjamin Otte
60ebac2c71 gdk: Add srgb_linear color profile
... and gdk_color_profile_is_linear()
2021-10-06 04:09:34 +02:00
Benjamin Otte
3424f25a1f gdk: Make gdk_texture_download_surface() take a target colorprofile
This way, the resulting surface can contain the pixels in the desired
color profile.
2021-10-06 04:09:34 +02:00
Benjamin Otte
3fef469797 broadway: Use gdk_texture_save_to_png_bytes()
Instead of using Cairo, save the texture directly.
2021-10-06 04:09:34 +02:00
Benjamin Otte
1dd812a858 gdk: Rework gdk_pixbuf_get_from_texture() 2021-10-06 04:09:34 +02:00
Benjamin Otte
38730808a5 cairo: Add color profile get/set
Add a centralized place to attach color profiles to.

Nothing uses that information yet, but all the backends do set it.
2021-10-06 04:09:34 +02:00
Benjamin Otte
0dedbb5b17 gl: Move gdk_gl_context_upload_texture() into NGL
It's the only user and the API is kinda clunky, so it's easier to
refactor it there.

Also make use of gdk_memory_texture_convert().
2021-10-06 04:09:33 +02:00
Benjamin Otte
a433828f1a memorytexture: Add gdk_memory_texture_convert()
Converts a memory texture to a new one with a specific format and color
profile. You can even pass a rectangle to restrict the result to a given
region.

The code is well optimized, so it avoids copies if things match and will
in fact return the texture itself if the same colorspace and format and
no/the full rectangle are passed, so it can be used without fear of
performance implications.

In fact, the following code should be used - without any additional
checks - to turn any texture into a desired color profile and format
(say for saving with gdk-pixbuf):

memtex = gdk_texture_download (texture);
memtex = gdk_memory_texture_convert (memory_texture,
                                     GDK_MEMORY_R8G8B8A8,
                                     gdk_color_profile_get_srgb(),
                                     NULL);
pixbuf = gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
                                   GDK_COLOR_SPACE_RGB,
                                   TRUE,
                                   8
                                   gdk_texture_get_width (memtex),
                                   gdk_texture_get_height (memtex),
                                   gdk_memory_texture_get_stride (memtex),
                                   g_object_unref_wrapper,
                                   memtex);
2021-10-06 04:08:08 +02:00
Benjamin Otte
9624b67fdd gl: Move memory <=> GL format mapping
Put it into gdkmemoryformat.c, where all the mapping goes.
2021-10-06 04:08:08 +02:00
Benjamin Otte
0df63b0286 API: Add GdkSurface::color-profile
Unused so far, but there's a private setter for backends and a public
readable property for code.
2021-10-06 04:08:07 +02:00
Matthias Clasen
34f2fc9203 Revamp the color profile demo
Add an explicit 'no profile' image.
2021-10-06 04:08:07 +02:00
Matthias Clasen
f90c0a30df gtk-demo: Add a color profile demo
This is using test images from http://displaycal.net/.
2021-10-06 04:08:07 +02:00
Benjamin Otte
3b6ce78400 widget-factory: Add gradient rendering test
Test how GTK draws gradients, by adding an sRGB and a linear colorspace
gradient and draw one with CSS.

Have a look which one (if any) matches.
2021-10-06 04:08:07 +02:00
Benjamin Otte
e7ba7d5540 jpeg: Parse ICC profiles
.. and pass them on.
2021-10-06 04:08:07 +02:00
Benjamin Otte
0ac0a5914c API: Add gdk_memory_texture_new_with_color_profile()
A version of gdk_memory_texture_new() that allows passing a color
profile. The old version t assumes sRGB.
2021-10-06 04:08:07 +02:00
Benjamin Otte
d976bf910c gl: Refactor texture upload code
Do the texture unpacking at the target, not at the source.

Also handle color profiles.
2021-10-06 04:08:07 +02:00
Benjamin Otte
db2aab289c memoryformat: Take a color profile when converting 2021-10-06 04:08:07 +02:00
Benjamin Otte
85e4e47d30 memorytexture: Split out GdkMemoryFormat handling
Also, now make gdk_memory_convert() the only conversion functions
and allow conversions between any 2 formats by going via a float[4].

This could be optimized via fast-paths, but so far it isn't.
2021-10-06 04:08:07 +02:00
Benjamin Otte
32740934b4 texture: Add a ::color-profile property
Returns the associated color profile. For now, this is always sRGB.
2021-10-06 04:08:07 +02:00
Benjamin Otte
8acf1b78cf gdk: Add GdkColorProfile
The code doesn't do anything yet, this is just the boilerplate.
2021-10-06 04:08:07 +02:00
Benjamin Otte
957a6505ca cms: Add lcms to the build 2021-10-06 04:08:07 +02:00
Benjamin Otte
cdc85232b2 egl: Implement HDR support
If EGL supports:
* no-config contexts
* >8bits pixel formats
* (optionally) floating point pixel formats

Then select such a profile as the HDR format and use it when HDR is
requested.
2021-10-06 03:44:59 +02:00
Benjamin Otte
5eb42dd9f3 gdk: Add GDK_DEBUG=hdr
Forces request_hdr = TRUE for all requests.

Backends should also use this when choosing whether to honor HDR
requests for low quality compositors - as long as the compositor
pretends to support HDR, shovel HDR at it.
2021-10-06 03:44:59 +02:00