]> git.sur5r.net Git - cc65/blobdiff - src/sp65/bitmap.c
Remove the bitmap type since it is not really needed and complicate things.
[cc65] / src / sp65 / bitmap.c
index 28757a4aa003fab50c042d8379307ef81ef4b451..e9fa676fb816f50251b38fd93abb423871861f80 100644 (file)
@@ -64,9 +64,7 @@ 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->Tag      = 0;
     B->Width    = Width;
     B->Height   = Height;
     B->Pal      = 0;
@@ -80,10 +78,13 @@ Bitmap* NewBitmap (unsigned Width, unsigned Height)
 void FreeBitmap (Bitmap* B)
 /* Free a dynamically allocated bitmap */
 {
-    /* Free the format specific data, the palette and then the bitmap */
-    xfree (B->Tag);
-    xfree (B->Pal);
-    xfree(B);
+    /* Alloc NULL pointers */
+    if (B != 0) {
+        /* Free name, palette and then the bitmap */
+        SB_Done (&B->Name);
+        xfree (B->Pal);
+        xfree(B);
+    }
 }
 
 
@@ -112,15 +113,12 @@ Bitmap* SliceBitmap (const Bitmap* O, unsigned OrigX, unsigned OrigY,
 
 
     /* Check the coordinates and size */
-    PRECONDITION (OrigX != 0 && OrigY != 0 &&
-                  OrigX + Width <= O->Width &&
-                  OrigY + Height <= O->Height);
+    PRECONDITION (OrigX + Width <= O->Width && OrigY + Height <= O->Height);
 
     /* Create a new bitmap with the given size */
     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);
@@ -180,3 +178,17 @@ Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y)
 
 
 
+unsigned GetBitmapColors (const Bitmap* B)
+/* Get the number of colors in an image. The function will return the number
+ * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
+ */
+{
+    if (B->Pal) {
+        return B->Pal->Count;
+    } else {
+        return (1U << 24);
+    }
+}
+
+
+