LookupTable has subclasses representing short and byte arrays, called ShortLookupTable and ByteLookupTable...

Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.
The two constructors for ShortLookupTable are shown below; the constructors for ByteLookupTable are identical except that they use bytes instead of shorts:
public ShortLookupTable(int offset, short[] data)
Use this constructor to create a ShortLookupTable based on the given array. Each source pixel color component is used as an index into the given array. The corresponding
destination pixel color component is the value at the given index. All color components use the given array. The supplied offset value is subtracted from the input before indexing the array. If you expect your input data to be in the range from 50 to 150, for example, you might create a ShortLookupTable using a 100 element array with an offset of 50. Note that if any input value is less than the offset, an exception will be thrown. Normally, color components range from to 255, so the array should contain 256 elements for an input offset of 0.
public ShortLookupTable(int offset, short[][] data)
This constructor works like the last one, but it uses a separate array (from the supplied two-dimensional array) for each color component. The offset works the same way, too. Note that the same offset is used for all of the arrays. Make sure you supply an array for each color component. If you're processing RGB images, for example, you should pass three arrays.
ARGB images require four arrays.
The LookupOp class represents an image operation based on a lookup table:
public LookupOp(LookupTable lookup, RenderingHints hints)
This constructor creates a lookup table operator using the given table.
The lookup table is a very versatile operator. I'll start with a simple table that inverts its values.
Here's the code that creates the data array, the LookupTable, and the lookup operator: short[] invert = new short[256];

page 184
Java 2D Graphics
for (int i = 0; i < 256; i++)
invert[i] = (short)(255 - i);
LookupTable table = new ShortLookupTable(0, invert);
LookupOp invertOp = new LookupOp(table, null);
Figure 15.19 shows the effect of this operator, which is much like a photographic negative.
Now suppose we only want to affect one color component. The following code shows how to create an operator that inverts just the red component in an RGB image:
short[] invert = new short[256];
short[] straight = new short[256];
for (int i = 0; i < 256; i++) {
invert[i] = (short)(255 - i);
straight[i] = (short)i;
}
short[][] redInvert = { invert, straight, straight };
LookupTable table = new ShortLookupTable(0, redInvert);
LookupOp redInvertOp = new LookupOp(table, null);
Figure 15.20 shows the effect of this operator. A very simple modification of this can be used to remove an entire color component from an image. The next example shows how to create an operator that removes the green component from an RGB image.
short[] zero = new short[256];
short[] straight = new short[256];
for (int i = 0; i < 256; i++) {
zero[i] = (short)0;
straight[i] = (short)i;
}
short[][] greenRemove = { straight, zero, straight };
LookupTable table = new ShortLookupTable(0, greenRemove);
LookupOp greenRemoveOp = new LookupOp(table, null);
An RGB image without its green component has only blue and red components, which makes it predominantly magenta. Figure 15.21 shows the effect of removing the green color component from our test image.
10.3.4 Adjusting Brightness
10.3.4.1 Using a rescaling operator
The simplest way to adjust the brightness of an image is to use a rescaling operator. Rescaling is a fancy name for multiplying every color component of every pixel by a scale factor. A scale factor of 1.0 leaves the image unchanged.
Rescaling is encapsulated in the java.awt.image.RescaleOp class. This class supports an offset in addition to the scale factor. The offset is added to the color component values after they have been scaled. The formula is shown here, where c is the new value of the color component and co is the original value:
c = scaleFactor·c + offset
0
The results of this calculation are bounded. If the new color component exceeds the maximum value, the maximum is used instead. If you repeatedly process an image with a RescaleOp using a scale factor greater than 1.0, eventually you'll end up with a completely white image.[5]

page 185
Java 2D Graphics
Powered by wordpress | Theme: simpletex | © Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.