Commit Graph

56 Commits

Author SHA1 Message Date
Benjamin Otte
5e4f692e63 tiff: Store RGBx images as 4 channels
Set the alpha channel to "undefined" in this case.

Gimp doesn't seem to like this when opening the image and insists to
doing something with it, that's a bit of a bummer.

But it allows GTK to load RGBx textures.
2024-09-09 01:25:03 +02:00
Matthias Clasen
d2028c7323 Cosmetics 2024-07-28 11:33:39 -04:00
Matthias Clasen
a5aac30843 jpeg: Load grayscale as-is
We can handle grayscale textures just fine nowadays, so no need to
convert them to RGB.
2024-07-27 19:20:14 -04:00
Matthias Clasen
3149493679 jpeg: Set downloader color state explictly
This avoids surprises.
2024-07-27 19:02:59 -04:00
Matthias Clasen
f4b35093bd jpeg: Port to GdkMemoryTextureBuilder
This is in preparation for some color state handling.
2024-07-26 16:43:54 -04:00
Matthias Clasen
64f4967867 png: Make loader use cicp api
This should make non-default color states work with our png
loading and saving machinery.
2024-07-24 08:16:08 -06:00
Benjamin Otte
31e0ec71f2 png: Add color state support
When loading or saving png files, encode the CICP flags of the color
state into the PNG.

When loading, decode the CICP flags if available and detect the
colorstate they use.
If we do not support the cicp tags, we do not load the image.

So far, we ignore the ICC profiles.

Includes regeneration of nodeparse test *reference* output to include
the new tags we write to PNGs.
The original tests do not include those tags, so we implicitly test that
we read untagged files correctly.
2024-07-16 22:04:10 +02:00
Benjamin Otte
6c33afc13c png: Move texture data download further down
We only download the data when we actually need it for writing into the
PNG stream.

This allows modifying the download parameters (in particular color state
in the next commit) while writing out their settings, so the code for
selecting the right colorstate liives in only one place.

We have to be careful though, because the download now happens after the
setjmp(), so we need to make sure the error path handles both cases
without leaking: Where the download has happened and where it hasn't.
2024-07-16 22:03:48 +02:00
Benjamin Otte
03daf42fb5 png: Port to MemoryTextureBuilder 2024-07-16 22:03:46 +02:00
Matthias Clasen
08d1353cde loaders: Make it possible to load png options
We want to store some metadata in our symbolic pngs, so make it
possible to get options when loading a png, along with the texture.

Update all callers.
2024-04-28 23:42:02 -04:00
Matthias Clasen
f779832861 Tweak profiling strings
Capitalize our mark names, and use GTK as category.

The justification is: it looks better in sysprof.
2024-01-21 14:02:08 -05:00
Benjamin Otte
64e5c76323 png: Don't set a size limit when saving
gdk_texture_save_to_png_bytes() cannot fail, so ensure that it doesn't.

Testsuite has been updated to check for this case.

Note that we do not load the PNG file that we generate here.
Loading is a lot more scary than saving after all.
If people want to load oversized PNG files, they should use a real PNG
loader.
2024-01-07 07:22:53 +01:00
Benjamin Otte
3e4d0b69d4 gdkpng: Make the png loader safer against overflows
Load images that result in a texture >4GB in size.

And now let me keep playing with my 60k x 60k image, thanks.
I'm trying to OOM my GPU.
2024-01-03 04:11:35 +01:00
Matthias Clasen
a90a6c4517 Address various static analysis complaints
These were picked out of the scan_build logs in ci.
2023-11-22 00:07:47 -05:00
Matthias Clasen
10250a0a6a Add XRGB memory formats
These are not uncommon in dmabufs,
and supporting them is easy.

Fixes: #6172
2023-10-20 17:58:06 -04:00
Matthias Clasen
bd974b08b3 Add GDK_MEMORY_A8B8G8R8_PREMULTIPLIED
We did have 4 ordering variations of ARGB straight,
but only 3 premultiplied. Add the missing one.

Update all the places where we switch over memory formats.
2023-10-20 16:42:40 -04:00
Benjamin Otte
27fbdcbecb gdk: Add A16_FLOAT and A32_FLOAT formats
We need them for mask-only textures.

