Commit Graph

1883 Commits

Author SHA1 Message Date
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 4109f54c4a test_load_2: Check some more y4m files 2024-01-01 16:57:36 +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 45d58cc268 test_save: Update crcs for jxl saver (libjxl 0.8.0)
Also add a couple of missing ifdefs.
2023-09-25 05:21:26 +02:00
Kim Woelders 9198db2536 v1.12.1 2023-09-21 16:45:53 +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 570c50d75a test_scale: MMX scaling is disabled 2023-09-03 17:11:21 +02:00
Kim Woelders 57403f2ec3 test_save: Fix for jxl loader on ix86
libjxl apparently behaves differently for ix86 and x86_64.
2023-09-03 17:11:21 +02:00
Kim Woelders 03cbf75a96 test_load_2: Add forgotten xeyes.png 2023-09-03 17:11:21 +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
Kim Woelders 5300f19575 v1.12.0 2023-08-17 16:41:56 +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 a22b9b88c0 test_scale: Exercise non-AA path too 2023-08-09 20:34:30 +02:00
Kim Woelders 4f17d66965 test_scale: Update for new scaling (re-applied) 2023-08-09 17:58:20 +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
Chema Gonzalez 63106616b9 test_load2: make error messages more descriptive
Tested:

Before:
```
$ IMLIB2_LOADER_PATH=../src/modules/loaders/.libs ./test_load_2
...
[ RUN      ] LOAD2.load_1
test_load_2.cpp:121: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i].crc
    Which is: 4016720483
test_load_2.cpp:128: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i].crc
    Which is: 4016720483
test_load_2.cpp:135: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i].crc
    Which is: 4016720483
[  FAILED  ] LOAD2.load_1 (70 ms)
...
```

After:
```
$ IMLIB2_LOADER_PATH=../src/modules/loaders/.libs ./test_load_2
...
test_load_2.cpp:122: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i].crc
    Which is: 4016720483
wrong crc file: ./images/icon-64.xpm expected: 4016720483 actual: 671661664
test_load_2.cpp:131: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i]. crc
    Which is: 4016720483
wrong crc file: ./images/icon-64.xpm expected: 4016720483 actual: 671661664
test_load_2.cpp:142: Failure
Expected equality of these values:
  crc
    Which is: 671661664
  tii[i]. crc
    Which is: 4016720483
wrong crc file: ./images/icon-64.xpm expected: 4016720483 actual: 671661664
[  FAILED  ] LOAD2.load_1 (69 ms)
...
```
2023-08-03 12:34:30 +02:00
Kim Woelders 310e9e162d Revert "test_scale: Update for new scaling"
This reverts commit 41be1c88f8.
2023-07-30 17:33:44 +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 1afc1302c9 test_load: Minor fix in debug message 2023-07-02 21:33:20 +02:00
Kim Woelders efd0bccb92 test: Bypass wrappers when running tests 2023-07-02 21:24:40 +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 41be1c88f8 test_scale: Update for new scaling 2023-06-24 17:32:39 +02:00