1 #ifndef __al_included_allegro5_aintern_bitmap_h
2 #define __al_included_allegro5_aintern_bitmap_h
3 
4 #include "allegro5/bitmap.h"
5 #include "allegro5/bitmap_lock.h"
6 #include "allegro5/display.h"
7 #include "allegro5/render_state.h"
8 #include "allegro5/transformations.h"
9 #include "allegro5/internal/aintern_display.h"
10 #include "allegro5/internal/aintern_list.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 typedef struct ALLEGRO_BITMAP_INTERFACE ALLEGRO_BITMAP_INTERFACE;
17 
18 struct ALLEGRO_BITMAP
19 {
20    ALLEGRO_BITMAP_INTERFACE *vt;
21 
22    /*
23     * When this is a sub-bitmap, these are inherited from the parent. Don't
24     * access them directly, but use al_get_bitmap_format/flags or
25     * _al_get_bitmap_display unless you are super sure this is not a sub-bitmap
26     * (e.g. when you're creating a new bitmap).
27     */
28    int _format;
29    int _flags;
30    int _depth;
31    int _samples;
32    ALLEGRO_DISPLAY *_display;
33    /* What format is used for the backing memory
34     * (can be different from _format, for e.g. compressed bitmaps) */
35    int _memory_format;
36 
37    int w, h;
38    /*
39     * The number of bytes between a pixel at (x,y) and (x,y+1).
40     * This is larger than w * pixel_size if there is padding between lines.
41     */
42    int pitch;
43    /*
44     * clip left, right, top, bottom
45     * Clip anything outside of this. cr/cb are exclusive, that is (0, 0, 1, 1)
46     * is the single pixel spawning a rectangle from floating point 0/0 to 1/1 -
47     * or in other words, the single pixel 0/0.
48     *
49     * There is always confusion as to whether cr/cb are exclusive, leading to
50     * subtle bugs.  The suffixes are supposed to help with that.
51     */
52    int cl;
53    int cr_excl;
54    int ct;
55    int cb_excl;
56    /*
57     * Locking info.
58     *
59     * These values represent the actual locking dimensions, which may be different
60     * from what was passed in to al_lock_bitmap_region. This is transparent to the
61     * user, but the internal drawing functions must take this into account. To
62     * that end, use this lock_data parameter value and NOT the one in locked_region.
63     *
64     * locked - locked or not?
65     * lock_x/y - top left of the locked region
66     * lock_w/h - width and height of the locked region
67     * lock_flags - flags the region was locked with
68     * lock_data - the pointer to the real locked data (see above)
69     * locked_region - a copy of the locked rectangle
70     */
71    bool locked;
72    int lock_x;
73    int lock_y;
74    int lock_w;
75    int lock_h;
76    void* lock_data;
77    int lock_flags;
78    ALLEGRO_LOCKED_REGION locked_region;
79 
80    /* Transformation for this bitmap */
81    ALLEGRO_TRANSFORM transform;
82    ALLEGRO_TRANSFORM inverse_transform;
83    bool              inverse_transform_dirty;
84    ALLEGRO_TRANSFORM proj_transform;
85 
86    /* Blender for this bitmap (if not set, use TLS) */
87    bool            use_bitmap_blender;
88    ALLEGRO_BLENDER blender;
89 
90    /* Shader applied to this bitmap.  Set this field with
91     * _al_set_bitmap_shader_field to maintain invariants.
92     */
93    ALLEGRO_SHADER *shader;
94 
95    /* Info for sub-bitmaps */
96    ALLEGRO_BITMAP *parent;
97    int xofs;
98    int yofs;
99 
100    /* A memory copy of the bitmap data. May be NULL for an empty bitmap. */
101    unsigned char *memory;
102 
103    /* Extra data for display bitmaps, like texture id and so on. */
104    void *extra;
105 
106    _AL_LIST_ITEM *dtor_item;
107 
108    /* set_target_bitmap and lock_bitmap mark bitmaps as dirty for preservation */
109    bool dirty;
110 };
111 
112 struct ALLEGRO_BITMAP_INTERFACE
113 {
114    int id;
115 
116    void (*draw_bitmap_region)(ALLEGRO_BITMAP *bitmap,
117       ALLEGRO_COLOR tint,float sx, float sy,
118       float sw, float sh, int flags);
119 
120    /* After the memory-copy of the bitmap has been modified, need to call this
121     * to update the display-specific copy. E.g. with an OpenGL driver, this
122     * might create/update a texture. Returns false on failure.
123     */
124    bool (*upload_bitmap)(ALLEGRO_BITMAP *bitmap);
125 
126    void (*update_clipping_rectangle)(ALLEGRO_BITMAP *bitmap);
127 
128    void (*destroy_bitmap)(ALLEGRO_BITMAP *bitmap);
129 
130    ALLEGRO_LOCKED_REGION * (*lock_region)(ALLEGRO_BITMAP *bitmap,
131       int x, int y, int w, int h, int format, int flags);
132 
133    void (*unlock_region)(ALLEGRO_BITMAP *bitmap);
134 
135    ALLEGRO_LOCKED_REGION * (*lock_compressed_region)(ALLEGRO_BITMAP *bitmap,
136       int x, int y, int w, int h, int flags);
137 
138    void (*unlock_compressed_region)(ALLEGRO_BITMAP *bitmap);
139 
140    /* Used to update any dangling pointers the bitmap driver might keep. */
141    void (*bitmap_pointer_changed)(ALLEGRO_BITMAP *bitmap, ALLEGRO_BITMAP *old);
142 
143    /* Back up texture to system RAM */
144    void (*backup_dirty_bitmap)(ALLEGRO_BITMAP *bitmap);
145 };
146 
147 ALLEGRO_BITMAP *_al_create_bitmap_params(ALLEGRO_DISPLAY *current_display,
148    int w, int h, int format, int flags, int depth, int samples);
149 
150 AL_FUNC(ALLEGRO_DISPLAY*, _al_get_bitmap_display, (ALLEGRO_BITMAP *bitmap));
151 
152 extern void (*_al_convert_funcs[ALLEGRO_NUM_PIXEL_FORMATS]
153    [ALLEGRO_NUM_PIXEL_FORMATS])(const void *, int, void *, int,
154    int, int, int, int, int, int);
155 
156 /* Bitmap conversion */
157 void _al_convert_bitmap_data(
158 	const void *src, int src_format, int src_pitch,
159 	void *dst, int dst_format, int dst_pitch,
160 	int sx, int sy, int dx, int dy,
161 	int width, int height);
162 
163 void _al_copy_bitmap_data(
164    const void *src, int src_pitch, void *dst, int dst_pitch,
165    int sx, int sy, int dx, int dy, int width, int height,
166    int format);
167 
168 /* Bitmap type conversion */
169 void _al_init_convert_bitmap_list(void);
170 void _al_register_convert_bitmap(ALLEGRO_BITMAP *bitmap);
171 void _al_unregister_convert_bitmap(ALLEGRO_BITMAP *bitmap);
172 void _al_convert_to_display_bitmap(ALLEGRO_BITMAP *bitmap);
173 void _al_convert_to_memory_bitmap(ALLEGRO_BITMAP *bitmap);
174 
175 /* Simple bitmap drawing */
176 void _al_put_pixel(ALLEGRO_BITMAP *bitmap, int x, int y, ALLEGRO_COLOR color);
177 
178 /* Bitmap I/O */
179 void _al_init_iio_table(void);
180 
181 
182 int _al_get_bitmap_memory_format(ALLEGRO_BITMAP *bitmap);
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif
189