提交 90230637 编写于 作者: O openharmony_ci 提交者: Gitee

!457 修复draw_utils.cpp code clean

Merge pull request !457 from guyuanzhang/code_check
......@@ -14,6 +14,7 @@
*/
#include "draw/draw_utils.h"
#include "draw/draw_triangle.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "font/ui_font.h"
......@@ -35,16 +36,16 @@
namespace OHOS {
// Preprocess operation for draw
#define DRAW_UTILS_PREPROCESS(gfxBufferInfo, opa) \
if ((opa) == OPA_TRANSPARENT) { \
return; \
} \
uint8_t* screenBuffer = static_cast<uint8_t*>(gfxBufferInfo.virAddr); \
if (screenBuffer == nullptr) { \
return; \
} \
ColorMode bufferMode = gfxBufferInfo.mode; \
uint8_t bufferPxSize = GetByteSizeByColorMode(bufferMode); \
#define DRAW_UTILS_PREPROCESS(gfxBufferInfo, opa) \
if ((opa) == OPA_TRANSPARENT) { \
return; \
} \
uint8_t* screenBuffer = static_cast<uint8_t*>(gfxBufferInfo.virAddr); \
if (screenBuffer == nullptr) { \
return; \
} \
ColorMode bufferMode = gfxBufferInfo.mode; \
uint8_t bufferPxSize = GetByteSizeByColorMode(bufferMode); \
uint16_t screenBufferWidth = gfxBufferInfo.width;
/* cover mode, src alpha is 255 */
......@@ -84,14 +85,14 @@ namespace OHOS {
ASSERT(0); \
}
#define COLOR_BLEND_RGBA(r1, g1, b1, a1, r2, g2, b2, a2) \
const float A1 = static_cast<float>(a1) / OPA_OPAQUE; \
const float A2 = static_cast<float>(a2) / OPA_OPAQUE; \
const float a = 1 - (1 - A1) * (1 - A2); \
(r1) = (A2 * (r2) + (1 - A2) * A1 * (r1)) / a; \
(g1) = (A2 * (g2) + (1 - A2) * A1 * (g1)) / a; \
(b1) = (A2 * (b2) + (1 - A2) * A1 * (b1)) / a; \
(a1) = a * OPA_OPAQUE;
#define COLOR_BLEND_RGBA(r1, g1, b1, a1, r2, g2, b2, a2) \
const float Alpha1 = static_cast<float>(a1) / OPA_OPAQUE; \
const float Alpha2 = static_cast<float>(a2) / OPA_OPAQUE; \
const float Alpha3 = 1 - (1 - Alpha1) * (1 - Alpha2); \
(r1) = (Alpha2 * (r2) + (1 - Alpha2) * Alpha1 * (r1)) / Alpha3; \
(g1) = (Alpha2 * (g2) + (1 - Alpha2) * Alpha1 * (g1)) / Alpha3; \
(b1) = (Alpha2 * (b2) + (1 - Alpha2) * Alpha1 * (b1)) / Alpha3; \
(a1) = Alpha3 * OPA_OPAQUE;
#define COLOR_BLEND_RGB(r1, g1, b1, r2, g2, b2, a2) \
(r1) = (((r2) * (a2)) / OPA_OPAQUE) + (((r1) * (OPA_OPAQUE - (a2))) / OPA_OPAQUE); \
......@@ -435,12 +436,8 @@ void DrawUtils::DrawImage(BufferInfo& gfxDstBuffer,
}
BufferInfo src;
src.rect = {
imageX,
imageY,
static_cast<int16_t>(imageX + maskedArea.GetWidth() - 1),
static_cast<int16_t>(imageY + maskedArea.GetHeight() - 1)
};
src.rect = {imageX, imageY, static_cast<int16_t>(imageX + maskedArea.GetWidth() - 1),
static_cast<int16_t>(imageY + maskedArea.GetHeight() - 1)};
src.virAddr = static_cast<void*>(const_cast<uint8_t*>(image));
src.stride = imageWidthInByte;
......@@ -862,7 +859,7 @@ void DrawUtils::DrawTriangleTrueColorBilinear565(const TriangleScanInfo& in, con
Color16 result;
#if ENABLE_FIXED_POINT
result.red = static_cast<uint8_t>(outR >>15); // 15: shift 15 bit right to convert fixed to int
result.red = static_cast<uint8_t>(outR >> 15); // 15: shift 15 bit right to convert fixed to int
result.green = static_cast<uint8_t>(outG >> 15); // 15: shift 15 bit right to convert fixed to int
result.blue = static_cast<uint8_t>(outB >> 15); // 15: shift 15 bit right to convert fixed to int
#else
......@@ -982,7 +979,7 @@ void DrawUtils::DrawTriangleTrueColorBilinear888(const TriangleScanInfo& in, con
Color24 result;
#if ENABLE_FIXED_POINT
result.red = static_cast<uint8_t>(outR >> 15); // 15: shift 15 bit right to convert fixed to int
result.red = static_cast<uint8_t>(outR >> 15); // 15: shift 15 bit right to convert fixed to int
result.green = static_cast<uint8_t>(outG >> 15); // 15: shift 15 bit right to convert fixed to int
result.blue = static_cast<uint8_t>(outB >> 15); // 15: shift 15 bit right to convert fixed to int
#else
......@@ -1082,11 +1079,11 @@ static void DrawTriangleTrueColorBilinear8888Inner(const TriangleScanInfo& in,
#endif
static void DrawFixedTriangleTrueColorBilinear8888Inner(const TriangleScanInfo& in,
uint8_t* screenBuffer,
int16_t len,
const ColorMode bufferMode,
int64_t u,
int64_t v)
uint8_t* screenBuffer,
int16_t len,
const ColorMode bufferMode,
int64_t u,
int64_t v)
{
for (int16_t x = 0; x < len; ++x) {
int16_t intU = FO_TO_INTEGER(u);
......@@ -1182,10 +1179,10 @@ static void DrawTriangleTrueColorBilinear8888InnerNeon(const TriangleScanInfo& i
#endif
}
// Monotonically increasing or decreasing, so only judge the beginning and end.
if ((arrayU[0] >= 0) && (arrayU[0] < in.info.header.width - 1) &&
(arrayV[0] >= 0) && (arrayV[0] < in.info.header.height - 1) &&
(arrayU[NEON_STEP_8 - 1] >= 0) && (arrayU[NEON_STEP_8 - 1] < in.info.header.width - 1) &&
(arrayV[NEON_STEP_8 - 1] >= 0) && (arrayV[NEON_STEP_8 - 1] < in.info.header.height - 1)) {
if ((arrayU[0] >= 0) && (arrayU[0] < in.info.header.width - 1) && (arrayV[0] >= 0) &&
(arrayV[0] < in.info.header.height - 1) && (arrayU[NEON_STEP_8 - 1] >= 0) &&
(arrayU[NEON_STEP_8 - 1] < in.info.header.width - 1) && (arrayV[NEON_STEP_8 - 1] >= 0) &&
(arrayV[NEON_STEP_8 - 1] < in.info.header.height - 1)) {
// Process the lower half of arrayU and arrayV
float32x4_t vU = vld1q_f32(arrayU);
float32x4_t vV = vld1q_f32(arrayV);
......@@ -1299,7 +1296,7 @@ void DrawUtils::Draw3DTriangleTrueColorBilinear8888(const TriangleScanInfo& in,
int64_t invMatrix30 = FO_TRANS_FLOAT_TO_FIXED(in.matrix.GetData()[6]);
int64_t invMatrix31 = FO_TRANS_FLOAT_TO_FIXED(in.matrix.GetData()[7]);
int64_t invMatrix32 = FO_TRANS_FLOAT_TO_FIXED(in.matrix.GetData()[8]);
#else // ENABLE_FIXED_POINT
#else // ENABLE_FIXED_POINT
float invMatrix00 = in.matrix.GetData()[0];
float invMatrix01 = in.matrix.GetData()[1];
float invMatrix02 = in.matrix.GetData()[2];
......@@ -1316,12 +1313,12 @@ void DrawUtils::Draw3DTriangleTrueColorBilinear8888(const TriangleScanInfo& in,
int16_t xMin = MATH_MAX(tempV, maskLeft);
tempV = FO_TO_INTEGER(in.edge2.curX) + xMaxErr;
int16_t xMax = MATH_MIN(tempV, maskRight);
#else // ENABLE_FIXED_POINT
#else // ENABLE_FIXED_POINT
int16_t xMin = MATH_MAX(static_cast<int16_t>(in.edge1.curX + xMinErr), maskLeft);
int16_t xMax = MATH_MIN(static_cast<int16_t>(in.edge2.curX + xMaxErr), maskRight);
#endif // ENABLE_FIXED_POINT
// move to current position
uint8_t* screenBuffer = in.screenBuffer + (y * in.screenBufferWidth + xMin) * in.bufferPxSize;
// move to current position
for (int16_t x = xMin; x <= xMax; x++) {
#if ENABLE_FIXED_POINT
int64_t w = invMatrix02 * x + invMatrix22 * y + invMatrix32;
......@@ -1329,7 +1326,7 @@ void DrawUtils::Draw3DTriangleTrueColorBilinear8888(const TriangleScanInfo& in,
int64_t v = FO_DIV((invMatrix01 * x + invMatrix21 * y + invMatrix31), w);
int16_t intU = FO_TO_INTEGER(u);
int16_t intV = FO_TO_INTEGER(v);
#else // ENABLE_FIXED_POINT
#else // ENABLE_FIXED_POINT
float w = invMatrix02 * x + invMatrix22 * y + invMatrix32;
float u = (invMatrix00 * x + invMatrix20 * y + invMatrix30) / w;
float v = (invMatrix01 * x + invMatrix21 * y + invMatrix31) / w;
......@@ -1341,7 +1338,7 @@ void DrawUtils::Draw3DTriangleTrueColorBilinear8888(const TriangleScanInfo& in,
uint32_t val1 = __SMUAD(intV, in.srcLineWidth);
uint32_t val2 = __SMUAD(intU, in.pixelSize);
uint32_t px1 = val1 + val2;
#else // ENABLE_ARM_MATH
#else // ENABLE_ARM_MATH
uint32_t px1 = intV * in.srcLineWidth + intU * in.pixelSize;
#endif // ENABLE_ARM_MATH
uint8_t* imgHead = const_cast<uint8_t*>(in.info.data);
......@@ -1396,7 +1393,7 @@ void DrawUtils::Draw3DTriangleTrueColorBilinear8888(const TriangleScanInfo& in,
__SMUAD(p1.blue, w1) + __SMUAD(p2.blue, w2) + __SMUAD(p3.blue, w3) + __SMUAD(p4.blue, w4);
const int32_t outA =
__SMUAD(p1.alpha, w1) + __SMUAD(p2.alpha, w2) + __SMUAD(p3.alpha, w3) + __SMUAD(p4.alpha, w4);
#else // ENABLE_ARM_MATH
#else // ENABLE_ARM_MATH
const int32_t outR = p1.red * w1 + p2.red * w2 + p3.red * w3 + p4.red * w4;
const int32_t outG = p1.green * w1 + p2.green * w2 + p3.green * w3 + p4.green * w4;
const int32_t outB = p1.blue * w1 + p2.blue * w2 + p3.blue * w3 + p4.blue * w4;
......@@ -1474,9 +1471,9 @@ void DrawUtils::DrawTriangleTrueColorBilinear8888(const TriangleScanInfo& in, co
in.init.verticalU += in.init.duVertical;
in.init.verticalV += in.init.dvVertical;
#if ENABLE_FIXED_POINT
int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
int16_t deltaX = FO_TO_INTEGER(in.edge1.curX) - xMin;
#else
int16_t deltaX = static_cast<int16_t>(in.edge1.curX) - xMin;
int16_t deltaX = static_cast<int16_t>(in.edge1.curX) - xMin;
#endif
in.init.verticalU += in.init.duHorizon * deltaX;
in.init.verticalV += in.init.dvHorizon * deltaX;
......@@ -1586,11 +1583,11 @@ void DrawUtils::DrawTriangleTrueColorNearest(const TriangleScanInfo& in, const C
void DrawUtils::DrawTriangleTransformPart(BufferInfo& gfxDstBuffer, const TrianglePartInfo& part)
{
#if ENABLE_FIXED_POINT
// parameters below are Q15 fixed-point number
// parameters below are Q15 fixed-point number
int64_t yMin = FO_TRANS_INTEGER_TO_FIXED(part.yMin);
part.edge1.curX += (static_cast<int64_t>(part.edge1.du) * (yMin - part.edge1.curY) / part.edge1.dv);
part.edge1.curX += (static_cast<int64_t>(part.edge1.du) * (yMin - part.edge1.curY) / part.edge1.dv);
part.edge1.curY = yMin;
part.edge2.curX += (static_cast<int64_t>(part.edge2.du) * (yMin - part.edge2.curY) / part.edge2.dv);
part.edge2.curX += (static_cast<int64_t>(part.edge2.du) * (yMin - part.edge2.curY) / part.edge2.dv);
part.edge2.curY = yMin;
Rect line;
line.SetLeft(FO_TO_INTEGER(part.edge1.curX));
......@@ -1739,7 +1736,7 @@ BottomHalf:
void DrawUtils::AddBorderToImageData(TransformDataInfo& newDataInfo)
{
int16_t border = 1; // 1 : border width
int16_t border = 1; // 1 : border width
int16_t offset = border * 2; // 2 : offset
uint16_t width = newDataInfo.header.width;
uint16_t height = newDataInfo.header.height;
......@@ -1789,8 +1786,8 @@ void DrawUtils::UpdateTransMap(int16_t width, int16_t height, TransformMap& tran
Rect rect = transMap.GetTransMapRect();
Matrix4<float> matrix = transMap.GetTransformMatrix();
matrix = matrix * (Matrix4<float>::Translate(Vector3<float>(-rect.GetX(), -rect.GetY(), 0)));
int16_t offsetX = (width - rect.GetWidth()) / 2; // 2 : half;
int16_t offsetY = (height - rect.GetHeight()) / 2; // 2 : half;
int16_t offsetX = (width - rect.GetWidth()) / 2; // 2 : half;
int16_t offsetY = (height - rect.GetHeight()) / 2; // 2 : half;
rect.SetPosition(rect.GetX() - offsetX, rect.GetY() - offsetY);
rect.Resize(width, height);
Polygon polygon = Polygon(rect);
......@@ -1816,8 +1813,7 @@ void DrawUtils::UpdateTransMap(int16_t width, int16_t height, TransformMap& tran
}
}
transMap.SetPolygon(polygon);
Matrix3<float> matrix3(matrix[0][0], matrix[0][1], matrix[0][3],
matrix[1][0], matrix[1][1], matrix[1][3],
Matrix3<float> matrix3(matrix[0][0], matrix[0][1], matrix[0][3], matrix[1][0], matrix[1][1], matrix[1][3],
matrix[3][0], matrix[3][1], matrix[3][3]);
transMap.invMatrix_ = (matrix3 * (Matrix3<float>::Translate(Vector2<float>(rect.GetX(), rect.GetY())))).Inverse();
}
......@@ -1947,8 +1943,7 @@ void DrawUtils::DrawTranspantArea(BufferInfo& gfxDstBuffer, const Rect& rect, co
FillArea(gfxDstBuffer, rect, mask, true, nullptr);
}
void DrawUtils::DrawWithBuffer(BufferInfo& gfxDstBuffer, const Rect& rect,
const Rect& mask, const ColorType* colorBuf)
void DrawUtils::DrawWithBuffer(BufferInfo& gfxDstBuffer, const Rect& rect, const Rect& mask, const ColorType* colorBuf)
{
FillArea(gfxDstBuffer, rect, mask, false, colorBuf);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册