GraphicsMagick: TGA: Enhance traces. Normalize on 'unsigned int...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.34478.1659795868.1353.graphicsmagick-commit@lists.sourceforge.net>
changeset 671a33015c59 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=671a33015c59
summary: TGA: Enhance traces.  Normalize on 'unsigned int' for more performance.

diffstat:

 ChangeLog                              |    6 +
 VisualMagick/installer/inc/version.isx |    4 +-
 coders/tga.c                           |  111 +++++++++++++++++++++++---------
 magick/version.h                       |    4 +-
 www/Changelog.html                     |    5 +
 5 files changed, 93 insertions(+), 37 deletions(-)

diffs (233 lines):

diff -r 2504f4ed1a52 -r 671a33015c59 ChangeLog
--- a/ChangeLog	Thu Aug 04 14:23:15 2022 -0500
+++ b/ChangeLog	Sat Aug 06 09:24:04 2022 -0500
@@ -1,3 +1,9 @@
+2022-08-06  Bob Friesenhahn  <[email protected]>
+
+        * coders/tga.c: Enhance 'coder' level trace information.
+        Normalize on 'unsigned int' as much as possible in order to use
+        natural types and likely help with function inligning.
+
 2022-08-04  Bob Friesenhahn  <[email protected]>
 
         * coders/tga.c (ReadTGAImage): Remove a defective validation of
diff -r 2504f4ed1a52 -r 671a33015c59 VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Thu Aug 04 14:23:15 2022 -0500
+++ b/VisualMagick/installer/inc/version.isx	Sat Aug 06 09:24:04 2022 -0500
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020220804"
-#define public MagickPackageReleaseDate "snapshot-20220804"
+#define public MagickPackageVersionAddendum ".020220806"
+#define public MagickPackageReleaseDate "snapshot-20220806"
diff -r 2504f4ed1a52 -r 671a33015c59 coders/tga.c
--- a/coders/tga.c	Thu Aug 04 14:23:15 2022 -0500
+++ b/coders/tga.c	Sat Aug 06 09:24:04 2022 -0500
@@ -1,5 +1,5 @@
 /*
-% Copyright (C) 2003 - 2020 GraphicsMagick Group
+% Copyright (C) 2003 - 2022 GraphicsMagick Group
 % Copyright (C) 2002 ImageMagick Studio
 % Copyright 1991-1999 E. I. du Pont de Nemours and Company
 %
@@ -40,6 +40,7 @@
 #include "magick/attribute.h"
 #include "magick/blob.h"
 #include "magick/colormap.h"
+#include "magick/enum_strings.h"
 #include "magick/log.h"
 #include "magick/magick.h"
 #include "magick/monitor.h"
@@ -53,42 +54,86 @@
   WriteTGAImage(const ImageInfo *,Image *);
 
 
-#define TGAColormap 1          /* Colormapped image data */
-#define TGARGB 2               /* Truecolor image data */
-#define TGAMonochrome 3        /* Monochrome image data */
-#define TGARLEColormap  9      /* Colormapped image data (encoded) */
-#define TGARLERGB  10          /* Truecolor image data (encoded) */
-#define TGARLEMonochrome  11   /* Monochrome image data (encoded) */
+#define TGAColormap 1U         /* Colormapped image data */
+#define TGARGB 2U              /* Truecolor image data */
+#define TGAMonochrome 3U       /* Monochrome image data */
+#define TGARLEColormap  9U     /* Colormapped image data (encoded) */
+#define TGARLERGB  10U         /* Truecolor image data (encoded) */
+#define TGARLEMonochrome  11U  /* Monochrome image data (encoded) */
 
 typedef struct _TGAInfo
 {
-  unsigned char
-    id_length,       /* Size of Image ID field (starting after header) */
-    colormap_type,   /* Color map type */
-    image_type;      /* Image type code */
+  unsigned int
+    id_length,       /* (U8) Size of Image ID field (starting after header) */
+    colormap_type,   /* (U8) Color map type */
+    image_type;      /* (U8) Image type code */
 
-  unsigned short
-    colormap_index,  /* Color map origin */
-    colormap_length; /* Color map length */
+  unsigned int
+    colormap_index,  /* (U16) Color map origin */
+    colormap_length; /* (U16) Color map length */
 
-  unsigned char
-    colormap_size;   /* Color map entry depth */
+  unsigned int
+    colormap_size;   /* (U8) Color map entry depth */
 
-  unsigned short
-    x_origin,        /* X origin of image */
-    y_origin,        /* Y orgin of image */
-    width,           /* Width of image */
-    height;          /* Height of image */
+  unsigned int
+    x_origin,        /* (U16) X origin of image */
+    y_origin,        /* (U16) Y orgin of image */
+    width,           /* (U16) Width of image */
+    height;          /* (U16) Height of image */
 
-  unsigned char
-    bits_per_pixel,  /* Image pixel size */
-    attributes;      /* Image descriptor byte */
+  unsigned int
+    bits_per_pixel,  /* (U8) Image pixel size */
+    attributes;      /* (U8) Image descriptor byte (see below) */
 } TGAInfo;
 
