source: trunk/src/gcc/libjava/gnu/awt/xlib/XGraphicsConfiguration.java@ 1392

Last change on this file since 1392 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.5 KB
Line 
1/* Copyright (C) 2000, 2003 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
8
9package gnu.awt.xlib;
10
11import java.awt.GraphicsConfiguration;
12import java.awt.Rectangle;
13import java.awt.Graphics2D;
14import java.awt.Graphics;
15import java.awt.GraphicsDevice;
16import java.awt.Point;
17import java.awt.Color;
18import java.awt.color.ColorSpace;
19import java.awt.image.*;
20import java.awt.geom.AffineTransform;
21import gnu.gcj.xlib.GC;
22import gnu.gcj.xlib.Drawable;
23import gnu.gcj.xlib.Window;
24import gnu.gcj.xlib.XImage;
25import gnu.gcj.xlib.Visual;
26import gnu.gcj.xlib.Colormap;
27import gnu.gcj.xlib.XColor;
28import gnu.gcj.xlib.Screen;
29import gnu.gcj.xlib.Display;
30import gnu.java.awt.Buffers;
31import java.util.Hashtable;
32
33public class XGraphicsConfiguration extends GraphicsConfiguration
34{
35 //public abstract GraphicsDevice getDevice();
36
37 Visual visual;
38 int format;
39 Colormap colormap;
40 ColorModel imageCM;
41 ColorModel pixelCM;
42
43 public XGraphicsConfiguration(Visual visual)
44 {
45 this.visual = visual;
46 }
47
48 public BufferedImage createCompatibleImage(int width, int height)
49 {
50 XImage ximg = new XImage(visual, width, height,
51 false // do not auto allocate memory
52 );
53
54 Point origin = new Point(0, 0);
55 WritableRaster raster = createRasterForXImage(ximg, origin);
56
57 /* This is not a good way of doing this. Multiple toolkits may
58 want to share the BufferedImage. */
59 Hashtable props = new Hashtable();
60 props.put("gnu.gcj.xlib.XImage", ximg);
61 props.put("java.awt.GraphicsConfiguration", this);
62
63 BufferedImage bimg = new BufferedImage(imageCM,raster, false, props);
64
65 DataBuffer dataB = raster.getDataBuffer();
66 attachData(ximg, dataB, 0);
67 return bimg;
68 }
69
70 WritableRaster createRasterForXImage(XImage ximage, Point origin)
71 {
72 if (imageCM == null) prepareColorModel(ximage);
73
74 /*
75 This will not work, since it creates a sample model that
76 does not necessarily match the format of the XImage.
77
78 WritableRaster raster =
79 imageCM.createCompatibleWritableRaster(width, height); */
80
81 // Create a sample model matching the XImage:
82
83 SampleModel imageSM = null;
84
85 int width = ximage.getWidth();
86 int height = ximage.getHeight();
87 int bitsPerPixel = ximage.getBitsPerPixel();
88 int dataType =
89 Buffers.smallestAppropriateTransferType(bitsPerPixel);
90 int bitsPerDataElement = DataBuffer.getDataTypeSize(dataType);
91 int scanlineStride = ximage.getBytesPerLine()*8/bitsPerDataElement;
92
93 if (imageCM instanceof IndexColorModel)
94 {
95 int[] bandOffsets = {0};
96 imageSM = new ComponentSampleModel(dataType,
97 width, height,
98 1, // pixel stride
99 scanlineStride,
100 bandOffsets);
101 }
102 else if (imageCM instanceof PackedColorModel)
103 {
104 PackedColorModel pcm = (PackedColorModel) imageCM;
105 int[] masks = pcm.getMasks();
106
107 imageSM = new SinglePixelPackedSampleModel(dataType,
108 width, height,
109 scanlineStride,
110 masks);
111 }
112
113 if (imageSM == null)
114 {
115 throw new UnsupportedOperationException("creating sample model " +
116 "for " + imageCM +
117 " not implemented");
118 }
119
120 WritableRaster raster = Raster.createWritableRaster(imageSM, origin);
121 return raster;