summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-23 13:16:26 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-23 13:59:25 +0100
commit49b0711dade7a926ba03309d376133be3f60bbf0 (patch)
tree557c042d11fcabee0711a10ecbddda5a4105d103 /vcl
parent15f66df8602b0920266ff2be86873246da4fda31 (diff)
vcl: add colorizeImage to BitmapProcessor
Change-Id: Ic90368e83d7f9a187eb8404d8aaec4380ff5bcb1
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/bitmap/BitmapProcessor.cxx69
1 files changed, 69 insertions, 0 deletions
diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx
index 5ac46804e103..20f812167373 100644
--- a/vcl/source/bitmap/BitmapProcessor.cxx
+++ b/vcl/source/bitmap/BitmapProcessor.cxx
@@ -127,4 +127,73 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
return aReturnBitmap;
}
+void BitmapProcessor::colorizeImage(BitmapEx& rBitmapEx, Color aColor)
+{
+ Bitmap aBitmap = rBitmapEx.GetBitmap();
+ Bitmap::ScopedWriteAccess pWriteAccess(aBitmap);
+
+ if (pWriteAccess)
+ {
+ BitmapColor aBitmapColor;
+ const long nW = pWriteAccess->Width();
+ const long nH = pWriteAccess->Height();
+ std::vector<sal_uInt8> pMapR(256);
+ std::vector<sal_uInt8> pMapG(256);
+ std::vector<sal_uInt8> pMapB(256);
+ long nX;
+ long nY;
+
+ const sal_uInt8 cR = aColor.GetRed();
+ const sal_uInt8 cG = aColor.GetGreen();
+ const sal_uInt8 cB = aColor.GetBlue();
+
+ for (nX = 0; nX < 256; ++nX)
+ {
+ pMapR[nX] = MinMax((nX + cR) / 2, 0, 255);
+ pMapG[nX] = MinMax((nX + cG) / 2, 0, 255);
+ pMapB[nX] = MinMax((nX + cB) / 2, 0, 255);
+ }
+
+ if (pWriteAccess->HasPalette())
+ {
+ for (sal_uInt16 i = 0, nCount = pWriteAccess->GetPaletteEntryCount(); i < nCount; i++)
+ {
+ const BitmapColor& rCol = pWriteAccess->GetPaletteColor(i);
+ aBitmapColor.SetRed(pMapR[rCol.GetRed()]);
+ aBitmapColor.SetGreen(pMapG[rCol.GetGreen()]);
+ aBitmapColor.SetBlue(pMapB[rCol.GetBlue()]);
+ pWriteAccess->SetPaletteColor(i, aBitmapColor);
+ }
+ }
+ else if (pWriteAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR)
+ {
+ for (nY = 0; nY < nH; ++nY)
+ {
+ Scanline pScan = pWriteAccess->GetScanline(nY);
+
+ for (nX = 0; nX < nW; ++nX)
+ {
+ *pScan = pMapB[*pScan]; pScan++;
+ *pScan = pMapG[*pScan]; pScan++;
+ *pScan = pMapR[*pScan]; pScan++;
+ }
+ }
+ }
+ else
+ {
+ for (nY = 0; nY < nH; ++nY)
+ {
+ for (nX = 0; nX < nW; ++nX)
+ {
+ aBitmapColor = pWriteAccess->GetPixel(nY, nX);
+ aBitmapColor.SetRed(pMapR[aBitmapColor.GetRed()]);
+ aBitmapColor.SetGreen(pMapG[aBitmapColor.GetGreen()]);
+ aBitmapColor.SetBlue(pMapB[aBitmapColor.GetBlue()]);
+ pWriteAccess->SetPixel(nY, nX, aBitmapColor);
+ }
+ }
+ }
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */