01: /*
02: * @(#)QtDefaultGraphicsConfiguration.java 1.14 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package java.awt;
28:
29: import java.awt.image.BufferedImage;
30: import java.awt.image.ColorModel;
31: import java.awt.image.DirectColorModel;
32: import java.awt.image.IndexColorModel;
33:
34: /**
35: @version 1.4, 05/03/02 */
36:
37: class QtDefaultGraphicsConfiguration extends QtGraphicsConfiguration {
38:
39: // See QtBackEnd.cpp for implementation
40: private static native ColorModel getQtColorModel();
41:
42: private ColorModel colorModel;
43:
44: QtDefaultGraphicsConfiguration(QtGraphicsDevice device) {
45: super (device);
46: getColorModel(); // side-effect of creating the imageType
47: }
48:
49: public synchronized ColorModel getColorModel() {
50: if (colorModel == null) {
51: colorModel = getQtColorModel();
52: imageType = toBufferedImageType(colorModel);
53: }
54:
55: return colorModel;
56: }
57:
58: private int toBufferedImageType(ColorModel cm) {
59: int type = BufferedImage.TYPE_CUSTOM;
60: switch (cm.getPixelSize()) {
61: case 32:
62: if (cm.isAlphaPremultiplied()) {
63: type = BufferedImage.TYPE_INT_ARGB_PRE;
64: } else {
65: type = BufferedImage.TYPE_INT_ARGB;
66: }
67: break;
68: case 24:
69: type = BufferedImage.TYPE_INT_RGB;
70: if (cm instanceof DirectColorModel) {
71: int blue_mask = ((DirectColorModel) cm).getBlueMask();
72: if ((blue_mask & 0x00FF0000) != 0) // is it BGR
73: type = BufferedImage.TYPE_INT_BGR;
74: }
75: break;
76: case 15:
77: type = BufferedImage.TYPE_USHORT_555_RGB;
78: break;
79: case 16:
80: type = BufferedImage.TYPE_USHORT_565_RGB;
81: break;
82: case 8:
83: if (cm instanceof IndexColorModel) {
84: type = BufferedImage.TYPE_BYTE_INDEXED;
85: }
86: break;
87: }
88:
89: return type;
90: }
91: }
|