static void cdpixel(cdCtxCanvas *ctxcanvas, int x, int y, long int color) { glColor4ub(cdRed(color), cdGreen(color), cdBlue(color), cdAlpha(color)); /* Draw pixel */ glPointSize(1); glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); /* restore the foreground color */ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground)); (void)ctxcanvas; }
static char* iColorbarGetCellAttrib(Ihandle* ih, const char* name_id) { char* buffer = iupStrGetMemory(100); int idx = -1; long color; iupStrToInt(name_id, &idx); if (idx < 0 || idx >= ih->data->num_cells) return NULL; color = ih->data->colors[idx]; sprintf(buffer, "%d %d %d", cdRed(color), cdGreen(color), cdBlue(color)); return buffer; }
void cdIupCalcShadows(long bgcolor, long *light_shadow, long *mid_shadow, long *dark_shadow) { int r, bg_r = cdRed(bgcolor); int g, bg_g = cdGreen(bgcolor); int b, bg_b = cdBlue(bgcolor); /* light_shadow */ int max = bg_r; if (bg_g > max) max = bg_g; if (bg_b > max) max = bg_b; if (255-max < 64) { r = 255; g = 255; b = 255; } else { /* preserve some color information */ if (bg_r == max) r = 255; else r = bg_r + (255-max); if (bg_g == max) g = 255; else g = bg_g + (255-max); if (bg_b == max) b = 255; else b = bg_b + (255-max); } if (light_shadow) *light_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); /* dark_shadow */ r = bg_r - 128; g = bg_g - 128; b = bg_b - 128; if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; if (dark_shadow) *dark_shadow = cdEncodeColor((unsigned char)r, (unsigned char)g, (unsigned char)b); /* mid_shadow = (dark_shadow+bgcolor)/2 */ if (mid_shadow) *mid_shadow = cdEncodeColor((unsigned char)((bg_r+r)/2), (unsigned char)((bg_g+g)/2), (unsigned char)((bg_b+b)/2)); }
static GdkPixbuf* cdgdkCreatePixbufMap(int width, int height, const long* colors, const unsigned char *map, int ix, int iy, int image_width) { GdkPixbuf* pixbuf; guchar *pixdata, *pixline_data; int rowstride, channels; const unsigned char *line_data; int x, y; pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height); if (!pixbuf) return NULL; pixdata = gdk_pixbuf_get_pixels(pixbuf); rowstride = gdk_pixbuf_get_rowstride(pixbuf); channels = gdk_pixbuf_get_n_channels(pixbuf); /* GdkPixbuf is top-bottom */ /* map is bottom-top */ for (y=0; y<height; y++) { line_data = map + (height-1 - y + iy) * image_width; /* map is bottom-top */ pixline_data = pixdata + y * rowstride; for (x=0; x<width; x++) { unsigned char index = line_data[x+ix]; long c = colors[index]; guchar *r = &pixline_data[channels*x], *g = r+1, *b = g+1; *r = cdRed(c); *g = cdGreen(c); *b = cdBlue(c); } } return pixbuf; }
static void cdfpoly(cdCtxCanvas *ctxcanvas, int mode, cdfPoint* poly, int n) { int i; if (mode == CD_CLIP) return; if (mode == CD_BEZIER) { int i, prec = 100; double (*points)[3] = malloc(n * sizeof(*points)); for(i = 0; i < n; i++) { points[i][0] = poly[i].x; points[i][1] = poly[i].y; points[i][2] = 0; } glMap1d(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, n, &points[0][0]); glEnable(GL_MAP1_VERTEX_3); glMapGrid1d(prec, 0.0, 1.0); glEvalMesh1(GL_LINE, 0, prec); glDisable(GL_MAP1_VERTEX_3); free(points); return; } if (mode == CD_PATH) { cdfSimPolyPath(ctxcanvas->canvas, poly, n); return; } switch (mode) { case CD_CLOSED_LINES : glBegin(GL_LINE_LOOP); break; case CD_OPEN_LINES : glBegin(GL_LINE_STRIP); break; case CD_FILL : if(ctxcanvas->canvas->back_opacity == CD_OPAQUE && glIsEnabled(GL_POLYGON_STIPPLE)) { glDisable(GL_POLYGON_STIPPLE); glColor4ub(cdRed(ctxcanvas->canvas->background), cdGreen(ctxcanvas->canvas->background), cdBlue(ctxcanvas->canvas->background), cdAlpha(ctxcanvas->canvas->background)); glBegin(GL_POLYGON); for(i = 0; i < n; i++) glVertex2d(poly[i].x, poly[i].y); glEnd(); /* restore the foreground color */ glColor4ub(cdRed(ctxcanvas->canvas->foreground), cdGreen(ctxcanvas->canvas->foreground), cdBlue(ctxcanvas->canvas->foreground), cdAlpha(ctxcanvas->canvas->foreground)); glEnable(GL_POLYGON_STIPPLE); } glBegin(GL_POLYGON); break; } for(i = 0; i < n; i++) glVertex2d(poly[i].x, poly[i].y); glEnd(); (void)ctxcanvas; }
static void simDrawTextBitmap(cdSimulation* simulation, FT_Bitmap* bitmap, int x, int y) { unsigned char *red, *green, *blue, *alpha, *bitmap_data; int width = bitmap->width; int height = bitmap->rows; int size = width*height; int rgba_data_size = size*4; int old_use_matrix = simulation->canvas->use_matrix; /* avoid spaces */ if (width == 0 || height == 0) return; if (!simulation->tt_text->rgba_data) simulation->tt_text->rgba_data = malloc(rgba_data_size); else if (rgba_data_size > simulation->tt_text->rgba_data_size) { simulation->tt_text->rgba_data = realloc(simulation->tt_text->rgba_data, rgba_data_size); simulation->tt_text->rgba_data_size = rgba_data_size; } /* disable image transformation */ simulation->canvas->use_matrix = 0; /* this is the char bitmap, contains an alpha map of the char to be combined with the foreground color */ bitmap_data = bitmap->buffer + (height-1)*width; /* bitmap is top down. */ /* this is the image used to draw the char with the foreground color */ red = simulation->tt_text->rgba_data; green = red + size; blue = green + size; alpha = blue + size; if (!simulation->canvas->cxPutImageRectRGBA && !simulation->canvas->cxGetImageRGB) { int i, j; unsigned char bg_red, bg_green, bg_blue, fg_red, fg_green, fg_blue, fg_alpha, calpha; long int c; /* must manually combine using only the background color, ignore canvas contents */ c = simulation->canvas->background; bg_red = cdRed(c); bg_green = cdGreen(c); bg_blue = cdBlue(c); c = simulation->canvas->foreground; fg_red = cdRed(c); fg_green = cdGreen(c); fg_blue = cdBlue(c); fg_alpha = cdAlpha(c); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (simulation->antialias) { if (fg_alpha == 255) calpha = bitmap_data[j]; else calpha = (fg_alpha*bitmap_data[j])/255; } else { if (bitmap_data[j] > 128) /* behave as 255 */ calpha = fg_alpha; else calpha = 0; } *red++ = CD_ALPHA_BLEND(fg_red, bg_red, calpha); *green++ = CD_ALPHA_BLEND(fg_green, bg_green, calpha); *blue++ = CD_ALPHA_BLEND(fg_blue, bg_blue, calpha); } bitmap_data -= width; } /* reset pointers */ red = simulation->tt_text->rgba_data; green = red + size; blue = green + size; /* draw the char */ simulation->canvas->cxPutImageRectRGB(simulation->canvas->ctxcanvas, width,height,red,green,blue,x,y,width,height,0,width-1,0,height-1); } else { int i, j; long int fg = simulation->canvas->foreground; unsigned char fg_alpha = cdAlpha(fg); memset(red, cdRed(fg), size); memset(green, cdGreen(fg), size); memset(blue, cdBlue(fg), size); /* alpha is the bitmap_data itself if the foreground color does not contains alpha. Also must invert since it is top-down. */ for (i = 0; i < height; i++) { if (simulation->antialias) { if (fg_alpha == 255) { memcpy(alpha, bitmap_data, width); alpha += width; } else { for (j = 0; j < width; j++) { *alpha++ = (fg_alpha*bitmap_data[j])/255; } } } else { for (j = 0; j < width; j++) { if (bitmap_data[j] > 128) /* behave as 255 */ *alpha++ = fg_alpha; else *alpha++ = 0; } } bitmap_data -= width; } /* reset alpha pointer */ alpha = blue + size; /* draw the char */ simulation->canvas->cxPutImageRectRGBA(simulation->canvas->ctxcanvas, width,height,red,green,blue,alpha,x,y,width,height,0,width-1,0,height-1); } simulation->canvas->use_matrix = old_use_matrix; }