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

📄 generic2.c

📁 linux嵌入式开发程序
💻 C
字号:
/************************************************************************* *     2D Graphics Library                                               * *     ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 1993-2002      * *     LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED           * *************************************************************************//*=======================================================================*    Example of customizing Graphics Library    This is a basic pattern of customization using VRAM address table,    hook table of implement modules. *=======================================================================*/#include "gl.h"#include "color.h"#ifndef NULL#define NULL            ((void *)0)#endif /* NULL *//*------------------------------------------------------------------------ *  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_VRAM256      /* Type of VRAM                 */#define VRAMBPP         8               /* Number of bytes per pixel    */#define PLANES          1               /* Number of Planes             */#define HOOKTABLE       _GL_defhook256  /* Implement modules            */                                        /* Hook table                   *//*------------------------------------------------------------------------ *  VRAM area * *      Defines VRAM area. *      If VRAM area is fixed in hardware, specify address directory. *      [Example] *      #define Vram (void *)0x00400000 */#define VRAMSIZE   ((VRAMBPP*WIDTH+7)/8*HEIGHT*PLANES)unsigned char    Vram[PAGES][VRAMSIZE] ;/*------------------------------------------------------------------------ *  VRAM address table * *     video_VRAMtbl[pageno][planeno] ; * *  In the VRAM address table, address where VRAM is stored in is described. *  Area of VRAM address must be enough for the size of number of *  sepecified pages x 4 planes. Even if the number of planes to be used is *  under 4, area must be enough for 4 planes. However, information *  on a plane that is not used has no means. * *  If each area of VRAM is continuous, it is possible to specify NULL *  to the member for VRAM address in the configuration table and set *  the entry of VRAM to the third argument of GL_setup. In this case, *  VRAM address table is not needed. * */const void *video_VRAMtbl[PAGES][4] = {    {        (void *)Vram[0],        (void *)Vram[1],        (void *)Vram[2],        (void *)Vram[3]    }};/*------------------------------------------------------------------------ *  Hook table for implement modules * *  If you want to embed the other type of VRAM, copy any implement tabel *  from hook.tbl. *  The followings are relation between VRAM types and name of tabels. * *       Table name     VRAM type (bit x plane) *       ----------     ----------------------- *        hooktbl1         1 x 1 *        hooktbl16        4 x 1 *        hooktbl16p       1 x 4 *        hooktbl256       8 x 1, 8 x 1 mono *        hooktbl64k      16 x 1 *        hooktbl16m      24 x 1 *        hooktbl16mp      8 x 3 *        hooktbl16mh     16 x 3 * *  These hook tables use implement modules embedded as default. *  Therefore, if using default, it is not needed to add new program. *  For example, if graphics library is implemented to pseudo VRAM *  on RAM, use these table without changes. * *  However, it is needed to re-write implement modules in many cases *  correspondto hardware(VRAM) in many cases. In this case, make new *  programs according to "Implement module spcification", and register *  entry of functions newly made to the hook table. * *  Modules which need to be re-writen is (*init)(), (*palette)(), *  (*dsppage)(), (*actpage)(), and (*selplane)() at least. *  However, if palette is not surported, page of VRAM is 1, or type *  of VRAM is not plane, re-writing module for them is not needed. * *  Also, if hardware supports drawing line, BitBLT, etc, it is preferable *  to improve performance by making implement modules according to them. * */const GL_HOOK video_hook256 = {    _GL_hinit,          /* (*init)(gp) ;            initialize              */    _GL_paletteset,     /* (*palette)(gp,palette,color) ; set a palette     */    _GL_actpage,        /* (*actpage)(gp,page) ;    select a active page    */    _GL_dsppage,        /* (*dsppage)(gp,page) ;    select a display page   */    _GL_selplane,       /* (*selplane)(gp,read,write) ; select plane(s)     */    _GL_cls256,         /* (*cls)(gp) ;             clear screen all        */    _GL_scrl256,        /* (*scroll)(gp) ;          scroll screen           */    _GL_pset256,        /* (*pset)(gp) ;            set a point             */    _GL_pget256,        /* (*pget)(gp) ;            get a point             */    _GL_dda256,         /* (*dda)(gp) ;             draw a line             */    _GL_bbset256,       /* (*bbset)(gp) ;           fill color              */    _GL_bbtile256,      /* (*bbtile)(gp) ;          fill tile               */    _GL_bbcopy256,      /* (*bbcopy)(gp) ;          copy image              */    _GL_bbget256,       /* (*bbget)(gp) ;           get image               */    _GL_bbput256,       /* (*bbput)(gp) ;           put image               */    _GL_bbdot256,       /* (*bbdot)(gp) ;           put dot image           */    _GL_findfont,       /* (*findfont)(gp) ;        select type face        */    _GL_getfont,        /* (*getfont)(gp) ;         get a font data         */    _GL_searchedge256,  /* (*searchedge)(gp,flood) ;search edge             */    _GL_bbmask256       /* (*bbmask(gp) ;           fill by mask pattern    */} ;/*------------------------------------------------------------------------ *  Configuration table * *  In configuration table, type of VRAM to be used, maximum number of *  each definitions, etc. are described. If type of VRAM is changed, *  this table must be changed also. */const GL_CONFIG video_config = {    VRAMTYPE,           /*VRAMmode ; VRAM type                          */                        /*              GL_VRAM1    (0)  1bit *1plane   */                        /*              GL_VRAM16P  (1)  1bit * 4planes */                        /*              GL_VRAM16   (2)  4bits* 1plane  */                        /*              GL_VRAM256  (3)  8bits* 1plane  */                        /*              GL_VRAM256G (4)  8bits* 1plane  */                        /*              GL_VRAM64K  (5) 16bits* 1plane  */                        /*              GL_VRAM16MP (6)  8bits* 3planes */                        /*              GL_VRAM16MH (7) 16bits* 3planes */                        /*              GL_VRAM16M  (8) 24bits* 1plane  */    0,                  /*VRAMbpl ; bytes per line of VRAM              */                        /*               0:automatic                    */    (void *((*)[4]))video_VRAMtbl,                        /* VRAMtbl ;    pointer of VRAM address table   */    &video_hook256,     /* *hook ;      pointer of a hook table         */    PAGES,              /* pages ;      VRAM pages                      */    WIDTH,              /* width ;      VRAM width                      */    HEIGHT,             /* lines ;      VRAM height                     */    STYLES,             /* styles ;     maximum of linestyles           */    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 for Graphics Library * *  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 stored at 64 bit address boundary. Entry point of *  work area is corrected in sample program (UserMain()). */char  glwork[GL_WORKSIZE(PAGES,STYLES,TILES,IMAGES,TMPAREASIZE)+8] ;/*---------------------------------------------------------------- *  Initialization of Graphics Library * *  Initialization is operation to available Graphics Library. *  Available work area and it's size are used as parameters usually. *  Pointer to a secure management table in work area is returned. *  If error occures in initialization, NULL is returned. * */GL_WP *GLSetup(char *workarea,long workmax){    GL_WP *gp ;    long  n ;    n = -(long)workarea & 7 ;    gp = (GL_WP *)((long)workarea+n) ;    workmax -= n ;    if(GL_setup(gp,workmax,NULL,(GL_CONFIG *)&video_config)==GL_Ok){        if(GL_init(gp,0)==GL_Ok)            return gp ;    }    return NULL ;}/*--------------------------------------------------------------------------- *  Main program * *      This is a sample program of painting with mask pattern. *      Initializes GL, and draws a circle, and paints in it with mask pattern. *      UserMain function is called from main function in main.c. * */int main(){    GL_WP *gp ;    gp = GLSetup(glwork,sizeof(glwork)) ;    if(gp!=NULL){        GL_filltype(gp, GL_FILL) ;        GL_color2(gp, GL_FILLC, White) ;        GL_circle(gp, 160, 100, 50) ;        GL_color2(gp, GL_FILLC, Blue) ;        GL_circle(gp, 160, 100, 40) ;        GL_sizechar(gp, 50, 40) ;        GL_color2(gp, GL_DRAWC, Yellow) ;        GL_putstr(gp, (short *)"\0O\0K", 2, 110, 80) ;    }    return 0;}

⌨️ 快捷键说明

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