ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gfx_def.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Graphic definitions and type/unit conversions.
25 //
26 //=============================================================================
27 
28 #ifndef AGS_SHARED_GFX_GFX_DEF_H
29 #define AGS_SHARED_GFX_GFX_DEF_H
30 
31 namespace AGS3 {
32 namespace AGS {
33 namespace Shared {
34 
35 enum GraphicFlip {
36  kFlip_None,
37  kFlip_Horizontal, // this means - mirror over horizontal middle line
38  kFlip_Vertical, // this means - mirror over vertical middle line
39  kFlip_Both // mirror over diagonal (horizontal and vertical)
40 };
41 
42 enum BlendMode {
43  // free blending (ARGB -> ARGB) modes
44  kBlendMode_NoAlpha = 0, // ignore alpha channel
45  kBlendMode_Alpha, // alpha-blend src to dest, combining src & dest alphas
46  // NOTE: add new modes here
47 
48  kNumBlendModes
49 };
50 
51 namespace GfxDef {
52 
53 // Converts percentage of transparency into alpha
54 inline int Trans100ToAlpha255(int transparency) {
55  return ((100 - transparency) * 255) / 100;
56 }
57 
58 // Converts alpha into percentage of transparency
59 inline int Alpha255ToTrans100(int alpha) {
60  return 100 - ((alpha * 100) / 255);
61 }
62 
63 // Special formulae to reduce precision loss and support flawless forth &
64 // reverse conversion for multiplies of 10%
65 inline int Trans100ToAlpha250(int transparency) {
66  return ((100 - transparency) * 25) / 10;
67 }
68 
69 inline int Alpha250ToTrans100(int alpha) {
70  return 100 - ((alpha * 10) / 25);
71 }
72 
73 // Convert correct 100-ranged transparency into legacy 255-ranged
74 // transparency; legacy inconsistent transparency value range:
75 // 0 = opaque,
76 // 255 = invisible,
77 // 1 -to- 254 = barely visible -to- mostly visible (as proper alpha)
78 inline int Trans100ToLegacyTrans255(int transparency) {
79  switch (transparency) {
80  case 0:
81  return 0; // this means opaque
82  case 100:
83  return 255; // this means invisible
84  default:
85  // the rest of the range works as alpha
86  return Trans100ToAlpha250(transparency);
87  }
88 }
89 
90 // Convert legacy 255-ranged "incorrect" transparency into proper
91 // 100-ranged transparency.
92 inline int LegacyTrans255ToTrans100(int legacy_transparency) {
93  switch (legacy_transparency) {
94  case 0:
95  return 0; // this means opaque
96  case 255:
97  return 100; // this means invisible
98  default:
99  // the rest of the range works as alpha
100  return Alpha250ToTrans100(legacy_transparency);
101  }
102 }
103 
104 // Convert legacy 100-ranged transparency into proper 255-ranged alpha
105 // 0 => alpha 255
106 // 100 => alpha 0
107 // 1 - 99 => alpha 1 - 244
108 inline int LegacyTrans100ToAlpha255(int legacy_transparency) {
109  switch (legacy_transparency) {
110  case 0:
111  return 255; // this means opaque
112  case 100:
113  return 0; // this means invisible
114  default:
115  // the rest of the range works as alpha (only 100-ranged)
116  return legacy_transparency * 255 / 100;
117  }
118 }
119 
120 // Convert legacy 255-ranged transparency into proper 255-ranged alpha
121 inline int LegacyTrans255ToAlpha255(int legacy_transparency) {
122  switch (legacy_transparency) {
123  case 0:
124  return 255; // this means opaque
125  case 255:
126  return 0; // this means invisible
127  default:
128  // the rest of the range works as alpha
129  return legacy_transparency;
130  }
131 }
132 
133 // Convert 255-ranged alpha into legacy 255-ranged transparency
134 inline int Alpha255ToLegacyTrans255(int alpha) {
135  switch (alpha) {
136  case 255:
137  return 0; // this means opaque
138  case 0:
139  return 255; // this means invisible
140  default:
141  // the rest of the range works as alpha
142  return alpha;
143  }
144 }
145 
146 } // namespace GfxDef
147 
148 } // namespace Shared
149 } // namespace AGS
150 } // namespace AGS3
151 
152 #endif
Definition: achievements_tables.h:27
Definition: ags.h:40