GraphicsMagick: coders/tga.c TGA footer is read, currently used ...
GraphicsMagick Commits <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.23274.1664749380.11362.graphicsmagick-commit@lists.sourceforge.net> |
changeset 33acd8182934 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=33acd8182934 summary: coders/tga.c TGA footer is read, currently used for logs only. diffstat: ChangeLog | 8 ++++++-- coders/tga.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diffs (121 lines): diff -r 95f1225117f6 -r 33acd8182934 ChangeLog --- a/ChangeLog Sun Oct 02 09:41:49 2022 -0500 +++ b/ChangeLog Mon Oct 03 00:22:15 2022 +0200 @@ -1,3 +1,7 @@ +2022-10-03 Fojtik Jaroslav <[email protected]> + + * coders/tga.c TGA footer is read, currently used for logs only. + 2022-10-02 Bob Friesenhahn <[email protected]> * scripts/rst2html5.py: Fix from Mark Mitchell to deal with RST @@ -29,11 +33,11 @@ 2022-10-01 Fojtik Jaroslav <[email protected]> - * coders/tga.c Monochromatic TGA could be written. + * coders/tga.c Monochromatic bilevel TGA could be written. 2022-09-29 Fojtik Jaroslav <[email protected]> - * coders/tga.c Monochromatic TGA could be read. + * coders/tga.c Monochromatic bilevel TGA could be read. 2022-09-28 Fojtik Jaroslav <[email protected]> diff -r 95f1225117f6 -r 33acd8182934 coders/tga.c --- a/coders/tga.c Sun Oct 02 09:41:49 2022 -0500 +++ b/coders/tga.c Mon Oct 03 00:22:15 2022 +0200 @@ -112,6 +112,17 @@ Top right | 1 | 1 */ + +typedef struct _TGAFooter +{ + magick_uint32_t ExtensionOffset; + magick_uint32_t DevelopperDirOffset; + char Signature[17]; /* 16 official bytes + zero terminator. */ + char Dot; + char Terminator; +} TGAFooter; + + static void LogTGAInfo(const TGAInfo *tga_info) { @@ -164,9 +175,22 @@ tga_info->width, tga_info->height, (unsigned int) tga_info->bits_per_pixel, tga_info->attributes,attribute_bits,OrientationTypeToString(orientation)); +} + +static void LogTGAFooter(const TGAFooter *ptga_footer) +{ + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "Targa Footer:\n" + " ExtensionOffset : %u\n" + " DevelopperDirOffset : %u\n" + " Signature : %s\n", + ptga_footer->ExtensionOffset, + ptga_footer->DevelopperDirOffset, + ptga_footer->Signature); } + static unsigned int ReadBlobLSBShortFromBuffer(unsigned char* buffer, size_t* readerpos) { unsigned int @@ -218,7 +242,6 @@ % % o exception: return any errors or warnings in this structure. % -% */ static Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception) { @@ -246,6 +269,7 @@ TGAInfo tga_info; + TGAFooter tga_footer; unsigned char runlength; @@ -291,6 +315,35 @@ tga_info.colormap_type=(unsigned char)ReadBlobByteFromBuffer(readbuffer, &readbufferpos); tga_info.image_type=(unsigned char)ReadBlobByteFromBuffer(readbuffer, &readbufferpos); + memset(&tga_footer, 0, sizeof(tga_footer)); + if(BlobIsSeekable(image) + && image->logging) /* TODO: Erase this line, footer is not doing anything usefull yet, logging only. */ + { + status = MagickTrue; + SeekBlob(image,-26, SEEK_END); + tga_footer.ExtensionOffset = ReadBlobLSBLong(image); + tga_footer.DevelopperDirOffset = ReadBlobLSBLong(image); + if(ReadBlob(image, 16, tga_footer.Signature) != 16) status=MagickFail; + else + { + if((tga_footer.Dot=ReadBlobByte(image)) != '.') status=MagickFail; + if((tga_footer.Terminator=ReadBlobByte(image)) != 0) status=MagickFail; + } + + if(status == MagickTrue) + { + if(image->logging) LogTGAFooter(&tga_footer); + if(strncmp(tga_footer.Signature,"TRUEVISION-XFILE",16)) status=MagickFail; + } + + if(status != MagickTrue) // Footer is invalid. + { + memset(&tga_footer, 0, sizeof(tga_footer)); + status = MagickTrue; + } + SeekBlob(image,3,SEEK_SET); + } + do { if (((tga_info.image_type != TGAColormap) &&