+/*
+  Image descriptor byte decode:
+
+  Bits 0 through 3 specify the number of attribute bits per pixel.
+
+  Bits 5 and 4 contain the image origin location.  These bits are used
+  to indicate the order in which pixel data is transferred from the
+  file to the screen.  Bit 4 is for left-to-right ordering, and bit 5
+  is for top-to-bottom ordering as shown below:
+
+    00 (0) - Bottom Left
+    10 (2) - Top Left
+    01 (1) - Bottom Right
+    11 (3) - Top Right
+
+    Screen destination  | Image Origin
+    of first pixel      | Bit 5 | Bit 4
+    --------------------+-------+------
+    Bottom left         |   0   |   0
+    Bottom right        |   0   |   1
+    Top left            |   1   |   0
+    Top right           |   1   |   1
+*/
+
 
-
 static void LogTGAInfo(const TGAInfo *tga_info)
 {
+  OrientationType orientation;
+  unsigned int attribute_bits;
+
+  attribute_bits = tga_info->attributes & 0xf;
+
+  switch((tga_info->attributes >> 4) & 3)
+    {
+    case 0:
+      orientation=BottomLeftOrientation;
+      break;
+    case 1:
+      orientation=BottomRightOrientation;
+      break;
+    case 2:
+      orientation=TopLeftOrientation;
+      break;
+    case 3:
+      orientation=TopRightOrientation;
+      break;
+    }
+
   (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                         "Targa Header:\n"
                         "    ImageType  : %s\n"
@@ -101,7 +146,7 @@
                         "    Width      : %u\n"
                         "    Height     : %u\n"
                         "    PixelDepth : %u\n"
-                        "    Attributes : 0x%.2x",
+                        "    Attributes : 0x%.2x (AttributeBits: %u, Orientation: %s)",
                         ((tga_info->image_type == TGAColormap) ? "Colormapped" :
                          (tga_info->image_type == TGARGB) ? "TrueColor" :
                          (tga_info->image_type == TGAMonochrome) ? "Monochrome" :
@@ -116,13 +161,13 @@
                         tga_info->x_origin, tga_info->y_origin,
                         tga_info->width, tga_info->height,
                         (unsigned int) tga_info->bits_per_pixel,
-                        tga_info->attributes);
+                        tga_info->attributes,attribute_bits,OrientationTypeToString(orientation));
 
 }
 
-static magick_uint16_t ReadBlobLSBShortFromBuffer(unsigned char* buffer, size_t* readerpos)
+static unsigned int ReadBlobLSBShortFromBuffer(unsigned char* buffer, size_t* readerpos)
 {
-  magick_uint16_t
+  unsigned int
     value;
 
   value=buffer[(*readerpos)+1] << 8;
@@ -132,12 +177,12 @@
 }
 
 
-static int ReadBlobByteFromBuffer(unsigned char* buffer, size_t* readerpos)
+static unsigned int ReadBlobByteFromBuffer(unsigned char* buffer, size_t* readerpos)
 {
-  int
+  unsigned int
     value;
 
-  value=(int)(buffer[*readerpos]);
+  value=(unsigned int)(buffer[*readerpos]);
   *readerpos = *readerpos + 1;
   return(value);
 }
@@ -458,7 +503,7 @@
       for (y=0; y < (long) image->rows; y++)
         {
           real=offset;
-          if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0)
+          if (((tga_info.attributes & 0x20) >> 5) == 0)
             real=image->rows-real-1;
           q=SetImagePixels(image,0,(long) real,image->columns,1);
           if (q == (PixelPacket *) NULL)
diff -r 2504f4ed1a52 -r 671a33015c59 magick/version.h
--- a/magick/version.h	Thu Aug 04 14:23:15 2022 -0500
+++ b/magick/version.h	Sat Aug 06 09:24:04 2022 -0500
@@ -38,8 +38,8 @@
 #define MagickLibVersion  0x272400
 #define MagickLibVersionText  "1.4"
 #define MagickLibVersionNumber 27,24,0
-#define MagickChangeDate   "20220804"
-#define MagickReleaseDate  "snapshot-20220804"
+#define MagickChangeDate   "20220806"
+#define MagickReleaseDate  "snapshot-20220806"
 
 /*
   The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r 2504f4ed1a52 -r 671a33015c59 www/Changelog.html
--- a/www/Changelog.html	Thu Aug 04 14:23:15 2022 -0500
+++ b/www/Changelog.html	Sat Aug 06 09:24:04 2022 -0500
@@ -35,6 +35,11 @@
 <div class="document">
 
 
+<p>2022-08-06  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
+<blockquote>
+* coders/tga.c: Enhance 'coder' level trace information.
+Normalize on 'unsigned int' as much as possible in order to use
+natural types and likely help with function inligning.</blockquote>
 <p>2022-08-04  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 * coders/tga.c (ReadTGAImage): Remove a defective validation of
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.