01: /*
02: * $RCSfile: RandomIterCSMByte.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:42 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.iterator;
13:
14: import java.awt.Rectangle;
15: import java.awt.image.DataBufferByte;
16: import java.awt.image.RenderedImage;
17: import java.awt.image.SampleModel;
18:
19: /**
20: * @since EA2
21: */
22: public class RandomIterCSMByte extends RandomIterCSM {
23:
24: byte[][] bankData;
25:
26: public RandomIterCSMByte(RenderedImage im, Rectangle bounds) {
27: super (im, bounds);
28: }
29:
30: protected final void dataBufferChanged() {
31: this .bankData = ((DataBufferByte) dataBuffer).getBankData();
32: }
33:
34: public final int getSample(int x, int y, int b) {
35: makeCurrent(x - boundsX, y - boundsY);
36: return bankData[b][(x - sampleModelTranslateX) * pixelStride
37: + (y - sampleModelTranslateY) * scanlineStride
38: + bandOffsets[b]] & 0xff;
39: }
40:
41: public final float getSampleFloat(int x, int y, int b) {
42: makeCurrent(x - boundsX, y - boundsX);
43: return (float) (bankData[b][(x - sampleModelTranslateX)
44: * pixelStride + (y - sampleModelTranslateY)
45: * scanlineStride + bandOffsets[b]] & 0xff);
46: }
47:
48: public final double getSampleDouble(int x, int y, int b) {
49: makeCurrent(x - boundsX, y - boundsX);
50: return (double) (bankData[b][(x - sampleModelTranslateX)
51: * pixelStride + (y - sampleModelTranslateY)
52: * scanlineStride + bandOffsets[b]] & 0xff);
53: }
54:
55: public int[] getPixel(int x, int y, int[] iArray) {
56: if (iArray == null) {
57: iArray = new int[numBands];
58: }
59:
60: int offset = (x - sampleModelTranslateX) * pixelStride
61: + (y - sampleModelTranslateY) * scanlineStride;
62: for (int b = 0; b < numBands; b++) {
63: iArray[b] = bankData[b][offset + bandOffsets[b]] & 0xff;
64: }
65: return iArray;
66: }
67: }
|