diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2024-09-02 01:15:35 +1000 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-09-30 08:38:29 +0200 |
commit | e5aff0ed177e218bfec7c9f57f393379c051166a (patch) | |
tree | db8db705d68e167071fc0fa80b1f6b9d8879209c /vcl/source/bitmap | |
parent | 89f0b965b26eca7ca9be18122881b955072f3fa8 (diff) |
vcl: flatten BitmapReadAccess functions
Change-Id: Ib18aeca38270192364a12b6496223b0cce476b16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173205
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/source/bitmap')
-rw-r--r-- | vcl/source/bitmap/BitmapReadAccess.cxx | 168 |
1 files changed, 77 insertions, 91 deletions
diff --git a/vcl/source/bitmap/BitmapReadAccess.cxx b/vcl/source/bitmap/BitmapReadAccess.cxx index f8240a733548..9a7c8082ed2d 100644 --- a/vcl/source/bitmap/BitmapReadAccess.cxx +++ b/vcl/source/bitmap/BitmapReadAccess.cxx @@ -142,90 +142,78 @@ BitmapColor BitmapReadAccess::GetInterpolatedColorWithFallback(double fY, double { // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!) - if (mpBuffer && fX >= 0.0 && fY >= 0.0) + if (!mpBuffer || fX < 0.0 || fY < 0.0) + return rFallback; + + const sal_Int64 nX(static_cast<sal_Int64>(fX)); + const sal_Int64 nY(static_cast<sal_Int64>(fY)); + + if (nX >= mpBuffer->mnWidth || nY >= mpBuffer->mnHeight) + return rFallback; + + // get base-return value from inside pixel + BitmapColor aRetval(GetColor(nY, nX)); + + // calculate deltas and indices for neighbour accesses + sal_Int16 nDeltaX((fX - (nX + 0.5)) * 255.0); // [-255 .. 255] + sal_Int16 nDeltaY((fY - (nY + 0.5)) * 255.0); // [-255 .. 255] + sal_Int16 nIndX(0); + sal_Int16 nIndY(0); + + if (nDeltaX > 0) { - const sal_Int64 nX(static_cast<sal_Int64>(fX)); - const sal_Int64 nY(static_cast<sal_Int64>(fY)); - - if (nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight) - { - // get base-return value from inside pixel - BitmapColor aRetval(GetColor(nY, nX)); - - // calculate deltas and indices for neighbour accesses - sal_Int16 nDeltaX((fX - (nX + 0.5)) * 255.0); // [-255 .. 255] - sal_Int16 nDeltaY((fY - (nY + 0.5)) * 255.0); // [-255 .. 255] - sal_Int16 nIndX(0); - sal_Int16 nIndY(0); - - if (nDeltaX > 0) - { - nIndX = nX + 1; - } - else - { - nIndX = nX - 1; - nDeltaX = -nDeltaX; - } - - if (nDeltaY > 0) - { - nIndY = nY + 1; - } - else - { - nIndY = nY - 1; - nDeltaY = -nDeltaY; - } - - // get right/left neighbour - BitmapColor aXCol(rFallback); - - if (nDeltaX && nIndX >= 0 && nIndX < mpBuffer->mnWidth) - { - aXCol = GetColor(nY, nIndX); - } - - // get top/bottom neighbour - BitmapColor aYCol(rFallback); - - if (nDeltaY && nIndY >= 0 && nIndY < mpBuffer->mnHeight) - { - aYCol = GetColor(nIndY, nX); - } - - // get one of four edge neighbours - BitmapColor aXYCol(rFallback); - - if (nDeltaX && nDeltaY && nIndX >= 0 && nIndY >= 0 && nIndX < mpBuffer->mnWidth - && nIndY < mpBuffer->mnHeight) - { - aXYCol = GetColor(nIndY, nIndX); - } - - // merge return value with right/left neighbour - if (aXCol != aRetval) - { - aRetval.Merge(aXCol, 255 - nDeltaX); - } - - // merge top/bottom neighbour with edge - if (aYCol != aXYCol) - { - aYCol.Merge(aXYCol, 255 - nDeltaX); - } - - // merge return value with already merged top/bottom neighbour - if (aRetval != aYCol) - { - aRetval.Merge(aYCol, 255 - nDeltaY); - } - - return aRetval; - } + nIndX = nX + 1; + } + else + { + nIndX = nX - 1; + nDeltaX = -nDeltaX; + } + + if (nDeltaY > 0) + { + nIndY = nY + 1; + } + else + { + nIndY = nY - 1; + nDeltaY = -nDeltaY; } - return rFallback; + // get right/left neighbour + BitmapColor aXCol(rFallback); + + if (nDeltaX && nIndX >= 0 && nIndX < mpBuffer->mnWidth) + aXCol = GetColor(nY, nIndX); + + // get top/bottom neighbour + BitmapColor aYCol(rFallback); + + if (nDeltaY && nIndY >= 0 && nIndY < mpBuffer->mnHeight) + aYCol = GetColor(nIndY, nX); + + // get one of four edge neighbours + BitmapColor aXYCol(rFallback); + + if (nDeltaX && nDeltaY && nIndX >= 0 && nIndY >= 0 && nIndX < mpBuffer->mnWidth + && nIndY < mpBuffer->mnHeight) + { + aXYCol = GetColor(nIndY, nIndX); + } + + // merge return value with right/left neighbour + if (aXCol != aRetval) + aRetval.Merge(aXCol, 255 - nDeltaX); + + // merge top/bottom neighbour with edge + if (aYCol != aXYCol) + aYCol.Merge(aXYCol, 255 - nDeltaX); + + // merge return value with already merged top/bottom neighbour + if (aRetval != aYCol) + aRetval.Merge(aYCol, 255 - nDeltaY); + + return aRetval; } BitmapColor BitmapReadAccess::GetColorWithFallback(double fY, double fX, @@ -233,18 +221,16 @@ BitmapColor BitmapReadAccess::GetColorWithFallback(double fY, double fX, { // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!) - if (mpBuffer && fX >= 0.0 && fY >= 0.0) - { - const sal_Int32 nX(static_cast<sal_Int32>(fX)); - const sal_Int32 nY(static_cast<sal_Int32>(fY)); + if (!mpBuffer || fX < 0.0 || fY < 0.0) + return rFallback; - if (nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight) - { - return GetColor(nY, nX); - } - } + const sal_Int32 nX(static_cast<sal_Int32>(fX)); + const sal_Int32 nY(static_cast<sal_Int32>(fY)); + + if (nX >= mpBuffer->mnWidth || nY >= mpBuffer->mnHeight) + return rFallback; - return rFallback; + return GetColor(nY, nX); } BitmapColor BitmapReadAccess::GetPixelForN1BitMsbPal(ConstScanline pScanline, tools::Long nX, |