Lines Matching refs:color

32  * An color quantizer based on the Median-cut algorithm, but optimized for picking out distinct
35 * The color space is represented as a 3-dimensional cube with each dimension being an RGB
36 * component. The cube is then repeatedly divided until we have reduced the color space to the
37 * requested number of colors. An average color is then generated from each cube.
40 * have roughly the same population, where this quantizer divides boxes based on their color volume.
41 * This means that the color space is divided into distinct colors, rather than representative
90 for (int color = 0; color < hist.length; color++) {
91 if (hist[color] > 0 && shouldIgnoreColor(color)) {
92 // If we should ignore the color, set the population to 0
93 hist[color] = 0;
95 if (hist[color] > 0) {
96 // If the color has population, increase the distinct color count
108 for (int color = 0; color < hist.length; color++) {
109 if (hist[color] > 0) {
110 colors[distinctColorIndex++] = color;
121 for (int color : colors) {
122 mQuantizedColors.add(new Swatch(approximateToRgb888(color), hist[color]));
159 // Finally, return the average colors of the color boxes
200 // As we're averaging a color box, we can still get colors which we do not want, so
209 * Represents a tightly fitting box around a color space.
256 final int color = colors[i];
257 count += hist[color];
259 final int r = quantizedRed(color);
260 final int g = quantizedGreen(color);
261 final int b = quantizedBlue(color);
292 * Split this color box at the mid-point along it's longest dimension
298 throw new IllegalStateException("Can not split a box with only 1 color");
306 // Now change this box's upperIndex and recompute the color boundaries
333 * This is calculated by finding the longest color dimension, and then sorting the
334 * sub-array based on that dimension value in each color. The colors are then iterated over
335 * until a color is found with at least the midpoint of the whole box's dimension midpoint.
344 // We need to sort the colors in this box based on the longest color dimension.
345 // As we can't use a Comparator to define the sort logic, we modify each color so that
367 * @return the average color of this box.
378 final int color = colors[i];
379 final int colorPopulation = hist[color];
382 redSum += colorPopulation * quantizedRed(color);
383 greenSum += colorPopulation * quantizedGreen(color);
384 blueSum += colorPopulation * quantizedBlue(color);
396 * Modify the significant octet in a packed color int. Allows sorting based on the value of a
397 * single color component. This relies on all components being the same word size.
410 final int color = a[i];
411 a[i] = quantizedGreen(color) << (QUANTIZE_WORD_WIDTH + QUANTIZE_WORD_WIDTH)
412 | quantizedRed(color) << QUANTIZE_WORD_WIDTH
413 | quantizedBlue(color);
419 final int color = a[i];
420 a[i] = quantizedBlue(color) << (QUANTIZE_WORD_WIDTH + QUANTIZE_WORD_WIDTH)
421 | quantizedGreen(color) << QUANTIZE_WORD_WIDTH
422 | quantizedRed(color);
434 private boolean shouldIgnoreColor(Swatch color) {
435 return shouldIgnoreColor(color.getRgb(), color.getHsl());
462 private static int quantizeFromRgb888(int color) {
463 int r = modifyWordWidth(Color.red(color), 8, QUANTIZE_WORD_WIDTH);
464 int g = modifyWordWidth(Color.green(color), 8, QUANTIZE_WORD_WIDTH);
465 int b = modifyWordWidth(Color.blue(color), 8, QUANTIZE_WORD_WIDTH);
478 private static int approximateToRgb888(int color) {
479 return approximateToRgb888(quantizedRed(color), quantizedGreen(color), quantizedBlue(color));
483 * @return red component of the quantized color
485 private static int quantizedRed(int color) {
486 return (color >> (QUANTIZE_WORD_WIDTH + QUANTIZE_WORD_WIDTH)) & QUANTIZE_WORD_MASK;
490 * @return green component of a quantized color
492 private static int quantizedGreen(int color) {
493 return (color >> QUANTIZE_WORD_WIDTH) & QUANTIZE_WORD_MASK;
497 * @return blue component of a quantized color
499 private static int quantizedBlue(int color) {
500 return color & QUANTIZE_WORD_MASK;