// Same as above except that it quickly uses a gworld to allow the systems excellent routines to do // the business instead. short RGB2IndexGW(CTabHandle theTable,RGBColor *theCol) { Boolean openWorld=false; short index=-1; if (gBL_TintWorld==0L) { openWorld=true; OpenTintWorld(theTable); } if (gBL_TintWorld) { CGrafPtr origPort; GDHandle origGD; GetGWorld(&origPort,&origGD); SetGWorld(gBL_TintWorld,0L); SetCPixel(0,0,theCol); index=GPixelColour(GetGWorldPixMap(gBL_TintWorld),0,0); SetGWorld(origPort,origGD); } else return -1; if (openWorld) CloseTintWorld(); return index; }
static void cellarray( double xmin, double xmax, double ymin, double ymax, int dx, int dy, int dimx, int *colia, int true_color) { double x1, y1, x2, y2; int ix1, ix2, iy1, iy2; int x, y, width, height; register int i, j, ix, iy, ind; int swapx, swapy; RGBColor color; int rgb, red, green, blue; WC_to_NDC(xmin, ymax, gkss->cntnr, x1, y1); seg_xform(&x1, &y1); NDC_to_DC(x1, y1, ix1, iy1); WC_to_NDC(xmax, ymin, gkss->cntnr, x2, y2); seg_xform(&x2, &y2); NDC_to_DC(x2, y2, ix2, iy2); width = abs(ix2 - ix1) + 1; height = abs(iy2 - iy1) + 1; x = min(ix1, ix2); y = min(iy1, iy2); swapx = ix1 > ix2; swapy = iy1 < iy2; for (j = 0; j < height; j++) { iy = dy * j / height; if (swapy) iy = dy - 1 - iy; for (i = 0; i < width; i++) { ix = dx * i / width; if (swapx) ix = dx - 1 - ix; if (!true_color) { ind = colia[iy * dimx + ix]; color.red = p->rgb[ind].red; color.green = p->rgb[ind].green; color.blue = p->rgb[ind].blue; } else { rgb = colia[iy * dimx + ix]; red = (rgb & 0xff); green = (rgb & 0xff00) >> 8; blue = (rgb & 0xff0000) >> 16; color.red = nint(red * 256); color.green = nint(green * 256); color.blue = nint(blue * 256); } SetCPixel(x + i, y + j, &color); } } }