📄 sample.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_VRAM64K /* Type of VRAM */#define VRAMBPP 2 /* Number of bytes per pixel */#define VRAMBPL (WIDTH*VRAMBPP)#define PLANES 1 /* Number of Planes */#define HOOKTABLE hookYUV422 /* Implement modules */ /* Hook table (YUV422) *//*------------------------------------------------------------------------ * 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; /* PSEUDO VRAM address *//*------------------------------------------------------------------------ * Hook table of implement modules * * This is hook table of implement modules for YCbCr422. * * 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_defhookYUV422. * * _GL_defhookYUV422 is in library file (im.a). * Source files of each modules registered to this table are stored in * directory trns_im/src/yuv422. * */int _GL_hinitYUV422(GL_WP *gp);int _GL_palettesetYUV422(GL_WP *gp,unsigned long palette,unsigned long color);int _GL_actpageYUV422(GL_WP *gp,short page);int _GL_dsppageYUV422(GL_WP *gp,short page);int _GL_selplaneYUV422(GL_WP *gp,short read,short write);int _GL_psetYUV422(GL_WP *gp);int _GL_pgetYUV422(GL_WP *gp);int _GL_ddaYUV422(GL_WP *gp);int _GL_bbsetYUV422(GL_WP *gp);int _GL_bbtileYUV422(GL_WP *gp);int _GL_bbcopyYUV422(GL_WP *gp);int _GL_bbgetYUV422(GL_WP *gp);int _GL_bbputYUV422(GL_WP *gp);int _GL_bbdotYUV422(GL_WP *gp);int _GL_findfontYUV422(GL_WP *gp);int _GL_getfontYUV422(GL_WP *gp);int _GL_searchedgeYUV422(GL_WP *gp, GL_FLOODWORK *fl);int _GL_bbmaskYUV422(GL_WP *gp);const GL_HOOK hookYUV422 = { _GL_hinitYUV422, /* (*init)(gp); */ _GL_palettesetYUV422, /* (*palette)(gp,palette,color);*/ _GL_actpageYUV422, /* (*actpage)(gp,page); */ _GL_dsppageYUV422, /* (*dsppage)(gp,page); */ _GL_selplaneYUV422, /* (*selplane)(gp,read,write); */ _GL_bbsetYUV422, /* (*cls)(gp); */ _GL_bbcopyYUV422, /* (*scroll)(gp); */ _GL_psetYUV422, /* (*pset)(gp); */ _GL_pgetYUV422, /* (*pget)(gp); */ _GL_ddaYUV422, /* (*dda)(gp); */ _GL_bbsetYUV422, /* (*bbset)(gp); */ _GL_bbtileYUV422, /* (*bbtile)(gp); */ _GL_bbcopyYUV422, /* (*bbcopy)(gp); */ _GL_bbgetYUV422, /* (*bbget)(gp); */ _GL_bbputYUV422, /* (*bbput)(gp); */ _GL_bbdotYUV422, /* (*bbdot)(gp); */ _GL_findfontYUV422, /* (*findfont)(gp); */ _GL_getfontYUV422, /* (*getfont)(gp); */ _GL_searchedgeYUV422, /* (*searchedge)(gp, flood); */ _GL_bbmaskYUV422, /* (*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_defhookYUV422;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 YUV_WHITE 0xff80ff80#define YUV_BLACK 0x00800080#define YUV_LIGHTBLUE 0xcc8ecc69/*------------------------------------------------------------------------ * * 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; ExpandReadyYUV422( &info ); ExpandNearestNeighborYUV422( &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; ExpandReadyYUV422( &info ); ExpandBilinearYUV422( &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; ExpandReadyYUV422( &info ); ExpandBicubicYUV422( &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; /*-- Begin : Hardware dependence -----------------------*/ /* */ Vram = (unsigned char *)vdc_init(); /* */ /*-- End : Hardware dependence -----------------------*/ /* Initialize 2D Graphics Library */ 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, YUV_BLACK); GL_color(gp, GL_DRAWC, YUV_WHITE); GL_color(gp, GL_FILLC, YUV_WHITE); GL_cls(gp, 0); /* Examples of how expanded function modules are used. */ r = 25; GL_color(gp, GL_BACKC, YUV_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_D16, 0,0, YUV_WHITE); /*-- Begin : Hardware dependence -------------------*/ /* */ /* Add routine for displaying image in pseudo VRAM */ /* */ /*-- End : Hardware dependence -------------------*/ vdc_close(); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -