Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:42

0001 #ifndef __XCB_PIXEL_H__
0002 #define __XCB_PIXEL_H__
0003 
0004 /* Copyright (C) 2007 Bart Massey
0005  *
0006  * Permission is hereby granted, free of charge, to any person obtaining a
0007  * copy of this software and associated documentation files (the "Software"),
0008  * to deal in the Software without restriction, including without limitation
0009  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0010  * and/or sell copies of the Software, and to permit persons to whom the
0011  * Software is furnished to do so, subject to the following conditions:
0012  * 
0013  * The above copyright notice and this permission notice shall be included in
0014  * all copies or substantial portions of the Software.
0015  * 
0016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0019  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0020  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0021  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0022  * 
0023  * Except as contained in this notice, the names of the authors or their
0024  * institutions shall not be used in advertising or otherwise to promote the
0025  * sale, use or other dealings in this Software without prior written
0026  * authorization from the authors.
0027  */
0028 
0029 #include <inttypes.h>
0030 #include <X11/Xfuncproto.h>
0031 #ifndef BUILD
0032 #include <xcb/xcb_bitops.h>
0033 #include <xcb/xcb_image.h>
0034 #endif
0035 
0036 /**
0037  * XCB Image fast pixel ops.
0038  *
0039  * Fast inline versions of xcb_image_get_pixel() and
0040  * xcb_image_put_pixel() for various common cases.
0041  * The naming convention is xcb_image_put_pixel_FUB()
0042  * where F is the format and is either XY for bitmaps
0043  * or Z for pixmaps, U is the bitmap unit size or pixmap
0044  * bits-per-pixel, and B is the endianness (if needed)
0045  * and is either M for most-significant-first or L for
0046  * least-significant-first.  Note that no checking
0047  * is done on the arguments to these routines---caller beware.
0048  * Also note that the pixel type is chosen to be appropriate
0049  * to the unit; bitmaps use int and pixmaps use the appropriate
0050  * size of unsigned.
0051  * @ingroup xcb__image_t
0052  */
0053 
0054 _X_INLINE static void
0055 xcb_image_put_pixel_XY32M (xcb_image_t *image,
0056               uint32_t x,
0057               uint32_t y,
0058               int pixel)
0059 {
0060   uint32_t   unit = (x >> 3) & ~xcb_mask(2);
0061   uint32_t   byte = xcb_mask(2) - ((x >> 3) & xcb_mask(2));
0062   uint32_t   bit = xcb_mask(3) - (x & xcb_mask(3));
0063   uint8_t    m = 1 << bit;
0064   uint8_t    p = pixel << bit;
0065   uint8_t *  bp = image->data + (y * image->stride) + (unit | byte);
0066   *bp = (*bp & ~m) | p;
0067 }
0068 
0069 _X_INLINE static void
0070 xcb_image_put_pixel_XY32L (xcb_image_t *image,
0071               uint32_t x,
0072               uint32_t y,
0073               int pixel)
0074 {
0075   uint32_t   bit = x & xcb_mask(3);
0076   uint8_t    m = 1 << bit;
0077   uint8_t    p = pixel << bit;
0078   uint8_t *  bp = image->data + (y * image->stride) + (x >> 3);
0079   *bp = (*bp & ~m) | p;
0080 }
0081 
0082 _X_INLINE static int
0083 xcb_image_get_pixel_XY32M (xcb_image_t *image,
0084               uint32_t x,
0085               uint32_t y)
0086 {
0087   uint32_t   unit = (x >> 3) & ~xcb_mask(2);
0088   uint32_t   byte = xcb_mask(2) - ((x >> 3) & xcb_mask(2));
0089   uint32_t   bit = xcb_mask(3) - (x & xcb_mask(3));
0090   uint8_t *  bp = image->data + (y * image->stride) + (unit | byte);
0091   return (*bp >> bit) & 1;
0092 }
0093 
0094 _X_INLINE static int
0095 xcb_image_get_pixel_XY32L (xcb_image_t *image,
0096               uint32_t x,
0097               uint32_t y)
0098 {
0099   uint32_t   bit = x & xcb_mask(3);
0100   uint8_t *  bp = image->data + (y * image->stride) + (x >> 3);
0101   return (*bp >> bit) & 1;
0102 }
0103 
0104 _X_INLINE static void
0105 xcb_image_put_pixel_Z8 (xcb_image_t *image,
0106             uint32_t x,
0107             uint32_t y,
0108             uint8_t pixel)
0109 {
0110   image->data[x + y * image->stride] = pixel;
0111 }
0112 
0113 _X_INLINE static uint8_t
0114 xcb_image_get_pixel_Z8 (xcb_image_t *image,
0115             uint32_t x,
0116             uint32_t y)
0117 {
0118   return image->data[x + y * image->stride];
0119 }
0120 
0121 _X_INLINE static void
0122 xcb_image_put_pixel_Z32M (xcb_image_t *image,
0123               uint32_t x,
0124               uint32_t y,
0125               uint32_t pixel)
0126 {
0127   uint8_t *  row = image->data + (y * image->stride);
0128   row[x << 2] = pixel >> 24;
0129   row[(x << 2) + 1] = pixel >> 16;
0130   row[(x << 2) + 2] = pixel >> 8;
0131   row[(x << 2) + 3] = pixel;
0132 }
0133 
0134 _X_INLINE static void
0135 xcb_image_put_pixel_Z32L (xcb_image_t *image,
0136               uint32_t x,
0137               uint32_t y,
0138               uint32_t pixel)
0139 {
0140   uint8_t *  row = image->data + (y * image->stride);
0141   row[x << 2] = pixel;
0142   row[(x << 2) + 1] = pixel >> 8;
0143   row[(x << 2) + 2] = pixel >> 16;
0144   row[(x << 2) + 3] = pixel >> 24;
0145 }
0146 
0147 _X_INLINE static uint32_t
0148 xcb_image_get_pixel_Z32M (xcb_image_t *image,
0149               uint32_t x,
0150               uint32_t y)
0151 {
0152   uint8_t *  row = image->data + (y * image->stride);
0153   uint32_t    pixel = row[x << 2] << 24;
0154   pixel |= row[(x << 2) + 1] << 16;
0155   pixel |= row[(x << 2) + 2] << 8;
0156   return pixel | row[(x << 2) + 3];
0157 }
0158 
0159 _X_INLINE static uint32_t
0160 xcb_image_get_pixel_Z32L (xcb_image_t *image,
0161               uint32_t x,
0162               uint32_t y)
0163 {
0164   uint8_t *  row = image->data + (y * image->stride);
0165   uint32_t    pixel = row[x << 2];
0166   pixel |= row[(x << 2) + 1] << 8;
0167   pixel |= row[(x << 2) + 2] << 16;
0168   return pixel | row[(x << 2) + 3] << 24;
0169 }
0170 
0171 #endif /* __XCB_PIXEL_H__ */