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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/*
*
* Copyright (C) 1999, Institute for MicroTherapy
*
* This software and supporting documentation were developed by
*
* University of Witten/Herdecke
* Department of Radiology and MicroTherapy
* Institute for MicroTherapy
* Medical computer science
*
* Universitaetsstrasse 142
* 44799 Bochum, Germany
*
* http://www.microtherapy.de/go/cs
* mailto:computer.science@microtherapy.de
*
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE INSTITUTE MAKES NO
* WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES
* OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY
* AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
* Author : $Author: kleber $
* Last update : $Date: 2001/06/06 10:32:30 $
* Revision : $Revision: 1.1.1.1 $
* State: $State: Exp $
*/
package main;
import java.awt.image.*;
import java.awt.*;
/**
* This class creates color models for this programm
*
* @author Klaus Kleber
* @since 30.04.99
*/
public class GrayColorIndex extends java.lang.Object
{
/**
* IndexColorModel for image data which contains 1 byte per pixel.
* Every pixel will be interpreted as gray color.
*
* @since 30.04.1999
*/
private static IndexColorModel gray12BitColorModel;
/**
* IndexColorModel for image data which contains 12 bits per pixel.
* Every value will be interpreted as a gray color.
*
* @since 30.04.1999
*/
private static IndexColorModel grayColorModel;
private static IndexColorModel overlayGrayColorModel;
private static IndexColorModel overlayGray12ColorModel;
private static int overlayColorBit = 255;
private static int overlay12ColorBit = 4095;
public static void fillGrayColorModel()
{
int bits = 8;
int size = 256;
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
for (int i = 0; i < size; i++)
{
r[i] = (byte)i;
g[i] = (byte)i;
b[i]= (byte)i;
a[i]= (byte)0xFF;
}
//Transparent Color
grayColorModel = new IndexColorModel(bits, size, r, g, b);
}
public static void fillGray12BitColorModel()
{
int bits = 16;
int size = 4096; //(12**8)
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
int x = 0;
int y = 0;
for (int i = 0; i < size; i++)
{
x++;
if ( x ==256)
{
x = 0;
y++;
}
r[i] = (byte)(x & 0xff);
g[i] = (byte)(y &0xff);
b[i]= (byte)0;
a[i]= (byte)0xFF;
}
//Transparent Color
gray12BitColorModel = new IndexColorModel(bits, size, r, g, b);
}
public static void fillIndexColorModel()
{
fillGrayColorModel();
fillGray12BitColorModel();
fillOverlayGrayColorModel(overlayColorBit);
fillOverlay12BitColorModel(overlay12ColorBit);
}
/**
* Returns the IndexColorModel for gray image data.
*
* @return IndexColorModel for image data.
* @since 30.04.1999
*/
public static IndexColorModel getGrayColorModel()
{
return grayColorModel;
}
/**
* Returns a IndexColorModel for overlay data.This ColorModel contains the same Colors as the grayColorModel.
* There are only one difference: One Color is transparent. This Color has an alpha-value of 0x00.
*
*
* @return IndexColorModel for image data.
* @since 30.04.1999
*/
public static void fillOverlayGrayColorModel(int colorBit)
{
overlayColorBit = colorBit;
int bits = 8;
int size = 256;
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
for (int i = 0; i < size; i++)
{
r[i] = (byte)(i&0xff);
g[i] = (byte)(i&0xff);
b[i]= (byte)(i&0xff);
a[i]= (byte)0x00;
}
a[colorBit] = (byte)0xFF;
//Transparent Color
overlayGrayColorModel = new IndexColorModel(bits, size, r, g, b,a);
}
public static void fillOverlay12BitColorModel(int colorBit)
{
overlay12ColorBit = colorBit;
int bits = 16;
int size = 4096; //(12**8)
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
byte[] a = new byte[size];
int x = 0;
int y = 0;
for (int i = 0; i < size; i++)
{
x++;
if ( x ==256)
{
x = 0;
y++;
}
r[i] = (byte)(x&0xff);
g[i] = (byte)(y&0xff);
b[i]= (byte)0x00;
a[i]= (byte)0x00;
}
//Transparent Color
a[colorBit] = (byte)0xFF;
//Transparent Color
overlayGray12ColorModel = new IndexColorModel(bits, size, r, g, b,a);
}
public static IndexColorModel getOverlayGrayColorModel(int colorBit)
{
if (colorBit != overlayColorBit) fillOverlayGrayColorModel(colorBit);
return overlayGrayColorModel;
}
public static IndexColorModel getOverlayGray12ColorModel(int colorBit)
{
if (colorBit != overlay12ColorBit) fillOverlay12BitColorModel(colorBit);
return overlayGray12ColorModel;
}
public static IndexColorModel getGray12BitColorModel()
{
return gray12BitColorModel;
}
public static Color getColor(int grayIndex)
{
return new Color(grayIndex, grayIndex,grayIndex);
}
public static Color get12Color(int grayIndex)
{
int r = grayIndex%256;
int g = grayIndex/256;
int b = 0;
return new Color (r,g,b);
}
/**
* Conts the values of the specified array.
*
* @param colorArray Specifies the array.
* @return The number of values in the array.
* @since 30.04.1999
*/
public static int[] countValues(byte[] colorArray)
{
int[] returnArray = new int [256];
for (int i = 0; i < colorArray.length; i++)
{
returnArray[colorArray[i]&0xff] = 1;
}
for (int i = 0; i < 256; i++)
{
System.out.println(" das ist der Wert i: " + i + " wert: " + returnArray[i]);
}
return returnArray;
}
/**
* Conts the values of the specified array.
*
* @param colorArray Specifies the array.
* @return The number of values in the array.
* @since 30.04.1999
*/
public static int[] countValues(short[] colorArray)
{
int[] returnArray = new int [256*256];
for (int i = 0; i < colorArray.length; i++)
{
returnArray[colorArray[i]] = 1;
}
for (int i = 0; i < returnArray.length; i++)
{
if (returnArray[i] != 0)System.out.println(" das ist der Wert i: " + i + " wert: " + returnArray[i]);
}
return returnArray;
}
}
/*
* CVS Log
* $Log: GrayColorIndex.java,v $
* Revision 1.1.1.1 2001/06/06 10:32:30 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|