From 656fe6e576c73fff9c5a1dae59e35c0d0fed7a7f Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 14 May 2024 00:56:39 +0200 Subject: [PATCH 1/4] seek for trailing signature and recognize v2 TGA files and hint that to ImageMagick --- Source/GSImageMagickImageRep.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/GSImageMagickImageRep.m b/Source/GSImageMagickImageRep.m index 385b2c5685..d89462f001 100644 --- a/Source/GSImageMagickImageRep.m +++ b/Source/GSImageMagickImageRep.m @@ -2,9 +2,11 @@ ImageMagick image representation. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011-2024 Free Software Foundation, Inc. Author: Eric Wasylishen + Riccardo Mottola + Date: June 2011 This file is part of the GNUstep Application Kit Library. @@ -130,6 +132,7 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages ExceptionInfo *exception = AcquireExceptionInfo(); ImageInfo *imageinfo = CloneImageInfo(NULL); Image *images, *image; + char signature[32]; // Set the background color to transparent // (otherwise SVG's are rendered against a white background by default) @@ -139,6 +142,14 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages QueryColorDatabase("none", &imageinfo->background_color, exception); #endif + bzero(signature, 32); + [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) From f02d54ee8a31b80d1def9fe016bbf64b44a1f7fd Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Fri, 17 May 2024 10:58:37 +0200 Subject: [PATCH 2/4] code reformat --- Source/GSImageMagickImageRep.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/GSImageMagickImageRep.m b/Source/GSImageMagickImageRep.m index d89462f001..1747fda806 100644 --- a/Source/GSImageMagickImageRep.m +++ b/Source/GSImageMagickImageRep.m @@ -131,7 +131,8 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages ExceptionInfo *exception = AcquireExceptionInfo(); ImageInfo *imageinfo = CloneImageInfo(NULL); - Image *images, *image; + Image *images; + Image *image; char signature[32]; // Set the background color to transparent @@ -143,7 +144,7 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages #endif bzero(signature, 32); - [data getBytes:signature range:NSMakeRange([data length]-18, 18)]; + [data getBytes: signature range: NSMakeRange([data length] - 18, 18)]; if (strncmp(signature, "TRUEVISION-XFILE.", 17) == 0) { NSWarnLog(@"Targa file detected!, giving a magick hint..."); From 7feeccceabfb4773cde4d95b445b3913c501c233 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Fri, 17 May 2024 11:37:57 +0200 Subject: [PATCH 3/4] use memset instead of bzeo, to conform to the rest of the file --- Source/GSImageMagickImageRep.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/GSImageMagickImageRep.m b/Source/GSImageMagickImageRep.m index 1747fda806..03e94fd412 100644 --- a/Source/GSImageMagickImageRep.m +++ b/Source/GSImageMagickImageRep.m @@ -143,7 +143,7 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages QueryColorDatabase("none", &imageinfo->background_color, exception); #endif - bzero(signature, 32); + memset(signature, 0, 32); [data getBytes: signature range: NSMakeRange([data length] - 18, 18)]; if (strncmp(signature, "TRUEVISION-XFILE.", 17) == 0) { From 3ec731943c4ef2fcfbe269612a016f88bde7ea3e Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 21 May 2024 14:38:26 +0200 Subject: [PATCH 4/4] use a constant for signature and use for now only the bytes needed for TGA --- Source/GSImageMagickImageRep.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/GSImageMagickImageRep.m b/Source/GSImageMagickImageRep.m index 03e94fd412..55d59b75bf 100644 --- a/Source/GSImageMagickImageRep.m +++ b/Source/GSImageMagickImageRep.m @@ -125,6 +125,8 @@ + (NSBitmapImageRep *) imageRepWithImageMagickImage: (Image *)image return bmp; } +#define SIGNATURE_LENGTH 18 + + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages { NSMutableArray *reps = [NSMutableArray array]; @@ -133,7 +135,7 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages ImageInfo *imageinfo = CloneImageInfo(NULL); Image *images; Image *image; - char signature[32]; + char signature[SIGNATURE_LENGTH]; // Set the background color to transparent // (otherwise SVG's are rendered against a white background by default) @@ -143,7 +145,7 @@ + (NSArray*) imageRepsWithData: (NSData *)data allImages: (BOOL)allImages QueryColorDatabase("none", &imageinfo->background_color, exception); #endif - memset(signature, 0, 32); + memset(signature, 0, SIGNATURE_LENGTH); [data getBytes: signature range: NSMakeRange([data length] - 18, 18)]; if (strncmp(signature, "TRUEVISION-XFILE.", 17) == 0) {