/** * Essentially merges in a given color to an existing pixel according to the * given weight. */ static void setWeightedPixel(Color_t *canvas, int width, int height, int x, int y, Color_t color, float weight) { Color_t avg = averageColors(canvas[coord_to_ind(x, y, width)], color, weight); setPixel(canvas, width, height, x, y, avg.red, avg.green, avg.blue); }
static tupletable2 colormapFromBv(unsigned int const newcolors, boxVector const bv, unsigned int const boxes, tupletable2 const colorfreqtable, unsigned int const depth, enum methodForRep const methodForRep) { /* ** Ok, we've got enough boxes. Now choose a representative color for ** each box. There are a number of possible ways to make this choice. ** One would be to choose the center of the box; this ignores any structure ** within the boxes. Another method would be to average all the colors in ** the box - this is the method specified in Heckbert's paper. A third ** method is to average all the pixels in the box. */ tupletable2 colormap; unsigned int bi; colormap = newColorMap(newcolors, depth); for (bi = 0; bi < boxes; ++bi) { switch (methodForRep) { case REP_CENTER_BOX: centerBox(bv[bi].ind, bv[bi].colors, colorfreqtable, depth, colormap.table[bi]->tuple); break; case REP_AVERAGE_COLORS: averageColors(bv[bi].ind, bv[bi].colors, colorfreqtable, depth, colormap.table[bi]->tuple); break; case REP_AVERAGE_PIXELS: averagePixels(bv[bi].ind, bv[bi].colors, colorfreqtable, depth, colormap.table[bi]->tuple); break; default: pm_error("Internal error: invalid value of methodForRep: %d", methodForRep); } } return colormap; }