Commit Graph

1221 Commits

Author SHA1 Message Date
Kim Woelders 15ab46d03e savers: Fix error returns
The savers did not return meaningful error codes in many cases.
2024-01-04 05:05:04 +01:00
Kim Woelders 66f39b6556 TIFF loader: Properly suppress messages from libtiff 2024-01-03 20:05:26 +01:00
Kim Woelders c0d2bce375 JPG saver: Fix error path
jpeg_finish_compress() may trigger longjmp() resulting in infinite loop.
2024-01-02 20:10:51 +01:00
Kim Woelders 7614a8d9e7 PNG saver: Avoid potential issues around setjmp/longjmp
Allocate the row buffer before calling setjmp().

See also #21.
2024-01-02 19:23:07 +01:00
Kim Woelders 30107247b6 Change formatting style
No tabs, more like K&R.
Also switch to indent 2.2.13.
2024-01-02 09:47:51 +01:00
NRK cd8c225ed0 Y4M loader: don't fail on newline
regression introduce in c08ae5f. if the color space was the last thing
in the header than it would be followed by a newline rather than space.

peek to ensure next char is either ' ' or newline to avoid falsly
matching problematic colorspaces. this will also work for other cases
like "mono-whatever" instead of working just for "420", "422" and "444".

also change the return code to unsupported instead of corrupted in these
cases.
2024-01-02 06:25:52 +01:00
Kim Woelders 2d210b9af3 Y4M loader: Fix warning in non-debug build
Also simplify error text handling.
2024-01-01 22:01:55 +01:00
Kim Woelders 820c5b2ebe PNG loader: Properly suppress messages from libpng 2024-01-01 21:47:09 +01:00
NRK 3e8c01bef6 PNG saver: avoid double-free on write errors
png_write_end may trigger a write error which sets off longjmp - which
then goes ahead and tries to free `misc.data` again. move the
png_write_end call before `quit` label to avoid this.

to reproduce, build scrot and imlib2 with ASan and then try to save a
screenshot to /dev/full (`scrot -o /dev/full`).
2024-01-01 17:37:53 +01:00
Kim Woelders 9ad4769e0a ANI loader: Avoid debug line when image does not have proper signature 2024-01-01 16:57:48 +01:00
Kim Woelders 06314730ff Y4M loader: Avoid use of sscanf() in frame rate parsing
Input data is not necessarily nul-terminated.
Simplify frame rate parsing in the process.

Use of sscanf() should also be eliminated when compiling with debug -
some other day.

Based on patch by NRK.
2024-01-01 16:57:48 +01:00
Kim Woelders 6ff2ac0815 Consistently use #if IMLIB2_DEBUG (not #ifdef) 2023-12-28 16:10:19 +01:00
Kim Woelders 1bdc69a6a1 Y4M loader: Guard some debug code properly
str is effectively unused when compiling without debug.

Also, don't cast away const and drop some unnecessary casts
2023-12-28 16:08:53 +01:00
Chema Gonzalez 96e04dd8cf Y4M loader: add error messages on parsing errors
Tested:

Image with 420p10 color space.

Before:
```
$ IMLIB2_DEBUG=31:0 imlib2_view out.y4m
...
LOAD: __imlib_FindBestLoader: fmt='y4m': /usr/local/lib/imlib2/loaders/y4m.so
IMG : __imlib_LoadImageWrapper: fmt='y4m' file='out.y4m'(out.y4m) frame=1, imm=1
IMG : __imlib_LoadImageWrapper: y4m : out.y4m: Elapsed time: 0.010 ms
...
```

After:
```
$ IMLIB2_DEBUG=31:0 imlib2_view out.y4m
...
LOAD: __imlib_FindBestLoader: fmt='y4m': /usr/local/lib/imlib2/loaders/y4m.so
IMG : __imlib_LoadImageWrapper: fmt='y4m' file='out.y4m'(out.y4m) frame=1, imm=1
LDR-y4m: y4m__parse_params: unknown C: 'C420p10'
IMG : __imlib_LoadImageWrapper: y4m : out.y4m: Elapsed time: 0.010 ms
...
```
2023-12-28 13:02:38 +01:00
Chema Gonzalez c08ae5fdfb Y4M loader: fix C option analysis
ffmpeg has added multiple color space types that start with "420",
"422", and "444" (e.g. "420p16").

We cannot parse them as 8-bit color. Let's fail earier.
2023-12-27 15:09:17 -08:00
Chema Gonzalez a780b47892 Y4M loader: fix support for unexpected framerates
Add support for F1:1 images, and in general with any framerate ratio.

Also added "F60:1" mode support.

Tested:

Added a test frame with a 1:1 framerate. This is produced by ffmpeg when
converting from another image format.
```
$ ffmpeg -i in.265 out.y4m
$ head -1 out.y4m
YUV4MPEG2 W490 H490 F1:1 Ip A0:0 C420jpeg XYSCSS=420JPEG XCOLORRANGE=FULL
```

Before
```
$ imlib2_view -v ./test/images/icon-64.framerate_1_1.y4m
Show  0: './test/images/icon-64.framerate_1_1.y4m'
*** Error -2:'Imlib2: No loader for file format' loading image: './test/images/icon-64.framerate_1_1.y4m'
```

After:
```
$ IMLIB2_DEBUG=31:0 IMLIB2_LOADER_PATH=./src/modules/loaders/.libs/ LD_LIBRARY_PATH=./src/lib/.libs:${LD_LIBRARY_PATH} ./src/bin/imlib2_view -v ./test/images/icon-64.framerate_1_1.y4m
Show  0: './test/images/icon-64.framerate_1_1.y4m'
IMG : __imlib_FindCachedImage: './test/images/icon-64.framerate_1_1.y4m' frame 1
IMG :  got none
LOAD: __imlib_FindBestLoader: file='./test/images/icon-64.framerate_1_1.y4m' fmt='(null)'
FILE: __imlib_FileExtension: './test/images/icon-64.framerate_1_1.y4m'
FILE: __imlib_FileIsFile: './src/modules/loaders/.libs//y4m.so'
FILE: __imlib_FileStat: './src/modules/loaders/.libs//y4m.so'
LOAD: __imlib_ProduceLoader: ./src/modules/loaders/.libs//y4m.so
LOAD: __imlib_LookupKnownLoader: 'y4m' -> 'y4m': 0x524d50
LOAD: __imlib_FindBestLoader: fmt='y4m': ./src/modules/loaders/.libs//y4m.so
IMG : __imlib_LoadImageWrapper: fmt='y4m' file='./test/images/icon-64.framerate_1_1.y4m'(./test/images/icon-64.framerate_1_1.y4m) frame=1, imm=1
IMG : __imlib_LoadImageWrapper: y4m : ./test/images/icon-64.framerate_1_1.y4m: Elapsed time: 18.099 ms
IMG : __imlib_AddImageToCache: 0x5139e0: './test/images/icon-64.framerate_1_1.y4m' frame 1
```
2023-12-27 14:41:59 -08:00
Kim Woelders 3106fbd0d2 x11_grab: Remove some obsolete code
Should have been removed as part of 8af7975804.
2023-09-30 21:41:27 +02:00
Kim Woelders 1bd9920c07 x11_grab: Use correct depth when grabbing
Use queried drawable depth, not the context one.

Fixes grabbing of bitmaps (now using intended colormap) in the
usual 24 bit depth case.
May fix other issues as well(?).

Broken by 3ab9498777 (in v1.11.0).
2023-09-21 09:15:00 +02:00
Kim Woelders 3fd4347cfa imlib2_grab, imlib2_view: Unset context colormap
Should normally not be set when grabbing.
2023-09-21 06:45:42 +02:00
Kim Woelders be9ac449e7 loaders: Fix CPPFLAGS order
Patch by Omar Polo:

while upgrading the OpenBSD package I've come across a weird issue.
Due to the order of the flags, the heif module was loading the system'
version of Imlib2_loader.h (in /usr/local/include) instead of the one
from the tarball.  This caused failure since the previous version
(1.11.0) didn't had IMLIB_LOADER_INEX.
2023-09-04 17:01:33 +02:00
Kim Woelders f16bb23864 RAW loader: Don't unload loader
Running with valgrind or asan seems to show that unloading/reloading the
loader causes memory leaks. Not dlcose()'ing the module avoids this.
2023-09-03 20:16:12 +02:00
Kim Woelders 1e5040e8e7 loaders: Fix build with -m32 --enable-debug 2023-09-03 17:11:21 +02:00
Kim Woelders 687e13b290 loading: Call module exit function also when not dlclosing module on unload
The proper thing to do.
Does not affect any of the current loaders.
2023-09-03 16:34:50 +02:00
Kim Woelders 66f48df4cf scaling: MMX asm scaling causes segv, disable for now
Broken in v1.12.0 by ee61df6877 (pointers
to indices), __imlib_Scale_mmx_AARGBA() needs to be fixed.
2023-09-03 10:32:10 +02:00
Kim Woelders 74dae151cd Fix some clang complaints 2023-08-24 19:07:43 +02:00
Chema Gonzalez 0b08655e40 Y4M loader: add support for images with unexpected aspects
Tested:

Added a new test case with an unknown aspect (A368:375).
2023-08-16 12:12:53 +02:00
Kim Woelders d6b86f307e scaling: Correct scaling up - take 2
When scaling up (with AA) it worked sort of like there was a 1 pixel
border right and bottom.
2023-08-09 17:58:20 +02:00
Kim Woelders 4d5b1413b1 scaling: Improve non-AA scale-up case
Make source sampling more evenly distributed.
Most visible for small source dimensions.
2023-08-09 17:58:05 +02:00
Kim Woelders 29397453e4 scaling: Various trivial changes 2023-08-09 17:58:05 +02:00
Chema Gonzalez a88b95c289 Y4M loader: fix support for 420 colorspaces
Includes:
* add support for 420mpeg2 (ffmpeg-only)
* add example for 420mpeg2
* add examples for 420, 420paldv
* fix 420jpeg example
2023-08-03 12:34:30 +02:00
Kim Woelders fae1423025 Revert "scaling: Correct scaling up"
Correction is not correct :(

This reverts commit 58f2fcb4c7.
2023-07-30 17:33:14 +02:00
Kim Woelders 9d5f704036 image cache: Rework cleanup
Eliminates a nested loop in __imlib_CurrentCacheSize().

Only add to cached size if image data are loaded.
2023-07-19 21:44:04 +02:00
Kim Woelders 26dd602fa0 image cache: Drop redundant cleanup
Already done in __imlib_CurrentCacheSize().
2023-07-19 21:44:04 +02:00
Kim Woelders 2474de6f94 image cache: Avoid negative refcounts
Presumably unintended, obscures things.
2023-07-19 21:44:04 +02:00
Kim Woelders 173edae4bf image: Fix preservation of alpha chanel flag in imlib_clone_image()
#17:

As per subject, the imlib_clone_image() function no longer preserves
the alpha channel value since imlib2 1.10.0.

This bug report was initially filed by Niko Tyni in Debian's bug tracker.
If you follow the subsequent link you will also find a test program that
demonstrates the regression.

https://bugs.debian.org/1041406

This upstream change is most likely the root cause of the problem

b39d33c800

It looks like an oversight where other functions were adapted
to the new alpha channel implementation, but imlib_clone_image() remains
unchanged and only copies the flags and not the new alpha byte.
2023-07-19 18:50:11 +02:00
NRK 50295779a1 introduce imlib_image_decache_file()
Fixes: #16
2023-07-07 18:49:08 +02:00
Kim Woelders a1ea31e070 image: Use sub-second time info when available 2023-07-07 13:14:35 +02:00
NRK cf5b462d92 file: Remove unused functions some more 2023-07-05 18:55:05 +02:00
Kim Woelders 70bd7e3488 TIFF loader: Slightly more strict signature check
Avoid starting libtiff on various raw image types.
2023-07-02 21:33:39 +02:00
Kim Woelders 59ab21a580 Add new raw loader
#10
2023-07-02 21:33:39 +02:00
Kim Woelders 31b50aee15 image: Fix potentially using incorrect file size - fixup
Close opened file if we don't like it (zero size, directory).
2023-07-02 21:24:40 +02:00
Kim Woelders 595d0a322d file: Remove a couple of unused functions
__imlib_IsRealFile() and __imlib_FileExists() are not used.
__imlib_FileStat() can now be private.
2023-06-26 08:13:25 +02:00
Kim Woelders aec432b3ce image: Fix potentially using incorrect file size
During load from file we would do stat(file), then fopen(file),
and assume the stat'ed size corresponds to the fopen'ed file.
However, the file may be changed between stat() and fopen(), which may
cause trouble.
This should now be fixed by always using fstat() on the opened file
descriptor.
2023-06-26 08:13:25 +02:00
Kim Woelders f1fcc4bfed image: Fix missing munmap() when using imlib_load_image_fd() 2023-06-25 12:01:47 +02:00
Kim Woelders 58f2fcb4c7 scaling: Correct scaling up
When scaling up it worked like there was a 1 pixel border right and
bottom.

This change may affect applications that rely on the old behavior.
Setting the environment variable IMLIB2_LEGACY_SCALING to any value will
make imlib2 use the old algorithm.

When using e16 with the new (default) algorithm a few themes have
incorrectly rendered elements (unintended window border fading, opaque
pager highligt frame, more?).

Hopefully this change should go mostly unnoticed but if it turns out it
causes grief the default will probably have to be changed back.
2023-06-24 17:32:05 +02:00
Kim Woelders a72fe3796b scaling: Minor refactoring 2023-06-24 17:01:15 +02:00
Kim Woelders 166de6a93e scaling: Cosmetics 2023-06-24 17:00:21 +02:00
Kim Woelders ee61df6877 scaling: Change ypoints[] from pointers to indices
Now the calculation of ypoints[] and xpoints[] can be done by the same
function and we can avoid some essentially duplicated code.
May be slightly less optimal although I doubt it makes any significant
difference.
2023-06-24 16:58:42 +02:00
Kim Woelders eafaa11ff3 scaling: Simplify scaling points calculation (eliminate j) 2023-06-24 16:58:42 +02:00
Kim Woelders a75fc4c5c8 scaling: Cosmetics (comments) 2023-06-24 16:57:56 +02:00