8 * Compose two values, using a bitmask as decision value
9 * This is equivalent to (a & mask) | (b & ~mask)
12 static inline unsigned long
13 comp(unsigned long a, unsigned long b, unsigned long mask)
15 return ((a ^ b) & mask) ^ b;
19 * Create a pattern with the given pixel's color
22 #if BITS_PER_LONG == 64
23 static inline unsigned long
24 pixel_to_pat( u32 bpp, u32 pixel)
28 return 0xfffffffffffffffful*pixel;
30 return 0x5555555555555555ul*pixel;
32 return 0x1111111111111111ul*pixel;
34 return 0x0101010101010101ul*pixel;
36 return 0x0001001001001001ul*pixel;
38 return 0x0001000100010001ul*pixel;
40 return 0x0000000001000001ul*pixel;
42 return 0x0000000100000001ul*pixel;
44 panic("pixel_to_pat(): unsupported pixelformat\n");
48 static inline unsigned long
49 pixel_to_pat( u32 bpp, u32 pixel)
53 return 0xfffffffful*pixel;
55 return 0x55555555ul*pixel;
57 return 0x11111111ul*pixel;
59 return 0x01010101ul*pixel;
61 return 0x00001001ul*pixel;
63 return 0x00010001ul*pixel;
65 return 0x00000001ul*pixel;
67 return 0x00000001ul*pixel;
69 panic("pixel_to_pat(): unsupported pixelformat\n");
74 #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
75 #if BITS_PER_LONG == 64
76 #define REV_PIXELS_MASK1 0x5555555555555555ul
77 #define REV_PIXELS_MASK2 0x3333333333333333ul
78 #define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful
80 #define REV_PIXELS_MASK1 0x55555555ul
81 #define REV_PIXELS_MASK2 0x33333333ul
82 #define REV_PIXELS_MASK4 0x0f0f0f0ful
85 static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
89 val = comp(val >> 1, val << 1, REV_PIXELS_MASK1);
91 val = comp(val >> 2, val << 2, REV_PIXELS_MASK2);
93 val = comp(val >> 4, val << 4, REV_PIXELS_MASK4);
96 static inline u32 fb_shifted_pixels_mask_u32(u32 index, u32 bswapmask)
101 mask = FB_SHIFT_HIGH(~(u32)0, index);
103 mask = 0xff << FB_LEFT_POS(8);
104 mask = FB_SHIFT_LOW(mask, index & (bswapmask)) & mask;
105 mask = FB_SHIFT_HIGH(mask, index & ~(bswapmask));
106 #if defined(__i386__) || defined(__x86_64__)
107 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
108 if(index + bswapmask < 32)
110 mask |= FB_SHIFT_HIGH(~(u32)0,
111 (index + bswapmask) & ~(bswapmask));
116 static inline unsigned long fb_shifted_pixels_mask_long(u32 index, u32 bswapmask)
121 mask = FB_SHIFT_HIGH(~0UL, index);
123 mask = 0xff << FB_LEFT_POS(8);
124 mask = FB_SHIFT_LOW(mask, index & (bswapmask)) & mask;
125 mask = FB_SHIFT_HIGH(mask, index & ~(bswapmask));
126 #if defined(__i386__) || defined(__x86_64__)
127 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
128 if(index + bswapmask < BITS_PER_LONG)
130 mask |= FB_SHIFT_HIGH(~0UL,
131 (index + bswapmask) & ~(bswapmask));
137 static inline u32 fb_compute_bswapmask(struct fb_info *info)
140 unsigned bpp = info->var.bits_per_pixel;
142 if ((bpp < 8) && (info->var.nonstd & FB_NONSTD_REV_PIX_IN_B)) {
144 * Reversed order of pixel layout in bytes
145 * works only for 1, 2 and 4 bpp
147 bswapmask = 7 - bpp + 1;
152 #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
154 static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
160 #define fb_shifted_pixels_mask_u32(i, b) FB_SHIFT_HIGH(~(u32)0, (i))
161 #define fb_shifted_pixels_mask_long(i, b) FB_SHIFT_HIGH(~0UL, (i))
162 #define fb_compute_bswapmask(...) 0
164 #endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
166 #endif /* FB_DRAW_H */