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;
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);
+ }
}
/* 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);
+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);
+ }
+}
+
+
+