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

📄 ads.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
//// $Id: ads.c,v 1.10 2002/01/15 06:09:30 ymwei Exp $//// ads.c: Low Level Graphics Engine for strongARM-based ADS Graphics Client.//// This is a customized graphics engine for ADS Graphics Client embedded system // which based on StrongARM.// // NOTE: You should use the native GAL engine for this system.///***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------////#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include "common.h"#include "gal.h"#include "ads.h"#define DOSHIFT(val, shift)  \    (((shift) >= 0) ? (val) << (shift) : (val) >> -(shift))static ADS  *ads;static int getclippingrect (int sx1,int sy1,int sx2,int sy2,int *dx1,int *dy1,int *dx2,int *dy2){	*dx1 = ((*dx1) > sx1) ? (*dx1) : sx1;	*dy1 = ((*dy1) > sy1) ? (*dy1) : sy1;	*dx2 = ((*dx2) < sx2) ? (*dx2) : sx2;	*dy2 = ((*dy2) < sy2) ? (*dy2) : sy2;	if ( *dx1 >= *dx2 || *dy1 >= *dy2 )	{		return FALSE;	}	return TRUE;}// GC propertiesstatic int bytes_per_pixel (GAL_GC gc){    return gc.ads->bpp;}static int bits_per_pixel (GAL_GC gc){    return gc.ads->depth;}static int width (GAL_GC gc){    return gc.ads->width;}static int height (GAL_GC gc){    return gc.ads->height;}static int colors (GAL_GC gc){    int depth = bits_per_pixel (gc);    return 1 << depth;}// Allocation and release of graphics contextstatic int allocategc (GAL_GC gc, int width, int height, int depth,                 GAL_GC* newgc){	newgc->ads = (ADS *)malloc(sizeof(ADS));	if ( newgc->ads == NULL )		return -1;	newgc->ads->bpp  =  gc.ads->bpp;	newgc->ads->bkcolor =  gc.ads->bkcolor;	newgc->ads->fgcolor =  gc.ads->fgcolor;	newgc->ads->x1 =  gc.ads->x1;	newgc->ads->y1 =  gc.ads->y1;	newgc->ads->x1 =  gc.ads->x1;	newgc->ads->y2 =  gc.ads->y2;	newgc->ads->stride =  gc.ads->stride;	newgc->ads->fb_buf =  gc.ads->fb_buf;	newgc->ads->width  = width;	newgc->ads->height = height;	newgc->ads->depth  = depth;    return 0;}// without any codestatic void freegc (GAL_GC gc){   free(gc.ads); }// Clipping of graphics context// without any codestatic void enableclipping (GAL_GC gc){	gc.ads->x1 = 0;	gc.ads->y1 = 0;	gc.ads->x2 = gc.ads->width-1;	gc.ads->y2 = gc.ads->height-1;}static void disableclipping (GAL_GC gc){	enableclipping(gc);}static int setclipping (GAL_GC gc, int x1, int y1, int x2, int y2){   // ggiSetGCClipping (gc.visual, x1, y1, x2 + 1, y2 + 1);	gc.ads->x1 = x1;	gc.ads->y1 = y1;	gc.ads->x2 = x2 + 1;	gc.ads->y2 = y2 + 1;    return 0;}static int getclipping (GAL_GC gc, int* x1, int* y1, int* x2, int* y2){	*x1 = gc.ads->x1;	*y1 = gc.ads->y1;	*x2 = gc.ads->x2 - 1;	*y2 = gc.ads->y2 - 1;    return 0;}// Background and foreground colors/*static int getbgcolor (GAL_GC gc, gal_pixel* color){    *color = gc.ads->bkcolor;    return 0;}static int setbgcolor (GAL_GC gc, gal_pixel color){    gc.ads->bkcolor = color;    return 0;}static int getfgcolor (GAL_GC gc, gal_pixel* color){    *color = gc.ads->fgcolor;    return 0;}static int setfgcolor (GAL_GC gc, gal_pixel color){    gc.ads->fgcolor = color;    return 0;}*/static int calc_total(unsigned int mask){    int total;    for (total=0; mask != 0; mask >>= 1, total++) {    }    return total;}static gal_pixel mapcolor(GAL_GC gc, GAL_Color *color){	gal_pixel    ret;    ret =   (DOSHIFT(color->r, gc.ads->r_map) &            gc.ads->r_mask) |            (DOSHIFT(color->g, gc.ads->g_map) &            gc.ads->g_mask) |            (DOSHIFT(color->b, gc.ads->b_map) &            gc.ads->b_mask);	return ret; }static int unmappixel (GAL_GC gc, gal_pixel pixel, GAL_Color* color){    color->r = DOSHIFT(pixel & gc.ads->r_mask,             (-gc.ads->r_map));    color->g = DOSHIFT(pixel & gc.ads->g_mask,             (-gc.ads->g_map));    color->b = DOSHIFT(pixel & gc.ads->b_mask,             (-gc.ads->b_map));    return 0;}// Palette operationsstatic int getpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){    int i;    for (i = 0; i < len; i++) {    cmap[i].r = DOSHIFT((s+i) & gc.ads->r_mask,             (-gc.ads->r_map));    cmap[i].g = DOSHIFT((s+i) & gc.ads->g_mask,             (-gc.ads->g_map));    cmap[i].b = DOSHIFT((s+i) & gc.ads->b_mask,             (-gc.ads->b_map));    }    return 0;}static int setpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){//    int i;//    for (i = 0; i < len; i++) {//        cmap [i].r = rgb8to16 (cmap [i].r);//        cmap [i].g = rgb8to16 (cmap [i].g);//        cmap [i].b = rgb8to16 (cmap [i].b);//    } //   ggiSetPalette(gc.visual, s, len, (ggi_color *)cmap);    return 0;}static int setcolorfulpalette (GAL_GC gc){//    ggiSetColorfulPalette (gc.visual);    return 0;}// Box operationsstatic size_t boxsize (GAL_GC gc, int w, int h){    return w * h * bytes_per_pixel (gc);}static int fillbox (GAL_GC gc, int x, int y, int w, int h,                gal_pixel pixel){	int i,j,x1,y1,x2,y2,ret,ww,hh;	unsigned char *dest;	getclipping(gc,&x1,&y1,&x2,&y2);	ww = w;	hh = h;	ww += x;	hh += y;		ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&hh);		if ( ret == -1 )		return -1;	ww -= x;	hh -= y;	for (i = 0; i < hh ; i++)	{		dest = gc.ads->fb_buf + (gc.ads->stride)*(y+i) + (gc.ads->stride)*x/MAX_X;//		for (j=0;j<ww;j++)//			*(dest++) = pixel;        memset(dest,pixel,ww);	}    return 0;}static int putbox (GAL_GC gc, int x, int y, int w, int h, void* buf){	int i,j,k,x1,x2,y1,y2,ret,ww,hh;	unsigned char *dest;//	k = 0;	getclipping(gc,&x1,&y1,&x2,&y2);	ww = w;	hh = h;	ww += x;	hh += y;		ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&hh);		if ( ret == -1 )		return -1;	ww -= x;	hh -= y;	for ( i = 0; i < h; i++ )	{		if ( i < hh ) 		{			dest = gc.ads->fb_buf + (gc.ads->stride)*(y+i) + (gc.ads->stride)*x/MAX_X;//			for ( j = 0; j < w; j++ )//			{//				if ( j < ww )//				{  //                  *(dest++) = (unsigned char *)buf[k]  ;					memcpy(dest,buf,ww);	//			}	//			k++;//			}		}//		else //			k += w;	}    return 0;}static int getbox (GAL_GC gc, int x, int y, int w, int h, void* buf){	int i,j,k,x1,y1,x2,y2;	unsigned char *dest;	k = 0;	getclipping(gc,&x1,&y1,&x2,&y2);	for ( i = 0; i < h; i++ )	{		if ( y+i <= y2 && y+i >= y1 )		{			dest = gc.ads->fb_buf+(gc.ads->stride)*(y+i)+(gc.ads->stride)*x/MAX_X;//			for ( j = 0; j < w; j++ )//			{//				if ( x+j <= x2 && x+j >= x1)//				{//                        (unsigned char *)buf[k] = *(dest++);			memcpy(buf,dest,min(x2-x,w));	//				}//				k++;//			}		}//		else //			k += w;	}    return 0;}static int putboxmask (GAL_GC gc, int x, int y, int w, int h, void* buf, gal_pixel transparent){    return 0;}/****************************************************************************//*      scalebox comes from SVGALib, Copyright 1993 Harm Hanemaayer         */typedef unsigned char uchar;/* We use the 32-bit to 64-bit multiply and 64-bit to 32-bit divide of the *//* 386 (which gcc doesn't know well enough) to efficiently perform integer *//* scaling without having to worry about overflows. */static inline int muldiv64 (int m1, int m2, int d){    long long int mul = (long long int) m1 * m2;    return (int) (mul / d);}/* This is a DDA-based algorithm. *//* Iteration over target bitmap. */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++;                }

⌨️ 快捷键说明

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