Commit Graph

45 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 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 4f928f53a7 WEBP saver: allow lossless and respect compression tag
this treats quality == 100 as lossless similar to some other savers.

in case of lossless encoding, compression is derived from "quality" if
compression_tag was not set. in case of lossy encoding, the default is
used when compression_tag isn't set.

additionally, this fixes a bug in the older saver where fwrite might
have been called with a null fdata (which is UB) in case of an error.
2023-05-12 16:21:35 +02:00
Kim Woelders 8a36ae6d8d loaders: Use common function to print error messages
Also:
- gif  loader: Add error about corrupt frame sequence
- tiff loader: Drop OOM message - Not done elsewhere
- webp loader: Drop messages about quality tag outside [0-100] -
               Not done elsewhere
2023-05-08 18:52:57 +02:00
Kim Woelders c3d524924e Savers: Centralize file open/close
As done for the loaders a while back.
2023-02-04 10:49:37 +01:00
Kim Woelders b6bf5d0520 multiframe: Allocate frame info only when needed 2022-11-15 11:54:06 +01:00
Kim Woelders e353a684c2 multiframe: Move frame info to allocated record
Avoid the overhead in ImlibImage when not doing multiframe loads.
2022-11-15 11:54:06 +01:00
Kim Woelders b1bbe1d9e8 multiframe: Centralize handling of frame update offsets 2022-11-15 11:54:06 +01:00
Kim Woelders 6df68e3e2e multiframe: Tweaks around frame number handling 2022-11-15 11:54:06 +01:00
Kim Woelders 6e2267e740 multiframe: Support loop count 2022-10-10 17:23:43 +02:00
Kim Woelders 753065d5a3 loading: Centralize mmap handling
Loader interface should be stable now.
2022-07-10 12:51:06 +02:00
Kim Woelders e55208f4d6 loading: Introduce __imlib_ImageFileContextPush/Pop()
Makes dealing with nested file contexts much easier.
2022-07-10 12:50:40 +02:00
Kim Woelders 5b357a815b loading: New loader infrastructure
Old loaders will no longer work.
Should be no big deal to migrate though.
2022-07-10 12:50:40 +02:00
Kim Woelders b39d33c800 image: Change has alpha flag to separate byte
It is the only flag that should be used by the loaders
2022-07-10 12:50:40 +02:00
Kim Woelders f44e52c62d Introduce Imlib2_Loader.h - all that is needed by loaders
Note! This changes breaks loader ABI due to reordering of elements in
ImlibImage.
Loader interface will be unstable until further notice.
2022-07-10 12:50:09 +02:00
Kim Woelders 3aeceb6a7b Loaders: Remove unnecessary calls to __imlib_FreeData()
__imlib_LoadImageWrapper() does it when required so no need for
doing it in every loader.
2022-03-31 21:49:56 +02:00
Kim Woelders 18d0befc57 Use stdint types instead of DATA32 etc.
This should make things slightly more consistent and unambiguous, and
the stdint types are already used here and there (in loaders).

I'm not aware of any systems where this change makes any difference.
If there are targets out there with 64 bit ints imlib2 might now work
there and on targets with 16 bit ints it most likely still doesn't.
2022-03-26 15:54:40 +01:00
Kim Woelders 7b671819f6 WEBP saver: Fix return code on success 2022-03-18 20:54:50 +01:00
Kim Woelders 3459740001 Loader includes tweaks 2022-03-06 18:42:28 +01:00
Kim Woelders fb4fb24e44 Refactor image flags stuff
For improved grepability.
2022-02-26 09:09:25 +01:00
Kim Woelders bf93574b8b Introduce more loader return codes
Used to avoid potentially wasting time trying to load corrupt images
by trying loaders which won't recognize the image anyway.
2021-12-28 16:08:06 +01:00
Kim Woelders 2bbd3dc7f9 Updates for animated image handling 2021-12-26 11:00:14 +01:00
Kim Woelders b2ac97d93a WEBP loader: Multiframe support 2021-12-19 14:58:43 +01:00
NRK 524d439adf WEBP loader: fix key selecting last frame
as far as i can tell, iter is being used uninitialized here leading to
reading garbage values resulting in the last frame always being selected
when key is present.
2021-11-29 17:37:20 +01:00
Kim Woelders d4fa61dc50 WEBP loader: Enable loading animated images (first frame by default) 2021-11-05 17:22:01 +01:00
Kim Woelders 59561dcb1b Introduce ARRAY_SIZE() 2021-11-05 17:22:01 +01:00
Kim Woelders 5433232308 Introduce UPDATE_FLAG()
Somewhat simpler.
2021-11-05 17:22:01 +01:00
Kim Woelders 51999ad031 WEBP loader: Use mmap() for loading 2021-10-22 19:27:47 +02:00
Kim Woelders 546bb20f52 WEBP loader: Cosmetics
Some variable renaming for consistency.
2021-10-22 19:27:47 +02:00
Kim Woelders b71221ce76 Revert "GIF, TIFF, WEBP loaders: Fix loading if filename does not have usual suffix"
This reverts commit 43f82f3bc8.
2021-09-15 19:43:48 +02:00
Kim Woelders 43f82f3bc8 GIF, TIFF, WEBP loaders: Fix loading if filename does not have usual suffix
Patch from Daniel Friesel <derf@finalrewind.org>:

---
Fix .gif loader if filename does not end in .gif

Imlib2 is currently unable to load gif images if the filename does not end in
.gif. This appears to be caused by imlib2 not resetting the file descriptor
back to 0 after trying to open the image with its different loaders.

While imlib2 does call rewind(FILE* im->fp) before invoking each loader, this
does not guarantee that the underlying FD is seeked as well. However, the GIF
loader uses the FD directly, and therefore tries to read from the middle of the
file (unless it is the first loader). This patch adds an explicit seek in the
same fashion as implemented in the TIFF loader.

Patch and debugging credits go to Lars Stoltenow.
---

Also fix same issue in TIFF and WEBP loaders.
2021-09-14 07:43:55 +02:00
Kim Woelders dbeb622c7a WEBP loader: Rename fd variable to be same as everywhere else 2021-09-14 07:42:34 +02:00
Kim Woelders c018a7687c WEBP loader: Remove forgotten debug printout 2021-09-14 07:42:34 +02:00
Kim Woelders 1a439ed4df WEBP saver: Use fopen() etc. like all other savers 2021-07-16 23:08:10 +02:00
Kim Woelders 381e65f567 Silence a couple of sign-compare warnings 2020-12-09 17:44:16 +01:00
Kim Woelders 64df90de3d WEBP loader: Add initial signature check
Avoid potentially wasting much time when loading/checking large
non-webp files.
2020-12-06 18:09:42 +01:00
Kim Woelders 6c2fe14b82 Move loaders to load2() 2020-02-29 18:04:34 +01:00
Kim Woelders 875bc82b49 Introduce __imlib_LoaderSetFormats() 2020-01-11 12:55:08 +01:00
Kim Woelders 0f5b4fb10a Loaders: Simplify/fix progress handling
Progress handling was broken in at least bmp, gif, lbm, and png loaders.
2020-01-04 15:30:20 +01:00
Kim Woelders 6a7eb67f46 Saver cleanups
- Do exit cleanups at exit.
- Use LOAD_FAIL/SUCCESS/BREAK for save() exit code.
- Cosmetics.
2019-12-23 12:55:46 +01:00
Kim Woelders bd3aa88242 Loader cleanups
- Do exit cleanups at exit.
- Merge data load conditions.
- Use LOAD_FAIL/SUCCESS/BREAK for load() exit code.
- Cosmetics.
2019-12-23 12:07:48 +01:00
Kim Woelders 1a6a6b6433 Remove __imlib_AllocateData() w,h args
im->w and im->h must always be set before __imlib_AllocateData() is
called due to non-immediate loading (__imlib_AllocateData() only
comes in play when the pixel data must be loaded).
2019-11-16 21:18:12 +01:00
Alexander Volkov 03665627db Allow to use custom memory management functions for loaded images
Summary:
... and add imlib_create_image_using_data_and_memory_function().

For example, it allows to load an image in one process and then
pass it through shared memory to another process without extra
memory copy.

Reviewers: kwo

Differential Revision: https://phab.enlightenment.org/D10222
2019-09-30 19:11:32 +02:00
Kim Woelders 701f87ffa6 WepP loader: Fix memory leak in error path 2019-09-29 18:40:03 +02:00
Kim Woelders 3f4d80dc82 Add new WebP loader
Contributed by Jason Andresen <jandrese@vt.edu>.
2019-08-15 15:44:49 +02:00