1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47:
48:
54: public class GtkImageConsumer implements ImageConsumer
55: {
56: private GtkImage target;
57: private int width, height;
58: private Hashtable<?,?> properties;
59: private int[] pixelCache = null;
60: private ImageProducer source;
61:
62: public GtkImageConsumer(GtkImage target, ImageProducer source)
63: {
64: this.target = target;
65: this.source = source;
66: }
67:
68: public synchronized void imageComplete (int status)
69: {
70:
71:
72: if (!(source instanceof MemoryImageSource))
73: source.removeConsumer(this);
74: target.setImage(width, height, pixelCache, properties);
75: }
76:
77: public synchronized void setColorModel (ColorModel model)
78: {
79:
80:
81:
82: }
83:
84: public synchronized void setDimensions (int width, int height)
85: {
86: pixelCache = new int[width*height];
87:
88: this.width = width;
89: this.height = height;
90: }
91:
92: public synchronized void setHints (int flags)
93: {
94:
95:
96:
97: }
98:
99: public synchronized void setPixels (int x, int y, int width, int height,
100: ColorModel cm, byte[] pixels,
101: int offset, int scansize)
102: {
103: setPixels (x, y, width, height, cm, convertPixels (pixels), offset,
104: scansize);
105: }
106:
107: public synchronized void setPixels (int x, int y, int width, int height,
108: ColorModel cm, int[] pixels,
109: int offset, int scansize)
110: {
111: if (pixelCache == null)
112: return;
113:
114: if (cm.equals(GtkImage.nativeModel))
115: for (int i = 0; i < height; i++)
116: System.arraycopy (pixels, offset + (i * scansize),
117: pixelCache, (y + i) * this.width + x,
118: width);
119: else
120: {
121: if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
122: {
123: for (int i = 0; i < height; i++)
124: for (int j = 0; j < width; j++)
125: {
126:
127: int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
128: int a = ((pix & 0xFF000000) >> 24) & 0xFF;
129: int rgb = (pix & 0x00FFFFFF) << 8;
130: pix = rgb | a;
131: pixelCache[(y + i) * this.width + x + j] = pix;
132: }
133: }
134: else
135: {
136: for (int i = 0; i < height; i++)
137: for (int j = 0; j < width; j++)
138: {
139:
140: int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
141: byte b = (byte)(pix & 0xFF);
142: byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
143: pix &= 0xFF00FF00;
144: pix |= ((b & 0xFF) << 16);
145: pix |= (r & 0xFF);
146: pixelCache[(y + i) * this.width + x + j] = pix;
147: }
148: }
149: }
150: }
151:
152:
155: private int[] convertPixels (byte[] pixels)
156: {
157: int ret[] = new int[pixels.length];
158:
159: for (int i = 0; i < pixels.length; i++)
160: ret[i] = pixels[i] & 0xFF;
161:
162: return ret;
163: }
164:
165: public synchronized void setProperties (Hashtable<?,?> props)
166: {
167: this.properties = props;
168: }
169: }