|
@@ -423,12 +423,11 @@ static bool _rasterBlendingRect(SwSurface* surface, const SwBBox& region, uint8_
|
|
|
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
|
|
auto color = surface->join(r, g, b, a);
|
|
|
auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x;
|
|
|
- auto ialpha = 255 - a;
|
|
|
|
|
|
for (uint32_t y = 0; y < h; ++y) {
|
|
|
auto dst = &buffer[y * surface->stride];
|
|
|
for (uint32_t x = 0; x < w; ++x, ++dst) {
|
|
|
- *dst = surface->blender(color, *dst, ialpha);
|
|
|
+ *dst = surface->blender(color, *dst, 255);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -595,17 +594,16 @@ static bool _rasterBlendingRle(SwSurface* surface, const SwRleData* rle, uint8_t
|
|
|
|
|
|
auto span = rle->spans;
|
|
|
auto color = surface->join(r, g, b, a);
|
|
|
- auto ialpha = 255 - a;
|
|
|
|
|
|
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
|
|
auto dst = &surface->buf32[span->y * surface->stride + span->x];
|
|
|
if (span->coverage == 255) {
|
|
|
for (uint32_t x = 0; x < span->len; ++x, ++dst) {
|
|
|
- *dst = surface->blender(color, *dst, ialpha);
|
|
|
+ *dst = surface->blender(color, *dst, 255);
|
|
|
}
|
|
|
} else {
|
|
|
for (uint32_t x = 0; x < span->len; ++x, ++dst) {
|
|
|
- auto tmp = surface->blender(color, *dst, ialpha);
|
|
|
+ auto tmp = surface->blender(color, *dst, 255);
|
|
|
*dst = INTERPOLATE(tmp, *dst, span->coverage);
|
|
|
}
|
|
|
}
|
|
@@ -813,9 +811,8 @@ static bool _rasterScaledBlendingRleImage(SwSurface* surface, const SwImage* ima
|
|
|
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) {
|
|
|
SCALED_IMAGE_RANGE_X
|
|
|
auto src = scaleMethod(image->buf32, image->stride, image->w, image->h, sx, sy, miny, maxy, sampleSize);
|
|
|
- if (opacity < 255) src = ALPHA_BLEND(src, opacity);
|
|
|
auto tmp = surface->blender(src, *dst, 255);
|
|
|
- *dst = INTERPOLATE(tmp, *dst, MULTIPLY(span->coverage, A(src)));
|
|
|
+ *dst = INTERPOLATE(tmp, *dst, MULTIPLY(alpha, A(src)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -981,18 +978,12 @@ static bool _rasterDirectBlendingRleImage(SwSurface* surface, const SwImage* ima
|
|
|
auto alpha = MULTIPLY(span->coverage, opacity);
|
|
|
if (alpha == 255) {
|
|
|
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
|
|
|
- *dst = surface->blender(*img, *dst, IA(*img));
|
|
|
- }
|
|
|
- } else if (opacity == 255) {
|
|
|
- for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
|
|
|
- auto tmp = surface->blender(*img, *dst, 255);
|
|
|
- *dst = INTERPOLATE(tmp, *dst, MULTIPLY(span->coverage, A(*img)));
|
|
|
+ *dst = surface->blender(*img, *dst, 255);
|
|
|
}
|
|
|
} else {
|
|
|
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
|
|
|
- auto src = ALPHA_BLEND(*img, opacity);
|
|
|
- auto tmp = surface->blender(src, *dst, IA(src));
|
|
|
- *dst = INTERPOLATE(tmp, *dst, MULTIPLY(span->coverage, A(src)));
|
|
|
+ auto tmp = surface->blender(*img, *dst, 255);
|
|
|
+ *dst = INTERPOLATE(tmp, *dst, MULTIPLY(alpha, A(*img)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1164,9 +1155,8 @@ static bool _rasterScaledBlendingImage(SwSurface* surface, const SwImage* image,
|
|
|
for (auto x = region.min.x; x < region.max.x; ++x, ++dst) {
|
|
|
SCALED_IMAGE_RANGE_X
|
|
|
auto src = scaleMethod(image->buf32, image->stride, image->w, image->h, sx, sy, miny, maxy, sampleSize);
|
|
|
- if (opacity < 255) ALPHA_BLEND(src, opacity);
|
|
|
auto tmp = surface->blender(src, *dst, 255);
|
|
|
- *dst = INTERPOLATE(tmp, *dst, A(src));
|
|
|
+ *dst = INTERPOLATE(tmp, *dst, MULTIPLY(opacity, A(src)));
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -1348,11 +1338,13 @@ static bool _rasterDirectMattedImage(SwSurface* surface, const SwImage* image, c
|
|
|
auto src = sbuffer;
|
|
|
if (opacity == 255) {
|
|
|
for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
|
|
- *dst = MULTIPLY(A(*src), alpha(cmp));
|
|
|
+ auto tmp = MULTIPLY(A(*src), alpha(cmp));
|
|
|
+ *dst = tmp + MULTIPLY(*dst, 255 - tmp);
|
|
|
}
|
|
|
} else {
|
|
|
for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
|
|
- *dst = MULTIPLY(A(*src), MULTIPLY(opacity, alpha(cmp)));
|
|
|
+ auto tmp = MULTIPLY(A(*src), MULTIPLY(opacity, alpha(cmp)));
|
|
|
+ *dst = tmp + MULTIPLY(*dst, 255 - tmp);
|
|
|
}
|
|
|
}
|
|
|
buffer += surface->stride;
|
|
@@ -1384,9 +1376,8 @@ static bool _rasterDirectBlendingImage(SwSurface* surface, const SwImage* image,
|
|
|
}
|
|
|
} else {
|
|
|
for (auto x = region.min.x; x < region.max.x; x++, dst++, src++) {
|
|
|
- auto tmp = ALPHA_BLEND(*src, opacity);
|
|
|
- auto tmp2 = surface->blender(tmp, *dst, 255);
|
|
|
- *dst = INTERPOLATE(tmp2, *dst, A(tmp));
|
|
|
+ auto tmp = surface->blender(*src, *dst, 255);
|
|
|
+ *dst = INTERPOLATE(tmp, *dst, MULTIPLY(opacity, A(*src)));
|
|
|
}
|
|
|
}
|
|
|
dbuffer += surface->stride;
|
|
@@ -1442,12 +1433,52 @@ static bool _rasterDirectImage(SwSurface* surface, const SwImage* image, const S
|
|
|
}
|
|
|
|
|
|
|
|
|
+static bool _rasterDirectMattedBlendingImage(SwSurface* surface, const SwImage* image, const SwBBox& region, uint8_t opacity)
|
|
|
+{
|
|
|
+ if (surface->channelSize == sizeof(uint8_t)) {
|
|
|
+ TVGERR("SW_ENGINE", "Not supported grayscale image!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
|
|
+ auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
|
|
+ auto csize = surface->compositor->image.channelSize;
|
|
|
+ auto alpha = surface->alpha(surface->compositor->method);
|
|
|
+ auto sbuffer = image->buf32 + (region.min.y + image->oy) * image->stride + (region.min.x + image->ox);
|
|
|
+ auto cbuffer = surface->compositor->image.buf8 + (region.min.y * surface->compositor->image.stride + region.min.x) * csize; //compositor buffer
|
|
|
+ auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x;
|
|
|
+
|
|
|
+ for (uint32_t y = 0; y < h; ++y) {
|
|
|
+ auto dst = buffer;
|
|
|
+ auto cmp = cbuffer;
|
|
|
+ auto src = sbuffer;
|
|
|
+ if (opacity == 255) {
|
|
|
+ for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
|
|
+ auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
|
|
+ *dst = INTERPOLATE(surface->blender(tmp, *dst, 255), *dst, A(tmp));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
|
|
+ auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
|
|
+ *dst = INTERPOLATE(surface->blender(tmp, *dst, 255), *dst, MULTIPLY(opacity, A(tmp)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buffer += surface->stride;
|
|
|
+ cbuffer += surface->compositor->image.stride * csize;
|
|
|
+ sbuffer += image->stride;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//Blenders for the following scenarios: [Composition / Non-Composition] * [Opaque / Translucent]
|
|
|
static bool _directImage(SwSurface* surface, const SwImage* image, const SwBBox& region, uint8_t opacity)
|
|
|
{
|
|
|
if (_compositing(surface)) {
|
|
|
- if (_matting(surface)) return _rasterDirectMattedImage(surface, image, region, opacity);
|
|
|
- else return _rasterDirectMaskedImage(surface, image, region, opacity);
|
|
|
+ if (_matting(surface)) {
|
|
|
+ if (_blending(surface)) return _rasterDirectMattedBlendingImage(surface, image, region, opacity);
|
|
|
+ else return _rasterDirectMattedImage(surface, image, region, opacity);
|
|
|
+ } else return _rasterDirectMaskedImage(surface, image, region, opacity);
|
|
|
} else if (_blending(surface)) {
|
|
|
return _rasterDirectBlendingImage(surface, image, region, opacity);
|
|
|
} else {
|
|
@@ -1843,7 +1874,7 @@ bool rasterCompositor(SwSurface* surface)
|
|
|
}
|
|
|
|
|
|
|
|
|
-bool rasterClear(SwSurface* surface, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
|
|
+bool rasterClear(SwSurface* surface, uint32_t x, uint32_t y, uint32_t w, uint32_t h, pixel_t val)
|
|
|
{
|
|
|
if (!surface || !surface->buf32 || surface->stride == 0 || surface->w == 0 || surface->h == 0) return false;
|
|
|
|
|
@@ -1851,11 +1882,11 @@ bool rasterClear(SwSurface* surface, uint32_t x, uint32_t y, uint32_t w, uint32_
|
|
|
if (surface->channelSize == sizeof(uint32_t)) {
|
|
|
//full clear
|
|
|
if (w == surface->stride) {
|
|
|
- rasterPixel32(surface->buf32, 0x00000000, surface->stride * y, w * h);
|
|
|
+ rasterPixel32(surface->buf32, val, surface->stride * y, w * h);
|
|
|
//partial clear
|
|
|
} else {
|
|
|
for (uint32_t i = 0; i < h; i++) {
|
|
|
- rasterPixel32(surface->buf32, 0x00000000, (surface->stride * y + x) + (surface->stride * i), w);
|
|
|
+ rasterPixel32(surface->buf32, val, (surface->stride * y + x) + (surface->stride * i), w);
|
|
|
}
|
|
|
}
|
|
|
//8 bits
|