01: /*
02: * CSampleModel.java
03: *
04: * Created on February 17, 2004, 2:34 AM
05: */
06:
07: package org.netbeans.imagecache;
08:
09: import java.awt.image.DataBuffer;
10: import java.awt.image.SampleModel;
11: import java.awt.image.SinglePixelPackedSampleModel;
12: import java.nio.IntBuffer;
13:
14: /**
15: *
16: * @author tim
17: */
18: public class CSampleModel extends SinglePixelPackedSampleModel {
19: private IntBuffer buf;
20: private int width;
21: private int height;
22:
23: static final int[] MASKS = new int[] { 0x00FF0000, 0x0000FF00,
24: 0x000000FF, 0xFF000000 };
25:
26: /** Creates a new instance of CSampleModel */
27: public CSampleModel(int width, int height) {
28: super (DataBuffer.TYPE_INT, width, height, MASKS);
29: this .buf = buf;
30: this .width = width;
31: this .height = height;
32: }
33:
34: public int getSampleSize(int band) {
35: return 8;
36: }
37:
38: public int[] getPixels(int x, int y, int w, int h, int iArray[],
39: DataBuffer data) {
40: System.err.println("GetPixels: " + x + "," + y + "," + w + ","
41: + h + " iArray: " + iArray + " data" + data);
42: /*
43: if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) {
44: throw new ArrayIndexOutOfBoundsException
45: ("Coordinate out of bounds!");
46: }
47: int pixels[];
48: if (iArray != null) {
49: pixels = iArray;
50: } else {
51: pixels = new int [w*h*numBands];
52: }
53: int lineOffset = y*scanlineStride + x;
54: int dstOffset = 0;
55:
56: for (int i = 0; i < h; i++) {
57: for (int j = 0; j < w; j++) {
58: int value = data.getElem(lineOffset+j);
59: for (int k=0; k < numBands; k++) {
60: pixels[dstOffset++] =
61: ((value & bitMasks[k]) >>> bitOffsets[k]);
62: }
63: }
64: lineOffset += scanlineStride;
65: }
66: return pixels;
67: */
68: return super .getPixels(x, y, w, h, iArray, data);
69: }
70:
71: //XXX do some optimized implementations of fetching pixels
72: }
|