📄 gdkrender-fb.c
字号:
#include <config.h>#include "gdkprivate-fb.h"#include <string.h>#include <signal.h>#include <sys/time.h>/* * Reading pixel values from a generic drawable. */static GetPixelRetgdk_fb_drawable_get_color (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *spot){ GetPixelRet retval = GPR_NONE; GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; switch (private->depth) { case 1: { guchar foo = mem[(x >> 3) + y * rowstride]; if (foo & (1 << (x % 8))) *spot = GDK_GC_FBDATA (gc)->values.foreground; else { retval = GPR_USED_BG; *spot = GDK_GC_FBDATA (gc)->values.background; } } break; case 71: if (mem[x + y * rowstride]) *spot = GDK_GC_FBDATA (gc)->values.foreground; else *spot = GDK_GC_FBDATA (gc)->values.background; break; case 77: retval = GPR_AA_GRAYVAL; spot->pixel = mem[x + y * rowstride] << 1; spot->red = spot->green = spot->blue = spot->pixel << 8; break; case 78: /* AA mode */ retval = GPR_AA_GRAYVAL; spot->pixel = mem[x + y * rowstride]; spot->red = spot->green = spot->blue = spot->pixel << 8; break; case 8: spot->pixel = mem[x + y * rowstride]; *spot = private->colormap->colors[spot->pixel]; break; case 16: { guint16 val16 = *((guint16 *)&mem[x*2 + y*rowstride]); spot->red = (((1<<gdk_display->modeinfo.red.length) - 1) & (val16 >> gdk_display->modeinfo.red.offset)) << (16 - gdk_display->modeinfo.red.length); spot->green = (((1<<gdk_display->modeinfo.green.length) - 1) & (val16 >> gdk_display->modeinfo.green.offset)) << (16 - gdk_display->modeinfo.green.length); spot->blue = (((1<<gdk_display->modeinfo.blue.length) - 1) & (val16 >> gdk_display->modeinfo.blue.offset)) << (16 - gdk_display->modeinfo.blue.length); spot->pixel = val16; } break; case 24: { guchar *smem = &mem[x*3 + y*rowstride]; spot->red = smem[gdk_display->red_byte] << 8; spot->green = smem[gdk_display->green_byte] << 8; spot->blue = smem[gdk_display->blue_byte] << 8;#if (G_BYTE_ORDER == G_BIG_ENDIAN) spot->pixel = (smem[0]<<16)|(smem[1]<<8)|smem[2];#else spot->pixel = smem[0]|(smem[1]<<8)|(smem[2]<<16);#endif } break; case 32: { guchar *smem = &mem[x*4 + y*rowstride]; spot->red = smem[gdk_display->red_byte] << 8; spot->green = smem[gdk_display->green_byte] << 8; spot->blue = smem[gdk_display->blue_byte] << 8; spot->pixel = *(guint32 *)smem; } break; } return retval;}/************************************* * gc->get_color() implementations *************************************/static GetPixelRetgdk_fb_get_color_1 (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *color){ GetPixelRet retval = GPR_NONE; GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guchar foo; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); foo = mem[(x >> 3) + y * rowstride]; if (foo & (1 << (x % 8))) *color = GDK_GC_FBDATA (gc)->values.foreground; else { retval = GPR_USED_BG; *color = GDK_GC_FBDATA (gc)->values.background; } return retval;}static GetPixelRetgdk_fb_get_color_8 (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *color){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; gint pixel; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); pixel = mem[x + y * rowstride]; *color = private->colormap->colors[pixel]; return GPR_NONE;}static GetPixelRetgdk_fb_get_color_16 (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *color){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guint16 val16; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); val16 = *((guint16 *)&mem[x*2 + y*rowstride]); color->red = (((1<<gdk_display->modeinfo.red.length) - 1) & (val16 >> gdk_display->modeinfo.red.offset)) << (16 - gdk_display->modeinfo.red.length); color->green = (((1<<gdk_display->modeinfo.green.length) - 1) & (val16 >> gdk_display->modeinfo.green.offset)) << (16 - gdk_display->modeinfo.green.length); color->blue = (((1<<gdk_display->modeinfo.blue.length) - 1) & (val16 >> gdk_display->modeinfo.blue.offset)) << (16 - gdk_display->modeinfo.blue.length); color->pixel = val16; return GPR_NONE;}static GetPixelRetgdk_fb_get_color_24 (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *color){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guchar *smem; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); smem = &mem[x*3 + y*rowstride]; color->red = smem[gdk_display->red_byte] << 8; color->green = smem[gdk_display->green_byte] << 8; color->blue = smem[gdk_display->blue_byte] << 8;#if (G_BYTE_ORDER == G_BIG_ENDIAN) color->pixel = (smem[0]<<16)|(smem[1]<<8)|smem[2];#else color->pixel = smem[0]|(smem[1]<<8)|(smem[2]<<16);#endif return GPR_NONE;}static GetPixelRetgdk_fb_get_color_32 (GdkDrawable *drawable, GdkGC *gc, int x, int y, GdkColor *color){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guchar *smem; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); smem = &mem[x*4 + y*rowstride]; color->red = smem[gdk_display->red_byte] << 8; color->green = smem[gdk_display->green_byte] << 8; color->blue = smem[gdk_display->blue_byte] << 8; color->pixel = *(guint32 *)smem; return GPR_NONE;}/************************************* * gc->set_pixel() implementations *************************************/static voidgdk_fb_set_pixel_1(GdkDrawable *drawable, GdkGC *gc, int x, int y, gulong pixel){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guchar *ptr; if (!_gdk_fb_is_active_vt) return; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); ptr = mem + (y*rowstride) + (x >> 3); if (pixel) *ptr |= (1 << (x % 8)); else *ptr &= ~(1 << (x % 8));}static voidgdk_fb_set_pixel_8(GdkDrawable *drawable, GdkGC *gc, int x, int y, gulong pixel){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; if (!_gdk_fb_is_active_vt) return; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); mem[x + y*rowstride] = pixel;}static voidgdk_fb_set_pixel_16(GdkDrawable *drawable, GdkGC *gc, int x, int y, gulong pixel){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guint16 *ptr; if (!_gdk_fb_is_active_vt) return; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); ptr = (guint16 *)&mem[x*2 + y*rowstride]; *ptr = pixel;}static voidgdk_fb_set_pixel_24(GdkDrawable *drawable, GdkGC *gc, int x, int y, gulong pixel){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guchar *smem; if (!_gdk_fb_is_active_vt) return; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); smem = &mem[x*3 + y*rowstride]; smem[0] = pixel & 0xff; smem[1] = (pixel >> 8) & 0xff; smem[2] = (pixel >> 16) & 0xff;}static voidgdk_fb_set_pixel_32(GdkDrawable *drawable, GdkGC *gc, int x, int y, gulong pixel){ GdkDrawableFBData *private = GDK_DRAWABLE_FBDATA (drawable); guchar *mem = private->mem; guint rowstride = private->rowstride; guint32 *smem; if (!_gdk_fb_is_active_vt) return; g_assert (private->depth == GDK_GC_FBDATA (gc)->depth); smem = (guint32 *)&mem[x*4 + y*rowstride]; *smem = pixel;}/************************************* * gc->fill_span() implementations *************************************/static voidgdk_fb_fill_span_generic (GdkDrawable *drawable, GdkGC *gc, GdkSpan *span, GdkColor *color){ int curx; GdkColor spot = *color; GdkGCFBData *gc_private; GdkDrawableFBData *private; gint left, right, y; int clipxoff, clipyoff; /* Amounts to add to curx & cury to get x & y in clip mask */ int tsxoff, tsyoff; GdkDrawable *cmask; guchar *clipmem; guint mask_rowstride; GdkPixmap *ts = NULL; GdkDrawableFBData *ts_private; gboolean solid_stipple; GdkFunction func; if (!_gdk_fb_is_active_vt) return; private = GDK_DRAWABLE_FBDATA (drawable); gc_private = GDK_GC_FBDATA (gc); g_assert (gc); y = span->y; left = span->x; right = span->x + span->width; func = gc_private->values.function; cmask = gc_private->values.clip_mask; clipxoff = clipyoff = tsxoff = tsyoff = 0; mask_rowstride = 0; solid_stipple = FALSE; clipmem = NULL; if (cmask) { GdkDrawableFBData *cmask_private; cmask_private = GDK_DRAWABLE_IMPL_FBDATA (cmask); clipmem = cmask_private->mem; clipxoff = cmask_private->abs_x - gc_private->values.clip_x_origin - private->abs_x; clipyoff = cmask_private->abs_y - gc_private->values.clip_y_origin - private->abs_y; mask_rowstride = cmask_private->rowstride; } if (gc_private->values.fill == GDK_TILED && gc_private->values.tile) { gint xstep; gint relx, rely; int drawh; GdkFBDrawingContext *dc, dc_data; dc = &dc_data; gdk_fb_drawing_context_init (dc, drawable, gc, FALSE, TRUE); ts = gc_private->values.tile; ts_private = GDK_DRAWABLE_IMPL_FBDATA (ts); rely = y - private->abs_y; drawh = (rely - gc_private->values.ts_y_origin) % ts_private->height; if (drawh < 0) drawh += ts_private->height; for (curx = left; curx < right; curx += xstep) { int draww; relx = curx - private->abs_x; draww = (relx - gc_private->values.ts_x_origin) % ts_private->width; if (draww < 0) draww += ts_private->width; xstep = MIN (ts_private->width - draww, right - relx); gdk_fb_draw_drawable_3 (drawable, gc, GDK_DRAWABLE_IMPL (ts), dc, draww, drawh, relx, rely, xstep, 1); } gdk_fb_drawing_context_finalize (dc); return; } else if ((gc_private->values.fill == GDK_STIPPLED || gc_private->values.fill == GDK_OPAQUE_STIPPLED) && gc_private->values.stipple) { ts = gc_private->values.stipple; tsxoff = - GDK_DRAWABLE_IMPL_FBDATA (ts)->abs_x - gc_private->values.ts_x_origin - private->abs_x; tsyoff = - GDK_DRAWABLE_IMPL_FBDATA (ts)->abs_y - gc_private->values.ts_y_origin - private->abs_y; solid_stipple = (gc_private->values.fill == GDK_OPAQUE_STIPPLED); } for (curx = left; curx < right; curx++) { int maskx = curx+clipxoff, masky = y + clipyoff; guchar foo; if (cmask) { foo = clipmem[masky*mask_rowstride + (maskx >> 3)]; if (!(foo & (1 << (maskx % 8)))) continue; } if (func == GDK_INVERT) { (gc_private->get_color) (drawable, gc, curx, y, &spot); spot.pixel = ~spot.pixel; spot.red = ~spot.red; spot.green = ~spot.green; spot.blue = ~spot.blue; } else if (func == GDK_XOR) { (gc_private->get_color) (drawable, gc, curx, y, &spot); spot.pixel ^= gc_private->values.foreground.pixel; } else if (func != GDK_COPY) { g_warning ("Unsupported GdkFunction %d\n", func); } else if (ts) { int wid, hih; ts_private = GDK_DRAWABLE_IMPL_FBDATA (ts); wid = ts_private->width; hih = ts_private->height; maskx = (curx+tsxoff)%wid; masky = (y+tsyoff)%hih; if (maskx < 0) maskx += wid; if (masky < 0) masky += hih; foo = ts_private->mem[(maskx >> 3) + ts_private->rowstride*masky]; if (foo & (1 << (maskx % 8))) { spot = gc_private->values.foreground; } else if (solid_stipple) { spot = gc_private->values.background; } else continue; } (gc_private->set_pixel) (drawable, gc, curx, y, spot.pixel); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -