bitmapex.cxx (f8c0d554) | bitmapex.cxx (49c58f9b) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 1004 unchanged lines hidden (view full) --- 1013 1014 return aRetval; 1015} 1016 1017// ------------------------------------------------------------------ 1018 1019BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const 1020{ | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 1004 unchanged lines hidden (view full) --- 1013 1014 return aRetval; 1015} 1016 1017// ------------------------------------------------------------------ 1018 1019BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const 1020{ |
1021 Bitmap aChangedBitmap(GetBitmap()); 1022 bool bDone(false); | 1021 Bitmap aChangedBitmap(GetBitmap()); 1022 bool bDone(false); |
1023 | 1023 |
1024 for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; ) 1025 { 1026 const basegfx::BColorModifier& rModifier = rBColorModifierStack.getBColorModifier(--a); 1027 1028 switch(rModifier.getMode()) 1029 { 1030 case basegfx::BCOLORMODIFYMODE_REPLACE : 1031 { 1032 // complete replace 1033 if(IsTransparent()) 1034 { 1035 // clear bitmap with dest color 1036 if(aChangedBitmap.GetBitCount() <= 8) 1037 { 1038 // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given 1039 // erase color is determined and used -> this may be different from what is 1040 // wanted here. Better create a new bitmap with the needed color explicitely 1041 BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess(); 1042 OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?"); | 1024 for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; ) 1025 { 1026 const basegfx::BColorModifierSharedPtr& rModifier = rBColorModifierStack.getBColorModifier(--a); 1027 const basegfx::BColorModifier_replace* pReplace = dynamic_cast< const basegfx::BColorModifier_replace* >(rModifier.get()); |
1043 | 1028 |
1044 if(pReadAccess) 1045 { 1046 BitmapPalette aNewPalette(pReadAccess->GetPalette()); 1047 aNewPalette[0] = BitmapColor(Color(rModifier.getBColor())); 1048 aChangedBitmap = Bitmap( 1049 aChangedBitmap.GetSizePixel(), 1050 aChangedBitmap.GetBitCount(), 1051 &aNewPalette); 1052 delete pReadAccess; 1053 } 1054 } 1055 else 1056 { 1057 aChangedBitmap.Erase(Color(rModifier.getBColor())); | 1029 if(pReplace) 1030 { 1031 // complete replace 1032 if(IsTransparent()) 1033 { 1034 // clear bitmap with dest color 1035 if(aChangedBitmap.GetBitCount() <= 8) 1036 { 1037 // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given 1038 // erase color is determined and used -> this may be different from what is 1039 // wanted here. Better create a new bitmap with the needed color explicitely 1040 BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess(); 1041 OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?"); 1042 1043 if(pReadAccess) 1044 { 1045 BitmapPalette aNewPalette(pReadAccess->GetPalette()); 1046 aNewPalette[0] = BitmapColor(Color(pReplace->getBColor())); 1047 aChangedBitmap = Bitmap( 1048 aChangedBitmap.GetSizePixel(), 1049 aChangedBitmap.GetBitCount(), 1050 &aNewPalette); 1051 delete pReadAccess; |
1058 } | 1052 } |
1059 } 1060 else 1061 { 1062 // erase bitmap, caller will know to paint direct 1063 aChangedBitmap.SetEmpty(); 1064 } 1065 1066 bDone = true; 1067 break; 1068 } | 1053 } 1054 else 1055 { 1056 aChangedBitmap.Erase(Color(pReplace->getBColor())); 1057 } 1058 } 1059 else 1060 { 1061 // erase bitmap, caller will know to paint direct 1062 aChangedBitmap.SetEmpty(); 1063 } 1064 1065 bDone = true; 1066 } 1067 else 1068 { 1069 BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess(); |
1069 | 1070 |
1070 default : // BCOLORMODIFYMODE_INTERPOLATE, BCOLORMODIFYMODE_GRAY, BCOLORMODIFYMODE_BLACKANDWHITE 1071 { 1072 BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess(); | 1071 if(pContent) 1072 { 1073 const double fConvertColor(1.0 / 255.0); |
1073 | 1074 |
1074 if(pContent) 1075 { 1076 const double fConvertColor(1.0 / 255.0); | 1075 if(pContent->HasPalette()) 1076 { 1077 const sal_uInt16 nCount(pContent->GetPaletteEntryCount()); |
1077 | 1078 |
1078 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) 1079 { 1080 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) 1081 { 1082 const BitmapColor aBMCol(pContent->GetColor(y, x)); 1083 const basegfx::BColor aBSource( 1084 (double)aBMCol.GetRed() * fConvertColor, 1085 (double)aBMCol.GetGreen() * fConvertColor, 1086 (double)aBMCol.GetBlue() * fConvertColor); 1087 const basegfx::BColor aBDest(rModifier.getModifiedColor(aBSource)); 1088 1089 pContent->SetPixel(y, x, BitmapColor(Color(aBDest))); 1090 } 1091 } | 1079 for(sal_uInt16 a(0); a < nCount; a++) 1080 { 1081 const BitmapColor& rCol = pContent->GetPaletteColor(a); 1082 const basegfx::BColor aBSource( 1083 rCol.GetRed() * fConvertColor, 1084 rCol.GetGreen() * fConvertColor, 1085 rCol.GetBlue() * fConvertColor); 1086 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); 1087 pContent->SetPaletteColor(a, BitmapColor(Color(aBDest))); 1088 } 1089 } 1090 else if(BMP_FORMAT_24BIT_TC_BGR == pContent->GetScanlineFormat()) 1091 { 1092 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) 1093 { 1094 Scanline pScan = pContent->GetScanline(y); |
1092 | 1095 |
1093 delete pContent; 1094 } 1095 1096 break; 1097 } 1098 } 1099 } | 1096 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) 1097 { 1098 const basegfx::BColor aBSource( 1099 *(pScan + 2)* fConvertColor, 1100 *(pScan + 1) * fConvertColor, 1101 *pScan * fConvertColor); 1102 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); 1103 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0); 1104 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0); 1105 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0); 1106 } 1107 } 1108 } 1109 else if(BMP_FORMAT_24BIT_TC_RGB == pContent->GetScanlineFormat()) 1110 { 1111 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) 1112 { 1113 Scanline pScan = pContent->GetScanline(y); |
1100 | 1114 |
1101 if(aChangedBitmap.IsEmpty()) 1102 { 1103 return BitmapEx(); 1104 } 1105 else 1106 { 1107 if(IsTransparent()) 1108 { 1109 if(IsAlpha()) 1110 { 1111 return BitmapEx(aChangedBitmap, GetAlpha()); 1112 } 1113 else 1114 { 1115 return BitmapEx(aChangedBitmap, GetMask()); 1116 } 1117 } 1118 else 1119 { 1120 return BitmapEx(aChangedBitmap); 1121 } 1122 } | 1115 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) 1116 { 1117 const basegfx::BColor aBSource( 1118 *pScan * fConvertColor, 1119 *(pScan + 1) * fConvertColor, 1120 *(pScan + 2) * fConvertColor); 1121 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); 1122 *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0); 1123 *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0); 1124 *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0); 1125 } 1126 } 1127 } 1128 else 1129 { 1130 for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) 1131 { 1132 for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) 1133 { 1134 const BitmapColor aBMCol(pContent->GetColor(y, x)); 1135 const basegfx::BColor aBSource( 1136 (double)aBMCol.GetRed() * fConvertColor, 1137 (double)aBMCol.GetGreen() * fConvertColor, 1138 (double)aBMCol.GetBlue() * fConvertColor); 1139 const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); 1140 1141 pContent->SetPixel(y, x, BitmapColor(Color(aBDest))); 1142 } 1143 } 1144 } 1145 1146 delete pContent; 1147 } 1148 } 1149 } 1150 1151 if(aChangedBitmap.IsEmpty()) 1152 { 1153 return BitmapEx(); 1154 } 1155 else 1156 { 1157 if(IsTransparent()) 1158 { 1159 if(IsAlpha()) 1160 { 1161 return BitmapEx(aChangedBitmap, GetAlpha()); 1162 } 1163 else 1164 { 1165 return BitmapEx(aChangedBitmap, GetMask()); 1166 } 1167 } 1168 else 1169 { 1170 return BitmapEx(aChangedBitmap); 1171 } 1172 } |
1123} 1124 1125// ----------------------------------------------------------------------------- 1126 1127BitmapEx VCL_DLLPUBLIC createBlendFrame( 1128 const Size& rSize, 1129 sal_uInt8 nAlpha, 1130 Color aColorTopLeft, --- 145 unchanged lines hidden --- | 1173} 1174 1175// ----------------------------------------------------------------------------- 1176 1177BitmapEx VCL_DLLPUBLIC createBlendFrame( 1178 const Size& rSize, 1179 sal_uInt8 nAlpha, 1180 Color aColorTopLeft, --- 145 unchanged lines hidden --- |