diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/page/cpdf_meshstream.cpp | 69 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_meshstream.h | 25 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_streamcontentparser.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_renderstatus.cpp | 104 |
4 files changed, 93 insertions, 115 deletions
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp index 75069cab7f..b852901794 100644 --- a/core/fpdfapi/page/cpdf_meshstream.cpp +++ b/core/fpdfapi/page/cpdf_meshstream.cpp @@ -83,12 +83,6 @@ bool IsValidBitsPerFlag(uint32_t x) { } // namespace -CPDF_MeshVertex::CPDF_MeshVertex() = default; - -CPDF_MeshVertex::CPDF_MeshVertex(const CPDF_MeshVertex&) = default; - -CPDF_MeshVertex::~CPDF_MeshVertex() = default; - CPDF_MeshStream::CPDF_MeshStream( ShadingType type, const std::vector<std::unique_ptr<CPDF_Function>>& funcs, @@ -154,47 +148,37 @@ bool CPDF_MeshStream::Load() { return true; } -uint32_t CPDF_MeshStream::ReadFlag() { +uint32_t CPDF_MeshStream::GetFlag() { ASSERT(ShouldCheckBitsPerFlag(m_type)); return m_BitStream.GetBits(m_nFlagBits) & 0x03; } -CFX_PointF CPDF_MeshStream::ReadCoords() { +void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) { ASSERT(ShouldCheckBPC(m_type)); - - CFX_PointF pos; if (m_nCoordBits == 32) { - pos.x = m_xmin + - m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / - static_cast<double>(m_CoordMax); - pos.y = m_ymin + - m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / - static_cast<double>(m_CoordMax); + x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * + (m_xmax - m_xmin) / (double)m_CoordMax); + y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * + (m_ymax - m_ymin) / (double)m_CoordMax); } else { - pos.x = m_xmin + - m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_CoordMax; - pos.y = m_ymin + - m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_CoordMax; + x = m_xmin + + m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_CoordMax; + y = m_ymin + + m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_CoordMax; } - return pos; } -std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT> CPDF_MeshStream::ReadColor() { +void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) { ASSERT(ShouldCheckBPC(m_type)); - FX_FLOAT color_value[kMaxComponents]; for (uint32_t i = 0; i < m_nComponents; ++i) { color_value[i] = m_ColorMin[i] + m_BitStream.GetBits(m_nComponentBits) * (m_ColorMax[i] - m_ColorMin[i]) / m_ComponentMax; } - - FX_FLOAT r; - FX_FLOAT g; - FX_FLOAT b; if (m_funcs.empty()) { m_pCS->GetRGB(color_value, r, g, b); - return std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT>(r, g, b); + return; } FX_FLOAT result[kMaxComponents]; @@ -204,32 +188,29 @@ std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT> CPDF_MeshStream::ReadColor() { if (func && func->CountOutputs() <= kMaxComponents) func->Call(color_value, 1, result, nResults); } - m_pCS->GetRGB(result, r, g, b); - return std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT>(r, g, b); } -CPDF_MeshVertex CPDF_MeshStream::ReadVertex(const CFX_Matrix& pObject2Bitmap, - uint32_t* flag) { - *flag = ReadFlag(); - - CPDF_MeshVertex vertex; - vertex.position = pObject2Bitmap.Transform(ReadCoords()); - std::tie(vertex.r, vertex.g, vertex.b) = ReadColor(); +uint32_t CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex, + CFX_Matrix* pObject2Bitmap) { + uint32_t flag = GetFlag(); + GetCoords(vertex.x, vertex.y); + pObject2Bitmap->TransformPoint(vertex.x, vertex.y); + GetColor(vertex.r, vertex.g, vertex.b); m_BitStream.ByteAlign(); - - return vertex; + return flag; } -bool CPDF_MeshStream::ReadVertexRow(const CFX_Matrix& pObject2Bitmap, - int count, - CPDF_MeshVertex* vertex) { +bool CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex, + int count, + CFX_Matrix* pObject2Bitmap) { for (int i = 0; i < count; i++) { if (m_BitStream.IsEOF()) return false; - vertex[i].position = pObject2Bitmap.Transform(ReadCoords()); - std::tie(vertex[i].r, vertex[i].g, vertex[i].b) = ReadColor(); + GetCoords(vertex[i].x, vertex[i].y); + pObject2Bitmap->TransformPoint(vertex[i].x, vertex[i].y); + GetColor(vertex[i].r, vertex[i].g, vertex[i].b); m_BitStream.ByteAlign(); } return true; diff --git a/core/fpdfapi/page/cpdf_meshstream.h b/core/fpdfapi/page/cpdf_meshstream.h index 24f1d66cfd..21a6c2fa8c 100644 --- a/core/fpdfapi/page/cpdf_meshstream.h +++ b/core/fpdfapi/page/cpdf_meshstream.h @@ -8,7 +8,6 @@ #define CORE_FPDFAPI_PAGE_CPDF_MESHSTREAM_H_ #include <memory> -#include <tuple> #include <vector> #include "core/fpdfapi/page/cpdf_shadingpattern.h" @@ -16,13 +15,9 @@ #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_system.h" -class CPDF_MeshVertex { - public: - CPDF_MeshVertex(); - CPDF_MeshVertex(const CPDF_MeshVertex&); - ~CPDF_MeshVertex(); - - CFX_PointF position; +struct CPDF_MeshVertex { + FX_FLOAT x; + FX_FLOAT y; FX_FLOAT r; FX_FLOAT g; FX_FLOAT b; @@ -42,14 +37,14 @@ class CPDF_MeshStream { bool Load(); - uint32_t ReadFlag(); - CFX_PointF ReadCoords(); - std::tuple<FX_FLOAT, FX_FLOAT, FX_FLOAT> ReadColor(); + uint32_t GetFlag(); + void GetCoords(FX_FLOAT& x, FX_FLOAT& y); + void GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b); - CPDF_MeshVertex ReadVertex(const CFX_Matrix& pObject2Bitmap, uint32_t* flag); - bool ReadVertexRow(const CFX_Matrix& pObject2Bitmap, - int count, - CPDF_MeshVertex* vertex); + uint32_t GetVertex(CPDF_MeshVertex& vertex, CFX_Matrix* pObject2Bitmap); + bool GetVertexRow(CPDF_MeshVertex* vertex, + int count, + CFX_Matrix* pObject2Bitmap); CFX_BitStream* BitStream() { return &m_BitStream; } uint32_t ComponentBits() const { return m_nComponentBits; } diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 0af43d08b2..61efb48529 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -99,7 +99,7 @@ CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading, while (!stream.BitStream()->IsEOF()) { uint32_t flag = 0; if (type != kLatticeFormGouraudTriangleMeshShading) - flag = stream.ReadFlag(); + flag = stream.GetFlag(); if (!bGouraud && flag) { point_count -= 4; @@ -107,11 +107,13 @@ CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading, } for (int i = 0; i < point_count; i++) { - CFX_PointF origin = stream.ReadCoords(); + FX_FLOAT x; + FX_FLOAT y; + stream.GetCoords(x, y); if (bStarted) { - rect.UpdateRect(origin.x, origin.y); + rect.UpdateRect(x, y); } else { - rect.InitRect(origin.x, origin.y); + rect.InitRect(x, y); bStarted = true; } } diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 05323ed49f..197a244e0b 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -369,65 +369,67 @@ void DrawFuncShading(CFX_DIBitmap* pBitmap, } bool GetScanlineIntersect(int y, - const CFX_PointF& first, - const CFX_PointF& second, + FX_FLOAT x1, + FX_FLOAT y1, + FX_FLOAT x2, + FX_FLOAT y2, FX_FLOAT* x) { - if (first.y == second.y) + if (y1 == y2) return false; - if (first.y < second.y) { - if (y < first.y || y > second.y) + if (y1 < y2) { + if (y < y1 || y > y2) + return false; + } else { + if (y < y2 || y > y1) return false; - } else if (y < second.y || y > first.y) { - return false; } - *x = first.x + ((second.x - first.x) * (y - first.y) / (second.y - first.y)); + *x = x1 + ((x2 - x1) * (y - y1) / (y2 - y1)); return true; } void DrawGouraud(CFX_DIBitmap* pBitmap, int alpha, CPDF_MeshVertex triangle[3]) { - FX_FLOAT min_y = triangle[0].position.y; - FX_FLOAT max_y = triangle[0].position.y; + FX_FLOAT min_y = triangle[0].y, max_y = triangle[0].y; for (int i = 1; i < 3; i++) { - min_y = std::min(min_y, triangle[i].position.y); - max_y = std::max(max_y, triangle[i].position.y); + if (min_y > triangle[i].y) { + min_y = triangle[i].y; + } + if (max_y < triangle[i].y) { + max_y = triangle[i].y; + } } - if (min_y == max_y) + if (min_y == max_y) { return; - - int min_yi = std::max(static_cast<int>(FXSYS_floor(min_y)), 0); - int max_yi = static_cast<int>(FXSYS_ceil(max_y)); - - if (max_yi >= pBitmap->GetHeight()) + } + int min_yi = (int)FXSYS_floor(min_y), max_yi = (int)FXSYS_ceil(max_y); + if (min_yi < 0) { + min_yi = 0; + } + if (max_yi >= pBitmap->GetHeight()) { max_yi = pBitmap->GetHeight() - 1; - + } for (int y = min_yi; y <= max_yi; y++) { int nIntersects = 0; - FX_FLOAT inter_x[3]; - FX_FLOAT r[3]; - FX_FLOAT g[3]; - FX_FLOAT b[3]; + FX_FLOAT inter_x[3], r[3], g[3], b[3]; for (int i = 0; i < 3; i++) { CPDF_MeshVertex& vertex1 = triangle[i]; CPDF_MeshVertex& vertex2 = triangle[(i + 1) % 3]; - CFX_PointF& position1 = vertex1.position; - CFX_PointF& position2 = vertex2.position; - bool bIntersect = - GetScanlineIntersect(y, position1, position2, &inter_x[nIntersects]); + bool bIntersect = GetScanlineIntersect(y, vertex1.x, vertex1.y, vertex2.x, + vertex2.y, &inter_x[nIntersects]); if (!bIntersect) continue; - FX_FLOAT y_dist = (y - position1.y) / (position2.y - position1.y); + FX_FLOAT y_dist = (y - vertex1.y) / (vertex2.y - vertex1.y); r[nIntersects] = vertex1.r + ((vertex2.r - vertex1.r) * y_dist); g[nIntersects] = vertex1.g + ((vertex2.g - vertex1.g) * y_dist); b[nIntersects] = vertex1.b + ((vertex2.b - vertex1.b) * y_dist); nIntersects++; } - if (nIntersects != 2) + if (nIntersects != 2) { continue; - + } int min_x, max_x, start_index, end_index; if (inter_x[0] < inter_x[1]) { min_x = (int)FXSYS_floor(inter_x[0]); @@ -440,12 +442,13 @@ void DrawGouraud(CFX_DIBitmap* pBitmap, start_index = 1; end_index = 0; } - - int start_x = std::max(min_x, 0); - int end_x = max_x; - if (end_x > pBitmap->GetWidth()) + int start_x = min_x, end_x = max_x; + if (start_x < 0) { + start_x = 0; + } + if (end_x > pBitmap->GetWidth()) { end_x = pBitmap->GetWidth(); - + } uint8_t* dib_buf = pBitmap->GetBuffer() + y * pBitmap->GetPitch() + start_x * 4; FX_FLOAT r_unit = (r[end_index] - r[start_index]) / (max_x - min_x); @@ -484,18 +487,17 @@ void DrawFreeGouraudShading( FXSYS_memset(triangle, 0, sizeof(triangle)); while (!stream.BitStream()->IsEOF()) { - uint32_t flag; - CPDF_MeshVertex vertex = stream.ReadVertex(*pObject2Bitmap, &flag); + CPDF_MeshVertex vertex; + uint32_t flag = stream.GetVertex(vertex, pObject2Bitmap); if (flag == 0) { triangle[0] = vertex; for (int j = 1; j < 3; j++) { - uint32_t tflag; - triangle[j] = stream.ReadVertex(*pObject2Bitmap, &tflag); + stream.GetVertex(triangle[j], pObject2Bitmap); } } else { - if (flag == 1) + if (flag == 1) { triangle[0] = triangle[1]; - + } triangle[1] = triangle[2]; triangle[2] = vertex; } @@ -523,14 +525,14 @@ void DrawLatticeGouraudShading( std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); - if (!stream.ReadVertexRow(*pObject2Bitmap, row_verts, vertex.get())) + if (!stream.GetVertexRow(vertex.get(), row_verts, pObject2Bitmap)) return; int last_index = 0; while (1) { CPDF_MeshVertex* last_row = vertex.get() + last_index * row_verts; CPDF_MeshVertex* this_row = vertex.get() + (1 - last_index) * row_verts; - if (!stream.ReadVertexRow(*pObject2Bitmap, row_verts, this_row)) + if (!stream.GetVertexRow(this_row, row_verts, pObject2Bitmap)) return; CPDF_MeshVertex triangle[3]; @@ -825,7 +827,7 @@ void DrawCoonPatchMeshes( CFX_PointF coords[16]; int point_count = type == kTensorProductPatchMeshShading ? 16 : 12; while (!stream.BitStream()->IsEOF()) { - uint32_t flag = stream.ReadFlag(); + uint32_t flag = stream.GetFlag(); int iStartPoint = 0, iStartColor = 0, i = 0; if (flag) { iStartPoint = 4; @@ -840,15 +842,13 @@ void DrawCoonPatchMeshes( tempColors[1] = patch.patch_colors[(flag + 1) % 4]; FXSYS_memcpy(patch.patch_colors, tempColors, sizeof(Coon_Color) * 2); } - for (i = iStartPoint; i < point_count; i++) - coords[i] = pObject2Bitmap->Transform(stream.ReadCoords()); - + for (i = iStartPoint; i < point_count; i++) { + stream.GetCoords(coords[i].x, coords[i].y); + pObject2Bitmap->TransformPoint(coords[i].x, coords[i].y); + } for (i = iStartColor; i < 4; i++) { - FX_FLOAT r; - FX_FLOAT g; - FX_FLOAT b; - std::tie(r, g, b) = stream.ReadColor(); - + FX_FLOAT r = 0.0f, g = 0.0f, b = 0.0f; + stream.GetColor(r, g, b); patch.patch_colors[i].comp[0] = (int32_t)(r * 255); patch.patch_colors[i].comp[1] = (int32_t)(g * 255); patch.patch_colors[i].comp[2] = (int32_t)(b * 255); |