1 /*
2  *******************************************************************************************
3  * Dgame (a D game framework) - Copyright (c) Randy Schütt
4  * 
5  * This software is provided 'as-is', without any express or implied warranty.
6  * In no event will the authors be held liable for any damages arising from
7  * the use of this software.
8  * 
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  * 
13  * 1. The origin of this software must not be misrepresented; you must not claim
14  *    that you wrote the original software. If you use this software in a product,
15  *    an acknowledgment in the product documentation would be appreciated but is
16  *    not required.
17  * 
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  *    misrepresented as being the original software.
20  * 
21  * 3. This notice may not be removed or altered from any source distribution.
22  *******************************************************************************************
23  */
24 module Dgame.Graphic.Masks;
25 
26 /**
27  * The RGBA-Mask are the bitmasks used to extract that color from a pixel.
28  * It is used to e.g. define the background of a newly created Surface.
29  * Using zeros for the RGB-Masks sets a default value, based on the depth
30  * But using zero for the Aalpha-Mask results in an Alpha-Mask of 0.
31  * By default Surfaces with an Alpha-Mask are set up for blending.
32  * You can change the blend mode with Surface.setBlendMode.
33  */
34 struct Masks {
35     /**
36      * The RGBA-Masks are zero.
37      * Using zeros for the RGB-Masks sets a default value, based on the given depth.
38      * Using zero for the Alpha-Mask results in an Alpha-Mask of 0.
39      */
40     static immutable Masks Zero = Masks(0, 0, 0, 0);
41 
42     version (LittleEndian) {
43         uint red = 0x000000ff; /// the red mask, default is 0x000000ff
44         uint green = 0x0000ff00; /// the green mask, default is 0x0000ff00
45         uint blue = 0x00ff0000; /// the blue mask, default is 0x00ff0000
46         uint alpha = 0xff000000; /// the alpha mask, default is 0xff000000
47     } else {
48         uint red = 0xff000000; /// the red mask, default is 0xff000000
49         uint green = 0x00ff0000; /// the green mask, default is 0x00ff0000
50         uint blue = 0x0000ff00; /// the blue mask, default is 0x0000ff00
51         uint alpha = 0x000000ff; /// the alpha mask, default is 0x000000ff
52     }
53 
54     /**
55      * CTor
56      */
57     @nogc
58     this(uint red, uint green, uint blue, uint alpha) pure nothrow {
59         this.red = red;
60         this.green = green;
61         this.blue = blue;
62         this.alpha = alpha;
63     }
64 }