For tiffs, we convert the formats to RGBA (the idea that tiff can save
everything needs to be buried I guess) as tiffs can't do alpha-only.
2023-07-22 01:33:44 +02:00
Sophie Herold
894a4bda85 gdk: Support gray/alpha in PNG loader 2023-05-30 14:41:01 -04:00
Sophie Herold
2b88505ca4 gdk: Support gray/alpha in TIFF loader
Use PHOTOMETRIC_MINISBLACK for grayscale image
2023-05-30 14:41:01 -04:00
Matthias Clasen
a1c5a806b3 Convert headers to #pragma once
The conversion was done by guard2one.
2023-03-31 15:11:10 -04:00
Benjamin Otte
c9f54ca371 texture: Export gdk_texture_get_format()
The API docs outline why quite well.

This should make it possible to do saving of textures to image files
without any private API with the same featureset that GTK uses.

Also remove the gsktextureprivate.h include where
gdk_texture_get_format() was the only reason for it.
2023-02-15 00:39:18 +01:00
Benjamin Otte
b30af72125 tiff: Use GdkTexureDownloader when saving 2023-02-15 00:39:18 +01:00
Benjamin Otte
eb45b8083a png: Use GdkTexureDownloader when saving 2023-02-15 00:39:18 +01:00
Benjamin Otte
f05d801e28 jpeg: Use GdkTexureDownloader when saving 2023-02-15 00:39:18 +01:00
Matthias Clasen
8c1a041104 gdk: Fix possible memory errors
clang complained that we may end up jumping
to the cleanup code without initializing data
in the jpeg code. Always initialize data to
NULL to prevent that eventuality.
2022-11-18 00:04:23 -05:00
Matthias Clasen
16b95939f9 gdk: Bump the jpeg malloc limit
Bump the limit for memory use during jpeg loading
to 1GB, matching what gdk-pixbuf has for this.
2022-10-31 20:35:15 -04:00
Matthias Clasen
4aabc45685 Drop gdkintl.h
This header was merely including gi18n-lib.h.
Just do that directly.
2022-09-23 23:33:42 -04:00
Matthias Clasen
d1755337a2 Bump the jpeg memory limit
Commit 59f6c50df8 set the memory limit to 100M,
which turns out to exclude some large, valid jpegs.
So, bump things to 300M, matching what was done
in gdk-pixbuf.
2022-08-22 10:48:00 -04:00
Matthias Clasen
59f6c50df8 jpeg loader: Limit memory consumption
This will prevent stupid oom situations with pathological
jpeg files, without affecting our ability to load reasonable
images.
2022-08-10 13:25:17 -04:00
Matthias Clasen
14cb208ec2 png loader: gray can have alpha 2022-07-16 09:43:46 -04:00
Mosè Giordano
4c211f1872 gdkjpeg: include stdlib.h necessary for free
`free` is defined in `stdlib.h`, see for example
<https://pubs.opengroup.org/onlinepubs/009604499/functions/free.html>.  Without
this include compilation can fail with the following error:

```
../gdk/loaders/gdkjpeg.c: In function ‘gdk_save_jpeg’:
../gdk/loaders/gdkjpeg.c:264:7: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
       free (data);
       ^
../gdk/loaders/gdkjpeg.c:264:7: warning: incompatible implicit declaration of built-in function ‘free’
../gdk/loaders/gdkjpeg.c:264:7: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
../gdk/loaders/gdkjpeg.c:302:67: error: ‘free’ undeclared (first use in this function)
   return g_bytes_new_with_free_func (data, size, (GDestroyNotify) free, NULL);
                                                                   ^
../gdk/loaders/gdkjpeg.c:302:67: note: each undeclared identifier is reported only once for each function it appears in
../gdk/loaders/gdkjpeg.c:303:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
```
2022-02-06 15:41:33 +00:00
Simon McVittie
979c124e57 png: Correct endianness for big-endian machines
libpng wants to receive samples in either RGB or RGBA order, whether
each sample is big-endian or not. This resolves test failures in
testsuite/gdk/memorytexture.c (and a lot of reftests) on s390x, and
probably the PowerPC family too.

