Commit Graph

65 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 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
Kim Woelders 1e5040e8e7 loaders: Fix build with -m32 --enable-debug 2023-09-03 17:11:21 +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 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 41c792bd7e loaders: Cosmetics
- Add missing const
- Consistently use imdata for pointer into imlib image data
- Minor changes
2023-05-01 11:19:24 +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 495fb5e6f8 Loaders: Debug macro cleanups 2023-01-28 16:25:15 +01: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 f756d91c31 TIFF loader: Change default save compression type
As of libtiff 4.4.0 saving an image with COMPRESSION_DEFLATE will
produce a warning:

 TIFFWriteDirectorySec: Warning, Creating TIFF with legacy Deflate codec identifier,
 COMPRESSION_ADOBE_DEFLATE is more widely supported.

So let's just use COMPRESSION_ADOBE_DEFLATE.
2022-06-30 09:38:02 +02:00
Kim Woelders 63dccd46c5 TIFF loader: Use mmap'ed file access
Doesn't seem to affect speed much.
2022-04-02 02:20:30 +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 e8e0130ce0 TIFF loader: Remove obsolete comment 2022-03-11 16:59:29 +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 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 66c941c267 TIFF loader: Use mmap() during signature check 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 e709825314 Loaders: Remove unnecessary headers 2021-07-16 19:40:03 +02:00
Kim Woelders 933fc2ab1f TIFF loader: Drop use of libtiff defined types deprecated in libtiff-4.3.0
Switch to using C99 types, uint8 -> uint8_t, etc. now used by libtiff.
2021-04-30 10:04:05 +02:00
Kim Woelders cd1a42dd07 Fix clang-analyzer warnings - loaders (trivial) 2021-04-16 17:15:06 +02:00
Kim Woelders 6c2fe14b82 Move loaders to load2() 2020-02-29 18:04:34 +01:00
Kim Woelders 4ec88a0dda TIFF loader: Minor speedup 2020-02-23 13:26:00 +01:00
Kim Woelders 875bc82b49 Introduce __imlib_LoaderSetFormats() 2020-01-11 12:55:08 +01:00
Kim Woelders 10e21579fa Savers: Simplify progress handling 2020-01-04 15:30:20 +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
Kim Woelders 9bae2c9f02 TGA loader: Tweak error handling 2019-11-16 21:09:16 +01:00
Kim Woelders 3e082b2310 Use macro for pixel color access in savers 2019-11-09 12:07:15 +01:00
Kim Woelders 2f228adbe1 Re-indent everything using indent-2.2.12 2019-11-08 18:57:36 +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 09d9a95054 Remove pointless im->data checks in loaders
im->data should always be NULL when entering the load() function.

We can therefore also remove free(im->data) calls before the buffer
is allocated.
2019-09-29 18:39:56 +02:00
Kim Woelders 89432fff5e Use common PIXEL_ARGB() macro to compose pixels 2018-07-17 19:31:04 +02:00
Kim Woelders 8fcdc4965d Centralize handling of im->format
Instead of assigning it (in different ways) in each loader, do it
centrally in __imlib_LoadImageWrapper().

And a couple of cleanups in code related to im->format.
2018-07-17 19:31:04 +02:00
Kim Woelders 868a40579a Cleanups in load() functions
When entering load we can assume that im != NULL and im->data == NULL.
2018-07-17 19:31:04 +02:00
Tobias Stoeckmann d5ebec2948 Properly release resources on error path
The code did not properly release resources in some error paths,
leading to memory leaks or possible double free issues.

If an image could not be loaded, some code paths check if width is 0
to determine if an error occurred. Therefore, always set width to 0
in such cases.
2017-03-12 09:52:02 +01:00
Mike Frysinger 560a58e617 check return value of fread/write funcs
This fixes warnings with newer compilers/distros that enable warning
flags by default:
loader_zlib.c: In function 'uncompress_file':
loader_zlib.c:33:17: warning: ignoring return value of 'write',
	declared with attribute warn_unused_result [-Wunused-result]
            write(dest, outbuf, bytes);
                 ^
2014-01-18 14:20:06 -05:00
Kim Woelders 357852ebb9 Silence compiler warnings (loaders). 2013-07-03 16:53:21 +02:00
Lucas De Marchi 35e8e96a61 Convert (hopefully) all comparisons to NULL
Apply badzero.cocci, badnull.coci and badnull2.cocci

This should convert all cases where there's a comparison to NULL to simpler
forms. This patch applies the following transformations:

code before patch               ||code after patch
===============================================================

return a == NULL;                 return !a;

return a != NULL;                 return !!a;

func(a == NULL);                  func(!a);

func(a != NULL);                  func(!!a);

b = a == NULL;                    b = !a;

b = a != NULL;                    b = !!a;

b = a == NULL ? c : d;            b = !a ? c : d;

b = a != NULL ? c : d;            b = a ? c : d;


other cases:

a == NULL                         !a
a != NULL                         a




SVN revision: 51487
2010-08-21 13:52:25 +00:00