001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: RenderedImageCachableRed.java 496576 2007-01-16 02:35:59Z cam $ */
019:
020: package org.apache.xmlgraphics.image.rendered;
021:
022: import java.awt.Rectangle;
023: import java.awt.Shape;
024: import java.awt.image.BufferedImage;
025: import java.awt.image.ColorModel;
026: import java.awt.image.Raster;
027: import java.awt.image.RenderedImage;
028: import java.awt.image.SampleModel;
029: import java.awt.image.WritableRaster;
030: import java.util.Vector;
031:
032: /**
033: * This implements CachableRed around a RenderedImage.
034: * You can use this to wrap a RenderedImage that you want to
035: * appear as a CachableRed.
036: * It essentially ignores the dependency and dirty region methods.
037: *
038: * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
039: * @version $Id: RenderedImageCachableRed.java 496576 2007-01-16 02:35:59Z cam $
040: */
041: public class RenderedImageCachableRed implements CachableRed {
042:
043: public static CachableRed wrap(RenderedImage ri) {
044: if (ri instanceof CachableRed)
045: return (CachableRed) ri;
046: if (ri instanceof BufferedImage)
047: return new BufferedImageCachableRed((BufferedImage) ri);
048: return new RenderedImageCachableRed(ri);
049: }
050:
051: private RenderedImage src;
052: private Vector srcs = new Vector(0);
053:
054: public RenderedImageCachableRed(RenderedImage src) {
055: if (src == null) {
056: throw new IllegalArgumentException();
057: }
058: this .src = src;
059: }
060:
061: public Vector getSources() {
062: return srcs; // should always be empty...
063: }
064:
065: public Rectangle getBounds() {
066: return new Rectangle(getMinX(), // could we cache the rectangle??
067: getMinY(), getWidth(), getHeight());
068: }
069:
070: public int getMinX() {
071: return src.getMinX();
072: }
073:
074: public int getMinY() {
075: return src.getMinY();
076: }
077:
078: public int getWidth() {
079: return src.getWidth();
080: }
081:
082: public int getHeight() {
083: return src.getHeight();
084: }
085:
086: public ColorModel getColorModel() {
087: return src.getColorModel();
088: }
089:
090: public SampleModel getSampleModel() {
091: return src.getSampleModel();
092: }
093:
094: public int getMinTileX() {
095: return src.getMinTileX();
096: }
097:
098: public int getMinTileY() {
099: return src.getMinTileY();
100: }
101:
102: public int getNumXTiles() {
103: return src.getNumXTiles();
104: }
105:
106: public int getNumYTiles() {
107: return src.getNumYTiles();
108: }
109:
110: public int getTileGridXOffset() {
111: return src.getTileGridXOffset();
112: }
113:
114: public int getTileGridYOffset() {
115: return src.getTileGridYOffset();
116: }
117:
118: public int getTileWidth() {
119: return src.getTileWidth();
120: }
121:
122: public int getTileHeight() {
123: return src.getTileHeight();
124: }
125:
126: public Object getProperty(String name) {
127: return src.getProperty(name);
128: }
129:
130: public String[] getPropertyNames() {
131: return src.getPropertyNames();
132: }
133:
134: public Raster getTile(int tileX, int tileY) {
135: return src.getTile(tileX, tileY);
136: }
137:
138: public WritableRaster copyData(WritableRaster raster) {
139: return src.copyData(raster);
140: }
141:
142: public Raster getData() {
143: return src.getData();
144: }
145:
146: public Raster getData(Rectangle rect) {
147: return src.getData(rect);
148: }
149:
150: public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
151: throw new IndexOutOfBoundsException(
152: "Nonexistant source requested.");
153: }
154:
155: public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
156: throw new IndexOutOfBoundsException(
157: "Nonexistant source requested.");
158: }
159: }
|