rc_pixel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #ifndef RC_PIXEL_H
00034 #define RC_PIXEL_H
00035
00036 #include <stdint.h>
00037 #include "rc_platform.h"
00038
00042 #define RC_PIXEL_GET_IDX(dim, off, x, y) \
00043 ((int)(y)*(int)(dim) + (((int)(x) + (int)(off)) >> 3))
00044
00048 #ifdef RC_BIG_ENDIAN
00049 #define RC_PIXEL_GET_BIT(dim, off, x) \
00050 (7 - (((int)(x) + (int)(off)) & 7))
00051 #else
00052 #define RC_PIXEL_GET_BIT(dim, off, x) \
00053 (((int)(x) + (int)(off)) & 7)
00054 #endif
00055
00059 #define RC_PIXEL_GET_BIN(buf, dim, off, x, y) \
00060 ((((const uint8_t*)(buf))[RC_PIXEL_GET_IDX(dim, off, x, y)] >> \
00061 RC_PIXEL_GET_BIT(dim, off, x)) & 1)
00062
00066 #define RC_PIXEL_SET_BIN(buf, dim, off, x, y, pix) \
00067 do { \
00068 if (pix) \
00069 (((uint8_t*)(buf))[RC_PIXEL_GET_IDX(dim, off, x, y)] |= \
00070 1 << RC_PIXEL_GET_BIT(dim, off, x)); \
00071 else \
00072 (((uint8_t*)(buf))[RC_PIXEL_GET_IDX(dim, off, x, y)] &= \
00073 ~(1 << RC_PIXEL_GET_BIT(dim, off, x))); \
00074 } while (0)
00075
00079 #define RC_PIXEL_GET_U8(buf, dim, x, y) \
00080 ((const uint8_t*)(buf))[(int)(y)*(int)(dim) + (int)(x)]
00081
00085 #define RC_PIXEL_SET_U8(buf, dim, x, y, pix) \
00086 (((uint8_t*)(buf))[(int)(y)*(int)(dim) + (int)(x)] = (uint8_t)(pix))
00087
00088
00089 #endif