1/*
2 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.awt;
27
28import java.awt.image.ComponentColorModel;
29import java.awt.image.PixelInterleavedSampleModel;
30import java.awt.image.WritableRaster;
31import java.awt.image.Raster;
32import java.awt.image.DataBuffer;
33import java.awt.image.SampleModel;
34import java.awt.color.ColorSpace;
35import java.awt.Transparency;
36
37/**
38 * This class creates a standard ComponentColorModel with the slight
39 * difference that it creates its Raster objects with the components
40 * in the reverse order from the base ComponentColorModel to match
41 * the ordering on a Windows 24-bit display.
42 */
43public class Win32ColorModel24 extends ComponentColorModel {
44    public Win32ColorModel24() {
45        super(ColorSpace.getInstance(ColorSpace.CS_sRGB),
46              new int[] {8, 8, 8}, false, false,
47              Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
48    }
49
50    /**
51     * Creates a WritableRaster with the specified width and height, that
52     * has a data layout (SampleModel) compatible with this ColorModel.
53     * @see WritableRaster
54     * @see SampleModel
55     */
56    public WritableRaster createCompatibleWritableRaster (int w, int h) {
57        int[] bOffs = {2, 1, 0};
58        return Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
59                                              w, h, w*3, 3,
60                                              bOffs, null);
61    }
62
63    /**
64     * Creates a SampleModel with the specified width and height, that
65     * has a data layout compatible with this ColorModel.
66     * @see SampleModel
67     */
68    public SampleModel createCompatibleSampleModel(int w, int h) {
69        int[] bOffs = {2, 1, 0};
70        return new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
71                                               w, h, 3, w*3, bOffs);
72    }
73}
74