00001 /* vGfx - interface to polymorphic graphic object 00002 * that currently can either be a memory buffer or 00003 * a postScript file. */ 00004 00005 #include "common.h" 00006 #include "vGfx.h" 00007 00008 static char const rcsid[] = "$Id: vGfx.c,v 1.6 2006/06/23 23:45:02 kent Exp $"; 00009 00010 00011 /* Most of the implementation of this is in macros in vGfx.h. */ 00012 00013 void vgClose(struct vGfx **pVg) 00014 /* Close down virtual graphics object, and finish writing it to file. */ 00015 { 00016 struct vGfx *vg = *pVg; 00017 if (vg != NULL) 00018 { 00019 vg->close(&vg->data); 00020 freez(pVg); 00021 } 00022 } 00023 00024 struct vGfx *vgHalfInit(int width, int height) 00025 /* Close down virtual graphics object, and finish writing it to file. */ 00026 { 00027 struct vGfx *vg; 00028 AllocVar(vg); 00029 vg->width = width; 00030 vg->height = height; 00031 return vg; 00032 } 00033 00034 int vgFindRgb(struct vGfx *vg, struct rgbColor *rgb) 00035 /* Find color index corresponding to rgb color. */ 00036 { 00037 return vgFindColorIx(vg, rgb->r, rgb->g, rgb->b); 00038 } 00039 00040 Color vgContrastingColor(struct vGfx *vg, int backgroundIx) 00041 /* Return black or white whichever would be more visible over 00042 * background. */ 00043 { 00044 struct rgbColor c = vgColorIxToRgb(vg, backgroundIx); 00045 int val = (int)c.r + c.g + c.g + c.b; 00046 if (val > 512) 00047 return MG_BLACK; 00048 else 00049 return MG_WHITE; 00050 } 00051
1.5.2