wip prep commit in lieu of gfx subsystem update changes.
[AROS.git] / workbench / libs / cgfx / lockbitmaptaglist.c
blob30c3db952ab75e8b55093efd8b5a8cddb05acb2a
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <hidd/gfx.h>
12 #include <proto/oop.h>
13 #include <proto/utility.h>
15 #include "cybergraphics_intern.h"
16 #include "gfxfuncsupport.h"
18 /*****************************************************************************
20 NAME */
21 #include <proto/cybergraphics.h>
23 AROS_LH2(APTR, LockBitMapTagList,
25 /* SYNOPSIS */
26 AROS_LHA(APTR , bitmap, A0),
27 AROS_LHA(struct TagItem *, tags, A1),
29 /* LOCATION */
30 struct Library *, CyberGfxBase, 28, Cybergraphics)
32 /* FUNCTION
33 Obtains exclusive access to a bitmap in preparation for direct access
34 to its pixel data. Direct access to a bitmap should only be done in
35 exceptional cases, and the locking period should be limited to at most
36 one frame.
38 A taglist is passed in that contains pointers to variables in which to
39 store the information necessary to directly access the bitmap. The
40 tags used are as follows:
41 LBMI_WIDTH (ULONG *) - the bitmap's width.
42 LBMI_HEIGHT (ULONG *) - the bitmap's height.
43 LBMI_DEPTH (ULONG *) - the bitmap's depth.
44 LBMI_PIXFMT (ULONG *) - the bitmap's pixel format.
45 LBMI_BYTESPERPIX (ULONG *) - the number of bytes per pixel.
46 LBMI_BYTESPERROW (ULONG *) - the number of bytes per row.
47 LBMI_BASEADDRESS (APTR *) - the start address of the pixel data.
49 The value returned for LBMI_PIXFMT will be one of the following
50 constants:
51 PIXFMT_RGB24 - 3 bytes per pixel: 1 byte per component, in
52 the order red, green, blue.
53 PIXFMT_RGBA32 - 4 bytes per pixel: 1 byte per component, in
54 the order red, green, blue, alpha.
55 PIXFMT_ARGB32 - 4 bytes per pixel: 1 byte per component, in
56 the order alpha, red, green, blue.
57 PIXFMT_LUT8 - 1 byte per pixel: each byte is a pen number
58 rather than a direct colour value.
59 PIXFMT_RGB15 - 2 bytes per pixel: one unused bit, then 5 bits
60 per component, in the order red, green, blue.
61 PIXFMT_BGR15 - 2 bytes per pixel: 1 unused bit, then 5 bits
62 per component, in the order blue, green, red.
63 PIXFMT_RGB15PC - 2 bytes per pixel, accessed as a little
64 endian value: 1 unused bit, then 5 bits per component, in
65 the order red, green, blue.
66 PIXFMT_BGR15PC - 2 bytes per pixel, accessed as a little
67 endian value: 1 unused bit, then 5 bits per component, in
68 the order blue, green, red.
69 PIXFMT_RGB16 - 2 bytes per pixel: 5 bits for red, then 6 bits
70 for green, then 5 bits for blue.
71 PIXFMT_BGR16 - 2 bytes per pixel: 5 bits for blue, then 6 bits
72 for green, then 5 bits for red.
73 PIXFMT_RGB16PC - 2 bytes per pixel, accessed as a little
74 endian value: 5 bits for red, then 6 bits for green, then
75 5 bits for blue.
76 PIXFMT_BGR16PC - 2 bytes per pixel, accessed as a little
77 endian value: 5 bits for blue, then 6 bits for green, then
78 5 bits for red.
79 PIXFMT_BGR24 - 3 bytes per pixel: 1 byte per component, in
80 the order blue, green, red.
81 PIXFMT_BGRA32 - 4 bytes per pixel: 1 byte per component, in
82 the order blue, green, red, alpha.
83 PIXFMT_ABGR32 - 4 bytes per pixel: 1 byte per component, in
84 the order alpha, blue, green, red (AROS extension).
85 PIXFMT_0RGB32 - 4 bytes per pixel: 1 unused byte, then 1 byte
86 per component, in the order red, green, blue (AROS
87 extension).
88 PIXFMT_BGR032 - 4 bytes per pixel: 1 byte per component, in
89 the order blue, green, red, followed by 1 unused byte
90 (AROS extension).
91 PIXFMT_RGB032 - 4 bytes per pixel: 1 byte per component, in
92 the order red, green, blue, followed by 1 unused byte
93 (AROS extension).
94 PIXFMT_0BGR32 - 4 bytes per pixel: 1 unused byte, then 1 byte
95 per component, in the order blue, green, red (AROS
96 extension).
98 INPUTS
99 bitmap - the bitmap to lock.
100 tags - a taglist that will be filled with information necessary to
101 directly access the bitmap.
103 RESULT
104 handle - a handle to be passed to UnLockBitMap() or
105 UnLockBitMapTagList(), or NULL for failure.
107 NOTES
108 While the bitmap is locked, no cybergraphics.library or
109 graphics.library related functions should be called (except to unlock
110 it).
112 EXAMPLE
114 BUGS
116 SEE ALSO
117 UnLockBitMap(), UnLockBitMapTagList()
119 INTERNALS
121 *****************************************************************************/
123 AROS_LIBFUNC_INIT
125 struct BitMap *bm = bitmap;
126 struct TagItem *tag;
127 UBYTE *baseaddress;
128 ULONG width, height, banksize, memsize;
129 OOP_Object *pf;
130 IPTR cpf;
132 if (!IS_HIDD_BM(bm))
134 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-HIDD BM !!!\n"));
135 return NULL;
138 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_PixFmt, (IPTR *)&pf);
139 OOP_GetAttr(pf, aHidd_PixFmt_CgxPixFmt, &cpf);
140 if (-1 == cpf)
142 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-CYBER PIXFMT BITMAP !!!\n"));
143 return NULL;
146 /* Get some info from the bitmap object */
147 if (!HIDD_BM_ObtainDirectAccess(HIDD_BM_OBJ(bm), &baseaddress, &width, &height, &banksize, &memsize)) {
148 D(bug("!!! CAN'T HIDD_BM_ObtainDirectAccess() on the object\n"));
149 return NULL;
152 while ((tag = NextTagItem(&tags)))
154 switch (tag->ti_Tag)
156 case LBMI_BASEADDRESS:
157 *((IPTR **)tag->ti_Data) = (IPTR *)baseaddress;
158 break;
160 case LBMI_BYTESPERROW:
161 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_BytesPerRow, (IPTR *)tag->ti_Data);
162 break;
164 case LBMI_BYTESPERPIX:
165 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, (IPTR *)tag->ti_Data);
166 break;
168 case LBMI_PIXFMT:
169 *((IPTR *)tag->ti_Data) = (IPTR)cpf;
170 break;
172 case LBMI_DEPTH:
173 OOP_GetAttr(pf, aHidd_PixFmt_Depth, (IPTR *)tag->ti_Data);
174 break;
176 case LBMI_WIDTH:
177 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Width, (IPTR *)tag->ti_Data);
178 break;
180 case LBMI_HEIGHT:
181 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Height, (IPTR *)tag->ti_Data);
182 break;
184 default:
185 D(bug("!!! UNKNOWN TAG PASSED TO LockBitMapTagList() !!!\n"));
186 break;
190 return bm;
192 AROS_LIBFUNC_EXIT
193 } /* LockBitMapTagList */