01: /*
02: * $RCSfile: ColorQuantizerRIF.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:56:17 $
10: * $State: Exp $
11: */package com.sun.media.jai.opimage;
12:
13: import java.awt.RenderingHints;
14: import java.awt.image.RenderedImage;
15: import java.awt.image.SampleModel;
16: import java.awt.image.DataBuffer;
17: import java.awt.image.MultiPixelPackedSampleModel;
18: import java.awt.image.renderable.RenderedImageFactory;
19: import java.awt.image.renderable.ParameterBlock;
20: import java.util.Map;
21: import javax.media.jai.BorderExtender;
22: import javax.media.jai.ImageLayout;
23: import javax.media.jai.JAI;
24: import javax.media.jai.ROI;
25: import javax.media.jai.operator.ColorQuantizerDescriptor;
26: import javax.media.jai.operator.ColorQuantizerType;
27:
28: /**
29: * <p> Class implementing the RIF interface for the ColorQuantizer
30: * operator. An instance of this class should be registered with the
31: * OperationRegistry with operation name "ColorQuantizer."
32: */
33: public class ColorQuantizerRIF implements RenderedImageFactory {
34:
35: /** <p> Default constructor (there is no input). */
36: public ColorQuantizerRIF() {
37: }
38:
39: /**
40: * <p> Creates a new instance of ColorQuantizerOpImage in the
41: * rendered layer. This method satisfies the implementation of RIF.
42: *
43: * @param paramBlock The source image, the color quantization algorithm
44: * name, the maximum number of colors, the
45: * parameter for training (the histogram size for
46: * median-cut, the cycle for neuquant, and maximum tree
47: * size for oct-tree), and the ROI.
48: * @param renderHints RenderingHints.
49: */
50: public RenderedImage create(ParameterBlock paramBlock,
51: RenderingHints renderHints) {
52: RenderedImage source = paramBlock.getRenderedSource(0);
53:
54: ImageLayout layout = renderHints == null ? null
55: : (ImageLayout) renderHints.get(JAI.KEY_IMAGE_LAYOUT);
56:
57: ColorQuantizerType algorithm = (ColorQuantizerType) paramBlock
58: .getObjectParameter(0);
59: int maxColorNum = paramBlock.getIntParameter(1);
60: int upperBound = paramBlock.getIntParameter(2);
61: ROI roi = (ROI) paramBlock.getObjectParameter(3);
62: int xPeriod = paramBlock.getIntParameter(4);
63: int yPeriod = paramBlock.getIntParameter(5);
64:
65: // check if 3-band byte-type image
66: SampleModel sm = source.getSampleModel();
67: if (sm.getNumBands() != 3
68: && sm.getDataType() == DataBuffer.TYPE_BYTE)
69: throw new IllegalArgumentException("ColorQuantizerRIF0");
70:
71: if (algorithm.equals(ColorQuantizerDescriptor.NEUQUANT))
72: return new NeuQuantOpImage(source, (Map) renderHints,
73: layout, maxColorNum, upperBound, roi, xPeriod,
74: yPeriod);
75:
76: if (algorithm.equals(ColorQuantizerDescriptor.OCTTREE))
77: return new OctTreeOpImage(source, (Map) renderHints,
78: layout, maxColorNum, upperBound, roi, xPeriod,
79: yPeriod);
80: else
81: return new MedianCutOpImage(source, (Map) renderHints,
82: layout, maxColorNum, upperBound, roi, xPeriod,
83: yPeriod);
84:
85: } // create
86:
87: } // ColorQuantizerRIF
|