2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2014-01-13 09:35:46 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
auto image::impose(blend mode, unsigned targetX, unsigned targetY, image source, unsigned sourceX, unsigned sourceY, unsigned sourceWidth, unsigned sourceHeight) -> void {
|
|
|
|
source.transform(_endian, _depth, _alpha.mask(), _red.mask(), _green.mask(), _blue.mask());
|
2014-01-13 09:35:46 +00:00
|
|
|
|
|
|
|
for(unsigned y = 0; y < sourceHeight; y++) {
|
2015-06-18 10:48:53 +00:00
|
|
|
const uint8_t* sp = source._data + source.pitch() * (sourceY + y) + source.stride() * sourceX;
|
|
|
|
uint8_t* dp = _data + pitch() * (targetY + y) + stride() * targetX;
|
2014-01-13 09:35:46 +00:00
|
|
|
for(unsigned x = 0; x < sourceWidth; x++) {
|
|
|
|
uint64_t sourceColor = source.read(sp);
|
|
|
|
uint64_t targetColor = read(dp);
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
int64_t sa = (sourceColor & _alpha.mask()) >> _alpha.shift();
|
|
|
|
int64_t sr = (sourceColor & _red.mask() ) >> _red.shift();
|
|
|
|
int64_t sg = (sourceColor & _green.mask()) >> _green.shift();
|
|
|
|
int64_t sb = (sourceColor & _blue.mask() ) >> _blue.shift();
|
2014-01-13 09:35:46 +00:00
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
int64_t da = (targetColor & _alpha.mask()) >> _alpha.shift();
|
|
|
|
int64_t dr = (targetColor & _red.mask() ) >> _red.shift();
|
|
|
|
int64_t dg = (targetColor & _green.mask()) >> _green.shift();
|
|
|
|
int64_t db = (targetColor & _blue.mask() ) >> _blue.shift();
|
2014-01-13 09:35:46 +00:00
|
|
|
|
|
|
|
uint64_t a, r, g, b;
|
|
|
|
|
|
|
|
switch(mode) {
|
|
|
|
case blend::add:
|
|
|
|
a = max(sa, da);
|
2015-06-18 10:48:53 +00:00
|
|
|
r = min(_red.mask() >> _red.shift(), ((sr * sa) >> _alpha.depth()) + ((dr * da) >> _alpha.depth()));
|
|
|
|
g = min(_green.mask() >> _green.shift(), ((sg * sa) >> _alpha.depth()) + ((dg * da) >> _alpha.depth()));
|
|
|
|
b = min(_blue.mask() >> _blue.shift(), ((sb * sa) >> _alpha.depth()) + ((db * da) >> _alpha.depth()));
|
2014-01-13 09:35:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case blend::sourceAlpha:
|
|
|
|
a = max(sa, da);
|
2015-06-18 10:48:53 +00:00
|
|
|
r = dr + (((sr - dr) * sa) >> _alpha.depth());
|
|
|
|
g = dg + (((sg - dg) * sa) >> _alpha.depth());
|
|
|
|
b = db + (((sb - db) * sa) >> _alpha.depth());
|
2014-01-13 09:35:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case blend::sourceColor:
|
|
|
|
a = sa;
|
|
|
|
r = sr;
|
|
|
|
g = sg;
|
|
|
|
b = sb;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case blend::targetAlpha:
|
|
|
|
a = max(sa, da);
|
2015-06-18 10:48:53 +00:00
|
|
|
r = sr + (((dr - sr) * da) >> _alpha.depth());
|
|
|
|
g = sg + (((dg - sg) * da) >> _alpha.depth());
|
|
|
|
b = sb + (((db - sb) * da) >> _alpha.depth());
|
2014-01-13 09:35:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case blend::targetColor:
|
|
|
|
a = da;
|
|
|
|
r = dr;
|
|
|
|
g = dg;
|
|
|
|
b = db;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:48:53 +00:00
|
|
|
write(dp, (a << _alpha.shift()) | (r << _red.shift()) | (g << _green.shift()) | (b << _blue.shift()));
|
|
|
|
sp += source.stride();
|
|
|
|
dp += stride();
|
2014-01-13 09:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|