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 size of the bitmap in pixels */
57 #define BM_MAX_SIZE 4194304UL
67 typedef enum BitmapType BitmapType;
69 /* Bitmap structure */
70 typedef struct Bitmap Bitmap;
73 /* Type of the bitmap */
76 /* Name of the bitmap. This is used for error messages and should be
77 * something that allows the user to identify which bitmap the message
78 * refers to. For bitmaps loaded from a file, using the file name is
83 /* Size of the bitmap */
87 /* Palette for monochrome and indexed bitmap types, otherwise NULL */
90 /* Pixel data, dynamically allocated */
96 /*****************************************************************************/
98 /*****************************************************************************/
102 Bitmap* NewBitmap (unsigned Width, unsigned Height);
103 /* Create a new bitmap. The type is set to unknown and the palette to NULL */
105 void FreeBitmap (Bitmap* B);
106 /* Free a dynamically allocated bitmap */
108 int ValidBitmapSize (unsigned Width, unsigned Height);
109 /* Return true if this is a valid size for a bitmap */
111 Bitmap* SliceBitmap (const Bitmap* Original,
112 unsigned X, unsigned Y,
113 unsigned Width, unsigned Height);
114 /* Create a slice of the given bitmap. The slice starts at position X/Y of
115 * the original and has the given width and height. Location 0/0 is at the
119 Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
120 /* Get the color for a given pixel. For indexed bitmaps, the palette entry
124 Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
125 /* Return a pixel from the bitmap. The returned value may either be a color
126 * or a palette index, depending on the type of the bitmap.
129 #if defined(HAVE_INLINE)
130 INLINE BitmapType GetBitmapType (const Bitmap* B)
131 /* Get the type of a bitmap */
136 # define GetBitmapType(B) ((B)->Type)
139 #if defined(HAVE_INLINE)
140 INLINE unsigned GetBitmapWidth (const Bitmap* B)
141 /* Get the width of a bitmap */
146 # define GetBitmapWidth(B) ((B)->Width)
149 #if defined(HAVE_INLINE)
150 INLINE unsigned GetBitmapHeight (const Bitmap* B)
151 /* Get the height of a bitmap */
156 # define GetBitmapHeight(B) ((B)->Height)
159 unsigned GetBitmapColors (const Bitmap* B);
160 /* Get the number of colors in an image. The function will return the number
161 * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps.
166 /* End of bitmap.h */