1 |
/* ColorModel.java -- |
/* LookupOp.java -- Filter that converts each pixel using a lookup table. |
2 |
Copyright (C) 2004 Free Software Foundation |
Copyright (C) 2004 Free Software Foundation |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
|
/* |
|
|
* Created on Oct 6, 2004 |
|
|
* |
|
|
* TODO To change the template for this generated file go to |
|
|
* Window - Preferences - Java - Code Style - Code Templates |
|
|
*/ |
|
38 |
package java.awt.image; |
package java.awt.image; |
39 |
|
|
40 |
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
61 |
* |
* |
62 |
* @author jlquinn |
* @author jlquinn |
63 |
*/ |
*/ |
64 |
public class LookupOp implements BufferedImageOp, RasterOp { |
public class LookupOp implements BufferedImageOp, RasterOp |
65 |
|
{ |
66 |
private LookupTable lut; |
private LookupTable lut; |
67 |
private RenderingHints hints; |
private RenderingHints hints; |
68 |
|
|
84 |
{ |
{ |
85 |
if (src.getColorModel() instanceof IndexColorModel) |
if (src.getColorModel() instanceof IndexColorModel) |
86 |
throw new IllegalArgumentException("LookupOp.filter: IndexColorModel " |
throw new IllegalArgumentException("LookupOp.filter: IndexColorModel " |
87 |
+ "not allowed"); |
+ "not allowed"); |
88 |
if (dst == null) |
if (dst == null) |
89 |
dst = createCompatibleDestImage(src, src.getColorModel()); |
dst = createCompatibleDestImage(src, src.getColorModel()); |
90 |
|
|
117 |
dr.setPixel(x, y, lut.lookupPixel(tmp, dbuf)); |
dr.setPixel(x, y, lut.lookupPixel(tmp, dbuf)); |
118 |
} |
} |
119 |
} |
} |
120 |
else if (lut.getNumComponents() != 1 && |
else if (lut.getNumComponents() != 1 |
121 |
lut.getNumComponents() != src.getColorModel().getNumComponents()) |
&& |
122 |
throw new IllegalArgumentException("LookupOp.filter: Incompatible lookup " |
lut.getNumComponents() != src.getColorModel().getNumComponents()) |
123 |
+ "table and source image"); |
throw new IllegalArgumentException("LookupOp.filter: " |
124 |
|
+ "Incompatible lookup " |
125 |
|
+ "table and source image"); |
126 |
|
|
127 |
// No alpha to ignore |
// No alpha to ignore |
128 |
int[] dbuf = new int[src.getColorModel().getNumComponents()]; |
int[] dbuf = new int[src.getColorModel().getNumComponents()]; |
157 |
* @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel) |
* @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel) |
158 |
*/ |
*/ |
159 |
public BufferedImage createCompatibleDestImage(BufferedImage src, |
public BufferedImage createCompatibleDestImage(BufferedImage src, |
160 |
ColorModel dstCM) |
ColorModel dstCM) |
161 |
{ |
{ |
162 |
// FIXME: set properties to those in src |
// FIXME: set properties to those in src |
163 |
return new BufferedImage(dstCM, |
return new BufferedImage(dstCM, |
164 |
src.getRaster().createCompatibleWritableRaster(), |
src.getRaster().createCompatibleWritableRaster(), |
165 |
src.isPremultiplied, null); |
src.isPremultiplied, null); |
166 |
} |
} |
167 |
|
|
168 |
/** Return corresponding destination point for source point. |
/** Return corresponding destination point for source point. |
174 |
*/ |
*/ |
175 |
public Point2D getPoint2D(Point2D src, Point2D dst) |
public Point2D getPoint2D(Point2D src, Point2D dst) |
176 |
{ |
{ |
177 |
if (dst == null) return (Point2D)src.clone(); |
if (dst == null) |
178 |
|
return (Point2D) src.clone(); |
179 |
|
|
180 |
dst.setLocation(src); |
dst.setLocation(src); |
181 |
return dst; |
return dst; |
182 |
} |
} |
217 |
if (src.getNumBands() != dest.getNumBands()) |
if (src.getNumBands() != dest.getNumBands()) |
218 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
219 |
|
|
220 |
if (lut.getNumComponents() != 1 && lut.getNumComponents() != src.getNumBands()) |
if (lut.getNumComponents() != 1 |
221 |
|
&& lut.getNumComponents() != src.getNumBands()) |
222 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
223 |
|
|
224 |
|
|