bitmap4.cxx (ca6f8f21) bitmap4.cxx (ff0f521c)
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

--- 991 unchanged lines hidden (view full) ---

1000 bRet = sal_True;
1001 }
1002 }
1003
1004 return bRet;
1005}
1006
1007// -----------------------------------------------------------------------------
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

--- 991 unchanged lines hidden (view full) ---

1000 bRet = sal_True;
1001 }
1002 }
1003
1004 return bRet;
1005}
1006
1007// -----------------------------------------------------------------------------
1008
1009void impMixPixel(BitmapWriteAccess& rAcc, long y, long x, const Color& rColor, sal_uInt8 nAlpha)
1010{
1011 const BitmapColor aBitmapColor(rColor);
1012
1013 if(nAlpha)
1014 {
1015 if(255 != nAlpha)
1016 {
1017 BitmapColor aTarget(rAcc.GetColor(y, x));
1018
1019 aTarget.Merge(aBitmapColor, nAlpha);
1020 rAcc.SetPixel(y, x, aTarget);
1021 }
1022 }
1023 else
1024 {
1025 rAcc.SetPixel(y, x, aBitmapColor);
1026 }
1027}
1028
1029inline bool impVisibleX(long x, const Size& rSizePixel)
1030{
1031 return x >= 0 && x < rSizePixel.Width();
1032}
1033
1034inline bool impVisibleY(long y, const Size& rSizePixel)
1035{
1036 return y >= 0 && y < rSizePixel.Width();
1037}
1038
1039inline bool impVisibleXY(long y, long x, const Size& rSizePixel)
1040{
1041 return impVisibleX(x, rSizePixel) && impVisibleY(y, rSizePixel);
1042}
1043
1044void Bitmap::DrawBlendFrame(
1045 const Point& rTopLeft,
1046 const Size& rSize,
1047 sal_uInt8 nAlpha,
1048 Color aColorTopLeft,
1049 Color aColorTopRight,
1050 Color aColorBottomRight,
1051 Color aColorBottomLeft)
1052{
1053 if(!IsEmpty())
1054 {
1055 const Size aSizePixel(GetSizePixel());
1056
1057 if(aSizePixel.Width() && aSizePixel.Height())
1058 {
1059 const long nW(rSize.Width());
1060 const long nH(rSize.Height());
1061
1062 if(nW || nH)
1063 {
1064 BitmapWriteAccess* pAcc = AcquireWriteAccess();
1065 const long nStartX(rTopLeft.X());
1066 const long nStartY(rTopLeft.X());
1067 const long nEndX(rTopLeft.X() + nW);
1068 const long nEndY(rTopLeft.X() + nH);
1069 long x(nStartX);
1070 long y(nStartY);
1071
1072 if(pAcc)
1073 {
1074 if(impVisibleXY(y, x, aSizePixel))
1075 {
1076 // x == nStartX, y == nStartY
1077 impMixPixel(*pAcc, y, x, aColorTopLeft, nAlpha);
1078 }
1079
1080 if(impVisibleY(y, aSizePixel))
1081 {
1082 for(x = 1; x < nEndX - 1; x++) // y == nStartY
1083 {
1084 if(impVisibleX(x, aSizePixel))
1085 {
1086 Color aMix(aColorTopLeft);
1087 aMix.Merge(aColorTopRight, 255 - sal_uInt8(((x - nStartX) * 255) / nW));
1088 impMixPixel(*pAcc, y, x, aMix, nAlpha);
1089 }
1090 }
1091 }
1092 else
1093 {
1094 x = nEndX - 1;
1095 }
1096
1097 if(impVisibleXY(y, x, aSizePixel))
1098 {
1099 // x == nEndX - 1, y == nStartY
1100 impMixPixel(*pAcc, y, x, aColorTopRight, nAlpha);
1101 }
1102
1103 const bool bLeftVisible(impVisibleX(nStartX, aSizePixel));
1104 const bool bRightVisible(impVisibleX(x, aSizePixel));
1105
1106 if(bLeftVisible || bRightVisible)
1107 {
1108 if(bLeftVisible)
1109 {
1110 for(y = 1; y < nEndY - 1; y++) // x == nStartX and nEndX-1
1111 {
1112 if(impVisibleY(y, aSizePixel))
1113 {
1114 Color aMix(aColorTopLeft);
1115 aMix.Merge(aColorBottomLeft, 255 - sal_uInt8(((y - nStartY) * 255) / nH));
1116 impMixPixel(*pAcc, y, nStartX, aMix, nAlpha);
1117 }
1118 }
1119 }
1120
1121 if(bRightVisible)
1122 {
1123 for(y = 1; y < nEndY - 1; y++) // x == nStartX and nEndX-1
1124 {
1125 if(impVisibleY(y, aSizePixel))
1126 {
1127 Color aMix(aColorTopRight);
1128 aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((y -nStartY) * 255) / nH));
1129 impMixPixel(*pAcc, y, x, aMix, nAlpha);
1130 }
1131 }
1132 }
1133 }
1134 else
1135 {
1136 y = nEndY - 1;
1137 }
1138
1139 if(impVisibleXY(y, x, aSizePixel))
1140 {
1141 x = nStartX; // x == nStartX, y == nEndY-1
1142 impMixPixel(*pAcc, y, x, aColorBottomLeft, nAlpha);
1143 }
1144
1145 if(impVisibleY(y, aSizePixel))
1146 {
1147 for(x = 1; x < nEndX - 1; x++) // y == nEndY-1
1148 {
1149 if(impVisibleX(x, aSizePixel))
1150 {
1151 Color aMix(aColorBottomLeft);
1152 aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - nStartX)* 255) / nW));
1153 impMixPixel(*pAcc, y, x, aMix, nAlpha);
1154 }
1155 }
1156 }
1157 else
1158 {
1159 x = nEndX - 1;
1160 }
1161
1162 if(impVisibleXY(y, x, aSizePixel))
1163 {
1164 // x == nEndX - 1, y == nEndY - 1
1165 impMixPixel(*pAcc, y, x, aColorBottomRight, nAlpha);
1166 }
1167
1168 ReleaseAccess(pAcc);
1169 }
1170 }
1171 }
1172 }
1173}
1174
1175void Bitmap::DrawBlendFrame(
1176 sal_uInt8 nAlpha,
1177 Color aColorTopLeft,
1178 Color aColorBottomRight)
1179{
1180 if(!IsEmpty())
1181 {
1182 const Point aTopLeft(0, 0);
1183 const Size aSize(GetSizePixel());
1184 const sal_uInt32 nW(aSize.Width());
1185 const sal_uInt32 nH(aSize.Height());
1186
1187 if(nW || nH)
1188 {
1189 Color aColTopRight(aColorTopLeft);
1190 Color aColBottomLeft(aColorTopLeft);
1191 const sal_uInt32 nDE(nW + nH);
1192
1193 aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
1194 aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
1195
1196 DrawBlendFrame(aTopLeft, aSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
1197 }
1198 }
1199}
1200
1201// -----------------------------------------------------------------------------
1202// eof
1008// eof