+/* Safety limit for the bitmap sizes */
+#define BM_MAX_WIDTH 4096U
+#define BM_MAX_HEIGHT 4096U
+
/* Safety limit for the size of the bitmap in pixels */
#define BM_MAX_SIZE 4194304UL
-/* Bitmap type */
-typedef enum BitmapType BitmapType;
-enum BitmapType {
- bmUnknown,
- bmMonochrome,
- bmIndexed,
- bmRGB,
- bmRGBA
-};
-
/* 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
- * a good idea.
- */
+ ** something that allows the user to identify which bitmap the message
+ ** refers to. For bitmaps loaded from a file, using the file name is
+ ** a good idea.
+ */
StrBuf Name;
- /* Pointer to some format specific data. May be used by the frontend.
- * The data is free'd as a block when calling FreeBitmap.
- */
- void* Tag;
-
/* Size of the 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 */
int ValidBitmapSize (unsigned Width, unsigned Height);
/* Return true if this is a valid size for a bitmap */
+Bitmap* SliceBitmap (const Bitmap* Original,
+ unsigned X, unsigned Y,
+ 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.
+*/
+
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.
+*/
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.
+*/
+
+#if defined(HAVE_INLINE)
+INLINE int BitmapIsIndexed (const Bitmap* B)
+/* Return true if this is an indexed bitmap */
+{
+ return (B->Pal != 0);
+}
+#else
+# define BitmapIsIndexed(B) ((B)->Pal != 0)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE unsigned GetBitmapWidth (const Bitmap* B)
+/* Get the width of a bitmap */
+{
+ return B->Width;
+}
+#else
+# define GetBitmapWidth(B) ((B)->Width)
+#endif
+#if defined(HAVE_INLINE)
+INLINE unsigned GetBitmapHeight (const Bitmap* B)
+/* Get the height of a bitmap */
+{
+ return B->Height;
+}
+#else
+# define GetBitmapHeight(B) ((B)->Height)
+#endif
+#if defined(HAVE_INLINE)
+INLINE const Palette* GetBitmapPalette (const Bitmap* B)
+/* Get the palette of a bitmap */
+{
+ return B->Pal;
+}
+#else
+# define GetBitmapPalette(B) ((B)->Pal)
+#endif
-/* End of bitmap.h */
+#if defined(HAVE_INLINE)
+INLINE const StrBuf* GetBitmapName (const Bitmap* B)
+/* Get the name of a bitmap */
+{
+ return &B->Name;
+}
+#else
+# define GetBitmapName(B) (&(B)->Name)
+#endif
+#if defined(HAVE_INLINE)
+INLINE 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.
+*/
+{
+ return B->Pal? B->Pal->Count : (1U << 24);
+}
+#else
+# define GetBitmapColors(B) ((B)->Pal? (B)->Pal->Count : (1U << 24))
#endif
+/* End of bitmap.h */
+
+#endif