📄 native.c
字号:
// $Id: native.c,v 1.4 2000/11/28 01:04:56 ymwei Exp $//// native.c: Native Low Level Graphics Engine 's interface file//// Written by Song Lixin, 2000/10/18///*** 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*///// TODO: //#include <stdio.h>#include <stdlib.h>#include <assert.h>#include "native.h"#include "../../ial/native/native.h"#ifndef __ECOS# include <syslog.h>#endif/* * Low Level Graphics Operations */static int bytesperpixel (GAL_GC gc) { return (gc.psd->bpp + 7) / 8; }static int bitsperpixel (GAL_GC gc) { return gc.psd->bpp; }static int width (GAL_GC gc) { return gc.psd->xres; }static int height (GAL_GC gc) { return gc.psd->yres; }static int colors (GAL_GC gc) { return gc.psd->ncolors; }/* * Allocation and release of graphics context */static int allocategc (GAL_GC gc, int width, int height, int depth, GAL_GC* newgc){ int linelen, size; PSD newpsd; void * pixels; int bpp; bpp = gc.psd->bpp; newpsd = gc.psd->AllocateMemGC(gc.psd); if(!newpsd) return -1; if(!native_gen_calcmemgcalloc(newpsd,width,height,0,bpp,&size,&linelen)) goto fail; pixels = malloc(size); if(!pixels) goto fail; newpsd->flags |= PSF_ADDRMALLOC; if(!newpsd->MapMemGC(newpsd,width,height,gc.psd->planes, bpp,linelen, size, pixels)) goto fail; newgc->psd = newpsd; return 0;fail: newpsd->FreeMemGC(newpsd); return -1;}static void freegc (GAL_GC gc){ PSD psd; psd = gc.psd; if(gc.psd->flags & PSF_ADDRMALLOC) free(gc.psd->addr); psd->FreeMemGC(psd);}static void enableclipping (GAL_GC gc){ PSD psd; psd = gc.psd; psd->doclip = 1; psd->clipminx = 0; psd->clipminy = 0; psd->clipmaxx = psd->xres - 1; psd->clipmaxy = psd->yres - 1;}static void disableclipping (GAL_GC gc){ PSD psd; psd = gc.psd; psd->doclip = 0;}static int setclipping (GAL_GC gc, int x1, int y1, int x2, int y2){ PSD psd; psd = gc.psd; if((x1 < 0) || (y1 < 0) || (x2 > psd->xres - 1) || (y2 > psd->yres - 1)) return -1; //syslog(LOG_INFO,"Setclipping:x1:%d,y1:%d,x2:%d,y2:%d",x1,y1,x2,y2); psd->doclip = 1; psd->clipminx = x1; psd->clipminy = y1; psd->clipmaxx = x2 + 1; psd->clipmaxy = y2 + 1; return 0;}static int getclipping (GAL_GC gc, int* x1, int* y1, int* x2, int* y2){ PSD psd; psd = gc.psd; *x1 = psd->clipminx; *y1 = psd->clipminy; *x2 = psd->clipmaxx - 1; *y2 = psd->clipmaxy - 1; return 0;}/* * Background and foreground colors */static int getbgcolor (GAL_GC gc, gal_pixel* color){ PSD psd; psd = gc.psd; *color = psd->gr_background; return 0;}static int setbgcolor(GAL_GC gc, gal_pixel color){ PSD psd; psd = gc.psd; psd->gr_background = color; return 0;}static int getfgcolor (GAL_GC gc, gal_pixel* color){ PSD psd; psd = gc.psd; *color = psd->gr_foreground; return 0;}static int setfgcolor (GAL_GC gc, gal_pixel color){ PSD psd; psd = gc.psd; psd->gr_foreground = color; return 0;}/* * Convertion between gal_color and gal_pixel * borrowed from gl lib. */static gal_pixel mapcolor (GAL_GC gc, gal_color *color){ unsigned v; switch (gc.psd->bpp) { case 4: /* Now this is real fun. Map to standard EGA palette. */ v = 0; if (color->b >= 64) v += 1; if (color->g >= 64) v += 2; if (color->r >= 64) v += 4; if (color->b >= 192 || color->g >= 192 || color->r >= 192) v += 8; return v; case 8: return RGB2PIXEL332 (color->r, color->g, color->b); case 15: return RGB2PIXEL555 (color->r, color->g, color->b); case 16: return RGB2PIXEL565 (color->r, color->g, color->b); case 24: case 32: return RGB2PIXEL888 (color->r, color->g, color->b); } return -1;}static int unmappixel (GAL_GC gc, gal_pixel pixel, gal_color* color){ switch (gc.psd->bpp) { case 4: color->r = SysPixelColor [pixel].r; color->g = SysPixelColor [pixel].g; color->b = SysPixelColor [pixel].b; break; case 8: color->r = PIXEL332RED (pixel) << 5; color->g = PIXEL332GREEN (pixel) << 5; color->b = PIXEL332BLUE (pixel) << 6; break; case 15: color->r = PIXEL555RED (pixel) << 3; color->g = PIXEL555GREEN (pixel) << 3; color->b = PIXEL555BLUE (pixel) << 3; break; case 16: color->r = PIXEL565RED (pixel) << 3; color->g = PIXEL565GREEN (pixel) << 2; color->b = PIXEL565BLUE (pixel) << 3; break; case 24: case 32: color->r = PIXEL888RED (pixel); color->g = PIXEL888GREEN (pixel); color->b = PIXEL888BLUE (pixel); break; } return 0;}static int packcolors (GAL_GC gc, void* buf, gal_color* colors, int len){ int ww = len; gal_pixel p; gal_uint8 *buf1 = (gal_uint8 *) buf; gal_uint16 *buf2 = (gal_uint16 *) buf; gal_uint32 *buf4 = (gal_uint32 *) buf; for (; ww > 0; ww--) { p = mapcolor (gc, colors); colors ++; switch (bytesperpixel (gc)) { case 1: *buf1++ = (gal_uint8)p; break; case 2: *buf2++ = (gal_uint16)p; break; case 3: *buf1++ = (gal_uint8)p; p >>= 8; *buf1++ = (gal_uint8)p; p >>= 8; *buf1++ = (gal_uint8)p; break; case 4: *buf4++ = p; break; } } return 0;}static int unpackpixels (GAL_GC gc, void* buf, gal_color* colors, int len){ int ww = len; gal_pixel p = 0; gal_uint8 *buf1 = (gal_uint8 *) buf; gal_uint16 *buf2 = (gal_uint16 *) buf; gal_uint32 *buf4 = (gal_uint32 *) buf; for (; ww > 0; ww--) { switch ( bytesperpixel (gc)) { case 1: p = *buf1; buf1 ++; break; case 2: p = *buf2; buf2 ++; break; case 3: p = *buf1; p <<= 8; buf1 ++; p |= *buf1; p <<= 8; buf1 ++; p |= *buf1; buf1 ++; break; case 4: p = *buf4; break; } unmappixel (gc, p, colors); colors ++; } return 0;}/* * Palette operations */static int getpalette (GAL_GC gc, int s, int len, gal_color* cmap){ gc.psd->GetPalette(gc.psd,s,len,cmap); return 0;}static int setpalette (GAL_GC gc, int s, int len, gal_color* cmap){ gc.psd->SetPalette(gc.psd,s,len,cmap); return 0;}/* * Specical functions work for <=8 bit color mode. */static int setcolorfulpalette (GAL_GC gc){ int i; gal_color pal[256]; if (gc.psd->bpp > 8) return 0; switch ( gc.psd->bpp ) { case 4: for (i = 0; i < 16; i++) { pal[i].b = SysPixelColor[i].b; pal[i].g = SysPixelColor[i].g; pal[i].r = SysPixelColor[i].r; pal[i].a = 0; } pal[i].b = pal[0].b; pal[i].g = pal[0].g; pal[i].r = pal[0].r; pal[i].a = pal[0].a; gc.psd->SetPalette(gc.psd,0,17,pal); break; case 8: for (i = 0; i < 256; i++) {#if 1 pal[i].r = PIXEL332RED (i) << 5; pal[i].g = PIXEL332GREEN (i) << 5; pal[i].b = PIXEL332BLUE (i) << 6;#else pal[i].b = (i & 7) * (64 / 2); /* 3 bits */ pal[i].g = ((i & 56) >> 3) * (64 / 2); /* 3 bits */ pal[i].r = ((i & 192) >> 6) * (64); /* 2 bits */#endif pal[i].a = 0; } gc.psd->SetPalette (gc.psd, 0, 256, pal); break; default: break; } return 0;}/* * Box operations * TODO: Currently we did not do clpping in putbox() or getbox() or other. * If we do clipping at early,we can spend time... */static size_t boxsize (GAL_GC gc, int w, int h){ if ((w <= 0) || (h <= 0)) return -1; return w * h * gc.psd->bpp;}static int fillbox (GAL_GC gc, int x, int y, int w, int h, gal_pixel pixel){ if ((w <= 0) || (h <= 0)) return -1; if (native_gen_clipbox (gc.psd, &x, &y, &w, &h) == CLIP_INVISIBLE ) return 0; gc.psd->FillRect (gc.psd, x, y, w, h, pixel) ; return 0;}static int putbox ( GAL_GC gc, int x, int y, int w, int h, void* buf ){ if ((w <= 0) || (h <= 0)) return -1; if (gc.psd->doclip) { if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx)) return -1; if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy)) return -1; } else { if ((x + w - 1 < 0) || (x >= gc.psd->xres)) return -1; if ((y + h - 1 < 0) || (y >= gc.psd->yres)) return -1; } gc.psd->PutBox(gc.psd,x,y,w,h,buf); return 0;}static int putboxmask ( GAL_GC gc, int x, int y, int w, int h, void* buf ){ if ((w <= 0) || (h <= 0)) return -1; if (gc.psd->doclip) { if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx)) return -1; if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy)) return -1; } else { if ((x + w - 1 < 0) || (x >= gc.psd->xres)) return -1; if ((y + h - 1 < 0) || (y >= gc.psd->yres)) return -1; } gc.psd->PutBoxMask(gc.psd,x,y,w,h,buf); return 0;}static int getbox (GAL_GC gc, int x, int y, int w, int h, void* buf){ if ((w <= 0) || (h <= 0)) return -1; if ((x + w - 1 < 0) || (x >= gc.psd->xres)) return -1; if ((y + h - 1 < 0) || (y >= gc.psd->yres)) return -1; gc.psd->GetBox(gc.psd,x,y,w,h,buf); return 0;}static int scalebox (GAL_GC gc, int sw, int sh, void* srcbuf, int dw, int dh, void* dstbuf){ native_gen_scalebox (gc.psd, sw, sh, srcbuf, dw, dh, dstbuf); return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -