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

📄 s3c44b0x.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
int scalebox (GAL_GC gc, int w1, int h1, void *_dp1, int w2, int h2, void *_dp2)
{
    uchar *dp1 = _dp1;
    uchar *dp2 = _dp2;
    int xfactor;
    int yfactor;

    if (w2 == 0 || h2 == 0)
        return 0;

    xfactor = muldiv64(w1, 65536, w2);        /* scaled by 65536 */
    yfactor = muldiv64(h1, 65536, h2);        /* scaled by 65536 */

    switch (bytes_per_pixel (gc)) {
    case 1:
        {
            int y, sy;
            sy = 0;
            for (y = 0; y < h2;) {
                int sx = 0;
                uchar *dp2old = dp2;
                int x;
                x = 0;
                while (x < w2 - 8) {
                    *(dp2 + x) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 1) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 2) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 3) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 4) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 5) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 6) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    *(dp2 + x + 7) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    x += 8;
                }
                while (x < w2) {
                    *(dp2 + x) = *(dp1 + (sx >> 16));
                    sx += xfactor;
                    x++;
                }
                dp2 += w2;
                y++;
                while (y < h2) {
                    int l;
                    int syint = sy >> 16;
                    sy += yfactor;
                    if ((sy >> 16) != syint)
                        break;
                    /* Copy identical lines. */
                    l = dp2 - dp2old;
                    memcpy(dp2, dp2old, l);
                    dp2old = dp2;
                    dp2 += l;
                    y++;
                }
                dp1 = _dp1 + (sy >> 16) * w1;
            }
        }
        break;
    case 2:
        {
            int y, sy;
            sy = 0;
            for (y = 0; y < h2;) {
                int sx = 0;
                uchar *dp2old = dp2;
                int x;
                x = 0;
                /* This can be greatly optimized with loop */
                /* unrolling; omitted to save space. */
                while (x < w2) {
                    *(unsigned short *) (dp2 + x * 2) =
                        *(unsigned short *) (dp1 + (sx >> 16) * 2);
                    sx += xfactor;
                    x++;
                }
                dp2 += w2 * 2;
                y++;
                while (y < h2) {
                    int l;
                    int syint = sy >> 16;
                    sy += yfactor;
                    if ((sy >> 16) != syint)
                        break;
                    /* Copy identical lines. */
                    l = dp2 - dp2old;
                    memcpy(dp2, dp2old, l);
                    dp2old = dp2;
                    dp2 += l;
                    y++;
                }
                dp1 = _dp1 + (sy >> 16) * w1 * 2;
            }
        }
        break;
    case 3:
        {
            int y, sy;
            sy = 0;
            for (y = 0; y < h2;) {
                int sx = 0;
                uchar *dp2old = dp2;
                int x;
                x = 0;
                /* This can be greatly optimized with loop */
                /* unrolling; omitted to save space. */
                while (x < w2) {
                    *(unsigned short *) (dp2 + x * 3) =
                        *(unsigned short *) (dp1 + (sx >> 16) * 3);
                    *(unsigned char *) (dp2 + x * 3 + 2) =
                        *(unsigned char *) (dp1 + (sx >> 16) * 3 + 2);
                    sx += xfactor;
                    x++;
                }
                dp2 += w2 * 3;
                y++;
                while (y < h2) {
                    int l;
                    int syint = sy >> 16;
                    sy += yfactor;
                    if ((sy >> 16) != syint)
                        break;
                    /* Copy identical lines. */
                    l = dp2 - dp2old;
                    memcpy(dp2, dp2old, l);
                    dp2old = dp2;
                    dp2 += l;
                    y++;
                }
                dp1 = _dp1 + (sy >> 16) * w1 * 3;
            }
        }
        break;
    case 4:
        {
            int y, sy;
            sy = 0;
            for (y = 0; y < h2;) {
                int sx = 0;
                uchar *dp2old = dp2;
                int x;
                x = 0;
                /* This can be greatly optimized with loop */
                /* unrolling; omitted to save space. */
                while (x < w2) {
                    *(unsigned *) (dp2 + x * 4) =
                        *(unsigned *) (dp1 + (sx >> 16) * 4);
                    sx += xfactor;
                    x++;
                }
                dp2 += w2 * 4;
                y++;
                while (y < h2) {
                    int l;
                    int syint = sy >> 16;
                    sy += yfactor;
                    if ((sy >> 16) != syint)
                        break;
                    /* Copy identical lines. */
                    l = dp2 - dp2old;
                    memcpy(dp2, dp2old, l);
                    dp2old = dp2;
                    dp2 += l;
                    y++;
                }
                dp1 = _dp1 + (sy >> 16) * w1 * 4;
            }
        }
        break;
    }

    return 0;
}
/****************************************************************************/

static int copybox (GAL_GC gc, int x, int y, int w, int h, int nx, int ny)
{
	int ret;
	unsigned char *temp_buf = (unsigned char *)alloca(gc.s3c44b0x->stride * h + 1 );
	ret = getbox(gc,x,y,w,h,temp_buf);
	if ( ret == -1 )
		return -1;
	ret = putbox(gc,nx,ny,w,h,temp_buf);
 	if ( ret == -1 )
		return -1;
    return 0;
}

static int crossblit (GAL_GC src, int sx, int sy, int sw, int sh,
                GAL_GC dst, int dx, int dy)
{
	int ret;
	unsigned char *temp_buf = (unsigned char *)alloca(src.s3c44b0x->stride * sh + 1 );
	ret = getbox(src,sx,sy,sw,sh,temp_buf);
	if ( ret == -1 )
		return -1;
	ret = putbox(dst,dx,dy,sw,sh,temp_buf);
 	if ( ret == -1 )
		return -1;
    return 0;
}


// Horizontal line operaions
static int drawhline (GAL_GC gc, int x, int y, int w, gal_pixel pixel)
{
	int i,x1,y1,x2,y2,ret,ww;
	int shift;
	unsigned char *dest;
	getclipping(gc,&x1,&y1,&x2,&y2);
	shift = gc.s3c44b0x->depth;
	ww = w;
	ww += x;
	ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&y);
	if ( ret == -1 )
		return -1;
	ww -= x;
#ifdef GRAY16
	for ( i = 0; i <= ww; i++ )
	{
		dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*y + (gc.s3c44b0x->stride)*(x+i)/MAX_X;
        	if ( (x+i) % (8/shift) == 1 )
        	{
            		*dest &= 0xff << shift;
            		pixel &= 0xff >> (8-shift);
            		*dest |= pixel;
        	}
        	else if ( (x+i) % (8/shift) == 0 )
        	{
            		*dest &= 0xff >> (8-shift);
            		pixel &= 0xff >> (8-shift);
            		*dest |= pixel << shift;
        	}
	}
#else
	i=i;	// for waning
	dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*y + (gc.s3c44b0x->stride)*x/MAX_X;
	memset(dest,pixel,ww);
#endif
    return 0;
}


// Vertical line operations
static int drawvline (GAL_GC gc, int x, int y, int h, gal_pixel pixel)
{
    int i,x1,y1,x2,y2,ret,hh;
    int shift;
    unsigned char *dest;
    getclipping(gc,&x1,&y1,&x2,&y2);
    shift = gc.s3c44b0x->depth;
    hh = h;
    hh += y;
    ret = getclippingrect(x1,y1,x2,y2,&x,&y,&x,&hh);
    if ( ret == -1 )
        return -1;
    hh -= y;
#ifdef GRAY16
    for ( i = 0; i <= hh; i++ )
    {
    	dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*x/MAX_X;
        if ( x % (8/shift) == 1 )
        {
            *dest &= 0xff  << shift;
            pixel &= 0xff  >> (8-shift);
            *dest |= pixel;
        }
        else if ( x % (8/shift) == 0 )
        {
            *dest &= 0xff >> (8-shift);
            pixel &= 0xff >> (8-shift);
            *dest |= pixel << shift;
        }
    }
#else
    for ( i = 0; i < hh; i++ )
    {
        dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*x/MAX_X;
        *dest = pixel;
    }
#endif
    return 0;
}


// Pixel operations
static int drawpixel (GAL_GC gc, int x, int y, gal_pixel pixel)
{
	int x1,y1,x2,y2;
	unsigned char   *dest;
	int shift; 
	getclipping(gc,&x1,&y1,&x2,&y2);
    shift = gc.s3c44b0x->depth;
	if ( x >= x1 && x <= x2 && y >= y1 && y <= y2 ) 
	{
#ifdef GRAY16
	 	dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*y+(gc.s3c44b0x->stride)*x/MAX_X;
        	if ( x % (8/shift) == 1 )
        	{
            		*dest &= 0xff << shift;
            		pixel &= 0xff >> (8-shift);
            		*dest |= pixel;
        	}
        	else if ( x % (8/shift) == 0 )
        	{
            		*dest &= 0xff >> (8-shift);
            		pixel &= 0xff >> (8-shift);
            		*dest |= pixel << shift;
	        }
#else
	    	dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*y+(gc.s3c44b0x->stride)*x/MAX_X;
		*dest = pixel;
#endif
    		return 0;
	}
	return -1;
}


static int getpixel (GAL_GC gc, int x, int y, gal_pixel* color)
{
    int x1,y1,x2,y2;
    unsigned char   *dest;
    int shift;
    getclipping(gc,&x1,&y1,&x2,&y2);
    shift = gc.s3c44b0x->depth;
    if ( x >= x1 && x <= x2 && y >= y1 && y <= y2 )
    {
#ifdef GRAY16
        dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*y+(gc.s3c44b0x->stride)*x/MAX_X;
        if ( x % (8/shift) == 1 )
            *color = (0xff >> (8-shift)) & (*dest);
        else if ( x % (8/shift) == 0 )
            *color =  *dest >>  (8-shift);
#else
        dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*y+(gc.s3c44b0x->stride)*x/MAX_X;
        *color = *dest;
#endif
        return 0;
    }
    return -1;
}


// Other drawing
// without any code
static int circle (GAL_GC gc, int x, int y, int r, gal_pixel pixel)
{
    return 0;
}

static int line (GAL_GC gc, int x1, int y1, int x2, int y2, 
                gal_pixel pixel)
{
    return 0;
}

static int rectangle (GAL_GC gc, int l, int t, int r, int b, 
                gal_pixel pixel)
{
	drawhline(gc,l,t,(r-l)+1,pixel);
	drawvline(gc,l,t,(b-t)+1,pixel);
	drawhline(gc,l,b,(r-l)+1,pixel);
	drawvline(gc,r,t,(b-t)+1,pixel);
    return 0;
}

static void panic (int exitcode)
{
}

BOOL Inits3c44b0x (GFX* gfx)
{
	int i;

	initlcd();	// init hardware
	
	s3c44b0x          =  (S3C44B0X *)malloc(sizeof(S3C44B0X));
	s3c44b0x->bpp     =  1;
	s3c44b0x->depth   =  PIXELBPP;
	s3c44b0x->width   =  MAX_X;
	s3c44b0x->height  =  MAX_Y;
	s3c44b0x->bkcolor =  0;
	s3c44b0x->fgcolor =  (1 << PIXELBPP)-1;
	s3c44b0x->shift   =  12; 	// gray 16
	s3c44b0x->stride  =  MAX_X / 8 * s3c44b0x->depth;
	s3c44b0x->fb_buf  =  (char*)FrameBuffer;
	
#ifdef GRAY16
	for (i=0; i<16; i++)
        	SysPixelIndex [i] =  i;
    	SysPixelIndex [16] = 0;
#else
    	for (i=0; i<17; i++)
        	SysPixelIndex [i] =  mapcolor (gfx->phygc, (gal_color *)(&SysPixelColor[i]));
#endif

    	gfx->phygc.s3c44b0x     = s3c44b0x;
    	gfx->bytes_per_phypixel = s3c44b0x->bpp;
    	gfx->bits_per_phypixel  = s3c44b0x->depth;
    	gfx->width_phygc        = s3c44b0x->width;
    	gfx->height_phygc       = s3c44b0x->height;
    	gfx->colors_phygc       = 1 << s3c44b0x->depth;
    	gfx->grayscale_screen   = FALSE;

    	gfx->bytesperpixel      = bytes_per_pixel;
    	gfx->bitsperpixel       = bits_per_pixel;
    	gfx->width              = width;
    	gfx->height             = height;
    	gfx->colors             = colors;
    	gfx->allocategc         = allocategc;
    	gfx->freegc             = freegc;
    	gfx->setgc              = NULL;
    	gfx->enableclipping     = enableclipping;
    	gfx->disableclipping    = disableclipping;
    	gfx->setclipping        = setclipping;
        gfx->getclipping        = getclipping;
    	gfx->getbgcolor         = NULL;
    	gfx->setbgcolor         = NULL;
    	gfx->getfgcolor         = NULL;
    	gfx->setfgcolor         = NULL;
    	gfx->mapcolor           = mapcolor;
    	gfx->unmappixel         = unmappixel;
    	gfx->getpalette         = getpalette;
    	gfx->setpalette         = setpalette;
    	gfx->setcolorfulpalette = setcolorfulpalette;
    	gfx->boxsize            = boxsize;
    	gfx->fillbox            = fillbox;
        gfx->putbox             = putbox;
    	gfx->getbox             = getbox;
    	gfx->putboxmask         = putboxmask;
    	gfx->scalebox           = scalebox;
    	gfx->copybox            = copybox;
    	gfx->crossblit          = crossblit;
    	gfx->drawhline          = drawhline;
    	gfx->drawvline          = drawvline;
    	gfx->drawpixel          = drawpixel;
    	gfx->getpixel           = getpixel;
    	gfx->circle             = circle;
    	gfx->line               = line;
        gfx->rectangle          = rectangle;
    	gfx->panic              = panic;
    	return TRUE;
}   	
    	
void Terms3c44b0x (GFX* gfx)
{ 
	free(s3c44b0x);
}

⌨️ 快捷键说明

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