1 /*****************************************************************************/
5 /* Bitmap definition for the sp65 sprite and bitmap utility */
9 /* (C) 2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
50 /*****************************************************************************/
52 /*****************************************************************************/
56 /* Safety limit for the bitmap sizes */
57 #define BM_MAX_WIDTH 4096U
58 #define BM_MAX_HEIGHT 4096U
60 /* Safety limit for the size of the bitmap in pixels */
61 #define BM_MAX_SIZE 4194304UL
63 /* Bitmap structure */
64 typedef struct Bitmap Bitmap;
67 /* Name of the bitmap. This is used for error messages and should be
68 * something that allows the user to identify which bitmap the message
69 * refers to. For bitmaps loaded from a file, using the file name is
74 /* Size of the bitmap */
78 /* Palette for indexed bitmap types, otherwise NULL */
81 /* Pixel data, dynamically allocated */
87 /*****************************************************************************/
89 /*****************************************************************************/
93 Bitmap* NewBitmap (unsigned Width, unsigned Height);
94 /* Create a new bitmap. The type is set to unknown and the palette to NULL */
96 void FreeBitmap (Bitmap* B);
97 /* Free a dynamically allocated bitmap */
99 int ValidBitmapSize (unsigned Width, unsigned Height);
100 /* Return true if this is a valid size for a bitmap */
102 Bitmap* SliceBitmap (const Bitmap* Original,
103 unsigned X, unsigned Y,
104 unsigned Width, unsigned Height);
105 /* Create a slice of the given bitmap. The slice starts at position X/Y of
106 * the original and has the given width and height. Location 0/0 is at the
110 Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
111 /* Get the color for a given pixel. For indexed bitmaps, the palette entry
115 Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
116 /* Return a pixel from the bitmap. The returned value may either be a color
117 * or a palette index, depending on the type of the bitmap.
120 #if defined(HAVE_INLINE)
121 INLINE int BitmapIsIndexed (const Bitmap* B)
122 /* Return true if this is an indexed bitmap */
124 return (B->Pal != 0);
127 # define BitmapIsIndexed(B) ((B)->Pal != 0)
130 #if defined(HAVE_INLINE)
131 INLINE unsigned GetBitmapWidth (const Bitmap* B)
132 /* Get the width of a bitmap */
137 # define GetBitmapWidth(B) ((B)->Width)
140 #if defined(HAVE_INLINE)
141 INLINE unsigned GetBitmapHeight (const Bitmap* B)
142 /* Get the height of a bitmap */
147 # define GetBitmapHeight(B) ((B)->Height)
150 #if defined(HAVE_INLINE)
151 INLINE const Palette* GetBitmapPalette (const Bitmap* B)
152 /* Get the palette of a bitmap */
157 # define GetBitmapPalette(B) ((B)->Pal)
160 #if defined(HAVE_INLINE)
161 INLINE const StrBuf* GetBitmapName (const Bitmap* B)
162 /* Get the name of a bitmap */
167 # define GetBitmapName(B) (&(B)->Name)
170 #if defined(HAVE_INLINE)
171 INLINE unsigned GetBitmapColors (const Bitmap* B)
172 /* Get the number of colors in an image. The function will return the number
173 * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
176 return B->Pal? B->Pal->Count : (1U << 24);
179 # define GetBitmapColors(B) ((B)->Pal? (B)->Pal->Count : (1U << 24))
184 /* End of bitmap.h */