⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbvga16.c

📁 MiniGUI for uCOS 移植实验全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        return (addr[(x>>1) + y * psd->linelen] >> ((1-(x&1))<<2) ) & 0x0f;

    src = SCREENBASE(psd) + (x>>3) + y * BYTESPERLINE(psd);
    for(plane = 0; plane < 4; ++plane) {
        set_read_plane(plane);
        if(GETBYTE(src) & mask[x&7])
            c |= 1 << plane;
    }
    return c;
}

/* Draw horizontal line from x1,y to x2,y including final point*/
static void fbvga16_drawhline (PSD psd, int x, int y, int w, gal_pixel c)
{
    gal_uint8    *addr= (gal_uint8 *)psd->addr;
    gal_uint8* dst, last;
    int cc;

    if (psd->flags & PSF_MEMORY) {
        addr += (x>>1) + y * psd->linelen;
        cc = c | (c << 4);
        if(psd->gr_mode == MODE_XOR) {
            if (x & 1) {
                *addr = (*addr & notmask[1]) | (c ^ (*addr & notmask[0]));
                addr++;
                w --;
            }
            while (w > 1) {
                *addr++ ^= cc ;
                w -= 2;
            }
            if (w == 1) 
                *addr = (*addr & notmask[0]) | ((c << 4)^(*addr & notmask[1]));
        } else {
            if (x & 1) {
                *addr = (*addr & notmask[1]) | c;
                addr++;
                w --;
            }
            while (w > 1) {
                *addr++ = cc ;
                w -= 2;
            }
            if (w == 1) 
                *addr = (*addr & notmask[0]) | (c << 4);
        }
        return;
    }


    set_color (c);
    set_op(mode_table[psd->gr_mode]);
    /*
    * The following fast drawhline code is buggy for XOR drawing,
    * for some reason.  So, we use the equivalent slower drawpixel
    * method when not drawing MODE_SET.
    */
    if(psd->gr_mode == MODE_SET) {
        dst = SCREENBASE(psd) + (x>>3) + y * BYTESPERLINE(psd);
        if ((x>>3) == ( (x + w - 1)>>3) ) {
            select_and_set_mask ((0xff >> (x & 7)) & (0xff << (7 - ((x + w - 1) & 7))));
            RMW (dst);
        } else {
            select_and_set_mask (0xff >> (x & 7));
            RMW (dst++);

            set_mask (0xff);
            last = SCREENBASE(psd)  + ( (x + w - 1) >>3) + y * BYTESPERLINE(psd);
            while (dst < last)
                PUTBYTE(dst++, 1);

            set_mask (0xff << (7 - ((x + w - 1) & 7)));
            RMW (dst);
        }
    } else {
        /* slower method, draw pixel by pixel*/
        select_mask ();
        while(w--) {
            set_mask (mask[x&7]);
            RMW ((gal_uint8*)SCREENBASE(psd)  + (x++>>3) + y * BYTESPERLINE(psd));
        }
    }
}

static void fbvga16_drawvline(PSD psd, int x, int y, int h, gal_pixel c)
{
    gal_uint8* addr= (gal_uint8 *)psd->addr;
    gal_uint8* dst;
    int linelen = psd->linelen;

    if (psd->flags & PSF_MEMORY) {
        addr += (x>>1) + y * linelen;
        if(psd->gr_mode == MODE_XOR)
            while(h--) {
                *addr ^= (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2) ^ (*addr&notmask[1 - (x&1)]));
                addr += linelen;
            }
        else
            while(h--) {
                *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
                addr += linelen;
            }
        return;
    }

    set_op(mode_table[psd->gr_mode]);
    set_color (c);
    select_and_set_mask (mask[x&7]);
    dst = SCREENBASE(psd)  + (x>>3) + y * BYTESPERLINE(psd);

    while (h--) {
        RMW (dst);
        dst += BYTESPERLINE(psd);
    }
}

/*clip to screen*/
static void fbvga16_getbox ( PSD psd, int x, int y, int w, int h, void* buf )
{
    gal_uint8 *dst = (gal_uint8*) buf;
    int dstwidth = w;

    if ( y < 0 ) {
        h += y;
        dst += -y * dstwidth;
        y = 0;
    }
    if ( x < 0 ) {
        w += x;
        dst += -x;
        x = 0;
    }        
    if ( y + h  - 1 >= psd->yres) 
        h = psd->yres - y ;
    if ( x + w  - 1 >= psd->xres) 
        w = psd->xres - x ;

    if (psd->flags & PSF_MEMORY) {
        gal_uint8    *src= (gal_uint8 *)psd->addr + y * psd->linelen + x;
        while ( h--) {
            memcpy(dst,src,w);
            src += psd->linelen;
            dst += dstwidth;
        }
    }
    else
            _vga16_getbox (psd, x, y, w, h, dst, dstwidth);
}

