MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / IntegerImage

Class IntegerImage

src/org/opensourcephysics/display/IntegerImage.java:34–329  ·  view source on GitHub ↗

A IntegerImage contains an array of integers int[row][col] where each integer represents an image pixel. The row index determines the y-location of the pixel and the col index determines the x-location in the drawing panel. @author Wolfgang Christian @created March 3, 2012 @version 1.0

Source from the content-addressed store, hash-verified

32 * @version 1.0
33 */
34public class IntegerImage implements Measurable {
35 int[] imagePixels; // array that gets mapped onto the image
36 MemoryImageSource imageSource; // object that converts the array to an image
37 Image image; // image to be rendered in drawing panel
38 int nrow, ncol; // number of rows and column in array
39 double xmin, xmax, ymin, ymax; // drawing scale
40 boolean visible = true;
41 boolean dirtyImage=true; // true if array elements have changed
42
43 /**
44 * Creates an IntegerImage with a gray-scale palette.
45 * @param data
46 * @return
47 */
48 static public IntegerImage getGrayscaleImage(int[][] data){
49 ComponentColorModel ccm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {16}, false, // hasAlpha
50 false, // alpha pre-multiplied
51 Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
52 return new IntegerImage(ccm, data);
53 }
54
55 /**
56 * Gets a two-color IntegerImage with 0 -> red and 1 -> blue.
57 */
58 static public IntegerImage getBinaryImage(int[][] data){
59 ColorModel colorModel = new IndexColorModel(1, 2,
60 new byte[] {(byte) 255, (byte) 0},
61 new byte[] {(byte) 0, (byte) 0},
62 new byte[] {(byte) 0, (byte) 255});
63 return new IntegerImage(colorModel, data);
64 }
65
66
67 /**
68 * Gets a 256 color IntegerImage with 0 -> blue, 128->green, and 255 -> red.
69 */
70 static public IntegerImage get256ColorImage(int[][] data){
71 byte [] reds = new byte[256];
72 byte [] greens = new byte[256];
73 byte [] blues = new byte[256];
74 for(int i = 0; i<256; i++) {
75 double x = (i<128) ? (i-100)/255.0 : -1;
76 double val = Math.exp(-x*x*8);
77 reds[i] = (byte) (255*val);
78 x = (i<128) ? i/255.0 : (255-i)/255.0;
79 val = Math.exp(-x*x*8);
80 greens[i] = (byte) (255*val);
81 x = (i<128) ? -1 : (i-156)/255.0;
82 val = Math.exp(-x*x*8);
83 blues[i] = (byte) (255*val);
84 }
85 ColorModel colorModel = new IndexColorModel(8, 256, reds, greens, blues);
86 return new IntegerImage(colorModel, data);
87 }
88
89 // Gets an IntegerImage with the given color palette and data.
90 static public IntegerImage getColorImage(Color[] colors, int[][] data){
91 int n=colors.length;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected