]> git.sur5r.net Git - cc65/blob - src/sp65/bitmap.h
New function to create a bitmap slice.
[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 typedef enum BitmapType BitmapType;
61 enum BitmapType {
62     bmUnknown,
63     bmMonochrome,
64     bmIndexed,
65     bmRGB,
66     bmRGBA
67 };
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     /* Pointer to some format specific data. May be used by the frontend.
84      * The data is free'd as a block when calling FreeBitmap.
85      */
86     void*       Tag;
87
88     /* Size of the bitmap */
89     unsigned    Width;
90     unsigned    Height;
91
92     /* Palette for monochrome and indexed bitmap types, otherwise NULL */
93     Palette*    Pal;
94
95     /* Pixel data, dynamically allocated */
96     Pixel       Data[1];
97 };
98
99
100
101 /*****************************************************************************/
102 /*                                   Code                                    */
103 /*****************************************************************************/
104
105
106
107 Bitmap* NewBitmap (unsigned Width, unsigned Height);
108 /* Create a new bitmap. The type is set to unknown and the palette to NULL */
109
110 void FreeBitmap (Bitmap* B);
111 /* Free a dynamically allocated bitmap */
112
113 int ValidBitmapSize (unsigned Width, unsigned Height);
114 /* Return true if this is a valid size for a bitmap */
115
116 Bitmap* SliceBitmap (const Bitmap* Original,
117                      unsigned X, unsigned Y,
118                      unsigned Width, unsigned Height);
119 /* Create a slice of the given bitmap. The slice starts at position X/Y of
120  * the original and has the given width and height. Location 0/0 is at the
121  * upper left corner.
122  */
123
124 Color GetPixelColor (const Bitmap* B, unsigned X, unsigned Y);
125 /* Get the color for a given pixel. For indexed bitmaps, the palette entry
126  * is returned.
127  */
128
129 Pixel GetPixel (const Bitmap* B, unsigned X, unsigned Y);
130 /* Return a pixel from the bitmap. The returned value may either be a color
131  * or a palette index, depending on the type of the bitmap.
132  */
133
134
135
136 /* End of bitmap.h */
137
138 #endif
139
140
141