void Winplot_init(int width, int height, int levels) { int i, R, G, B; double hue; levels = (levels > COLORS) ? COLORS : levels; winplot_levels = levels; winplot_width = width; winplot_height = height; ax = (win98width - 1.0) / (width * plot_mag - 1); ay = (win98height - 1.0) / (height * plot_mag - 1); ax = ay = MIN(ax, ay); if (ax > 1) ax = ay = 1; bx = ((win98width - 1) - ax * (width * plot_mag - 1)) / 2 + 0.5; by = ((win98height - 1) - ay * (height * plot_mag - 1)) / 2 + 0.5; al = ((double) COLORS) / levels; if(levels == 2) { for(i = 0; i < COLORS / 2; i++) colors[i][0] = colors[i][1] = colors[i][2] = 0; for(i = COLORS / 2; i < COLORS; i++) colors[i][0] = colors[i][1] = colors[i][2] = 255; } else { for(i = 0; i < COLORS; i++) { if(i > 0) { hue = i / (COLORS - 1.0); hsb_to_rgb(hue, &R, &G, &B); colors[i][0] = R; colors[i][1] = G; colors[i][2] = B; } else if(levels >= 32) colors[i][0] = colors[i][1] = colors[i][2] = 0; else if(levels < 32 && i == 0) colors[i][0] = colors[i][1] = colors[i][2] = 0; else if(levels < 32 && i == COLORS - 1) colors[i][0] = colors[i][1] = colors[i][2] = COLORS - 1; } } }
static gstack_t* rectify_rgb(grd5_grad_custom_t* gradc, pssvg_opt_t opt) { grd5_colour_stop_t *grd5_stop = gradc->colour.stops; int n = gradc->colour.n; if (n<2) { btrace("input (grd5) has %i rgb stop(s)", n); return NULL; } for (int i = 0 ; i < n ; i++) { grd5_colour_stop_t *stop = grd5_stop + i; switch(stop->type) { case GRD5_MODEL_RGB: break; case GRD5_MODEL_GRSC: grsc_to_rgb(stop); break; case GRD5_MODEL_HSB: hsb_to_rgb(stop); break; case GRD5_MODEL_CMYC: cmyc_to_rgb(stop); break; case GRD5_MODEL_LAB: lab_to_rgb(stop); break; case GRD5_MODEL_BCKC: stop->u.rgb.Rd = opt.bg.red; stop->u.rgb.Grn = opt.bg.green; stop->u.rgb.Bl = opt.bg.blue; stop->type = GRD5_MODEL_RGB; break; case GRD5_MODEL_FRGC: stop->u.rgb.Rd = opt.fg.red; stop->u.rgb.Grn = opt.fg.green; stop->u.rgb.Bl = opt.fg.blue; stop->type = GRD5_MODEL_RGB; break; case GRD5_MODEL_BOOK: btrace("stop %i (book colour) not converted", i); return NULL; default: btrace("stop %i unknown colour type %i", i, stop->type); return NULL; } if (stop->type != GRD5_MODEL_RGB) { btrace("stop %i is non-RGB (type %i)", i, stop->type); return NULL; } } gstack_t *stack = gstack_new(sizeof(rgb_stop_t), 2*n, n); if (stack != NULL) { if (rectify_rgb2(gradc, stack, opt) == 0) return stack; gstack_destroy(stack); } return NULL; }