]> git.sur5r.net Git - cc65/commitdiff
Remove the bitmap type since it is not really needed and complicate things.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 11:10:41 +0000 (11:10 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 11:10:41 +0000 (11:10 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5603 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/bitmap.c
src/sp65/bitmap.h
src/sp65/koala.c
src/sp65/palette.c
src/sp65/pcx.c
src/sp65/vic2sprite.c

index b00a01651b65c7aa022814923613d5ebaa21536f..e9fa676fb816f50251b38fd93abb423871861f80 100644 (file)
@@ -64,7 +64,6 @@ Bitmap* NewBitmap (unsigned Width, unsigned Height)
     B = xmalloc (sizeof (*B) + (Size - 1) * sizeof (B->Data[0]));
 
     /* Initialize the data */
-    B->Type     = bmUnknown;
     B->Name     = EmptyStrBuf;
     B->Width    = Width;
     B->Height   = Height;
@@ -120,7 +119,6 @@ Bitmap* SliceBitmap (const Bitmap* O, unsigned OrigX, unsigned OrigY,
     B = NewBitmap (Width, Height);
 
     /* Copy fields from the original */
-    B->Type = O->Type;
     if (SB_GetLen (&O->Name) > 0) {
         SB_CopyStr (&B->Name, "Slice of ");
         SB_Append (&B->Name, &O->Name);
@@ -185,15 +183,11 @@ unsigned GetBitmapColors (const Bitmap* B)
  * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
  */
 {
-    switch (B->Type) {
-        case bmMonochrome:      return 2;
-        case bmIndexed:         return B->Pal->Count;
-        case bmRGB:
-        case bmRGBA:            return (1U << 24);
-        default:                Internal ("Unknown bitmap type %u", B->Type);
+    if (B->Pal) {
+        return B->Pal->Count;
+    } else {
+        return (1U << 24);
     }
-    /* NOTREACHED */
-    return 0;
 }
 
 
index 5c111a27bb49b1a021fd63a21043c7449db201a4..d4e09e84d135e8c401c910e229e68216e31569c2 100644 (file)
 /* Safety limit for the size of the bitmap in pixels */
 #define BM_MAX_SIZE     4194304UL
 
-/* Bitmap type */
-enum BitmapType {
-    bmUnknown,
-    bmMonochrome,
-    bmIndexed,
-    bmRGB,
-    bmRGBA
-};
-typedef enum BitmapType BitmapType;
-
 /* Bitmap structure */
 typedef struct Bitmap Bitmap;
 struct Bitmap {
 
-    /* Type of the bitmap */
-    BitmapType  Type;
-
     /* Name of the bitmap. This is used for error messages and should be
      * something that allows the user to identify which bitmap the message
      * refers to. For bitmaps loaded from a file, using the file name is
@@ -88,7 +75,7 @@ struct Bitmap {
     unsigned    Width;
     unsigned    Height;
 
-    /* Palette for monochrome and indexed bitmap types, otherwise NULL */
+    /* Palette for indexed bitmap types, otherwise NULL */
     Palette*    Pal;
 
     /* Pixel data, dynamically allocated */
@@ -131,13 +118,13 @@ Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
  */
 
 #if defined(HAVE_INLINE)
-INLINE BitmapType GetBitmapType (const Bitmap* B)
-/* Get the type of a bitmap */
+INLINE int BitmapIsIndexed (const Bitmap* B)
+/* Return true if this is an indexed bitmap */
 {
-    return B->Type;
+    return (B->Pal != 0);
 }
 #else
-#  define GetBitmapType(B)      ((B)->Type)
+#  define BitmapIsIndexed(B)    ((B)->Pal != 0)
 #endif
 
 #if defined(HAVE_INLINE)
index 723cd0f5fef87a1818f0655a424ad60ba8d8a4e2..9212f97511b14c6ee5cf6aa049e874ba36c7fdb7 100644 (file)
@@ -71,7 +71,7 @@ StrBuf* GenKoala (const Bitmap* B, const Collection* A attribute ((unused)))
     unsigned char X, Y;
 
     /* Koala pictures are always 160x200 in size with 16 colors */
-    if (GetBitmapType (B)   != bmIndexed ||
+    if (!BitmapIsIndexed (B)             ||
         GetBitmapColors (B) > 16         ||
         GetBitmapHeight (B) != HEIGHT    ||
         GetBitmapWidth (B)  != WIDTH) {
index 4aa4e7036b575659a74d2c6e20eb99ff236d5111..afde3d7a24a1171c4a289ff843b689e291262954 100644 (file)
@@ -86,7 +86,12 @@ Palette* NewMonochromePalette (void)
 
 Palette* DupPalette (const Palette* P)
 /* Create a copy of a palette */
-{                                      
+{
+    /* Allow to pass a NULL palette */
+    if (P == 0) {
+        return 0;
+    }
+
     /* Create a new palette */
     Palette* N = NewPalette (P->Count);
 
index 7dc9d9c9b46bb1a2443822c8e8a8c89a2ecaea0a..51767c931127255fc77aec7080a07abf712ab996 100644 (file)
@@ -275,14 +275,6 @@ Bitmap* ReadPCXFile (const Collection* A)
     /* Create the bitmap */
     B = NewBitmap (P->Width, P->Height);
 
-    /* Determine the type of the bitmap */
-    switch (P->Planes) {
-        case 1: B->Type = (P->PalInfo? bmIndexed : bmMonochrome);       break;
-        case 3: B->Type = bmRGB;                                        break;
-        case 4: B->Type = bmRGBA;                                       break;
-        default:Internal ("Unexpected number of planes");
-    }
-
     /* Copy the name */
     SB_CopyStr (&B->Name, Name);
 
@@ -332,7 +324,75 @@ Bitmap* ReadPCXFile (const Collection* A)
                 }
             }
         }
+
+        /* One plane means we have a palette which is either part of the header
+         * or follows.
+         */
+        if (P->PalInfo == 0) {
+
+            /* Create the monochrome palette */
+            B->Pal = NewMonochromePalette ();
+
+        } else {
+
+            unsigned      Count;
+            unsigned      I;
+            unsigned char Palette[256][3];
+            unsigned long EndPos;
+
+            /* Determine the current file position */
+            unsigned long CurPos = FileGetPos (F);
+
+            /* Seek to the end of the file */
+            (void) fseek (F, 0, SEEK_END);
+
+            /* Get this position */
+            EndPos = FileGetPos (F);
+
+            /* There's a palette if the old location is 769 bytes from the end */
+            if (EndPos - CurPos == sizeof (Palette) + 1) {
+
+                /* Seek back */
+                FileSetPos (F, CurPos);
+
+                /* Check for palette marker */
+                if (Read8 (F) != 0x0C) {
+                    Error ("Invalid palette marker in PCX file `%s'", Name);
+                }
+
+            } else if (EndPos == CurPos) {
+
+                /* The palette is in the header */
+                FileSetPos (F, 16);
+
+                /* Check the maximum index for safety */
+                if (MaxIdx > 15) {
+                    Error ("PCX file `%s' contains more than 16 indexed colors "
+                           "but no extra palette", Name);
+                }
+
+            } else {
+                Error ("Error in PCX file `%s': %lu bytes at end of pixel data",
+                       Name, EndPos - CurPos);
+            }
+
+            /* Read the palette. We will just read what we need. */
+            Count = MaxIdx + 1;
+            ReadData (F, Palette, Count * sizeof (Palette[0]));
+
+            /* Create the palette from the data */
+            B->Pal = NewPalette (Count);
+            for (I = 0; I < Count; ++I) {
+                B->Pal->Entries[I].R = Palette[I][0];
+                B->Pal->Entries[I].G = Palette[I][1];
+                B->Pal->Entries[I].B = Palette[I][2];
+                B->Pal->Entries[I].A = 0;
+            }
+
+        }
+
     } else {
+
         /* 3 or 4 planes are RGB or RGBA (don't know if this exists) */
         for (Y = 0, Px = B->Data; Y < P->Height; ++Y) {
 
@@ -368,72 +428,6 @@ Bitmap* ReadPCXFile (const Collection* A)
         }
     }
 
-    /* One plane means we have a palette which is either part of the header
-     * or follows.
-     */
-    if (B->Type == bmMonochrome) {
-
-        /* Create the monochrome palette */
-        B->Pal = NewMonochromePalette ();
-
-    } else if (B->Type == bmIndexed) {
-
-        unsigned      Count;
-        unsigned      I;
-        unsigned char Palette[256][3];
-        unsigned long EndPos;
-
-        /* Determine the current file position */
-        unsigned long CurPos = FileGetPos (F);
-
-        /* Seek to the end of the file */
-        (void) fseek (F, 0, SEEK_END);
-
-        /* Get this position */
-        EndPos = FileGetPos (F);
-
-        /* There's a palette if the old location is 769 bytes from the end */
-        if (EndPos - CurPos == sizeof (Palette) + 1) {
-
-            /* Seek back */
-            FileSetPos (F, CurPos);
-
-            /* Check for palette marker */
-            if (Read8 (F) != 0x0C) {
-                Error ("Invalid palette marker in PCX file `%s'", Name);
-            }
-
-        } else if (EndPos == CurPos) {
-
-            /* The palette is in the header */
-            FileSetPos (F, 16);
-
-            /* Check the maximum index for safety */
-            if (MaxIdx > 15) {
-                Error ("PCX file `%s' contains more than 16 indexed colors "
-                       "but no extra palette", Name);
-            }
-
-        } else {
-            Error ("Error in PCX file `%s': %lu bytes at end of pixel data",
-                   Name, EndPos - CurPos);
-        }
-
-        /* Read the palette. We will just read what we need. */
-        Count = MaxIdx + 1;
-        ReadData (F, Palette, Count * sizeof (Palette[0]));
-
-        /* Create the palette from the data */
-        B->Pal = NewPalette (Count);
-        for (I = 0; I < Count; ++I) {
-            B->Pal->Entries[I].R = Palette[I][0];
-            B->Pal->Entries[I].G = Palette[I][1];
-            B->Pal->Entries[I].B = Palette[I][2];
-            B->Pal->Entries[I].A = 0;
-        }
-
-    }
-
     /* Close the file */
     fclose (F);
 
index 371b9616bdeaffdbb6f06294fc3a05a706939921..bc4de4bf775bdf347b30674fccd65b1140825725 100644 (file)
@@ -74,10 +74,10 @@ StrBuf* GenVic2Sprite (const Bitmap* B, const Collection* A attribute ((unused))
     /* Output the image properties */
     Print (stdout, 1, "Image is %ux%u with %u colors%s\n",
            GetBitmapWidth (B), GetBitmapHeight (B), GetBitmapColors (B),
-           (GetBitmapType (B) == bmIndexed)? " (indexed)" : "");
+           BitmapIsIndexed (B)? " (indexed)" : "");
 
     /* Sprites pictures are always 24x21 in size with 2 colors */
-    if (GetBitmapType (B)   != bmIndexed ||
+    if (!BitmapIsIndexed (B)             ||
         GetBitmapColors (B) != 2         ||
         GetBitmapHeight (B) != HEIGHT    ||
         GetBitmapWidth (B)  != WIDTH) {