| 1 | #ifndef __XCB_PIXEL_H__ |
| 2 | #define __XCB_PIXEL_H__ |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | #include <inttypes.h> |
| 30 | #include <X11/Xfuncproto.h> |
| 31 | #ifndef BUILD |
| 32 | #include <xcb/xcb_bitops.h> |
| 33 | #include <xcb/xcb_image.h> |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | _X_INLINE static void |
| 55 | xcb_image_put_pixel_XY32M (xcb_image_t *image, |
| 56 | uint32_t x, |
| 57 | uint32_t y, |
| 58 | int pixel) |
| 59 | { |
| 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)); |
| 63 | uint8_t m = 1 << bit; |
| 64 | uint8_t p = pixel << bit; |
| 65 | uint8_t * bp = image->data + (y * image->stride) + (unit | byte); |
| 66 | *bp = (*bp & ~m) | p; |
| 67 | } |
| 68 | |
| 69 | _X_INLINE static void |
| 70 | xcb_image_put_pixel_XY32L (xcb_image_t *image, |
| 71 | uint32_t x, |
| 72 | uint32_t y, |
| 73 | int pixel) |
| 74 | { |
| 75 | uint32_t bit = x & xcb_mask(3); |
| 76 | uint8_t m = 1 << bit; |
| 77 | uint8_t p = pixel << bit; |
| 78 | uint8_t * bp = image->data + (y * image->stride) + (x >> 3); |
| 79 | *bp = (*bp & ~m) | p; |
| 80 | } |
| 81 | |
| 82 | _X_INLINE static int |
| 83 | xcb_image_get_pixel_XY32M (xcb_image_t *image, |
| 84 | uint32_t x, |
| 85 | uint32_t y) |
| 86 | { |
| 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; |
| 92 | } |
| 93 | |
| 94 | _X_INLINE static int |
| 95 | xcb_image_get_pixel_XY32L (xcb_image_t *image, |
| 96 | uint32_t x, |
| 97 | uint32_t y) |
| 98 | { |
| 99 | uint32_t bit = x & xcb_mask(3); |
| 100 | uint8_t * bp = image->data + (y * image->stride) + (x >> 3); |
| 101 | return (*bp >> bit) & 1; |
| 102 | } |
| 103 | |
| 104 | _X_INLINE static void |
| 105 | xcb_image_put_pixel_Z8 (xcb_image_t *image, |
| 106 | uint32_t x, |
| 107 | uint32_t y, |
| 108 | uint8_t pixel) |
| 109 | { |
| 110 | image->data[x + y * image->stride] = pixel; |
| 111 | } |
| 112 | |
| 113 | _X_INLINE static uint8_t |
| 114 | xcb_image_get_pixel_Z8 (xcb_image_t *image, |
| 115 | uint32_t x, |
| 116 | uint32_t y) |
| 117 | { |
| 118 | return image->data[x + y * image->stride]; |
| 119 | } |
| 120 | |
| 121 | _X_INLINE static void |
| 122 | xcb_image_put_pixel_Z32M (xcb_image_t *image, |
| 123 | uint32_t x, |
| 124 | uint32_t y, |
| 125 | uint32_t pixel) |
| 126 | { |
| 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; |
| 132 | } |
| 133 | |
| 134 | _X_INLINE static void |
| 135 | xcb_image_put_pixel_Z32L (xcb_image_t *image, |
| 136 | uint32_t x, |
| 137 | uint32_t y, |
| 138 | uint32_t pixel) |
| 139 | { |
| 140 | uint8_t * row = image->data + (y * image->stride); |
| 141 | row[x << 2] = pixel; |
| 142 | row[(x << 2) + 1] = pixel >> 8; |
| 143 | row[(x << 2) + 2] = pixel >> 16; |
| 144 | row[(x << 2) + 3] = pixel >> 24; |
| 145 | } |
| 146 | |
| 147 | _X_INLINE static uint32_t |
| 148 | xcb_image_get_pixel_Z32M (xcb_image_t *image, |
| 149 | uint32_t x, |
| 150 | uint32_t y) |
| 151 | { |
| 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]; |
| 157 | } |
| 158 | |
| 159 | _X_INLINE static uint32_t |
| 160 | xcb_image_get_pixel_Z32L (xcb_image_t *image, |
| 161 | uint32_t x, |
| 162 | uint32_t y) |
| 163 | { |
| 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; |
| 169 | } |
| 170 | |
| 171 | #endif |