| 1312 | |
| 1313 | |
| 1314 | class ContrastPlot extends Canvas implements MouseListener { |
| 1315 | Color[] hColors; |
| 1316 | static final int WIDTH=128, HEIGHT=64; |
| 1317 | double defaultMin = 0; |
| 1318 | double defaultMax = 255; |
| 1319 | double min = 0; |
| 1320 | double max = 255; |
| 1321 | int[] histogram; |
| 1322 | int hmax; |
| 1323 | Image os; |
| 1324 | Graphics osg; |
| 1325 | Color color = Color.gray; |
| 1326 | double scale = Prefs.getGuiScale(); |
| 1327 | int width = WIDTH; |
| 1328 | int height = HEIGHT; |
| 1329 | |
| 1330 | public ContrastPlot() { |
| 1331 | addMouseListener(this); |
| 1332 | width = (int)(width*1.3); // increase size |
| 1333 | height = (int)(height*1.3); // increase size |
| 1334 | if (scale>1.0) { |
| 1335 | width = (int)(width*scale); |
| 1336 | height = (int)(height*scale); |
| 1337 | } |
| 1338 | setSize(width+1, height+1); |
| 1339 | } |
| 1340 | |
| 1341 | /** Overrides Component getPreferredSize(). Added to work |
| 1342 | around a bug in Java 1.4.1 on Mac OS X.*/ |
| 1343 | public Dimension getPreferredSize() { |
| 1344 | return new Dimension(width+1, height+1); |
| 1345 | } |
| 1346 | |
| 1347 | void setHistogram(ImageStatistics stats, boolean isLogHist) { |
| 1348 | histogram = stats.histogram; |
| 1349 | if (isLogHist) { |
| 1350 | for (int j=0;j<256;j++) { |
| 1351 | histogram[j]=(int)(Math.log(histogram[j])*100); |
| 1352 | } |
| 1353 | } |
| 1354 | ImagePlus imp = WindowManager.getCurrentImage(); |
| 1355 | hColors = new Color[256]; |
| 1356 | for (int i=0; i<256; i++) { // set the default histogram color when there is no LUT |
| 1357 | hColors[i] = new Color(110, 110,150); |
| 1358 | } |
| 1359 | int impType= imp.getType(); |
| 1360 | if ((impType == ImagePlus.GRAY8) || (impType == ImagePlus.GRAY16) || (impType == ImagePlus.GRAY32)) { //if image has LUT |
| 1361 | ImageProcessor ip = imp.getProcessor(); |
| 1362 | ColorModel cm = ip.getColorModel(); |
| 1363 | IndexColorModel icm = (IndexColorModel)cm; |
| 1364 | int mapSize = icm.getMapSize(); |
| 1365 | if (mapSize!=256) |
| 1366 | return; |
| 1367 | byte[] red = new byte[256]; |
| 1368 | byte[] green = new byte[256]; |
| 1369 | byte[] blue = new byte[256]; |
| 1370 | icm.getReds(red); |
| 1371 | icm.getGreens(green); |
nothing calls this directly
no test coverage detected