/*do clip*/
static void fbvga16_putbox ( PSD psd, int x, int y, int w, int h, void *buf)
{
    gal_uint8    *src = (gal_uint8*) buf;
    int srcwidth = w;

    if (psd->doclip) {    
        if (y < psd->clipminy) {
            h -= psd->clipminy - y;
            src += (psd->clipminy - y) * srcwidth;
            y = psd->clipminy;
        }
        if (x < psd->clipminx) {
            w -= psd->clipminx - x;
            src += psd->clipminx - x;
            x = psd->clipminx;
        }        
        if (y + h - 1 >= psd->clipmaxy) 
            h =  psd->clipmaxy- y;
        if (x + w - 1 >= psd->clipmaxx) 
            w =  psd->clipmaxx- x;
    }
    else {
        if ( y < 0 ) {
            h += y;
            src += -y * srcwidth;
            y = 0;
        }
        if ( x < 0 ) {
            w += x;
            src += -x;
            x = 0;
        }        
        if ( y + h  -1 >= psd->yres) 
            h = psd->yres - y ;
        if ( x + w  -1 >= psd->xres) 
            w = psd->xres - x ;
    }

    if (psd->flags & PSF_MEMORY) {
        gal_uint8    *dst= (gal_uint8 *)psd->addr + y * psd->linelen + x;
        while ( h--) {
            memcpy(dst,src,w);
            dst += psd->linelen;
            src += srcwidth;
        }
    }
    else
        _vga16_putbox (psd, x, y, w, h, src, srcwidth);
}

static void fbvga16_putboxmask (PSD psd, int x, int y, int w, int h, void *buf, gal_pixel cxx)
{
    gal_uint8 *src= (gal_uint8*) buf;
    int srcwidth =  w ;

    if (psd->doclip) {    
        if (y < psd->clipminy) {
            h -= psd->clipminy - y;
            src += (psd->clipminy - y) * srcwidth;
            y = psd->clipminy;
        }
        if (x < psd->clipminx) {
            w -= psd->clipminx - x;
            src += psd->clipminx - x;
            x = psd->clipminx;
        }        
        if (y + h - 1 >= psd->clipmaxy) 
            h =  psd->clipmaxy- y;
        if (x + w - 1 >= psd->clipmaxx) 
            w =  psd->clipmaxx- x;
    }
    else {
        if ( y < 0 ) {
            h += y;
            src += -y * srcwidth;
            y = 0;
        }
        if ( x < 0 ) {
            w += x;
            src += -x;
            x = 0;
        }        
        if ( y + h  -1 >= psd->yres) 
            h = psd->yres - y ;
        if ( x + w  -1 >= psd->xres) 
            w = psd->xres - x ;
    }

    if (psd->flags & PSF_MEMORY) {
        gal_uint8    *dst= (gal_uint8 *)psd->addr + y * psd->linelen + x;
        gal_uint8 c;

        while ( h--) {
            int w1 = w;
            gal_uint8 *src1 = src;
            gal_uint8 *dst1 = dst;
            while(w1--) {
                c = *src1;
                if (c != cxx) 
                    *dst1 = c;
                    src1++;
                    dst1++;
            }
            dst += psd->linelen;
            src += srcwidth;
        }
    }
    else
        _vga16_putboxmask (psd, x, y, w, h, src, srcwidth, cxx);

}

static void fbvga16_copybox
(PSD psd,int x1, int y1, int w, int h, int x2, int y2)
{
    gal_uint8 *buf;

    buf = (gal_uint8 *) malloc (w * h);
    if (psd->flags & PSF_MEMORY) {
        _mem16_getbox (psd, x1, y1, w, h, buf, w);
        _mem16_putbox (psd, x1, y1, w, h, buf, w);
    } else {
        _vga16_getbox (psd, x2, y2, w, h, buf, w);
        _vga16_putbox (psd, x2, y2, w, h, buf, w);
    }
    free (buf);
}

/* 
 *  Bitblt,not do clip
 *  opcode is currently ignored
 *  WARNING: src & dst can not be same psd!
 */
static void fbvga16_blit (PSD dstpsd, int dstx, int dsty, int w, int h,
    PSD srcpsd, int srcx, int srcy)
{
    int srcvga, dstvga;

    srcvga = srcpsd->flags & PSF_SCREEN;
    dstvga = dstpsd->flags & PSF_SCREEN;

    if(srcvga) {
        if(dstvga)
            _vga16_to_vga16_blit(dstpsd, dstx, dsty, w, h,
                srcpsd, srcx, srcy);
        else
            _vga16_to_mem16_blit(dstpsd, dstx, dsty, w, h,
                srcpsd, srcx, srcy);
    } else {
        if(dstvga)
            _mem16_to_vga16_blit(dstpsd, dstx, dsty, w, h,
                srcpsd, srcx, srcy);
        else {
            gal_uint8 *    dst;
            gal_uint8 *    src;
            dst = (char *)dstpsd->addr + dstx + dsty * dstpsd->linelen;
            src = (char *)srcpsd->addr + srcx + srcy * srcpsd->linelen;
            memcpy(dst, src, w*h);
        }
    }
}

SUBDRIVER fbvga16 = {
    fbvga16_init,
    fbvga16_drawpixel,
    fbvga16_readpixel,
    fbvga16_drawhline,
    fbvga16_drawvline,
    fbvga16_blit,
    fbvga16_putbox,
    fbvga16_getbox,
    fbvga16_putboxmask,
    fbvga16_copybox
};

#endif /* _FBVGA16_SUPPORT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -