Constructs ByteImage with the given data. @param data
(byte[][] data)
| 78 | * @param data |
| 79 | */ |
| 80 | public ByteImage(byte[][] data) { |
| 81 | byte [] reds = new byte[256]; |
| 82 | byte [] greens = new byte[256]; |
| 83 | byte [] blues = new byte[256]; |
| 84 | for(int i = 0; i<256; i++) { |
| 85 | double x = (i<128) ? (i-100)/255.0 : -1; |
| 86 | double val = Math.exp(-x*x*8); |
| 87 | reds[i] = (byte) (255*val); |
| 88 | x = (i<128) ? i/255.0 : (255-i)/255.0; |
| 89 | val = Math.exp(-x*x*8); |
| 90 | greens[i] = (byte) (255*val); |
| 91 | x = (i<128) ? -1 : (i-156)/255.0; |
| 92 | val = Math.exp(-x*x*8); |
| 93 | blues[i] = (byte) (255*val); |
| 94 | } |
| 95 | ColorModel colorModel = new IndexColorModel(8, 256, reds, greens, blues); |
| 96 | nrow = data.length; |
| 97 | ncol = data[0].length; |
| 98 | imagePixels = new byte[nrow * ncol]; |
| 99 | for (int i = 0; i < nrow; i++) { |
| 100 | byte[] row = data[i]; |
| 101 | System.arraycopy(row, 0, imagePixels, i * ncol, ncol); |
| 102 | } |
| 103 | imageSource = new MemoryImageSource(ncol, nrow,colorModel, imagePixels, 0, ncol); |
| 104 | imageSource.setAnimated(true); |
| 105 | image = Toolkit.getDefaultToolkit().createImage(imageSource); |
| 106 | dirtyImage=false; |
| 107 | xmin = 0; |
| 108 | xmax = ncol; |
| 109 | ymin = nrow; |
| 110 | ymax = 0; // zero is on top |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Constructs IntegerImage with the given ColorModel and data. |
nothing calls this directly
no test coverage detected