File: ClassicGlow.java

package info (click to toggle)
threeb 0.0~git20220106110332.a3144e0-7
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,296 kB
  • sloc: cpp: 5,188; java: 1,741; ansic: 1,336; sh: 568; makefile: 62; awk: 26
file content (79 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import ij.plugin.*;
import ij.process.*;
import ij.gui.*;
import ij.*;

import java.awt.image.*;


///Plugin implementing the classic glow/hot
///LUT which seems to be missing from ImageJ
///@ingroup gPlugin
public class ClassicGlow implements PlugIn
{
	static byte red[];
	static byte green[];
	static byte blue[];

	static{
		red = new byte[256];
		green = new byte[256];
		blue = new byte[256];
		
		for(int i=0; i < 256; i++)
		{
			if(i < 85)
				red[i] = (byte)((i*3) & 0xff);
			else
				red[i] = (byte)(255 & 0xff);

			if(i < 85)	
				green[i] = 0;
			else if(i -85 < 85)
				green[i] = (byte)(((i-85)*3) & 0xff);
			else
				green[i] = (byte)(255 & 0xff);

			if(i < 170)
				blue[i] = 0;
			else
				blue[i] = (byte)(((i-170)*3) & 0xff);
		}
	}


	public void run(String arg)
	{
		ImagePlus imp = WindowManager.getCurrentImage();

		//If the image exists, it must be of the correct type, otherwise, make a ramp.
		if (imp!=null)
		{
			if (imp.getType()==ImagePlus.COLOR_RGB)
			{
				IJ.error("Color tables cannot be assiged to RGB Images.");
				return;
			}
		}
		else
		{
			//Create a ramp
			ByteProcessor r = new ByteProcessor(256, 32);

			for(int y=0; y < 32; y++)
				for(int x=0; x < 256; x++)
					r.set(x, y, x);

			imp = new ImagePlus("Glow", r);
			imp.show();
		}


		ImageProcessor ip = imp.getProcessor();
		ColorModel cm = new IndexColorModel(8, 256, red, green, blue);
		ip.setColorModel(cm);
		if (imp.getStackSize()>1) 
			imp.getStack().setColorModel(cm);
		imp.updateAndDraw();
	}
}