22 #include "graphics/blit.h" 30 template<
bool doscale,
bool rgbmod,
bool alphamod>
32 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
33 uint32 ina = in[BlendBlit::kAIndex] * ca >> 8;
37 const uint outb = (out[BlendBlit::kBIndex] * (255 - ina) >> 8);
38 const uint outg = (out[BlendBlit::kGIndex] * (255 - ina) >> 8);
39 const uint outr = (out[BlendBlit::kRIndex] * (255 - ina) >> 8);
41 out[BlendBlit::kAIndex] = 255;
42 out[BlendBlit::kBIndex] = outb + (in[BlendBlit::kBIndex] * ina * cb >> 16);
43 out[BlendBlit::kGIndex] = outg + (in[BlendBlit::kGIndex] * ina * cg >> 16);
44 out[BlendBlit::kRIndex] = outr + (in[BlendBlit::kRIndex] * ina * cr >> 16);
46 out[BlendBlit::kAIndex] = 255;
47 out[BlendBlit::kBIndex] = (out[BlendBlit::kBIndex] * (255 - ina) + in[BlendBlit::kBIndex] * ina) >> 8;
48 out[BlendBlit::kGIndex] = (out[BlendBlit::kGIndex] * (255 - ina) + in[BlendBlit::kGIndex] * ina) >> 8;
49 out[BlendBlit::kRIndex] = (out[BlendBlit::kRIndex] * (255 - ina) + in[BlendBlit::kRIndex] * ina) >> 8;
56 template<
bool doscale,
bool rgbmod,
bool alphamod>
58 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
59 uint32 ina = in[BlendBlit::kAIndex] * ca >> 8;
62 out[BlendBlit::kBIndex] = out[BlendBlit::kBIndex] * ((in[BlendBlit::kBIndex] * cb * ina) >> 16) >> 8;
63 out[BlendBlit::kGIndex] = out[BlendBlit::kGIndex] * ((in[BlendBlit::kGIndex] * cg * ina) >> 16) >> 8;
64 out[BlendBlit::kRIndex] = out[BlendBlit::kRIndex] * ((in[BlendBlit::kRIndex] * cr * ina) >> 16) >> 8;
69 template<
bool doscale,
bool rgbmod,
bool alphamod>
71 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
72 *(uint32 *)out = *(
const uint32 *)in | BlendBlit::kAModMask;
76 template<
bool doscale,
bool rgbmod,
bool alphamod>
78 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
79 uint32 pix = *(
const uint32 *)in;
80 int a = in[BlendBlit::kAIndex];
84 out[BlendBlit::kAIndex] = 0xFF;
89 template<
bool doscale,
bool rgbmod,
bool alphamod>
91 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
92 uint32 ina = in[BlendBlit::kAIndex] * ca >> 8;
95 out[BlendBlit::kBIndex] = out[BlendBlit::kBIndex] + ((in[BlendBlit::kBIndex] * cb * ina) >> 16);
96 out[BlendBlit::kGIndex] = out[BlendBlit::kGIndex] + ((in[BlendBlit::kGIndex] * cg * ina) >> 16);
97 out[BlendBlit::kRIndex] = out[BlendBlit::kRIndex] + ((in[BlendBlit::kRIndex] * cr * ina) >> 16);
102 template<
bool doscale,
bool rgbmod,
bool alphamod>
104 static inline void normal(
const byte *in, byte *out,
const byte ca,
const byte cr,
const byte cg,
const byte cb) {
105 out[BlendBlit::kAIndex] = 255;
106 out[BlendBlit::kBIndex] = MAX<int32>(out[BlendBlit::kBIndex] - ((in[BlendBlit::kBIndex] * cb * (out[BlendBlit::kBIndex]) * in[BlendBlit::kAIndex]) >> 24), 0);
107 out[BlendBlit::kGIndex] = MAX<int32>(out[BlendBlit::kGIndex] - ((in[BlendBlit::kGIndex] * cg * (out[BlendBlit::kGIndex]) * in[BlendBlit::kAIndex]) >> 24), 0);
108 out[BlendBlit::kRIndex] = MAX<int32>(out[BlendBlit::kRIndex] - ((in[BlendBlit::kRIndex] * cr * (out[BlendBlit::kRIndex]) * in[BlendBlit::kAIndex]) >> 24), 0);
115 void BlendBlit::blitT(Args &args,
const TSpriteBlendMode &blendMode,
const AlphaType &alphaType) {
116 bool rgbmod = ((args.color & kRGBModMask) != kRGBModMask);
117 bool alphamod = ((args.color & kAModMask) != kAModMask);
118 if (args.scaleX == SCALE_THRESHOLD && args.scaleY == SCALE_THRESHOLD) {
119 if (args.color == 0xffffffff && blendMode == BLEND_NORMAL && alphaType == ALPHA_OPAQUE) {
120 T::template blitInnerLoop<T::template OpaqueBlend, false, false, false, false, true>(args);
121 }
else if (args.color == 0xffffffff && blendMode == BLEND_NORMAL && alphaType == ALPHA_BINARY) {
122 T::template blitInnerLoop<T::template BinaryBlend, false, false, false, false, true>(args);
124 if (blendMode == BLEND_ADDITIVE) {
127 T::template blitInnerLoop<T::template AdditiveBlend, false, true, true, false, true>(args);
129 T::template blitInnerLoop<T::template AdditiveBlend, false, true, false, false, true>(args);
133 T::template blitInnerLoop<T::template AdditiveBlend, false, false, true, false, true>(args);
135 T::template blitInnerLoop<T::template AdditiveBlend, false, false, false, false, true>(args);
138 }
else if (blendMode == BLEND_SUBTRACTIVE) {
140 T::template blitInnerLoop<T::template SubtractiveBlend, false, true, false, false, true>(args);
142 T::template blitInnerLoop<T::template SubtractiveBlend, false, false, false, false, true>(args);
144 }
else if (blendMode == BLEND_MULTIPLY) {
147 T::template blitInnerLoop<T::template MultiplyBlend, false, true, true, false, true>(args);
149 T::template blitInnerLoop<T::template MultiplyBlend, false, true, false, false, true>(args);
153 T::template blitInnerLoop<T::template MultiplyBlend, false, false, true, false, true>(args);
155 T::template blitInnerLoop<T::template MultiplyBlend, false, false, false, false, true>(args);
159 assert(blendMode == BLEND_NORMAL);
162 T::template blitInnerLoop<T::template AlphaBlend, false, true, true, false, true>(args);
164 T::template blitInnerLoop<T::template AlphaBlend, false, true, false, false, true>(args);
168 T::template blitInnerLoop<T::template AlphaBlend, false, false, true, false, true>(args);
170 T::template blitInnerLoop<T::template AlphaBlend, false, false, false, false, true>(args);
176 if (args.color == 0xffffffff && blendMode == BLEND_NORMAL && alphaType == ALPHA_OPAQUE) {
177 T::template blitInnerLoop<T::template OpaqueBlend, true, false, false, false, true>(args);
178 }
else if (args.color == 0xffffffff && blendMode == BLEND_NORMAL && alphaType == ALPHA_BINARY) {
179 T::template blitInnerLoop<T::template BinaryBlend, true, false, false, false, true>(args);
181 if (blendMode == BLEND_ADDITIVE) {
184 T::template blitInnerLoop<T::template AdditiveBlend, true, true, true, false, true>(args);
186 T::template blitInnerLoop<T::template AdditiveBlend, true, true, false, false, true>(args);
190 T::template blitInnerLoop<T::template AdditiveBlend, true, false, true, false, true>(args);
192 T::template blitInnerLoop<T::template AdditiveBlend, true, false, false, false, true>(args);
195 }
else if (blendMode == BLEND_SUBTRACTIVE) {
197 T::template blitInnerLoop<T::template SubtractiveBlend, true, true, false, false, true>(args);
199 T::template blitInnerLoop<T::template SubtractiveBlend, true, false, false, false, true>(args);
201 }
else if (blendMode == BLEND_MULTIPLY) {
204 T::template blitInnerLoop<T::template MultiplyBlend, true, true, true, false, true>(args);
206 T::template blitInnerLoop<T::template MultiplyBlend, true, true, false, false, true>(args);
210 T::template blitInnerLoop<T::template MultiplyBlend, true, false, true, false, true>(args);
212 T::template blitInnerLoop<T::template MultiplyBlend, true, false, false, false, true>(args);
216 assert(blendMode == BLEND_NORMAL);
219 T::template blitInnerLoop<T::template AlphaBlend, true, true, true, false, true>(args);
221 T::template blitInnerLoop<T::template AlphaBlend, true, true, false, false, true>(args);
225 T::template blitInnerLoop<T::template AlphaBlend, true, false, true, false, true>(args);
227 T::template blitInnerLoop<T::template AlphaBlend, true, false, false, false, true>(args);
Definition: blit-alpha.h:31
Definition: blit-alpha.h:90
Definition: blit-alpha.h:77
Definition: formatinfo.h:28
Definition: blit-alpha.h:103
Definition: blit-alpha.h:57
Definition: blit-alpha.h:70
Definition: blit-alpha.h:26