| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 void DrawFreeGouraudShading( | 405 void DrawFreeGouraudShading( |
| 406 CFX_DIBitmap* pBitmap, | 406 CFX_DIBitmap* pBitmap, |
| 407 CFX_Matrix* pObject2Bitmap, | 407 CFX_Matrix* pObject2Bitmap, |
| 408 CPDF_Stream* pShadingStream, | 408 CPDF_Stream* pShadingStream, |
| 409 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 409 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 410 CPDF_ColorSpace* pCS, | 410 CPDF_ColorSpace* pCS, |
| 411 int alpha) { | 411 int alpha) { |
| 412 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 412 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 413 | 413 |
| 414 CPDF_MeshStream stream(funcs, pCS); | 414 CPDF_MeshStream stream(kFreeFormGouraudTriangleMeshShading, funcs, |
| 415 if (!stream.Load(pShadingStream)) | 415 pShadingStream, pCS); |
| 416 if (!stream.Load()) |
| 416 return; | 417 return; |
| 417 | 418 |
| 418 CPDF_MeshVertex triangle[3]; | 419 CPDF_MeshVertex triangle[3]; |
| 419 FXSYS_memset(triangle, 0, sizeof(triangle)); | 420 FXSYS_memset(triangle, 0, sizeof(triangle)); |
| 420 | 421 |
| 421 while (!stream.BitStream()->IsEOF()) { | 422 while (!stream.BitStream()->IsEOF()) { |
| 422 CPDF_MeshVertex vertex; | 423 CPDF_MeshVertex vertex; |
| 423 uint32_t flag = stream.GetVertex(vertex, pObject2Bitmap); | 424 uint32_t flag = stream.GetVertex(vertex, pObject2Bitmap); |
| 424 if (flag == 0) { | 425 if (flag == 0) { |
| 425 triangle[0] = vertex; | 426 triangle[0] = vertex; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 443 CPDF_Stream* pShadingStream, | 444 CPDF_Stream* pShadingStream, |
| 444 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 445 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 445 CPDF_ColorSpace* pCS, | 446 CPDF_ColorSpace* pCS, |
| 446 int alpha) { | 447 int alpha) { |
| 447 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 448 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 448 | 449 |
| 449 int row_verts = pShadingStream->GetDict()->GetIntegerBy("VerticesPerRow"); | 450 int row_verts = pShadingStream->GetDict()->GetIntegerBy("VerticesPerRow"); |
| 450 if (row_verts < 2) | 451 if (row_verts < 2) |
| 451 return; | 452 return; |
| 452 | 453 |
| 453 CPDF_MeshStream stream(funcs, pCS); | 454 CPDF_MeshStream stream(kLatticeFormGouraudTriangleMeshShading, funcs, |
| 454 if (!stream.Load(pShadingStream)) | 455 pShadingStream, pCS); |
| 456 if (!stream.Load()) |
| 455 return; | 457 return; |
| 456 | 458 |
| 457 std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( | 459 std::unique_ptr<CPDF_MeshVertex, FxFreeDeleter> vertex( |
| 458 FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); | 460 FX_Alloc2D(CPDF_MeshVertex, row_verts, 2)); |
| 459 if (!stream.GetVertexRow(vertex.get(), row_verts, pObject2Bitmap)) | 461 if (!stream.GetVertexRow(vertex.get(), row_verts, pObject2Bitmap)) |
| 460 return; | 462 return; |
| 461 | 463 |
| 462 int last_index = 0; | 464 int last_index = 0; |
| 463 while (1) { | 465 while (1) { |
| 464 CPDF_MeshVertex* last_row = vertex.get() + last_index * row_verts; | 466 CPDF_MeshVertex* last_row = vertex.get() + last_index * row_verts; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 D1.second_half(), m2s); | 719 D1.second_half(), m2s); |
| 718 Draw(x_scale, y_scale, left + 1, bottom, C1.second_half(), m1s, m2f, | 720 Draw(x_scale, y_scale, left + 1, bottom, C1.second_half(), m1s, m2f, |
| 719 D2.first_half()); | 721 D2.first_half()); |
| 720 Draw(x_scale, y_scale, left + 1, bottom + 1, m1s, C2.second_half(), m2s, | 722 Draw(x_scale, y_scale, left + 1, bottom + 1, m1s, C2.second_half(), m2s, |
| 721 D2.second_half()); | 723 D2.second_half()); |
| 722 } | 724 } |
| 723 } | 725 } |
| 724 } | 726 } |
| 725 }; | 727 }; |
| 726 | 728 |
| 727 bool CheckCoonTensorPara(const CPDF_MeshStream& stream) { | |
| 728 uint32_t coord = stream.CoordBits(); | |
| 729 bool bCoordBitsValid = | |
| 730 (coord == 1 || coord == 2 || coord == 4 || coord == 8 || coord == 12 || | |
| 731 coord == 16 || coord == 24 || coord == 32); | |
| 732 | |
| 733 uint32_t comp = stream.CompBits(); | |
| 734 bool bCompBitsValid = (comp == 1 || comp == 2 || comp == 4 || comp == 8 || | |
| 735 comp == 12 || comp == 16); | |
| 736 | |
| 737 uint32_t flag = stream.FlagBits(); | |
| 738 bool bFlagBitsValid = (flag == 2 || flag == 4 || flag == 8); | |
| 739 | |
| 740 return bCoordBitsValid && bCompBitsValid && bFlagBitsValid; | |
| 741 } | |
| 742 | |
| 743 void DrawCoonPatchMeshes( | 729 void DrawCoonPatchMeshes( |
| 744 FX_BOOL bTensor, | 730 ShadingType type, |
| 745 CFX_DIBitmap* pBitmap, | 731 CFX_DIBitmap* pBitmap, |
| 746 CFX_Matrix* pObject2Bitmap, | 732 CFX_Matrix* pObject2Bitmap, |
| 747 CPDF_Stream* pShadingStream, | 733 CPDF_Stream* pShadingStream, |
| 748 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, | 734 const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
| 749 CPDF_ColorSpace* pCS, | 735 CPDF_ColorSpace* pCS, |
| 750 int fill_mode, | 736 int fill_mode, |
| 751 int alpha) { | 737 int alpha) { |
| 752 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); | 738 ASSERT(pBitmap->GetFormat() == FXDIB_Argb); |
| 739 ASSERT(type == kCoonsPatchMeshShading || |
| 740 type == kTensorProductPatchMeshShading); |
| 753 | 741 |
| 754 CFX_FxgeDevice device; | 742 CFX_FxgeDevice device; |
| 755 device.Attach(pBitmap, false, nullptr, false); | 743 device.Attach(pBitmap, false, nullptr, false); |
| 756 CPDF_MeshStream stream(funcs, pCS); | 744 CPDF_MeshStream stream(type, funcs, pShadingStream, pCS); |
| 757 if (!stream.Load(pShadingStream)) | 745 if (!stream.Load()) |
| 758 return; | |
| 759 if (!CheckCoonTensorPara(stream)) | |
| 760 return; | 746 return; |
| 761 | 747 |
| 762 CPDF_PatchDrawer patch; | 748 CPDF_PatchDrawer patch; |
| 763 patch.alpha = alpha; | 749 patch.alpha = alpha; |
| 764 patch.pDevice = &device; | 750 patch.pDevice = &device; |
| 765 patch.fill_mode = fill_mode; | 751 patch.fill_mode = fill_mode; |
| 766 patch.path.SetPointCount(13); | 752 patch.path.SetPointCount(13); |
| 767 FX_PATHPOINT* pPoints = patch.path.GetPoints(); | 753 FX_PATHPOINT* pPoints = patch.path.GetPoints(); |
| 768 pPoints[0].m_Flag = FXPT_MOVETO; | 754 pPoints[0].m_Flag = FXPT_MOVETO; |
| 769 for (int i = 1; i < 13; i++) { | 755 for (int i = 1; i < 13; i++) |
| 770 pPoints[i].m_Flag = FXPT_BEZIERTO; | 756 pPoints[i].m_Flag = FXPT_BEZIERTO; |
| 771 } | |
| 772 CFX_PointF coords[16]; | 757 CFX_PointF coords[16]; |
| 773 int point_count = bTensor ? 16 : 12; | 758 int point_count = type == kTensorProductPatchMeshShading ? 16 : 12; |
| 774 while (!stream.BitStream()->IsEOF()) { | 759 while (!stream.BitStream()->IsEOF()) { |
| 775 uint32_t flag = stream.GetFlag(); | 760 uint32_t flag = stream.GetFlag(); |
| 776 int iStartPoint = 0, iStartColor = 0, i = 0; | 761 int iStartPoint = 0, iStartColor = 0, i = 0; |
| 777 if (flag) { | 762 if (flag) { |
| 778 iStartPoint = 4; | 763 iStartPoint = 4; |
| 779 iStartColor = 2; | 764 iStartColor = 2; |
| 780 CFX_PointF tempCoords[4]; | 765 CFX_PointF tempCoords[4]; |
| 781 for (i = 0; i < 4; i++) { | 766 for (i = 0; i < 4; i++) { |
| 782 tempCoords[i] = coords[(flag * 3 + i) % 12]; | 767 tempCoords[i] = coords[(flag * 3 + i) % 12]; |
| 783 } | 768 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 if (CPDF_Stream* pStream = ToStream(pPattern->GetShadingObject())) { | 912 if (CPDF_Stream* pStream = ToStream(pPattern->GetShadingObject())) { |
| 928 DrawLatticeGouraudShading(pBitmap, &FinalMatrix, pStream, funcs, | 913 DrawLatticeGouraudShading(pBitmap, &FinalMatrix, pStream, funcs, |
| 929 pColorSpace, alpha); | 914 pColorSpace, alpha); |
| 930 } | 915 } |
| 931 } break; | 916 } break; |
| 932 case kCoonsPatchMeshShading: | 917 case kCoonsPatchMeshShading: |
| 933 case kTensorProductPatchMeshShading: { | 918 case kTensorProductPatchMeshShading: { |
| 934 // The shading object can be a stream or a dictionary. We do not handle | 919 // The shading object can be a stream or a dictionary. We do not handle |
| 935 // the case of dictionary at the moment. | 920 // the case of dictionary at the moment. |
| 936 if (CPDF_Stream* pStream = ToStream(pPattern->GetShadingObject())) { | 921 if (CPDF_Stream* pStream = ToStream(pPattern->GetShadingObject())) { |
| 937 DrawCoonPatchMeshes( | 922 DrawCoonPatchMeshes(pPattern->GetShadingType(), pBitmap, &FinalMatrix, |
| 938 pPattern->GetShadingType() == kTensorProductPatchMeshShading, | 923 pStream, funcs, pColorSpace, fill_mode, alpha); |
| 939 pBitmap, &FinalMatrix, pStream, funcs, pColorSpace, fill_mode, | |
| 940 alpha); | |
| 941 } | 924 } |
| 942 } break; | 925 } break; |
| 943 } | 926 } |
| 944 if (bAlphaMode) | 927 if (bAlphaMode) |
| 945 pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha); | 928 pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha); |
| 946 | 929 |
| 947 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) | 930 if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) |
| 948 pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor); | 931 pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor); |
| 949 buffer.OutputToDevice(); | 932 buffer.OutputToDevice(); |
| 950 } | 933 } |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 } | 1190 } |
| 1208 } | 1191 } |
| 1209 if (bStroke) { | 1192 if (bStroke) { |
| 1210 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); | 1193 CPDF_Color& StrokeColor = *pPathObj->m_ColorState.GetStrokeColor(); |
| 1211 if (StrokeColor.IsPattern()) { | 1194 if (StrokeColor.IsPattern()) { |
| 1212 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); | 1195 DrawPathWithPattern(pPathObj, pObj2Device, &StrokeColor, TRUE); |
| 1213 bStroke = FALSE; | 1196 bStroke = FALSE; |
| 1214 } | 1197 } |
| 1215 } | 1198 } |
| 1216 } | 1199 } |
| OLD | NEW |