1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56: public class GtkVolatileImage extends VolatileImage
57: {
58: int width, height;
59: private ImageCapabilities caps;
60:
61: final GtkComponentPeer component;
62:
63: static ColorModel gdkColorModel = new DirectColorModel(32,
64: 0x000000FF,
65: 0x0000FF00,
66: 0x00FF0000,
67: 0xFF000000);
68:
69:
72: long nativePointer;
73:
74: native long init(GtkComponentPeer component, int width, int height);
75:
76: native void destroy(long pointer);
77:
78: native int[] nativeGetPixels(long pointer);
79:
80:
90: public int[] getPixels()
91: {
92: return nativeGetPixels(nativePointer);
93: }
94:
95: native void nativeCopyArea(long pointer, int x, int y, int w, int h, int dx,
96: int dy );
97: public void copyArea(int x, int y, int w, int h, int dx, int dy)
98: {
99: nativeCopyArea(nativePointer, x, y, w, h, dx, dy);
100: }
101:
102: native void nativeDrawVolatile(long pointer, long srcPtr, int x, int y,
103: int w, int h );
104: public void drawVolatile(long srcPtr, int x, int y, int w, int h )
105: {
106: nativeDrawVolatile(nativePointer, srcPtr, x, y, w, h);
107: }
108:
109: public GtkVolatileImage(GtkComponentPeer component,
110: int width, int height, ImageCapabilities caps)
111: {
112: this.width = width;
113: this.height = height;
114: this.caps = caps;
115: this.component = component;
116: nativePointer = init( component, width, height );
117: }
118:
119: public GtkVolatileImage(int width, int height, ImageCapabilities caps)
120: {
121: this(null, width, height, caps);
122: }
123:
124: public GtkVolatileImage(int width, int height)
125: {
126: this(null, width, height, null);
127: }
128:
129: public void finalize()
130: {
131: dispose();
132: }
133:
134: public void dispose()
135: {
136: destroy(nativePointer);
137: }
138:
139: public BufferedImage getSnapshot()
140: {
141: WritableRaster raster = Raster.createWritableRaster(createGdkSampleModel(width, height),
142: new Point(0, 0));
143: raster.setDataElements(0, 0, getPixels());
144: return new BufferedImage(gdkColorModel, raster,
145: gdkColorModel.isAlphaPremultiplied(), null);
146: }
147:
148: public Graphics getGraphics()
149: {
150: return createGraphics();
151: }
152:
153: public Graphics2D createGraphics()
154: {
155: return new VolatileImageGraphics( this );
156: }
157:
158: public int validate(GraphicsConfiguration gc)
159: {
160: return VolatileImage.IMAGE_OK;
161: }
162:
163: public boolean contentsLost()
164: {
165: return false;
166: }
167:
168: public ImageCapabilities getCapabilities()
169: {
170: return caps;
171: }
172:
173: public int getWidth()
174: {
175: return width;
176: }
177:
178: public int getHeight()
179: {
180: return height;
181: }
182:
183: public int getWidth(java.awt.image.ImageObserver observer)
184: {
185: return width;
186: }
187:
188: public int getHeight(java.awt.image.ImageObserver observer)
189: {
190: return height;
191: }
192:
193: public Object getProperty(String name, ImageObserver observer)
194: {
195: return null;
196: }
197:
198:
201: protected static SampleModel createGdkSampleModel(int w, int h)
202: {
203: return new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h,
204: new int[]{0x000000FF, 0x0000FF00,
205: 0x00FF0000, 0xFF000000});
206: }
207: }