View Javadoc

1   // Copyright 2006, FreeHEP.
2   package org.freehep.graphicsio.gif;
3   
4   /**
5    * Just maps the colors straight into a map.
6    * 
7    * Slow implementation...
8    * 
9    * @author duns
10   * @version $Id$
11   */
12  public class GIFPlainColorMap implements GIFColorMap {
13      
14      public int[] create(int[][] pixels, int maxColors) {
15          int[] colors = new int[maxColors];
16          int n = 0;
17          int e = 0;
18          
19          for (int x = 0; x < pixels.length; x++) {
20              for (int y = 0; y < pixels[x].length; y++) {
21                  int i = 0;
22                  while (i<n) {
23                      if (colors[i] == pixels[x][y]) break;
24                      i++;
25                  }
26                  if (i==n) {
27                      if (i < maxColors) {
28                          colors[i] = pixels[x][y];
29                          n++;
30                      } else {
31                      	e++;
32                      }
33                  }
34                  pixels[x][y] = i;
35              }
36          }
37          
38          if (e > 0) {
39          	String msg = "GIFPlainColorMap: Too many colors "+(n+e)+" > "+maxColors;
40          	throw new IllegalArgumentException(msg);
41          }
42          return colors;
43      }
44  
45  }