Skip to content

Commit

Permalink
Merge pull request #275 from gnustep/Magick_TGA
Browse files Browse the repository at this point in the history
ImageMagick TGA support fix
  • Loading branch information
rmottola authored May 22, 2024
2 parents 8913711 + 3ec7319 commit 6094e40
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Source/GSImageMagickImageRep.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<abstract>ImageMagick image representation.</abstract>
Copyright (C) 2011 Free Software Foundation, Inc.
Copyright (C) 2011-2024 Free Software Foundation, Inc.
Author: Eric Wasylishen <[email protected]>
Riccardo Mottola
Date: June 2011
This file is part of the GNUstep Application Kit Library.
Expand Down Expand Up @@ -123,13 +125,17 @@ + (NSBitmapImageRep *) imageRepWithImageMagickImage: (Image *)image
return bmp;
}

#define SIGNATURE_LENGTH 18

+ (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages
{
NSMutableArray *reps = [NSMutableArray array];

ExceptionInfo *exception = AcquireExceptionInfo();
ImageInfo *imageinfo = CloneImageInfo(NULL);
Image *images, *image;
Image *images;
Image *image;
char signature[SIGNATURE_LENGTH];

// Set the background color to transparent
// (otherwise SVG's are rendered against a white background by default)
Expand All @@ -139,6 +145,14 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages
QueryColorDatabase("none", &imageinfo->background_color, exception);
#endif

memset(signature, 0, SIGNATURE_LENGTH);
[data getBytes: signature range: NSMakeRange([data length] - 18, 18)];
if (strncmp(signature, "TRUEVISION-XFILE.", 17) == 0)
{
NSWarnLog(@"Targa file detected!, giving a magick hint...");
strcpy(imageinfo->magick, "TGA");
}

images = BlobToImage(imageinfo, [data bytes], [data length], exception);

if (exception->severity != UndefinedException)
Expand Down

0 comments on commit 6094e40

Please sign in to comment.