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.
This commit is contained in:
Kim Woelders 2018-02-22 09:21:41 +01:00
parent 868a40579a
commit 8fcdc4965d
13 changed files with 22 additions and 71 deletions

View File

@ -1661,12 +1661,8 @@ imlib_image_set_format(const char *format)
CHECK_PARAM_POINTER("imlib_image_set_format", "image", ctx->image);
CHECK_PARAM_POINTER("imlib_image_set_format", "format", format);
CAST_IMAGE(im, ctx->image);
if (im->format)
free(im->format);
if (format)
im->format = strdup(format);
else
im->format = NULL;
free(im->format);
im->format = (format) ? strdup(format) : NULL;
if (!(im->flags & F_FORMAT_IRRELEVANT))
{
__imlib_DirtyImage(im);
@ -2499,15 +2495,9 @@ imlib_clone_image(void)
im->border = im_old->border;
im->loader = im_old->loader;
if (im_old->format)
{
im->format = malloc(strlen(im_old->format) + 1);
strcpy(im->format, im_old->format);
}
im->format = strdup(im_old->format);
if (im_old->file)
{
im->file = malloc(strlen(im_old->file) + 1);
strcpy(im->file, im_old->file);
}
im->file = strdup(im_old->file);
return (Imlib_Image) im;
}

View File

@ -869,6 +869,11 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im,
im->format = NULL;
}
}
else
{
if (!im->format && l->formats && l->formats[0])
im->format = strdup(l->formats[0]);
}
return rc;
}

View File

@ -41,14 +41,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
}
im->w = w;
im->h = h;
if (!im->format)
{
if (alpha)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("argb");
}
if (alpha)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
}
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{

View File

@ -298,11 +298,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
im->w = w;
im->h = h;
if (!im->format)
{
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("bmp");
}
UNSET_FLAG(im->flags, F_HAS_ALPHA);
}
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{

View File

@ -38,16 +38,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
return 0;
}
/* set format */
if (!im->loader)
{
if (!(im->format = strdup("ff")))
{
im->w = 0;
fclose(f);
return 0;
}
}
SET_FLAG(im->flags, F_HAS_ALPHA);
/* load the data */

View File

@ -126,13 +126,8 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
goto quit2;
}
/* set the format string member to the lower-case full extension */
/* name for the format - so example names would be: */
/* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */
im->w = w;
im->h = h;
if (!im->format)
im->format = strdup("gif");
if (im->loader || immediate_load || progress)
{

View File

@ -74,7 +74,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!IMAGE_DIMENSIONS_OK(w, h))
goto quit_error;
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("jpeg");
}
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))

View File

@ -503,9 +503,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
|| !strcmp(env, "on")))
UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (!im->format)
im->format = strdup("lbm");
ilbm.ham = 0;
ilbm.hbrite = 0;
if (ilbm.depth <= 8)

View File

@ -91,11 +91,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
/* set the format string member to the lower-case full extension */
/* name for the format - so example names would be: */
/* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */
if (!im->loader)
im->format = strdup("png");
}
/* if its the second phase load OR its immediate load or a progress */
/* callback is set then load the data */

View File

@ -121,14 +121,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!IMAGE_DIMENSIONS_OK(w, h))
goto quit;
if (!im->format)
{
if (p == '8')
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("pnm");
}
if (p == '8')
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
rc = 1; /* Ok */

View File

@ -296,14 +296,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
return 0;
}
if (!im->format)
{
if (bpp == 32)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("tga");
}
if (bpp == 32)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
/* if we need to actually read the pixel data... */
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))

View File

@ -335,8 +335,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (!im->format)
im->format = strdup("tiff");
if ((im->loader) || (immediate_load) || (progress))
{

View File

@ -214,8 +214,6 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
}
im->w = w;
im->h = h;
if (!im->format)
im->format = strdup("xpm");
cmap = malloc(sizeof(struct _cmap) * ncolors);