1:
8:
9: package ;
10:
11: import ;
12: import ;
13: import ;
14: import ;
15: import ;
16: import ;
17: import ;
18: import ;
19: import ;
20: import ;
21: import ;
22: import ;
23: import ;
24: import ;
25: import ;
26: import ;
27: import ;
28:
29:
38: public class XOffScreenImage extends Image
39: implements IntegerGraphicsState.ScreenCoupledImage,
40: ImageConsumer
41: {
42: private Pixmap pixmap;
43: private XGraphicsConfiguration config;
44: private int width;
45: private int height;
46: private Drawable drawable;
47: private ImageProducer prod;
48: private GC gc;
49: private ColorModel pixmapColorModel;
50:
51:
59: XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, int width, int height, ColorModel cm)
60: {
61: this.config = config;
62: this.width = width;
63: this.height = height;
64: this.drawable = drawable;
65: pixmapColorModel = cm;
66: pixmap = new Pixmap (drawable, width, height, drawable.getDepth ());
67: gc = GC.create (pixmap);
68: }
69:
70:
77: XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, ImageProducer prod, ColorModel cm)
78: {
79: this.config = config;
80: this.width = 0;
81: this.height = 0;
82: this.drawable = drawable;
83: this.prod = prod;
84: pixmapColorModel = cm;
85: prod.startProduction (this);
86: }
87:
88:
91: public Pixmap getPixmap ()
92: {
93: return pixmap;
94: }
95:
96:
99: public void flush ()
100: {
101:
102: pixmap = null;
103: }
104:
105:
111: public Graphics getGraphics ()
112: {
113: DirectRasterGraphics gfxDevice = new XGraphics (pixmap, config);
114: IntegerGraphicsState igState = new IntegerGraphicsState (gfxDevice);
115: Graphics2DImpl gfx2d = new Graphics2DImpl (config);
116: gfx2d.setState (igState);
117: return gfx2d;
118: }
119:
120:
128: public int getHeight (ImageObserver observer)
129: {
130: return height;
131: }
132:
133:
140: public int getHeight ()
141: {
142: return height;
143: }
144:
145:
150: public ImageProducer getSource ()
151: {
152: if (prod == null)
153: throw new UnsupportedOperationException ("getSource not supported");
154: else
155: return prod;
156: }
157:
158:
166: public int getWidth (ImageObserver observer)
167: {
168: return width;
169: }
170:
171:
178: public int getWidth ()
179: {
180: return width;
181: }
182:
183:
195: public Object getProperty (String name, ImageObserver observer)
196: {
197: return null;
198: }
199:
200:
203: public GraphicsConfiguration getGraphicsConfiguration ()
204: {
205: return config;
206: }
207:
208: public void imageComplete (int status)
209: {
210: }
211:
212: public void setColorModel (ColorModel model)
213: {
214: }
215:
216: public void setDimensions (int width, int height)
217: {
218: this.width = width;
219: this.height = height;
220: pixmap = new Pixmap (drawable, width, height, drawable.getDepth ());
221: gc = GC.create (pixmap);
222: }
223:
224: public void setHints (int flags)
225: {
226: }
227:
228: public void setPixels (int x, int y, int w, int h, ColorModel model, int[] pixels, int offset, int scansize)
229: {
230: int idx = 0;
231: float[] normalizedComponents = new float [4];
232: int[] unnormalizedComponents = { 0, 0, 0, 0xff };
233: normalizedComponents[3] = 1;
234: for (int yp=y; yp < (y + h); yp++)
235: {
236: for (int xp=x; xp < (x + w); xp++)
237: {
238: int p = (yp - y) * scansize + (xp - x) + offset;
239:
240: normalizedComponents[0] = (float)model.getRed (pixels[p]) / 255F;
241: normalizedComponents[1] = (float)model.getGreen (pixels[p]) / 255F;
242: normalizedComponents[2] = (float)model.getBlue (pixels[p]) / 255F;
243: pixmapColorModel.getUnnormalizedComponents (normalizedComponents, 0,
244: unnormalizedComponents, 0);
245: int pixelColor = pixmapColorModel.getDataElement (unnormalizedComponents, 0);
246: gc.setForeground (pixelColor);
247: gc.drawPoint (xp, yp);
248: }
249: }
250: }
251:
252: public void setPixels (int x, int y, int w, int h, ColorModel model, byte[] pixels, int offset, int scansize)
253: {
254: int idx = 0;
255: float[] normalizedComponents = new float [4];
256: int[] unnormalizedComponents = { 0, 0, 0, 0xff };
257: normalizedComponents[3] = 1;
258: for (int yp=y; yp < (y + h); yp++)
259: {
260: for (int xp=x; xp < (x + w); xp++)
261: {
262:
263: int p = (yp - y) * scansize + (xp - x) + offset;
264: normalizedComponents[0] = (float)model.getRed (pixels[p]) / 255F;
265: normalizedComponents[1] = (float)model.getGreen (pixels[p]) / 255F;
266: normalizedComponents[2] = (float)model.getBlue (pixels[p]) / 255F;
267: pixmapColorModel.getUnnormalizedComponents (normalizedComponents, 0,
268: unnormalizedComponents, 0);
269: int pixelColor = pixmapColorModel.getDataElement (unnormalizedComponents, 0);
270: gc.setForeground (pixelColor);
271: gc.drawPoint (xp, yp);
272: }
273: }
274: }
275:
276: public void setProperties (Hashtable props)
277: {
278: }
279:
280: }