Modifying the test to show the color in use and write out the PNG bytes
to a file, and running the memorytexture test on s390x, produces a PNG
that loads with the correct color values in GIMP (on an x86_64 machine),
which seems like evidence that this is the correct change and not just
compensating errors.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/4616
Signed-off-by: Simon McVittie <smcv@debian.org>
2022-01-08 17:09:29 +00:00
Matthias Clasen
4d865cd7ba tiff loader: Catch more errors
tiff_open_read may fail, and we should not crash
in that case but return an error.
2021-12-13 17:54:11 -05:00
Yuri Chornoivan
e80d938ee5 Fix minor typo: Unsupportd -> Unsupported 2021-11-05 18:42:20 +00:00
Benjamin Otte
ae117d0cfa png: allocate data before sigsetjmp()
Makes the static analyzer not trip up when trying to analyze memory
leaks.
2021-10-23 00:03:51 +02:00
Benjamin Otte
b2f9a907ce tiff: Fix variable assignment 2021-10-22 23:50:45 +02:00
Benjamin Otte
7eceed8d4d jpeg: Use gdk_memory_texture_from_texture() 2021-10-18 12:08:57 +02:00
Benjamin Otte
800246402f tiff: Refactor
Now we support all the formats.
2021-10-18 12:08:57 +02:00
Benjamin Otte
c2368cc605 png: Refactor png saving
Do all the memory format shenanigans in GTK now and support all the PNG
formats.
2021-10-13 14:33:44 +02:00
Benjamin Otte
1e7fb52b21 Add memory formats used by libpng
Add unpremultiplied high-depth formats. They are used in the real world,
so let's support them.
2021-10-13 14:33:44 +02:00
Benjamin Otte
7b41738979 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-12 02:06:44 +02:00
Benjamin Otte
b65b64628d texture: Refactor downloading
Pass a format do GdkTextureClass::download(). That way we can download
data in any format.

Also replace gdk_texture_download_texture() with
gdk_memory_texture_from_texture() which again takes a format.

The old functionality is still there for code that wants it: Just pass
gdk_texture_get_format (texture) as the format argument.
2021-10-12 02:06:43 +02:00
Matthias Clasen
144f727d5a Rename ngl to gl
We have only one gl renderer now, and it is
a bit odd for it not be called gl.
2021-10-07 13:05:53 -04:00
Benjamin Otte
8950c0dc96 texture: Make format a property of GdkTexture
For MemoryTexture, this is a simple change.

For GLTexture, we need to query the format at texture creation. This
sounds like a bad idea and extra work until one realizes that we'd
need to do that anyway when using the texure the first time - either
when downloading, or when trying to use it in a rendernode, where we
will soon need that information to determine if the texture prefers high
depth.
2021-10-07 02:41:30 +02:00
Benjamin Otte
48781cf7f7 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 22:50:07 +02:00
Timm Bäder
1efccfcced gdk loaders: Add noreturn attribtues where appropriate 2021-10-02 09:08:14 +02:00
Matthias Clasen
56e6a51ac0 Merge branch 'delayed-loading' into 'master'
gtk-demo: Cosmetics

See merge request GNOME/gtk!3975
2021-09-18 23:02:00 +00:00
Matthias Clasen
c9135546b6 loaders: Add profiler marks
These are potentially expensive calls, we
should make sure they show up in profiles.
2021-09-18 17:35:00 -04:00
Timm Bäder
c24b7877a0 gdktiff: Use guint32 instead of int32
The latter seems to be deprecated.
2021-09-18 09:00:16 +02:00
Benjamin Otte
b271a94f92 texture: Rework error enum
1. Change INSUFFICIENT_MEMORY to TOO_LARGE
   GTK crashes on insufficient memory, we don't emit GErrors.

2. Split UNSUPPORTED into UNSUPPORTED_CONTENT and UNSUPPORTED_FORMAT
   So we know if you need to find an RPM with a loader or curse and
   the weird file.

3. Translate error messages, they are meant for end users.
2021-09-17 03:25:35 +02:00