0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/module.h>
0014 #include <linux/string.h>
0015 #include <linux/fb.h>
0016 #include <asm/types.h>
0017
0018 #define DEBUG
0019
0020 #ifdef DEBUG
0021 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt,__func__,## args)
0022 #else
0023 #define DPRINTK(fmt, args...)
0024 #endif
0025
0026 static const u32 cfb_tab8_be[] = {
0027 0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
0028 0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
0029 0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
0030 0xffff0000,0xffff00ff,0xffffff00,0xffffffff
0031 };
0032
0033 static const u32 cfb_tab8_le[] = {
0034 0x00000000,0xff000000,0x00ff0000,0xffff0000,
0035 0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
0036 0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
0037 0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
0038 };
0039
0040 static const u32 cfb_tab16_be[] = {
0041 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
0042 };
0043
0044 static const u32 cfb_tab16_le[] = {
0045 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
0046 };
0047
0048 static const u32 cfb_tab32[] = {
0049 0x00000000, 0xffffffff
0050 };
0051
0052 static void color_imageblit(const struct fb_image *image, struct fb_info *p,
0053 void *dst1, u32 start_index, u32 pitch_index)
0054 {
0055
0056 u32 *dst, *dst2;
0057 u32 color = 0, val, shift;
0058 int i, n, bpp = p->var.bits_per_pixel;
0059 u32 null_bits = 32 - bpp;
0060 u32 *palette = (u32 *) p->pseudo_palette;
0061 const u8 *src = image->data;
0062
0063 dst2 = dst1;
0064 for (i = image->height; i--; ) {
0065 n = image->width;
0066 dst = dst1;
0067 shift = 0;
0068 val = 0;
0069
0070 if (start_index) {
0071 u32 start_mask = ~(FB_SHIFT_HIGH(p, ~(u32)0,
0072 start_index));
0073 val = *dst & start_mask;
0074 shift = start_index;
0075 }
0076 while (n--) {
0077 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
0078 p->fix.visual == FB_VISUAL_DIRECTCOLOR )
0079 color = palette[*src];
0080 else
0081 color = *src;
0082 color <<= FB_LEFT_POS(p, bpp);
0083 val |= FB_SHIFT_HIGH(p, color, shift);
0084 if (shift >= null_bits) {
0085 *dst++ = val;
0086
0087 val = (shift == null_bits) ? 0 :
0088 FB_SHIFT_LOW(p, color, 32 - shift);
0089 }
0090 shift += bpp;
0091 shift &= (32 - 1);
0092 src++;
0093 }
0094 if (shift) {
0095 u32 end_mask = FB_SHIFT_HIGH(p, ~(u32)0, shift);
0096
0097 *dst &= end_mask;
0098 *dst |= val;
0099 }
0100 dst1 += p->fix.line_length;
0101 if (pitch_index) {
0102 dst2 += p->fix.line_length;
0103 dst1 = (u8 *)((long)dst2 & ~(sizeof(u32) - 1));
0104
0105 start_index += pitch_index;
0106 start_index &= 32 - 1;
0107 }
0108 }
0109 }
0110
0111 static void slow_imageblit(const struct fb_image *image, struct fb_info *p,
0112 void *dst1, u32 fgcolor, u32 bgcolor,
0113 u32 start_index, u32 pitch_index)
0114 {
0115 u32 shift, color = 0, bpp = p->var.bits_per_pixel;
0116 u32 *dst, *dst2;
0117 u32 val, pitch = p->fix.line_length;
0118 u32 null_bits = 32 - bpp;
0119 u32 spitch = (image->width+7)/8;
0120 const u8 *src = image->data, *s;
0121 u32 i, j, l;
0122
0123 dst2 = dst1;
0124 fgcolor <<= FB_LEFT_POS(p, bpp);
0125 bgcolor <<= FB_LEFT_POS(p, bpp);
0126
0127 for (i = image->height; i--; ) {
0128 shift = val = 0;
0129 l = 8;
0130 j = image->width;
0131 dst = dst1;
0132 s = src;
0133
0134
0135 if (start_index) {
0136 u32 start_mask = ~(FB_SHIFT_HIGH(p, ~(u32)0,
0137 start_index));
0138 val = *dst & start_mask;
0139 shift = start_index;
0140 }
0141
0142 while (j--) {
0143 l--;
0144 color = (*s & (1 << l)) ? fgcolor : bgcolor;
0145 val |= FB_SHIFT_HIGH(p, color, shift);
0146
0147
0148 if (shift >= null_bits) {
0149 *dst++ = val;
0150 val = (shift == null_bits) ? 0 :
0151 FB_SHIFT_LOW(p, color, 32 - shift);
0152 }
0153 shift += bpp;
0154 shift &= (32 - 1);
0155 if (!l) { l = 8; s++; }
0156 }
0157
0158
0159 if (shift) {
0160 u32 end_mask = FB_SHIFT_HIGH(p, ~(u32)0, shift);
0161
0162 *dst &= end_mask;
0163 *dst |= val;
0164 }
0165
0166 dst1 += pitch;
0167 src += spitch;
0168 if (pitch_index) {
0169 dst2 += pitch;
0170 dst1 = (u8 *)((long)dst2 & ~(sizeof(u32) - 1));
0171 start_index += pitch_index;
0172 start_index &= 32 - 1;
0173 }
0174
0175 }
0176 }
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 static void fast_imageblit(const struct fb_image *image, struct fb_info *p,
0187 void *dst1, u32 fgcolor, u32 bgcolor)
0188 {
0189 u32 fgx = fgcolor, bgx = bgcolor, bpp = p->var.bits_per_pixel;
0190 u32 ppw = 32/bpp, spitch = (image->width + 7)/8;
0191 u32 bit_mask, eorx, shift;
0192 const char *s = image->data, *src;
0193 u32 *dst;
0194 const u32 *tab;
0195 size_t tablen;
0196 u32 colortab[16];
0197 int i, j, k;
0198
0199 switch (bpp) {
0200 case 8:
0201 tab = fb_be_math(p) ? cfb_tab8_be : cfb_tab8_le;
0202 tablen = 16;
0203 break;
0204 case 16:
0205 tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
0206 tablen = 4;
0207 break;
0208 case 32:
0209 tab = cfb_tab32;
0210 tablen = 2;
0211 break;
0212 default:
0213 return;
0214 }
0215
0216 for (i = ppw-1; i--; ) {
0217 fgx <<= bpp;
0218 bgx <<= bpp;
0219 fgx |= fgcolor;
0220 bgx |= bgcolor;
0221 }
0222
0223 bit_mask = (1 << ppw) - 1;
0224 eorx = fgx ^ bgx;
0225 k = image->width/ppw;
0226
0227 for (i = 0; i < tablen; ++i)
0228 colortab[i] = (tab[i] & eorx) ^ bgx;
0229
0230 for (i = image->height; i--; ) {
0231 dst = dst1;
0232 shift = 8;
0233 src = s;
0234
0235
0236
0237
0238
0239
0240 switch (ppw) {
0241 case 4:
0242 for (j = k; j >= 2; j -= 2, ++src) {
0243 *dst++ = colortab[(*src >> 4) & bit_mask];
0244 *dst++ = colortab[(*src >> 0) & bit_mask];
0245 }
0246 break;
0247 case 2:
0248 for (j = k; j >= 4; j -= 4, ++src) {
0249 *dst++ = colortab[(*src >> 6) & bit_mask];
0250 *dst++ = colortab[(*src >> 4) & bit_mask];
0251 *dst++ = colortab[(*src >> 2) & bit_mask];
0252 *dst++ = colortab[(*src >> 0) & bit_mask];
0253 }
0254 break;
0255 case 1:
0256 for (j = k; j >= 8; j -= 8, ++src) {
0257 *dst++ = colortab[(*src >> 7) & bit_mask];
0258 *dst++ = colortab[(*src >> 6) & bit_mask];
0259 *dst++ = colortab[(*src >> 5) & bit_mask];
0260 *dst++ = colortab[(*src >> 4) & bit_mask];
0261 *dst++ = colortab[(*src >> 3) & bit_mask];
0262 *dst++ = colortab[(*src >> 2) & bit_mask];
0263 *dst++ = colortab[(*src >> 1) & bit_mask];
0264 *dst++ = colortab[(*src >> 0) & bit_mask];
0265 }
0266 break;
0267 }
0268
0269
0270
0271
0272
0273
0274 for (; j--; ) {
0275 shift -= ppw;
0276 *dst++ = colortab[(*src >> shift) & bit_mask];
0277 if (!shift) {
0278 shift = 8;
0279 ++src;
0280 }
0281 }
0282
0283 dst1 += p->fix.line_length;
0284 s += spitch;
0285 }
0286 }
0287
0288 void sys_imageblit(struct fb_info *p, const struct fb_image *image)
0289 {
0290 u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
0291 u32 bpl = sizeof(u32), bpp = p->var.bits_per_pixel;
0292 u32 width = image->width;
0293 u32 dx = image->dx, dy = image->dy;
0294 void *dst1;
0295
0296 if (p->state != FBINFO_STATE_RUNNING)
0297 return;
0298
0299 bitstart = (dy * p->fix.line_length * 8) + (dx * bpp);
0300 start_index = bitstart & (32 - 1);
0301 pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
0302
0303 bitstart /= 8;
0304 bitstart &= ~(bpl - 1);
0305 dst1 = (void __force *)p->screen_base + bitstart;
0306
0307 if (p->fbops->fb_sync)
0308 p->fbops->fb_sync(p);
0309
0310 if (image->depth == 1) {
0311 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
0312 p->fix.visual == FB_VISUAL_DIRECTCOLOR) {
0313 fgcolor = ((u32*)(p->pseudo_palette))[image->fg_color];
0314 bgcolor = ((u32*)(p->pseudo_palette))[image->bg_color];
0315 } else {
0316 fgcolor = image->fg_color;
0317 bgcolor = image->bg_color;
0318 }
0319
0320 if (32 % bpp == 0 && !start_index && !pitch_index &&
0321 ((width & (32/bpp-1)) == 0) &&
0322 bpp >= 8 && bpp <= 32)
0323 fast_imageblit(image, p, dst1, fgcolor, bgcolor);
0324 else
0325 slow_imageblit(image, p, dst1, fgcolor, bgcolor,
0326 start_index, pitch_index);
0327 } else
0328 color_imageblit(image, p, dst1, start_index, pitch_index);
0329 }
0330
0331 EXPORT_SYMBOL(sys_imageblit);
0332
0333 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
0334 MODULE_DESCRIPTION("1-bit/8-bit to 1-32 bit color expansion (sys-to-sys)");
0335 MODULE_LICENSE("GPL");
0336