📄 fblin16.c
字号:
/* Do pixels of partial first byte */ if (prefix_first_bit) { bitmap_byte = *src++; for (mask = prefix_first_bit; mask; MWI_ADVANCE_BIT(mask)) { *dst++ = (mask & bitmap_byte) ? fg : bg; } } /* Do all pixels of main part one byte at a time */ for (t = size_main; t != 0; t--) { bitmap_byte = *src++; *dst++ = (MWI_BIT_NO(0) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(1) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(2) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(3) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(4) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(5) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(6) & bitmap_byte) ? fg : bg; *dst++ = (MWI_BIT_NO(7) & bitmap_byte) ? fg : bg; } /* Do last few bits of line */ if (postfix_last_bit) { bitmap_byte = *src++; for (mask = postfix_first_bit; MWI_IS_BIT_BEFORE_OR_EQUAL(mask, postfix_last_bit); MWI_ADVANCE_BIT(mask)) { *dst++ = (mask & bitmap_byte) ? fg : bg; } } src += advance_src; dst += advance_dst; } } else { for (y = 0; y < gc->dsth; y++) { /* Do pixels of partial first byte */ if (prefix_first_bit) { bitmap_byte = *src++; for (mask = prefix_first_bit; mask; MWI_ADVANCE_BIT(mask)) { if (mask & bitmap_byte) *dst = fg; dst++; } } /* Do all pixels of main part one byte at a time */ for (t = size_main; t != 0; t--) { bitmap_byte = *src++; if (MWI_BIT_NO(0) & bitmap_byte) dst[0] = fg; if (MWI_BIT_NO(1) & bitmap_byte) dst[1] = fg; if (MWI_BIT_NO(2) & bitmap_byte) dst[2] = fg; if (MWI_BIT_NO(3) & bitmap_byte) dst[3] = fg; if (MWI_BIT_NO(4) & bitmap_byte) dst[4] = fg; if (MWI_BIT_NO(5) & bitmap_byte) dst[5] = fg; if (MWI_BIT_NO(6) & bitmap_byte) dst[6] = fg; if (MWI_BIT_NO(7) & bitmap_byte) dst[7] = fg; dst += 8; } /* Do last few bits of line */ if (postfix_last_bit) { bitmap_byte = *src++; for (mask = postfix_first_bit; MWI_IS_BIT_BEFORE_OR_EQUAL(mask, postfix_last_bit); MWI_ADVANCE_BIT(mask)) { if (mask & bitmap_byte) *dst = fg; dst++; } } src += advance_src; dst += advance_dst; } } DRAWOFF;#undef MWI_IS_BIT_BEFORE_OR_EQUAL#undef MWI_ADVANCE_BIT#undef MWI_BIT_NO#undef MWI_FIRST_BIT#undef MWI_LAST_BIT}#endif /* MW_FEATURE_PSDOP_BITMAP_BYTES_MSB_FIRST */#if MW_FEATURE_PSDOP_ALPHAMAP/* FIXME should make linear16_drawarea_alphamap() work in 5/5/5 mode * (currently it assumes 5/6/5 mode). */#if MWPIXEL_FORMAT == MWPF_TRUECOLOR555#error PSDOP_ALPHAMAP does not work in 5/5/5 mode!!#endifstatic unsigned short *low2scale = 0, *high2scale = 0;static voidinit_alpha_lookup(void){ unsigned short a, x; unsigned short r, g, b; unsigned short idx; low2scale = malloc(32 * 256 * sizeof(low2scale[0])); high2scale = malloc(32 * 256 * sizeof(high2scale[0])); if (high2scale == 0 || low2scale == 0) exit(17); for ( a=0; a < 32; a++ ) for ( x=0; x < 256; x++ ) { idx = (a << 8) | x; /* High byte */ r = (x >> 3) * a / 31; g = ((x << 3) & 0x38) * a / 31; high2scale[idx] = (r << 11) | (g << 5); /* Low byte */ b = (x & 0x1f) * a / 31; g = ((x >> 5) & 0x7) * a / 31; low2scale[idx] = (g << 5) | b; }}static voidlinear16_drawarea_alphamap(PSD psd, driver_gc_t * gc){ ADDR16 src, dst; ADDR8 alpha; unsigned short ps, pd; unsigned as, ad; int x, y; int src_row_step, dst_row_step; if ( low2scale == 0 ) init_alpha_lookup(); src = ((ADDR16) gc->pixels) + gc->srcx + gc->src_linelen * gc->srcy; alpha = ((ADDR8) gc->misc) + gc->src_linelen * gc->srcy + gc->srcx; dst = ((ADDR16) psd->addr) + psd->linelen * gc->dsty + gc->dstx; src_row_step = gc->src_linelen - gc->dstw; dst_row_step = psd->linelen - gc->dstw; DRAWON; for (y = 0; y < gc->dsth; y++) { for (x = 0; x < gc->dstw; x++) { as = (((unsigned short) ((*alpha++) >> 3)) << 8); ad = (31 << 8) - as; ps = *src++; pd = *dst++; *dst++ = ((as == 0) ? pd : ((ad == 0) ? ps : low2scale[as | (ps >> 8)] + high2scale[as | (ps & 0xFF)] + low2scale[ad | (pd >> 8)] + high2scale[ad | (pd & 0xFF)])); } alpha += src_row_step; src += src_row_step; dst += dst_row_step; } DRAWOFF;}#endif /* MW_FEATURE_PSDOP_ALPHAMAP */#if MW_FEATURE_PSDOP_ALPHACOLstatic voidlinear16_drawarea_alphacol(PSD psd, driver_gc_t * gc){ ADDR16 dst; ADDR8 alpha; unsigned ps, pd; int as; long psr, psg, psb; int x, y; int src_row_step, dst_row_step; alpha = ((ADDR8) gc->misc) + gc->src_linelen * gc->srcy + gc->srcx; dst = ((ADDR16) psd->addr) + psd->linelen * gc->dsty + gc->dstx; ps = gc->fg_color; src_row_step = gc->src_linelen - gc->dstw; dst_row_step = psd->linelen - gc->dstw;#define COLOR_MASK_R_565 0xF800U#define COLOR_MASK_G_565 0x07E0U#define COLOR_MASK_B_565 0x001FU#define COLOR_MASK_R_555 0x7C00U#define COLOR_MASK_G_555 0x03E0U#define COLOR_MASK_B_555 0x001FU DRAWON; if (psd->pixtype == MWPF_TRUECOLOR565) { psr = (long) (ps & COLOR_MASK_R_565); psg = (long) (ps & COLOR_MASK_G_565); psb = (long) (ps & COLOR_MASK_B_565); for (y = 0; y < gc->dsth; y++) { for (x = 0; x < gc->dstw; x++) { as = *alpha++; if (as == 255) { *dst++ = ps; } else if (as != 0) { /* * Scale alpha value from 255ths to 256ths * (In other words, if as >= 128, add 1 to it) * * Also flip the direction of alpha, so it's * backwards from it's usual meaning. * This is because the equation below is most * easily written with source and dest interchanged * (since we can split ps into it's components * before we enter the loop) */ as = 256 - (as + (as >> 7)); pd = *dst; *dst++ = ((unsigned) (((((long) (pd & COLOR_MASK_R_565) - psr) * as) >> 8) + psr) & COLOR_MASK_R_565) | ((unsigned) (((((long) (pd & COLOR_MASK_G_565) - psg) * as) >> 8) + psg) & COLOR_MASK_G_565) | ((unsigned) (((((long) (pd & COLOR_MASK_B_565) - psb) * as) >> 8) + psb) & COLOR_MASK_B_565); } else { dst++; } } alpha += src_row_step; dst += dst_row_step; } } else { psr = (long) (ps & COLOR_MASK_R_555); psg = (long) (ps & COLOR_MASK_G_555); psb = (long) (ps & COLOR_MASK_B_555); for (y = 0; y < gc->dsth; y++) { for (x = 0; x < gc->dstw; x++) { as = *alpha++; if (as == 255) { *dst++ = ps; } else if (as != 0) { /* * Scale alpha value from 255ths to 256ths * (In other words, if as >= 128, add 1 to it) * * Also flip the direction of alpha, so it's * backwards from it's usual meaning. * This is because the equation below is most * easily written with source and dest interchanged * (since we can split ps into it's components * before we enter the loop) */ as = 256 - (as + (as >> 7)); pd = *dst; *dst++ = ((unsigned) (((((long) (pd & COLOR_MASK_R_555) - psr) * as) >> 8) + psr) & COLOR_MASK_R_555) | ((unsigned) (((((long) (pd & COLOR_MASK_G_555) - psg) * as) >> 8) + psg) & COLOR_MASK_G_555) | ((unsigned) (((((long) (pd & COLOR_MASK_B_555) - psb) * as) >> 8) + psb) & COLOR_MASK_B_555); } else { dst++; } } alpha += src_row_step; dst += dst_row_step; } } DRAWOFF;}#endif /* MW_FEATURE_PSDOP_ALPHACOL */#if MW_FEATURE_PSDOP_COPYstatic voidlinear16_drawarea_copyall(PSD psd, driver_gc_t * gc){ ADDR16 src16, dst; int linesize, x, y; unsigned short pcol; linesize = 2 * gc->dstw; src16 = ((ADDR16) gc->pixels) + gc->srcx + gc->src_linelen * gc->srcy; dst = ((ADDR16) psd->addr) + gc->dstx + psd->linelen * gc->dsty; DRAWON; for (y = 1; y < gc->dsth; y++) { memcpy(dst, src16, linesize); src16 += gc->src_linelen; dst += psd->linelen; } memcpy(dst, src16, linesize); /* To be seriously ANSI */ DRAWOFF;}static voidlinear16_drawarea_copytrans(PSD psd, driver_gc_t * gc){ ADDR16 src16, dst, rsrc, rdst; int linesize, x, y; unsigned short pcol; src16 = ((ADDR16) gc->pixels) + gc->srcx + gc->src_linelen * gc->srcy; dst = ((ADDR16) psd->addr) + gc->dstx + psd->linelen * gc->dsty; DRAWON; for (y = 0; y < gc->dsth; y++) { rdst = dst; rsrc = src16; for (x = 0; x < gc->dstw; x++) { pcol = *rsrc++; if (pcol == gc->bg_color) rdst++; else *rdst++ = pcol; } dst += psd->linelen; src16 += gc->src_linelen; } DRAWOFF;}#endifstatic voidlinear16_drawarea(PSD psd, driver_gc_t * gc, int op){ assert(psd->addr != 0); /*assert(gc->dstw <= gc->srcw);*/ assert(gc->dstx >= 0 && gc->dstx+gc->dstw <= psd->xres); /*assert(gc->dsty >= 0 && gc->dsty+gc->dsth <= psd->yres);*/ /*assert(gc->srcx >= 0 && gc->srcx+gc->dstw <= gc->srcw);*/ assert(gc->srcy >= 0); /*DPRINTF("linear16_drawarea op=%d dstx=%d dsty=%d\n", op, gc->dstx, gc->dsty);*/ switch (op) {#if MW_FEATURE_PSDOP_COPY case PSDOP_COPY: if (gc->gr_usebg) { linear16_drawarea_copyall(psd, gc); } else { linear16_drawarea_copytrans(psd, gc); } break; case PSDOP_COPYALL: linear16_drawarea_copyall(psd, gc); break; case PSDOP_COPYTRANS: linear16_drawarea_copytrans(psd, gc); break;#endif /* MW_FEATURE_PSDOP_COPY */#if MW_FEATURE_PSDOP_ALPHAMAP case PSDOP_ALPHAMAP: linear16_drawarea_alphamap(psd, gc); break;#endif /* MW_FEATURE_PSDOP_ALPHAMAP */#if MW_FEATURE_PSDOP_ALPHACOL case PSDOP_ALPHACOL: linear16_drawarea_alphacol(psd, gc); break;#endif /* MW_FEATURE_PSDOP_ALPHACOL */#if MW_FEATURE_PSDOP_BITMAP_BYTES_LSB_FIRST case PSDOP_BITMAP_BYTES_LSB_FIRST: linear16_drawarea_bitmap_bytes_lsb_first(psd, gc); break;#endif /* MW_FEATURE_PSDOP_BITMAP_BYTES_LSB_FIRST */#if MW_FEATURE_PSDOP_BITMAP_BYTES_MSB_FIRST case PSDOP_BITMAP_BYTES_MSB_FIRST: linear16_drawarea_bitmap_bytes_msb_first(psd, gc); break;#endif /* MW_FEATURE_PSDOP_BITMAP_BYTES_MSB_FIRST */ }}SUBDRIVER fblinear16 = { linear16_init, linear16_drawpixel, linear16_readpixel, linear16_drawhorzline, linear16_drawvertline, gen_fillrect, linear16_blit, linear16_drawarea, linear16_stretchblit, linear16_stretchblitex,};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -