]> git.sur5r.net Git - cc65/blob - src/sp65/bitmap.h
Remove the "Tag" field in struct Bitmap since it is of no real use.
[cc65] / src / sp65 / bitmap.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 bitmap.h                                  */
4 /*                                                                           */
5 /*         Bitmap definition for the sp65 sprite and bitmap utility          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2012,      Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef BITMAP_H
37 #define BITMAP_H
38
39
40
41 /* common */
42 #include "strbuf.h"
43
44 /* sp65 */
45 #include "palette.h"
46 #include "pixel.h"
47
48
49
50 /*****************************************************************************/
51 /*                                   Data                                    */
52 /*****************************************************************************/
53
54
55
56 /* Safety limit for the size of the bitmap in pixels */
57 #define BM_MAX_SIZE     4194304UL
58
59 /* Bitmap type */
60 enum BitmapType {
61     bmUnknown,
62     bmMonochrome,
63     bmIndexed,
64     bmRGB,
65     bmRGBA
66 };
67 typedef enum BitmapType BitmapType;
68
69 /* Bitmap structure */
70 typedef struct Bitmap Bitmap;
71 struct Bitmap {
72
73     /* Type of the bitmap */
74     BitmapType  Type;
75
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
79      * a good idea.
80      */
81     StrBuf      Name;
82
83     /* Size of the bitmap */
84     unsigned    Width;
85     unsigned    Height;
86
87     /* Palette for monochrome and indexed bitmap types, otherwise NULL */
88     Palette*    Pal;
89
90     /* Pixel data, dynamically allocated */
91     Pixel       Data[1];
92 };
93
94
95
96 /*****************************************************************************/
97 /*                                   Code                                    */
98 /*****************************************************************************/
99
100
101
102 Bitmap* NewBitmap (unsigned Width, unsigned Height);
103 /* Create a new bitmap. The type is set to unknown and the palette to NULL */
104
105 void FreeBitmap (Bitmap* B);
106 /* Free a dynamically allocated bitmap */
107
108 int ValidBitmapSize (unsigned Width, unsigned Height);
109 /* Return true if this is a valid size for a bitmap */
110
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
116  * upper left corner.
117  */
118
119 Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
120 /* Get the color for a given pixel. For indexed bitmaps, the palette entry
121  * is returned.
122  */
123
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.
127  */
128
129
130
131 /* End of bitmap.h */
132
133 #endif
134
135
136