summaryrefslogtreecommitdiff
path: root/vcl/source/bitmap/bitmap.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/source/bitmap/bitmap.cxx')
-rw-r--r--vcl/source/bitmap/bitmap.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 9e769b13cee1..f0404fa80a18 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -2141,6 +2141,44 @@ Bitmap Bitmap::Modify(const basegfx::BColorModifierStack& rBColorModifierStack)
return aChangedBitmap;
}
+/** Get the average color of the entire image.
+ i.e. like scaling it down to a 1x1 pixel image.
+*/
+Color Bitmap::GetAverageColor() const
+{
+ BitmapScopedReadAccess xContent(*this);
+ assert(xContent);
+ if(!xContent)
+ return Color();
+
+ double fRed = 0;
+ double fGreen = 0;
+ double fBlue = 0;
+ double fAlpha = 0;
+ int nCnt = 0;
+ for(tools::Long y(0), nHeight(xContent->Height()); y < nHeight; y++)
+ {
+ Scanline pScanline = xContent->GetScanline( y );
+ for(tools::Long x(0), nWidth(xContent->Width()); x < nWidth; x++)
+ {
+ const BitmapColor aCol(xContent->GetPixelFromData(pScanline, x));
+ fRed += aCol.GetRed();
+ fGreen += aCol.GetGreen();
+ fBlue += aCol.GetBlue();
+ fAlpha += aCol.GetAlpha();
+ nCnt++;
+ }
+ }
+
+ if(!nCnt)
+ return Color();
+
+ return Color(ColorAlpha, static_cast<sal_uInt8>(fAlpha / nCnt),
+ static_cast<sal_uInt8>(fRed / nCnt),
+ static_cast<sal_uInt8>(fGreen / nCnt),
+ static_cast<sal_uInt8>(fBlue / nCnt));
+}
+
void Bitmap::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
{
pOutDev->DrawBitmapEx( rDestPt, *this );