📄 libggi.c
字号:
*(dp2 + x + 1) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 2) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 3) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 4) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 5) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 6) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 7) = *(dp1 + (sx >> 16)); sx += xfactor;#endif x += 8; } while (x < w2) { *(dp2 + x) = *(dp1 + (sx >> 16)); sx += xfactor; x++; } dp2 += w2; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1; } } break; case 2: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned short *) (dp2 + x * 2) = *(unsigned short *) (dp1 + (sx >> 16) * 2); sx += xfactor; x++; } dp2 += w2 * 2; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 2; } } break; case 3: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned short *) (dp2 + x * 3) = *(unsigned short *) (dp1 + (sx >> 16) * 3); *(unsigned char *) (dp2 + x * 3 + 2) = *(unsigned char *) (dp1 + (sx >> 16) * 3 + 2); sx += xfactor; x++; } dp2 += w2 * 3; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 3; } } break; case 4: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned *) (dp2 + x * 4) = *(unsigned *) (dp1 + (sx >> 16) * 4); sx += xfactor; x++; } dp2 += w2 * 4; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 4; } } break; } return 0;}/****************************************************************************/static int copybox (GAL_GC gc, int x, int y, int w, int h, int nx, int ny){ ggiCopyBox(gc.visual, x, y, w, h, nx, ny); return 0;}static int crossblit (GAL_GC src, int sx, int sy, int sw, int wh, GAL_GC dst, int dx, int dy){ ggiCrossBlit(src.visual, sx, sy, sw, wh, dst.visual, dx, dy); return 0;}// Horizontal line operaionsstatic int drawhline (GAL_GC gc, int x, int y, int w, gal_pixel pixel){ ggiDrawHLine(gc.visual, x, y, w); return 0;}// Vertical line operationsstatic int drawvline (GAL_GC gc, int x, int y, int h, gal_pixel pixel){ ggiDrawVLine(gc.visual, x, y, h); return 0;}// Pixel operationsstatic int drawpixel (GAL_GC gc, int x, int y, gal_pixel pixel){ ggiDrawPixel(gc.visual, x, y); return 0;}static int getpixel (GAL_GC gc, int x, int y, gal_pixel* color){ ggiGetPixel(gc.visual, x, y, (ggi_pixel *)color); return 0;}// Other drawing// without any codestatic int circle (GAL_GC gc, int x, int y, int r, gal_pixel pixel){ return 0;}static int line (GAL_GC gc, int x1, int y1, int x2, int y2, gal_pixel pixel){ ggiDrawLine(gc.visual, x1, y1, x2, y2); return 0;}static int rectangle (GAL_GC gc, int l, int t, int r, int b, gal_pixel pixel){ ggiDrawHLine(gc.visual, l, t, (r - l) + 1); ggiDrawVLine(gc.visual, r, t, (b - t) + 1); ggiDrawHLine(gc.visual, l, b, (r - l) + 1); ggiDrawVLine(gc.visual, l, t, (b - t) + 1); return 0;}#if 0// Simple Character outputstatic int myputchar (GAL_GC gc, int x, int y, char c){ ggiPutc (gc.visual, x, y, c); return 0;}static int putstr (GAL_GC gc, int x, int y, const char* str){ ggiPuts (gc.visual, x, y, str); return 0;}static int getcharsize (GAL_GC gc, int* width, int* height){ *width = 8; *height = 8; return 0;}// without any codestatic int setputcharmode (GAL_GC gc, int mode){ return 0;}static int setfontcolors(GAL_GC gc, gal_pixel fg, gal_pixel bg){ ggiSetGCForeground (gc.visual, (ggi_pixel)fg); ggiSetGCBackground (gc.visual, (ggi_pixel)bg); return 0;}static void flush (GAL_GC gc){ ggiFlush (gc.visual);}static void flushregion (GAL_GC gc, int x, int y, int w, int h){ ggiFlushRegion (gc.visual, x, y, w, h);}#endifstatic void panic (int exitcode){ ggiPanic ("MiniGUI Panic. Exit Code: %d\n", exitcode);}// Initialization and termination of LibGGIBOOL InitLibGGI (struct tagGFX* gfx){ int i; ggi_visual_t visual; const ggi_pixelformat* pf; ggi_mode tm = { 1, {GGI_AUTO, GGI_AUTO}, {GGI_AUTO, GGI_AUTO}, {0, 0}, GT_AUTO, {GGI_AUTO, GGI_AUTO} }; if (ggiInit() != 0) { fprintf(stderr, "unable to initialize LibGGI, exiting.\n"); return FALSE; } visual = ggiOpen (NULL); if (visual == NULL) { fprintf(stderr, "unable to open default visual, exiting.\n"); ggiExit(); return FALSE; }// ggiSetFlags (visual, GGIFLAG_ASYNC); ggiCheckMode (visual, &tm); if (ggiSetMode (visual, &tm)) { fprintf (stderr,"Can't set mode\n"); ggiClose (visual); ggiExit (); return FALSE; } if (GT_SCHEME (tm.graphtype) == GT_PALETTE) { ggiSetColorfulPalette (visual); } for (i = 0; i < 17; i++) { ggi_color color; color.r = rgb8to16 (SysPixelColor[i].r); color.g = rgb8to16 (SysPixelColor[i].g); color.b = rgb8to16 (SysPixelColor[i].b); SysPixelIndex [i] = ggiMapColor (visual, &color); } pf = ggiGetPixelFormat (visual); gfx->phygc.visual = visual; gfx->bytes_per_phypixel = (pf->size + 7) >> 3; gfx->bits_per_phypixel = pf->depth; gfx->width_phygc = tm.visible.x; gfx->height_phygc = tm.visible.y; if (pf->depth == 32) gfx->colors_phygc = 1 << 24; else gfx->colors_phygc = 1 << pf->depth; gfx->grayscale_screen = FALSE;#ifdef _DEBUG fprintf (stderr, "GGI Mode: bpp %d, depth %d, width %d, height %d.\n", gfx->bytes_per_phypixel, gfx->bits_per_phypixel, gfx->width_phygc, gfx->height_phygc);#endif gfx->bytesperpixel = bytes_per_pixel; gfx->bitsperpixel = bits_per_pixel; gfx->width = width; gfx->height = height; gfx->colors = colors; gfx->allocategc = allocategc; gfx->freegc = freegc; gfx->setgc = NULL; gfx->enableclipping = enableclipping; gfx->disableclipping = disableclipping; gfx->setclipping = setclipping; gfx->getclipping = getclipping; gfx->getbgcolor = getbgcolor; gfx->setbgcolor = setbgcolor; gfx->getfgcolor = getfgcolor; gfx->setfgcolor = setfgcolor; gfx->mapcolor = mapcolor; gfx->unmappixel = unmappixel; gfx->getpalette = getpalette; gfx->setpalette = setpalette; gfx->setcolorfulpalette = setcolorfulpalette; gfx->boxsize = boxsize; gfx->fillbox = fillbox; gfx->putbox = putbox; gfx->getbox = getbox; gfx->putboxmask = putboxmask; gfx->scalebox = scalebox; gfx->copybox = copybox; gfx->crossblit = crossblit; gfx->drawhline = drawhline; gfx->drawvline = drawvline; gfx->drawpixel = drawpixel; gfx->getpixel = getpixel; gfx->circle = circle; gfx->line = line; gfx->rectangle = rectangle; gfx->panic = panic; return TRUE;}void TermLibGGI (struct tagGFX* gfx){ ggiClose (gfx->phygc.visual); ggiExit ();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -