image: Fix undesired change of format

In a previous commit im->format was always set before calling a loader
in order to make it available e.g. from loader progress callbacks via
imlib_image_format().

However, setting the format with imlib_image_set_format() on a
non-immediately loaded image would be overridden when the image data
was subsequently loaded.

Also move the initial setting of im->format up front so it's also set
for legacy load()s.
This commit is contained in:
Kim Woelders 2022-04-07 10:50:30 +02:00
parent d56be3b8df
commit c85d63d710
1 changed files with 3 additions and 2 deletions

View File

@ -284,6 +284,9 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im, int load_data)
unsigned int t0 = __imlib_time_us();
#endif
if (!im->format)
im->format = strdup(l->formats[0]);
if (l->load2)
{
FILE *fp = NULL;
@ -294,8 +297,6 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im, int load_data)
if (!im->fp)
return 0;
}
free(im->format);
im->format = strdup(l->formats[0]);
rc = l->load2(im, load_data);
if (fp)