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

📄 sample.c

📁 linux嵌入式开发程序
💻 C
字号:
/****************************************************************************	2D Graphics Library	ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 2001-2002	LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED ****************************************************************************/#include "gl.h"#include "expand.h"/*------------------------------------------------------------------------ * Summary of this sample program * *  This program is an example of how 2D Graphics Library, extended *  function modules, implement modules for transparent attribute are *  used. *-----------------------------------------------------------------------*//*------------------------------------------------------------------------ *  Definition of parameter * *  Defines parameter of GL. */#define PAGES           1               /* Number of pages              */#define STYLES          2               /* Number of line styles        */#define TILES           2               /* Number of tiles              */#define IMAGES          2               /* Number of images             */#define WIDTH           320             /* Number of horizontal pixels  */#define HEIGHT          240             /* Number of vertical pixels    */#define TMPAREASIZE     16384           /* Size of temporary buffer     */#define VRAMTYPE        GL_VRAM16M      /* Type of VRAM                 */#define VRAMBPP         3               /* Number of bytes per pixel    */#define VRAMBPL         (WIDTH*VRAMBPP)#define PLANES          1               /* Number of Planes             */#define HOOKTABLE       hookRGB888      /* Implement modules            */	                                /* Hook table (RGB888)          *//*------------------------------------------------------------------------ *  VRAM area * *      Defines VRAM area. *      In this sample, VRAM area is defined in other source file. * *      If VRAM area is fixed in hardware, specify address directory. *      [Example] *      #define Vram (void *)0x00400000 */unsigned char *Vram;/*------------------------------------------------------------------------ *  Hook table of implement modules * *  This is hook table of implement modules for RGB888. * *  If you want to custmize implement modules, create new implement *  modules and register them to this table. * *  If custmization is not needed, use this table without change or *  use _GL_defhookRGB888. * *  _GL_defhookRGB888 is in library file (im.a). *  Source files of each modules registered to this table are stored in *  directory trns_im/src/rgb888. * */int _GL_hinitRGB888(GL_WP *gp);int _GL_palettesetRGB888(GL_WP *gp,unsigned long palette,unsigned long color);int _GL_actpageRGB888(GL_WP *gp,short page);int _GL_dsppageRGB888(GL_WP *gp,short page);int _GL_selplaneRGB888(GL_WP *gp,short read,short write);int _GL_psetRGB888(GL_WP *gp);int _GL_pgetRGB888(GL_WP *gp);int _GL_ddaRGB888(GL_WP *gp);int _GL_bbsetRGB888(GL_WP *gp);int _GL_bbtileRGB888(GL_WP *gp);int _GL_bbcopyRGB888(GL_WP *gp);int _GL_bbgetRGB888(GL_WP *gp);int _GL_bbputRGB888(GL_WP *gp);int _GL_bbdotRGB888(GL_WP *gp);int _GL_findfontRGB888(GL_WP *gp);int _GL_getfontRGB888(GL_WP *gp);int _GL_bbmaskRGB888(GL_WP *gp);const GL_HOOK hookRGB888 = {	_GL_hinitRGB888,        /* (*init)(gp);                */	_GL_palettesetRGB888,   /* (*palette)(gp,palette,color);*/	_GL_actpageRGB888,      /* (*actpage)(gp,page);        */	_GL_dsppageRGB888,      /* (*dsppage)(gp,page);        */	_GL_selplaneRGB888,     /* (*selplane)(gp,read,write); */	_GL_bbsetRGB888,        /* (*cls)(gp);                 */	_GL_bbcopyRGB888,       /* (*scroll)(gp);              */	_GL_psetRGB888,         /* (*pset)(gp);                */	_GL_pgetRGB888,         /* (*pget)(gp);                */	_GL_ddaRGB888,          /* (*dda)(gp);                 */	_GL_bbsetRGB888,        /* (*bbset)(gp);               */	_GL_bbtileRGB888,       /* (*bbtile)(gp);              */	_GL_bbcopyRGB888,       /* (*bbcopy)(gp);              */	_GL_bbgetRGB888,        /* (*bbget)(gp);               */	_GL_bbputRGB888,        /* (*bbput)(gp);               */	_GL_bbdotRGB888,        /* (*bbdot)(gp);               */	_GL_findfontRGB888,     /* (*findfont)(gp);            */	_GL_getfontRGB888,      /* (*getfont)(gp);             */	_GL_searchedge16m,      /* (*searchedge)(gp, flood);   */	_GL_bbmaskRGB888,       /* (*bbmask(gp);               */};/*------------------------------------------------------------------------ *  Configuration table * *  In configuration table, type of VRAM to be used, maximum number of *  each definitions, etc. are described. */extern  const GL_HOOK _GL_defhookRGB888;const GL_CONFIG video_config = {	VRAMTYPE,	/*VRAMmode;	VRAM type			*/	VRAMBPL,	/*VRAMbpl;	Bytes per line of VRAM		*/			/*		0:automatic			*/	(void *)0,	/* VRAMtbl;	Pointer to VRAM address table	*/	&HOOKTABLE,	/* *hook;	Pointer to a hook table		*/	PAGES,		/* pages;	VRAM pages			*/	WIDTH,		/* width;	VRAM width			*/	HEIGHT,		/* lines;	VRAM height			*/	STYLES,		/* styles;	Maximum of line styles		*/	TILES,		/* tiles;	Maximum of tile patterns	*/	IMAGES,		/* images;	Maximum of images		*/	1,		/* linesize;	Standard line size		*/	0		/* ciradj;	Adjustment of circle (n:256)	*/};/*------------------------------------------------------------------------ *  Work area * * This is work area for graphics library. Accurate size of a temporary * buffer in this area (defined as TMPAREASIZE here) depends on type of * VRAM, the number of definition of tiles, etc. For detailed information, * refer to specification. * * Work area must be set at 64 bit address boundary. Entry point of work * area is corrected in Sample program (main()). * */char  glwork[GL_WORKSIZE(PAGES,STYLES,TILES,IMAGES,TMPAREASIZE)+8];/*------------------------------------------------------------------------ * * Sample data * *  XD ... Source horizontal pixels. *  YD ... Source vertical pixels. * */#define XD      288#define YD      288#define DATANAME    image1Dataextern  const unsigned char DATANAME[];extern  const unsigned char image2Data[];#define RGB_WHITE       0x00ffffff#define RGB_BLACK       0x00000000#define RGB_LIGHTBLUE   0x00add8e6/*------------------------------------------------------------------------ * *  Interpolates image by nearest neighbor interpolation * */voidNearestNeighbor(int x, int y, int nWidth, int nHeight, int nRotate, int nSlope){	GL_EXPAND   info;	info.pSrcData   = (unsigned char *)DATANAME;	info.nSrcWidth  = XD;	info.nSrcHeight = YD;	info.nSrcBpl    = XD * VRAMBPP;	info.pDstData   = (unsigned char *)Vram;	info.nDstWidth  = nWidth;	info.nDstHeight = nHeight;	info.nDstBpl    = VRAMBPL;	info.dx         = x;	info.dy         = y;	info.vx1        = 0;	info.vy1        = 0;	info.vx2        = WIDTH-1;	info.vy2        = HEIGHT-1;	info.nRotate    = nRotate;	info.nSlope     = nSlope;	info.nBpp       = VRAMBPP;	info.nAxis      = GL_EXPAND_AXIS_BOTTOMLEFT;	ExpandReadyRGB888( &info );	ExpandNearestNeighborRGB888( &info );}/*------------------------------------------------------------------------ * *  Interpolates image by bi-linear interpolation * */voidBilinear(int x, int y, int nWidth, int nHeight, int nRotate, int nSlope){	GL_EXPAND   info;	info.pSrcData   = (unsigned char *)DATANAME;	info.nSrcWidth  = XD;	info.nSrcHeight = YD;	info.nSrcBpl    = XD * VRAMBPP;	info.pDstData   = (unsigned char *)Vram;	info.nDstWidth  = nWidth;	info.nDstHeight = nHeight;	info.nDstBpl    = VRAMBPL;	info.dx         = x;	info.dy         = y;	info.vx1        = 0;	info.vy1        = 0;	info.vx2        = WIDTH-1;	info.vy2        = HEIGHT-1;	info.nRotate    = nRotate;	info.nSlope     = nSlope;	info.nBpp       = VRAMBPP;	info.nAxis      = GL_EXPAND_AXIS_BOTTOMLEFT;	ExpandReadyRGB888( &info );	ExpandBilinearRGB888( &info );}/*------------------------------------------------------------------------ * *  Interpolates image by bi-cubic interpolation * */voidBicubic(int x, int y, int nWidth, int nHeight, int nRotate, int nSlope){	GL_EXPAND   info;	info.pSrcData   = (unsigned char *)DATANAME;	info.nSrcWidth  = XD;	info.nSrcHeight = YD;	info.nSrcBpl    = XD * VRAMBPP;	info.pDstData   = (unsigned char *)Vram;	info.nDstWidth  = nWidth;	info.nDstHeight = nHeight;	info.nDstBpl    = VRAMBPL;	info.dx         = x;	info.dy         = y;	info.vx1        = 0;	info.vy1        = 0;	info.vx2        = WIDTH-1;	info.vy2        = HEIGHT-1;	info.nRotate    = nRotate;	info.nSlope     = nSlope;	info.nBpp       = VRAMBPP;	info.nAxis      = GL_EXPAND_AXIS_BOTTOMLEFT;	info.pTable     = ExpandBicubicTableAlpha_0_5;	ExpandReadyRGB888( &info );	ExpandBicubicRGB888( &info );}/*--------------------------------------------------------------------------- * *  Transparency * */void trans_image(GL_WP *gp, GL_IDSC *idsc, void *dp, short width, short lines,	                char type, char bpp, short x, short y, unsigned long col){	idsc->dp = dp;	idsc->width = width;	idsc->lines = lines;	idsc->type = type;	idsc->bpp = bpp;	idsc->bpl = 0;	idsc->bpu = 0;	GL_color(gp, GL_BACKC, col);	GL_logic(gp, GL_PSET|GL_TRANS);	GL_putimage(gp, idsc, x, y);}/*--------------------------------------------------------------------------- * *  Main program * */int main(){	GL_WP	*gp;	long	n, workmax;	int	r;	GL_IDSC idsc;	Vram = (unsigned char *)vdc_init();	n = -(long)glwork & 7;	gp = (GL_WP *)((long)glwork+n);	workmax = sizeof(glwork)-n;	GL_setup(gp, workmax, Vram, (GL_CONFIG *)&video_config);	GL_init(gp,0);	/*	    Set black to background color, white to drawing and painting color.	    And initialize VRAM with background color (black).	 */	GL_color(gp, GL_BACKC, RGB_BLACK);	GL_color(gp, GL_DRAWC, RGB_WHITE);	GL_color(gp, GL_FILLC, RGB_WHITE);	GL_cls(gp, 0);	/*	    Examples of how expanded function modules are used.	 */	r = 25;	GL_color(gp, GL_BACKC, RGB_LIGHTBLUE);	GL_cls(gp, 0);	Bilinear(0, 100, 120, 120, r, 0);	Bicubic(120, 140, 120, 120, r, 0);	NearestNeighbor(100, 280, 120, 120, r, 0);	trans_image(gp, &idsc, (void *)image2Data, 256, 320, GL_PACKED, GL_D24,	    0, 0, RGB_WHITE);	sleep(10);	vdc_close();		return 0;}

⌨️ 快捷键说明

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