📄 floodf2.c
字号:
/*************************************************************************
* 2D Graphics Library *
* ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 1993-2002 *
* LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED *
*************************************************************************/
/*=======================================================================*
Sample program to speed up operation of painting with mask pattern
*=======================================================================*/
#include "gl.h"
/*------------------------------------------------------------------------
* Labels for selection of type of VRAM
*
* This sample program supports two types of VRAM, 1 bit x 4 planes
* and 4 bits x 1 plane.
* Select type of VRAM by defining ether of the following two labels.
*
* VRAM16 1 4 bits x 1 plane
* VRAM16P 1 1 bit x 4 planes
*
*/
/*#define VRAM16 1*/
#define VRAM16P 1
#define SPEEDUP 1
/*------------------------------------------------------------------------
* Definition of parameter
*/
#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 */
#ifdef VRAM16P
#define VRAMTYPE GL_VRAM16P /* Type of VRAM */
#define VRAMBPP 1 /* Number of bytes per pixel */
#define PLANES 4 /* Number of Planes */
#define HOOKTABLE _GL_defhook16p /* Hook table for implement */
#endif
#ifdef VRAM16
#define VRAMTYPE GL_VRAM16 /* Type of VRAM */
#define VRAMBPP 4 /* Number of bytes per pixel */
#define PLANES 1 /* Number of Planes */
#define HOOKTABLE _GL_defhook16 /* Hook table for implement */
#endif
/*------------------------------------------------------------------------
* 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] ;
/*------------------------------------------------------------------------
* 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 *)0, /* VRAMtbl ; pointer of VRAM address table */
&HOOKTABLE, /* *hook ; pointer of 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 (UserMain()).
*
*/
char glwork[GL_WORKSIZE(PAGES,STYLES,TILES,IMAGES,TMPAREASIZE)+8] ;
/*------------------------------------------------------------------------
* Optimized mask operation
*
* BitBLTMask16p ... Mask pattern operation for 1 bit x 4 planes.
* BitBLTMask16 ... Mask pattern operation for 4 bits x 1 plane.
*
*/
#ifdef VRAM16P
extern int BitBLTMask16p() ;
#endif
#ifdef VRAM16
extern int BitBLTMask16() ;
#endif
/*------------------------------------------------------------------------
* Definition of mask pattern
*
* Defines a mask pattern.
* GL treats a mask pattern as stored in 32x32 bits area. If the pattern
* doesn't begin at 4 bytes boundary address or size of the mask pattern
* is not 32x32 pixels, GL may not work correctly.
*/
const unsigned long maskdata[] = {
0xf0f0f0f0,
0x78787878,
0x3c3c3c3c,
0x1e1e1e1e,
0x0f0f0f0f,
0x87878787,
0xc3c3c3c3,
0xe1e1e1e1,
0xf0f0f0f0,
0x78787878,
0x3c3c3c3c,
0x1e1e1e1e,
0x0f0f0f0f,
0x87878787,
0xc3c3c3c3,
0xe1e1e1e1,
0xf0f0f0f0,
0x78787878,
0x3c3c3c3c,
0x1e1e1e1e,
0x0f0f0f0f,
0x87878787,
0xc3c3c3c3,
0xe1e1e1e1,
0xf0f0f0f0,
0x78787878,
0x3c3c3c3c,
0x1e1e1e1e,
0x0f0f0f0f,
0x87878787,
0xc3c3c3c3,
0xe1e1e1e1,
} ;
const GL_IDSC mask_dsc = { (void *)maskdata, 32, 32, GL_MONO, GL_D1, 0, 0} ;
/*---------------------------------------------------------------------------
* Main program
This example shows how to speed up operation of painting with mask pattern.
In painting with mask pattern in floodfill, function (*hook.bbmask)() in
implement modules is used.
Speeding up operation of painting with mask pattern is implemented by
setting/resetting an implement module optimized for certain conditions
before/after execution of GL_floodfill function.
Optimized implememt modules is defined in source files cbbm16p.c and
cbbm16.c.
[Example of optimized operation of using bit pattern]
int (*SaveFunc)(GL_WP *);
GL_filltype(gp, GL_FRAME | GL_MASK);
GL_color2(gp, GL_FILLC, Yellow);
GL_setimage(gp, 1, (GL_IDSC *)&mask1_dsc);
GL_mask(gp, 1);
SaveFunc = gp->hook.bbmask;
gp->hook.bbmask = Funciton name of optimized operation of bit pattern
GL_floodfill(gp, 15, 320, 240);
gp->hook.bbmask = SaveFunc;
*/
int main()
{
GL_WP *gp ;
long n, workmax ;
int (*SaveFunc)(GL_WP *) ;
/* Initialization */
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) ;
/* Drawing */
GL_circle(gp, 160, 120, 60) ;
GL_filltype(gp, GL_FRAME | GL_MASK) ;
GL_color(gp, GL_FILLC, 14) ;
GL_setimage(gp, 1, (GL_IDSC *)&mask_dsc) ;
GL_mask(gp, 1) ;
#ifdef SPEEDUP
SaveFunc = gp->hook.bbmask ; /* Saves default mask operation */
#ifdef VRAM16
gp->hook.bbmask = BitBLTMask16 ; /* Sets optimized mask operation */
#endif
#ifdef VRAM16P
gp->hook.bbmask = BitBLTMask16p ; /* Sets optimized mask operation */
#endif
#endif
GL_floodfill(gp, 15, 160, 120) ; /* Painting */
#ifdef SPEEDUP
gp->hook.bbmask = SaveFunc ; /* Restore dafault mask operation */
#endif
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -