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;
Bitmap* SliceBitmap (const Bitmap* O, unsigned OrigX, unsigned OrigY,
unsigned Width, unsigned Height)
/* Create a slice of the given bitmap. The slice starts at position X/Y of
- * the original and has the given width and height. Location 0/0 is at the
- * upper left corner.
- */
+** the original and has the given width and height. Location 0/0 is at the
+** upper left corner.
+*/
{
Bitmap* B;
unsigned Y;
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);
Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y)
/* Get the color for a given pixel. For indexed bitmaps, the palette entry
- * is returned.
- */
+** is returned.
+*/
{
/* Get the pixel at the given coordinates */
Pixel P = GetPixel (B, X, Y);
/* If the bitmap has a palette, return the color from the palette. For
- * simplicity, we will only check the palette, not the type.
- */
+ ** simplicity, we will only check the palette, not the type.
+ */
if (B->Pal) {
if (P.Index >= B->Pal->Count) {
/* Palette index is invalid */
Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y)
/* Return a pixel from the bitmap. The returned value may either be a color
- * or a palette index, depending on the type of the bitmap.
- */
+** or a palette index, depending on the type of the bitmap.
+*/
{
/* Check the coordinates */
PRECONDITION (X < B->Width && Y < B->Height);
/* Return the pixel */
return B->Data[Y * B->Width + X];
}
-
-
-
-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.
- */
-{
- 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);
- }
- /* NOTREACHED */
- return 0;
-}
-
-
-