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
71 typedef enum BitmapType BitmapType;
73 /* Bitmap structure */
74 typedef struct Bitmap Bitmap;
77 /* Type of the bitmap */
80 /* Name of the bitmap. This is used for error messages and should be
81 * something that allows the user to identify which bitmap the message
82 * refers to. For bitmaps loaded from a file, using the file name is
87 /* Size of the bitmap */
91 /* Palette for monochrome and indexed bitmap types, otherwise NULL */
94 /* Pixel data, dynamically allocated */
100 /*****************************************************************************/
102 /*****************************************************************************/
106 Bitmap* NewBitmap (unsigned Width, unsigned Height);
107 /* Create a new bitmap. The type is set to unknown and the palette to NULL */
109 void FreeBitmap (Bitmap* B);
110 /* Free a dynamically allocated bitmap */
112 int ValidBitmapSize (unsigned Width, unsigned Height);
113 /* Return true if this is a valid size for a bitmap */
115 Bitmap* SliceBitmap (const Bitmap* Original,
116 unsigned X, unsigned Y,
117 unsigned Width, unsigned Height);
118 /* Create a slice of the given bitmap. The slice starts at position X/Y of
119 * the original and has the given width and height. Location 0/0 is at the
123 Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
124 /* Get the color for a given pixel. For indexed bitmaps, the palette entry
128 Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
129 /* Return a pixel from the bitmap. The returned value may either be a color
130 * or a palette index, depending on the type of the bitmap.
133 #if defined(HAVE_INLINE)
134 INLINE BitmapType GetBitmapType (const Bitmap* B)
135 /* Get the type of a bitmap */
140 # define GetBitmapType(B) ((B)->Type)
143 #if defined(HAVE_INLINE)
144 INLINE unsigned GetBitmapWidth (const Bitmap* B)
145 /* Get the width of a bitmap */
150 # define GetBitmapWidth(B) ((B)->Width)
153 #if defined(HAVE_INLINE)
154 INLINE unsigned GetBitmapHeight (const Bitmap* B)
155 /* Get the height of a bitmap */
160 # define GetBitmapHeight(B) ((B)->Height)
163 unsigned GetBitmapColors (const Bitmap* B);
164 /* Get the number of colors in an image. The function will return the number
165 * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
170 /* End of bitmap.h */