1 #ifndef __XCB_PIXEL_H__
2 #define __XCB_PIXEL_H__
4 /* Copyright (C) 2007 Bart Massey
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Except as contained in this notice, the names of the authors or their
24 * institutions shall not be used in advertising or otherwise to promote the
25 * sale, use or other dealings in this Software without prior written
26 * authorization from the authors.
30 #include <X11/Xfuncproto.h>
32 #include <xcb/xcb_bitops.h>
33 #include <xcb/xcb_image.h>
37 * XCB Image fast pixel ops.
39 * Fast inline versions of xcb_image_get_pixel() and
40 * xcb_image_put_pixel() for various common cases.
41 * The naming convention is xcb_image_put_pixel_FUB()
42 * where F is the format and is either XY for bitmaps
43 * or Z for pixmaps, U is the bitmap unit size or pixmap
44 * bits-per-pixel, and B is the endianness (if needed)
45 * and is either M for most-significant-first or L for
46 * least-significant-first. Note that no checking
47 * is done on the arguments to these routines---caller beware.
48 * Also note that the pixel type is chosen to be appropriate
49 * to the unit; bitmaps use int and pixmaps use the appropriate
51 * @ingroup xcb__image_t
55 xcb_image_put_pixel_XY32M (xcb_image_t *image,
60 uint32_t unit = (x >> 3) & ~xcb_mask(2);
61 uint32_t byte = xcb_mask(2) - ((x >> 3) & xcb_mask(2));
62 uint32_t bit = xcb_mask(3) - (x & xcb_mask(3));
64 uint8_t p = pixel << bit;
65 uint8_t * bp = image->data + (y * image->stride) + (unit | byte);
70 xcb_image_put_pixel_XY32L (xcb_image_t *image,
75 uint32_t bit = x & xcb_mask(3);
77 uint8_t p = pixel << bit;
78 uint8_t * bp = image->data + (y * image->stride) + (x >> 3);
83 xcb_image_get_pixel_XY32M (xcb_image_t *image,
87 uint32_t unit = (x >> 3) & ~xcb_mask(2);
88 uint32_t byte = xcb_mask(2) - ((x >> 3) & xcb_mask(2));
89 uint32_t bit = xcb_mask(3) - (x & xcb_mask(3));
90 uint8_t * bp = image->data + (y * image->stride) + (unit | byte);
91 return (*bp >> bit) & 1;
95 xcb_image_get_pixel_XY32L (xcb_image_t *image,
99 uint32_t bit = x & xcb_mask(3);
100 uint8_t * bp = image->data + (y * image->stride) + (x >> 3);
101 return (*bp >> bit) & 1;
104 _X_INLINE static void
105 xcb_image_put_pixel_Z8 (xcb_image_t *image,
110 image->data[x + y * image->stride] = pixel;
113 _X_INLINE static uint8_t
114 xcb_image_get_pixel_Z8 (xcb_image_t *image,
118 return image->data[x + y * image->stride];
121 _X_INLINE static void
122 xcb_image_put_pixel_Z32M (xcb_image_t *image,
127 uint8_t * row = image->data + (y * image->stride);
128 row[x << 2] = pixel >> 24;
129 row[(x << 2) + 1] = pixel >> 16;
130 row[(x << 2) + 2] = pixel >> 8;
131 row[(x << 2) + 3] = pixel;
134 _X_INLINE static void
135 xcb_image_put_pixel_Z32L (xcb_image_t *image,
140 uint8_t * row = image->data + (y * image->stride);
142 row[(x << 2) + 1] = pixel >> 8;
143 row[(x << 2) + 2] = pixel >> 16;
144 row[(x << 2) + 3] = pixel >> 24;
147 _X_INLINE static uint32_t
148 xcb_image_get_pixel_Z32M (xcb_image_t *image,
152 uint8_t * row = image->data + (y * image->stride);
153 uint32_t pixel = row[x << 2] << 24;
154 pixel |= row[(x << 2) + 1] << 16;
155 pixel |= row[(x << 2) + 2] << 8;
156 return pixel | row[(x << 2) + 3];
159 _X_INLINE static uint32_t
160 xcb_image_get_pixel_Z32L (xcb_image_t *image,
164 uint8_t * row = image->data + (y * image->stride);
165 uint32_t pixel = row[x << 2];
166 pixel |= row[(x << 2) + 1] << 8;
167 pixel |= row[(x << 2) + 2] << 16;
168 return pixel | row[(x << 2) + 3] << 24;
171 #endif /* __XCB_PIXEL_H__ */