001 /* 002 * WebsafePaletteCreator 003 * 004 * Copyright (c) 2001, 2002, 2003 Marco Schmidt. 005 * All rights reserved. 006 */ 007 008 package net.sourceforge.jiu.color; 009 010 import net.sourceforge.jiu.data.Palette; 011 import net.sourceforge.jiu.data.RGBIndex; 012 013 /** 014 * This class creates {@link net.sourceforge.jiu.data.Palette} objects that 015 * contain the so-called <em>websafe palette</em>. 016 * This palette has 216 entries which are uniformly spread over the RGB color 017 * cube. 018 * Each component (red / green / blue) takes each of the six values 0, 51, 101, 019 * 153, 204 and 255 (note that the difference is almost equal between two consecutive 020 * values, between 50 and 52). 021 * Therefore, the palette will have 6<sup>3</sup> = 6 * 6 * 6 = 216 entries. 022 * <p> 023 * This palette was designed with computer systems in mind that can only display 024 * 256 colors at a time. 025 * With the 216 colors that are uniformly spread over RGB color space, there is 026 * at least a somewhat similar match for each possible input color. 027 * 028 * @author Marco Schmidt 029 * @since 0.5.0 030 */ 031 public class WebsafePaletteCreator implements RGBIndex 032 { 033 private static final int[] SAMPLES = {0x00, 0x33, 0x66, 0x99, 0xcc, 0xff}; 034 035 private WebsafePaletteCreator() 036 { 037 // private so that this class cannot be instantiated 038 } 039 040 /** 041 * Creates a new palette with the 216 websafe colors. 042 * @return new palette object 043 */ 044 public static Palette create() 045 { 046 Palette result = new Palette(216, 255); 047 int index = 0; 048 for (int r = 0; r < 6; r++) 049 { 050 for (int g = 0; g < 6; g++) 051 { 052 for (int b = 0; b < 6; b++) 053 { 054 result.put(index++, SAMPLES[r], SAMPLES[g], SAMPLES[b]); 055 } 056 } 057 } 058 return result; 059 } 060 }