1 /*
2  * Copyright (c) 2006, 2009, 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 
26 #ifndef AWT_BITMAP_UTIL_H
27 #define AWT_BITMAP_UTIL_H
28 
29 class BitmapUtil {
30 public:
31     /**
32      * Creates B&W Bitmap with transparency mask from specified ARGB input data
33      * 0 for opaque pixels, 1 for transparent.
34      * MSDN article for ICONINFO says that 'for color icons, this mask only
35      * defines the AND bitmask of the icon'. That's wrong! If mask bit for
36      * specific pixel is 0, the pixel is drawn opaque, otherwise it's XORed
37      * with background.
38      */
39     static HBITMAP CreateTransparencyMaskFromARGB(int width, int height, int* imageData);
40 
41     /**
42      * Creates 32-bit ARGB V4 Bitmap (Win95-compatible) from specified ARGB input data
43      * The color for transparent pixels (those with 0 alpha) is reset to 0 (BLACK)
44      * to prevent errors on systems prior to XP.
45      */
46     static HBITMAP CreateV4BitmapFromARGB(int width, int height, int* imageData);
47 
48     /**
49      * Creates 32-bit premultiplied ARGB V4 Bitmap (Win95-compatible) from
50      * specified ARGB Pre input data.
51      */
52     static HBITMAP CreateBitmapFromARGBPre(int width, int height,
53                                            int srcStride,
54                                            int* imageData);
55 
56     /**
57      * Transforms the given bitmap into an HRGN representing the transparency
58      * of the bitmap.
59      */
60     static HRGN BitmapToRgn(HBITMAP hBitmap);
61 
62     /**
63      * Makes a copy of the given bitmap. Blends every pixel of the source
64      * with the given blendColor and alpha. If alpha == 0, the function
65      * simply makes a plain copy of the source without any blending.
66      */
67     static HBITMAP BlendCopy(HBITMAP hSrcBitmap, COLORREF blendColor, BYTE alpha);
68 
69     /**
70      * Creates a 32 bit ARGB bitmap. Returns the bitmap handle.
71      * The pointer to the bitmap data is stored into bitmapBitsPtr.
72      */
73     static HBITMAP CreateARGBBitmap(int width, int height, void ** bitmapBitsPtr);
74 };
75 
76 #endif
77