Skip to content

Commit

Permalink
Moved AutoResizeImage method closer to the write method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed May 24, 2024
1 parent 2439753 commit 57eae13
Showing 1 changed file with 58 additions and 57 deletions.
115 changes: 58 additions & 57 deletions coders/icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,63 +112,6 @@ static Image
static MagickBooleanType
WriteICONImage(const ImageInfo *,Image *);

Image *AutoResizeImage(const Image *image,const char *option,
MagickOffsetType *count,ExceptionInfo *exception)
{
#define MAX_SIZES 16

char
*q;

const char
*p;

Image
*resized,
*images;

size_t
sizes[MAX_SIZES]={256, 192, 128, 96, 64, 48, 40, 32, 24, 16};

ssize_t
i;

images=NULL;
*count=0;
i=0;
p=option;
while (*p != '\0' && i < MAX_SIZES)
{
size_t
size;

while ((isspace((int) ((unsigned char) *p)) != 0))
p++;
size=(size_t)strtol(p,&q,10);
if ((p == q) || (size < 16) || (size > 256))
return((Image *) NULL);
p=q;
sizes[i++]=size;
while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
p++;
}
if (i == 0)
i=10;
*count=i;
for (i=0; i < *count; i++)
{
resized=ResizeImage(image,sizes[i],sizes[i],image->filter,image->blur,
exception);
if (resized == (Image *) NULL)
return(DestroyImageList(images));
if (images == (Image *) NULL)
images=resized;
else
AppendImageToList(&images,resized);
}
return(images);
}

static IconDirectory *RelinquishIconDirectory(IconDirectory *directory)
{
ssize_t
Expand Down Expand Up @@ -980,6 +923,64 @@ ModuleExport void UnregisterICONImage(void)
% o image: The image.
%
*/

Image *AutoResizeImage(const Image *image,const char *option,
MagickOffsetType *count,ExceptionInfo *exception)
{
#define MAX_SIZES 16

char
*q;

const char
*p;

Image
*resized,
*images;

size_t
sizes[MAX_SIZES]={256, 192, 128, 96, 64, 48, 40, 32, 24, 16};

ssize_t
i;

images=NULL;
*count=0;
i=0;
p=option;
while (*p != '\0' && i < MAX_SIZES)
{
size_t
size;

while ((isspace((int) ((unsigned char) *p)) != 0))
p++;
size=(size_t)strtol(p,&q,10);
if ((p == q) || (size < 16) || (size > 256))
return((Image *) NULL);
p=q;
sizes[i++]=size;
while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
p++;
}
if (i == 0)
i=10;
*count=i;
for (i=0; i < *count; i++)
{
resized=ResizeImage(image,sizes[i],sizes[i],image->filter,image->blur,
exception);
if (resized == (Image *) NULL)
return(DestroyImageList(images));
if (images == (Image *) NULL)
images=resized;
else
AppendImageToList(&images,resized);
}
return(images);
}

static MagickBooleanType WriteICONImage(const ImageInfo *image_info,
Image *image)
{
Expand Down

0 comments on commit 57eae13

Please sign in to comment.