File indexing completed on 2025-01-18 10:14:42
0001 #ifndef __XCB_PIXEL_H__
0002 #define __XCB_PIXEL_H__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
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
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
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