summaryrefslogtreecommitdiff
path: root/xBRZ/src/xbrz_tools.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2021-03-03 01:18:05 +0000
committerB Stack <bgstack15@gmail.com>2021-03-03 01:18:05 +0000
commit320f1ae680d73da35a0cfe4846eb687d8616bcac (patch)
tree6fb17404841b30822a2d9204e3e0932e55f05ebb /xBRZ/src/xbrz_tools.h
parentMerge branch '11.6' into 'master' (diff)
parentadd upstream 11.7 (diff)
downloadFreeFileSync-11.7.tar.gz
FreeFileSync-11.7.tar.bz2
FreeFileSync-11.7.zip
Merge branch '11.7' into 'master'11.7
add upstream 11.7 See merge request opensource-tracking/FreeFileSync!31
Diffstat (limited to 'xBRZ/src/xbrz_tools.h')
-rw-r--r--xBRZ/src/xbrz_tools.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/xBRZ/src/xbrz_tools.h b/xBRZ/src/xbrz_tools.h
index 98164678..d6e48c0c 100644
--- a/xBRZ/src/xbrz_tools.h
+++ b/xBRZ/src/xbrz_tools.h
@@ -87,10 +87,35 @@ void nearestNeighborScale(PixReader srcReader /* (int x, int y, BytePixel& pix)
}
+inline
+unsigned int uintDivRound(unsigned int num, unsigned int den)
+{
+ assert(den != 0);
+ return (num + den / 2) / den;
+}
+
+
+inline
+unsigned char premultiply(unsigned char c, unsigned char alpha)
+{
+ return static_cast<unsigned char>(uintDivRound(static_cast<unsigned int>(c) * alpha, 255));
+ //premultiply/demultiply using int div round is more accurate than int div floor/ceil pair
+}
+
+
+inline
+unsigned char demultiply(unsigned char c, unsigned char alpha)
+{
+ return static_cast<unsigned char>(alpha == 0 ? 0 :
+ std::clamp(uintDivRound(static_cast<unsigned int>(c) * 255, alpha), 0U, 255U));
+}
+
+
+//caveat: treats alpha channel like regular color! => caller needs to pre/de-multiply alpha!
template <class PixReader, class PixWriter>
-void bilinearScale(PixReader srcReader /* (int x, int y, BytePixel& pix) */, int srcWidth, int srcHeight,
- PixWriter trgWriter /* (const BytePixel& pix) */, int trgWidth, int trgHeight,
- int yFirst, int yLast)
+void bilinearScaleSimple(PixReader srcReader /* (int x, int y, BytePixel& pix) */, int srcWidth, int srcHeight,
+ PixWriter trgWriter /* (const BytePixel& pix) */, int trgWidth, int trgHeight,
+ int yFirst, int yLast)
{
yFirst = std::max(yFirst, 0);
yLast = std::min(yLast, trgHeight);
@@ -121,7 +146,7 @@ void bilinearScale(PixReader srcReader /* (int x, int y, BytePixel& pix) */, int
const double xx1 = x / scaleX - x1;
const double x2x = 1 - xx1;
- buf[x] = { x1, x2, xx1, x2x };
+ buf[x] = {x1, x2, xx1, x2x};
}
for (int y = yFirst; y < yLast; ++y)
bgstack15