01: /*
02: * $RCSfile: WritableRandomIterFallback.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:55:45 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.iterator;
13:
14: import java.awt.Rectangle;
15: import java.awt.image.Raster;
16: import java.awt.image.WritableRenderedImage;
17: import javax.media.jai.iterator.WritableRandomIter;
18:
19: /**
20: * @since EA2
21: */
22: public final class WritableRandomIterFallback extends
23: RandomIterFallback implements WritableRandomIter {
24:
25: WritableRenderedImage wim;
26:
27: public WritableRandomIterFallback(WritableRenderedImage im,
28: Rectangle bounds) {
29: super (im, bounds);
30: this .wim = im;
31: }
32:
33: private void makeCurrentWritable(int xLocal, int yLocal) {
34: int xIDNew = xTiles[xLocal];
35: int yIDNew = yTiles[yLocal];
36:
37: if ((xIDNew != xID) || (yIDNew != yID) || (dataBuffer == null)) {
38: if (dataBuffer != null) {
39: wim.releaseWritableTile(xID, yID);
40: }
41: xID = xIDNew;
42: yID = yIDNew;
43: Raster tile = wim.getWritableTile(xID, yID);
44:
45: this .dataBuffer = tile.getDataBuffer();
46: this .sampleModelTranslateX = tile
47: .getSampleModelTranslateX();
48: this .sampleModelTranslateY = tile
49: .getSampleModelTranslateY();
50: }
51: }
52:
53: public void setSample(int x, int y, int b, int s) {
54: makeCurrentWritable(x - boundsX, y - boundsY);
55: sampleModel.setSample(x - sampleModelTranslateX, y
56: - sampleModelTranslateY, b, s, dataBuffer);
57: }
58:
59: public void setSample(int x, int y, int b, float s) {
60: makeCurrentWritable(x - boundsX, y - boundsY);
61: sampleModel.setSample(x - sampleModelTranslateX, y
62: - sampleModelTranslateY, b, s, dataBuffer);
63: }
64:
65: public void setSample(int x, int y, int b, double s) {
66: makeCurrentWritable(x - boundsX, y - boundsY);
67: sampleModel.setSample(x - sampleModelTranslateX, y
68: - sampleModelTranslateY, b, s, dataBuffer);
69: }
70:
71: public void setPixel(int x, int y, int[] iArray) {
72: makeCurrentWritable(x - boundsX, y - boundsY);
73: sampleModel.setPixel(x - sampleModelTranslateX, y
74: - sampleModelTranslateY, iArray, dataBuffer);
75: }
76:
77: public void setPixel(int x, int y, float[] fArray) {
78: makeCurrentWritable(x - boundsX, y - boundsY);
79: sampleModel.setPixel(x - sampleModelTranslateX, y
80: - sampleModelTranslateY, fArray, dataBuffer);
81: }
82:
83: public void setPixel(int x, int y, double[] dArray) {
84: makeCurrentWritable(x - boundsX, y - boundsY);
85: sampleModel.setPixel(x - sampleModelTranslateX, y
86: - sampleModelTranslateY, dArray, dataBuffer);
87: }
88:
89: public void done() {
90: if (dataBuffer != null) {
91: wim.releaseWritableTile(xID, yID);
92: }
93: dataBuffer = null;
94: }
95: }
|