Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1000)

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 1832173003: Remove FX_DWORD from core/ and delete definition (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <memory> 10 #include <memory>
(...skipping 20 matching lines...) Expand all
31 unsigned int byte = pData[bitpos / 8]; 31 unsigned int byte = pData[bitpos / 8];
32 if (nbits == 8) { 32 if (nbits == 8) {
33 return byte; 33 return byte;
34 } else if (nbits == 16) { 34 } else if (nbits == 16) {
35 return byte * 256 + pData[bitpos / 8 + 1]; 35 return byte * 256 + pData[bitpos / 8 + 1];
36 } 36 }
37 37
38 return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1); 38 return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1);
39 } 39 }
40 40
41 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc, FX_DWORD components, int width) { 41 FX_SAFE_DWORD CalculatePitch8(uint32_t bpc, uint32_t components, int width) {
42 FX_SAFE_DWORD pitch = bpc; 42 FX_SAFE_DWORD pitch = bpc;
43 pitch *= components; 43 pitch *= components;
44 pitch *= width; 44 pitch *= width;
45 pitch += 7; 45 pitch += 7;
46 pitch /= 8; 46 pitch /= 8;
47 return pitch; 47 return pitch;
48 } 48 }
49 49
50 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { 50 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) {
51 FX_SAFE_DWORD pitch = bpp; 51 FX_SAFE_DWORD pitch = bpp;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { 141 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const {
142 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { 142 if (pBitmap && pBitmap != m_pCachedBitmap.get()) {
143 delete pBitmap; 143 delete pBitmap;
144 } 144 }
145 } 145 }
146 146
147 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, 147 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc,
148 const CPDF_Stream* pStream, 148 const CPDF_Stream* pStream,
149 CPDF_DIBSource** ppMask, 149 CPDF_DIBSource** ppMask,
150 FX_DWORD* pMatteColor, 150 uint32_t* pMatteColor,
151 CPDF_Dictionary* pFormResources, 151 CPDF_Dictionary* pFormResources,
152 CPDF_Dictionary* pPageResources, 152 CPDF_Dictionary* pPageResources,
153 FX_BOOL bStdCS, 153 FX_BOOL bStdCS,
154 FX_DWORD GroupFamily, 154 uint32_t GroupFamily,
155 FX_BOOL bLoadMask) { 155 FX_BOOL bLoadMask) {
156 if (!pStream) { 156 if (!pStream) {
157 return FALSE; 157 return FALSE;
158 } 158 }
159 m_pDocument = pDoc; 159 m_pDocument = pDoc;
160 m_pDict = pStream->GetDict(); 160 m_pDict = pStream->GetDict();
161 if (!m_pDict) { 161 if (!m_pDict) {
162 return FALSE; 162 return FALSE;
163 } 163 }
164 m_pStream = pStream; 164 m_pStream = pStream;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 m_Pitch = pitch.ValueOrDie(); 267 m_Pitch = pitch.ValueOrDie();
268 return 1; 268 return 1;
269 } 269 }
270 270
271 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, 271 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc,
272 const CPDF_Stream* pStream, 272 const CPDF_Stream* pStream,
273 FX_BOOL bHasMask, 273 FX_BOOL bHasMask,
274 CPDF_Dictionary* pFormResources, 274 CPDF_Dictionary* pFormResources,
275 CPDF_Dictionary* pPageResources, 275 CPDF_Dictionary* pPageResources,
276 FX_BOOL bStdCS, 276 FX_BOOL bStdCS,
277 FX_DWORD GroupFamily, 277 uint32_t GroupFamily,
278 FX_BOOL bLoadMask) { 278 FX_BOOL bLoadMask) {
279 if (!pStream) { 279 if (!pStream) {
280 return 0; 280 return 0;
281 } 281 }
282 m_pDocument = pDoc; 282 m_pDocument = pDoc;
283 m_pDict = pStream->GetDict(); 283 m_pDict = pStream->GetDict();
284 m_pStream = pStream; 284 m_pStream = pStream;
285 m_bStdCS = bStdCS; 285 m_bStdCS = bStdCS;
286 m_bHasMask = bHasMask; 286 m_bHasMask = bHasMask;
287 m_Width = m_pDict->GetIntegerBy("Width"); 287 m_Width = m_pDict->GetIntegerBy("Width");
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, 474 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode,
475 FX_BOOL& bColorKey) { 475 FX_BOOL& bColorKey) {
476 if (!m_pColorSpace) { 476 if (!m_pColorSpace) {
477 return nullptr; 477 return nullptr;
478 } 478 }
479 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); 479 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
480 int max_data = (1 << m_bpc) - 1; 480 int max_data = (1 << m_bpc) - 1;
481 CPDF_Array* pDecode = m_pDict->GetArrayBy("Decode"); 481 CPDF_Array* pDecode = m_pDict->GetArrayBy("Decode");
482 if (pDecode) { 482 if (pDecode) {
483 for (FX_DWORD i = 0; i < m_nComponents; i++) { 483 for (uint32_t i = 0; i < m_nComponents; i++) {
484 pCompData[i].m_DecodeMin = pDecode->GetNumberAt(i * 2); 484 pCompData[i].m_DecodeMin = pDecode->GetNumberAt(i * 2);
485 FX_FLOAT max = pDecode->GetNumberAt(i * 2 + 1); 485 FX_FLOAT max = pDecode->GetNumberAt(i * 2 + 1);
486 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data; 486 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data;
487 FX_FLOAT def_value; 487 FX_FLOAT def_value;
488 FX_FLOAT def_min; 488 FX_FLOAT def_min;
489 FX_FLOAT def_max; 489 FX_FLOAT def_max;
490 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); 490 m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max);
491 if (m_Family == PDFCS_INDEXED) { 491 if (m_Family == PDFCS_INDEXED) {
492 def_max = max_data; 492 def_max = max_data;
493 } 493 }
494 if (def_min != pCompData[i].m_DecodeMin || def_max != max) { 494 if (def_min != pCompData[i].m_DecodeMin || def_max != max) {
495 bDefaultDecode = FALSE; 495 bDefaultDecode = FALSE;
496 } 496 }
497 } 497 }
498 } else { 498 } else {
499 for (FX_DWORD i = 0; i < m_nComponents; i++) { 499 for (uint32_t i = 0; i < m_nComponents; i++) {
500 FX_FLOAT def_value; 500 FX_FLOAT def_value;
501 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, 501 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin,
502 pCompData[i].m_DecodeStep); 502 pCompData[i].m_DecodeStep);
503 if (m_Family == PDFCS_INDEXED) { 503 if (m_Family == PDFCS_INDEXED) {
504 pCompData[i].m_DecodeStep = max_data; 504 pCompData[i].m_DecodeStep = max_data;
505 } 505 }
506 pCompData[i].m_DecodeStep = 506 pCompData[i].m_DecodeStep =
507 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; 507 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data;
508 } 508 }
509 } 509 }
510 if (!m_pDict->KeyExist("SMask")) { 510 if (!m_pDict->KeyExist("SMask")) {
511 CPDF_Object* pMask = m_pDict->GetElementValue("Mask"); 511 CPDF_Object* pMask = m_pDict->GetElementValue("Mask");
512 if (!pMask) { 512 if (!pMask) {
513 return pCompData; 513 return pCompData;
514 } 514 }
515 if (CPDF_Array* pArray = pMask->AsArray()) { 515 if (CPDF_Array* pArray = pMask->AsArray()) {
516 if (pArray->GetCount() >= m_nComponents * 2) { 516 if (pArray->GetCount() >= m_nComponents * 2) {
517 for (FX_DWORD i = 0; i < m_nComponents; i++) { 517 for (uint32_t i = 0; i < m_nComponents; i++) {
518 int min_num = pArray->GetIntegerAt(i * 2); 518 int min_num = pArray->GetIntegerAt(i * 2);
519 int max_num = pArray->GetIntegerAt(i * 2 + 1); 519 int max_num = pArray->GetIntegerAt(i * 2 + 1);
520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); 520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0);
521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); 521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data);
522 } 522 }
523 } 523 }
524 bColorKey = TRUE; 524 bColorKey = TRUE;
525 } 525 }
526 } 526 }
527 return pCompData; 527 return pCompData;
528 } 528 }
529 529
530 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( 530 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
531 const uint8_t* src_buf, 531 const uint8_t* src_buf,
532 FX_DWORD src_size, 532 uint32_t src_size,
533 int width, 533 int width,
534 int height, 534 int height,
535 const CPDF_Dictionary* pParams); 535 const CPDF_Dictionary* pParams);
536 536
537 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( 537 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(
538 const uint8_t* src_buf, 538 const uint8_t* src_buf,
539 FX_DWORD src_size, 539 uint32_t src_size,
540 int width, 540 int width,
541 int height, 541 int height,
542 int nComps, 542 int nComps,
543 int bpc, 543 int bpc,
544 const CPDF_Dictionary* pParams); 544 const CPDF_Dictionary* pParams);
545 545
546 int CPDF_DIBSource::CreateDecoder() { 546 int CPDF_DIBSource::CreateDecoder() {
547 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 547 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
548 if (decoder.IsEmpty()) { 548 if (decoder.IsEmpty()) {
549 return 1; 549 return 1;
550 } 550 }
551 if (m_bDoBpcCheck && m_bpc == 0) { 551 if (m_bDoBpcCheck && m_bpc == 0) {
552 return 0; 552 return 0;
553 } 553 }
554 const uint8_t* src_data = m_pStreamAcc->GetData(); 554 const uint8_t* src_data = m_pStreamAcc->GetData();
555 FX_DWORD src_size = m_pStreamAcc->GetSize(); 555 uint32_t src_size = m_pStreamAcc->GetSize();
556 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 556 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
557 if (decoder == "CCITTFaxDecode") { 557 if (decoder == "CCITTFaxDecode") {
558 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, 558 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width,
559 m_Height, pParams)); 559 m_Height, pParams));
560 } else if (decoder == "DCTDecode") { 560 } else if (decoder == "DCTDecode") {
561 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( 561 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
562 src_data, src_size, m_Width, m_Height, m_nComponents, 562 src_data, src_size, m_Width, m_Height, m_nComponents,
563 pParams ? pParams->GetIntegerBy("ColorTransform", 1) : 1)); 563 pParams ? pParams->GetIntegerBy("ColorTransform", 1) : 1));
564 if (!m_pDecoder) { 564 if (!m_pDecoder) {
565 FX_BOOL bTransform = FALSE; 565 FX_BOOL bTransform = FALSE;
566 int comps; 566 int comps;
567 int bpc; 567 int bpc;
568 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); 568 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule();
569 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, 569 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps,
570 bpc, bTransform)) { 570 bpc, bTransform)) {
571 if (m_nComponents != static_cast<FX_DWORD>(comps)) { 571 if (m_nComponents != static_cast<uint32_t>(comps)) {
572 FX_Free(m_pCompData); 572 FX_Free(m_pCompData);
573 m_nComponents = static_cast<FX_DWORD>(comps); 573 m_nComponents = static_cast<uint32_t>(comps);
574 if (m_Family == PDFCS_LAB && m_nComponents != 3) { 574 if (m_Family == PDFCS_LAB && m_nComponents != 3) {
575 m_pCompData = nullptr; 575 m_pCompData = nullptr;
576 return 0; 576 return 0;
577 } 577 }
578 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); 578 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey);
579 if (!m_pCompData) { 579 if (!m_pCompData) {
580 return 0; 580 return 0;
581 } 581 }
582 } 582 }
583 m_bpc = bpc; 583 m_bpc = bpc;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 631 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
632 if (!pJpxModule) 632 if (!pJpxModule)
633 return; 633 return;
634 634
635 std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule)); 635 std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule));
636 context->set_decoder(pJpxModule->CreateDecoder( 636 context->set_decoder(pJpxModule->CreateDecoder(
637 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); 637 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace));
638 if (!context->decoder()) 638 if (!context->decoder())
639 return; 639 return;
640 640
641 FX_DWORD width = 0; 641 uint32_t width = 0;
642 FX_DWORD height = 0; 642 uint32_t height = 0;
643 FX_DWORD components = 0; 643 uint32_t components = 0;
644 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); 644 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components);
645 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height) 645 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height)
646 return; 646 return;
647 647
648 FX_BOOL bSwapRGB = FALSE; 648 FX_BOOL bSwapRGB = FALSE;
649 if (m_pColorSpace) { 649 if (m_pColorSpace) {
650 if (components != m_pColorSpace->CountComponents()) 650 if (components != m_pColorSpace->CountComponents())
651 return; 651 return;
652 652
653 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { 653 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) {
(...skipping 21 matching lines...) Expand all
675 format = FXDIB_Rgb; 675 format = FXDIB_Rgb;
676 } 676 }
677 677
678 m_pCachedBitmap.reset(new CFX_DIBitmap); 678 m_pCachedBitmap.reset(new CFX_DIBitmap);
679 if (!m_pCachedBitmap->Create(width, height, format)) { 679 if (!m_pCachedBitmap->Create(width, height, format)) {
680 m_pCachedBitmap.reset(); 680 m_pCachedBitmap.reset();
681 return; 681 return;
682 } 682 }
683 m_pCachedBitmap->Clear(0xFFFFFFFF); 683 m_pCachedBitmap->Clear(0xFFFFFFFF);
684 std::vector<uint8_t> output_offsets(components); 684 std::vector<uint8_t> output_offsets(components);
685 for (FX_DWORD i = 0; i < components; ++i) 685 for (uint32_t i = 0; i < components; ++i)
686 output_offsets[i] = i; 686 output_offsets[i] = i;
687 if (bSwapRGB) { 687 if (bSwapRGB) {
688 output_offsets[0] = 2; 688 output_offsets[0] = 2;
689 output_offsets[2] = 0; 689 output_offsets[2] = 0;
690 } 690 }
691 if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(), 691 if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(),
692 m_pCachedBitmap->GetPitch(), output_offsets)) { 692 m_pCachedBitmap->GetPitch(), output_offsets)) {
693 m_pCachedBitmap.reset(); 693 m_pCachedBitmap.reset();
694 return; 694 return;
695 } 695 }
696 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED && 696 if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
697 m_bpc < 8) { 697 m_bpc < 8) {
698 int scale = 8 - m_bpc; 698 int scale = 8 - m_bpc;
699 for (FX_DWORD row = 0; row < height; ++row) { 699 for (uint32_t row = 0; row < height; ++row) {
700 uint8_t* scanline = 700 uint8_t* scanline =
701 const_cast<uint8_t*>(m_pCachedBitmap->GetScanline(row)); 701 const_cast<uint8_t*>(m_pCachedBitmap->GetScanline(row));
702 for (FX_DWORD col = 0; col < width; ++col) { 702 for (uint32_t col = 0; col < width; ++col) {
703 *scanline = (*scanline) >> scale; 703 *scanline = (*scanline) >> scale;
704 ++scanline; 704 ++scanline;
705 } 705 }
706 } 706 }
707 } 707 }
708 m_bpc = 8; 708 m_bpc = 8;
709 } 709 }
710 710
711 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { 711 CPDF_DIBSource* CPDF_DIBSource::LoadMask(uint32_t& MatteColor) {
712 MatteColor = 0xFFFFFFFF; 712 MatteColor = 0xFFFFFFFF;
713 CPDF_Stream* pSoftMask = m_pDict->GetStreamBy("SMask"); 713 CPDF_Stream* pSoftMask = m_pDict->GetStreamBy("SMask");
714 if (pSoftMask) { 714 if (pSoftMask) {
715 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArrayBy("Matte"); 715 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArrayBy("Matte");
716 if (pMatte && m_pColorSpace && 716 if (pMatte && m_pColorSpace &&
717 m_pColorSpace->CountComponents() <= m_nComponents) { 717 m_pColorSpace->CountComponents() <= m_nComponents) {
718 std::vector<FX_FLOAT> colors(m_nComponents); 718 std::vector<FX_FLOAT> colors(m_nComponents);
719 for (FX_DWORD i = 0; i < m_nComponents; i++) { 719 for (uint32_t i = 0; i < m_nComponents; i++) {
720 colors[i] = pMatte->GetFloatAt(i); 720 colors[i] = pMatte->GetFloatAt(i);
721 } 721 }
722 FX_FLOAT R, G, B; 722 FX_FLOAT R, G, B;
723 m_pColorSpace->GetRGB(colors.data(), R, G, B); 723 m_pColorSpace->GetRGB(colors.data(), R, G, B);
724 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 724 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
725 FXSYS_round(B * 255)); 725 FXSYS_round(B * 255));
726 } 726 }
727 return LoadMaskDIB(pSoftMask); 727 return LoadMaskDIB(pSoftMask);
728 } 728 }
729 729
730 if (CPDF_Stream* pStream = ToStream(m_pDict->GetElementValue("Mask"))) 730 if (CPDF_Stream* pStream = ToStream(m_pDict->GetElementValue("Mask")))
731 return LoadMaskDIB(pStream); 731 return LoadMaskDIB(pStream);
732 732
733 return nullptr; 733 return nullptr;
734 } 734 }
735 735
736 int CPDF_DIBSource::StratLoadMask() { 736 int CPDF_DIBSource::StratLoadMask() {
737 m_MatteColor = 0XFFFFFFFF; 737 m_MatteColor = 0XFFFFFFFF;
738 m_pMaskStream = m_pDict->GetStreamBy("SMask"); 738 m_pMaskStream = m_pDict->GetStreamBy("SMask");
739 if (m_pMaskStream) { 739 if (m_pMaskStream) {
740 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte"); 740 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte");
741 if (pMatte && m_pColorSpace && 741 if (pMatte && m_pColorSpace &&
742 m_pColorSpace->CountComponents() <= m_nComponents) { 742 m_pColorSpace->CountComponents() <= m_nComponents) {
743 FX_FLOAT R, G, B; 743 FX_FLOAT R, G, B;
744 std::vector<FX_FLOAT> colors(m_nComponents); 744 std::vector<FX_FLOAT> colors(m_nComponents);
745 for (FX_DWORD i = 0; i < m_nComponents; i++) { 745 for (uint32_t i = 0; i < m_nComponents; i++) {
746 colors[i] = pMatte->GetFloatAt(i); 746 colors[i] = pMatte->GetFloatAt(i);
747 } 747 }
748 m_pColorSpace->GetRGB(colors.data(), R, G, B); 748 m_pColorSpace->GetRGB(colors.data(), R, G, B);
749 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 749 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
750 FXSYS_round(B * 255)); 750 FXSYS_round(B * 255));
751 } 751 }
752 return StartLoadMaskDIB(); 752 return StartLoadMaskDIB();
753 } 753 }
754 754
755 m_pMaskStream = ToStream(m_pDict->GetElementValue("Mask")); 755 m_pMaskStream = ToStream(m_pDict->GetElementValue("Mask"));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 return; 846 return;
847 } 847 }
848 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY) && 848 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICEGRAY) &&
849 m_bpc == 8 && m_bDefaultDecode) { 849 m_bpc == 8 && m_bDefaultDecode) {
850 } else { 850 } else {
851 int palette_count = 1 << (m_bpc * m_nComponents); 851 int palette_count = 1 << (m_bpc * m_nComponents);
852 CFX_FixedBufGrow<FX_FLOAT, 16> color_values(m_nComponents); 852 CFX_FixedBufGrow<FX_FLOAT, 16> color_values(m_nComponents);
853 FX_FLOAT* color_value = color_values; 853 FX_FLOAT* color_value = color_values;
854 for (int i = 0; i < palette_count; i++) { 854 for (int i = 0; i < palette_count; i++) {
855 int color_data = i; 855 int color_data = i;
856 for (FX_DWORD j = 0; j < m_nComponents; j++) { 856 for (uint32_t j = 0; j < m_nComponents; j++) {
857 int encoded_component = color_data % (1 << m_bpc); 857 int encoded_component = color_data % (1 << m_bpc);
858 color_data /= 1 << m_bpc; 858 color_data /= 1 << m_bpc;
859 color_value[j] = m_pCompData[j].m_DecodeMin + 859 color_value[j] = m_pCompData[j].m_DecodeMin +
860 m_pCompData[j].m_DecodeStep * encoded_component; 860 m_pCompData[j].m_DecodeStep * encoded_component;
861 } 861 }
862 FX_FLOAT R = 0, G = 0, B = 0; 862 FX_FLOAT R = 0, G = 0, B = 0;
863 if (m_nComponents == 1 && m_Family == PDFCS_ICCBASED && 863 if (m_nComponents == 1 && m_Family == PDFCS_ICCBASED &&
864 m_pColorSpace->CountComponents() > 1) { 864 m_pColorSpace->CountComponents() > 1) {
865 int nComponents = m_pColorSpace->CountComponents(); 865 int nComponents = m_pColorSpace->CountComponents();
866 std::vector<FX_FLOAT> temp_buf(nComponents); 866 std::vector<FX_FLOAT> temp_buf(nComponents);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 return; 965 return;
966 } 966 }
967 } 967 }
968 CFX_FixedBufGrow<FX_FLOAT, 16> color_values1(m_nComponents); 968 CFX_FixedBufGrow<FX_FLOAT, 16> color_values1(m_nComponents);
969 FX_FLOAT* color_values = color_values1; 969 FX_FLOAT* color_values = color_values1;
970 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; 970 FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f;
971 if (m_bpc == 8) { 971 if (m_bpc == 8) {
972 uint64_t src_byte_pos = 0; 972 uint64_t src_byte_pos = 0;
973 size_t dest_byte_pos = 0; 973 size_t dest_byte_pos = 0;
974 for (int column = 0; column < m_Width; column++) { 974 for (int column = 0; column < m_Width; column++) {
975 for (FX_DWORD color = 0; color < m_nComponents; color++) { 975 for (uint32_t color = 0; color < m_nComponents; color++) {
976 uint8_t data = src_scan[src_byte_pos++]; 976 uint8_t data = src_scan[src_byte_pos++];
977 color_values[color] = m_pCompData[color].m_DecodeMin + 977 color_values[color] = m_pCompData[color].m_DecodeMin +
978 m_pCompData[color].m_DecodeStep * data; 978 m_pCompData[color].m_DecodeStep * data;
979 } 979 }
980 if (TransMask()) { 980 if (TransMask()) {
981 FX_FLOAT k = 1.0f - color_values[3]; 981 FX_FLOAT k = 1.0f - color_values[3];
982 R = (1.0f - color_values[0]) * k; 982 R = (1.0f - color_values[0]) * k;
983 G = (1.0f - color_values[1]) * k; 983 G = (1.0f - color_values[1]) * k;
984 B = (1.0f - color_values[2]) * k; 984 B = (1.0f - color_values[2]) * k;
985 } else { 985 } else {
986 m_pColorSpace->GetRGB(color_values, R, G, B); 986 m_pColorSpace->GetRGB(color_values, R, G, B);
987 } 987 }
988 R = ClampValue(R, 1.0f); 988 R = ClampValue(R, 1.0f);
989 G = ClampValue(G, 1.0f); 989 G = ClampValue(G, 1.0f);
990 B = ClampValue(B, 1.0f); 990 B = ClampValue(B, 1.0f);
991 dest_scan[dest_byte_pos] = static_cast<uint8_t>(B * 255); 991 dest_scan[dest_byte_pos] = static_cast<uint8_t>(B * 255);
992 dest_scan[dest_byte_pos + 1] = static_cast<uint8_t>(G * 255); 992 dest_scan[dest_byte_pos + 1] = static_cast<uint8_t>(G * 255);
993 dest_scan[dest_byte_pos + 2] = static_cast<uint8_t>(R * 255); 993 dest_scan[dest_byte_pos + 2] = static_cast<uint8_t>(R * 255);
994 dest_byte_pos += 3; 994 dest_byte_pos += 3;
995 } 995 }
996 } else { 996 } else {
997 uint64_t src_bit_pos = 0; 997 uint64_t src_bit_pos = 0;
998 size_t dest_byte_pos = 0; 998 size_t dest_byte_pos = 0;
999 for (int column = 0; column < m_Width; column++) { 999 for (int column = 0; column < m_Width; column++) {
1000 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1000 for (uint32_t color = 0; color < m_nComponents; color++) {
1001 unsigned int data = GetBits8(src_scan, src_bit_pos, m_bpc); 1001 unsigned int data = GetBits8(src_scan, src_bit_pos, m_bpc);
1002 color_values[color] = m_pCompData[color].m_DecodeMin + 1002 color_values[color] = m_pCompData[color].m_DecodeMin +
1003 m_pCompData[color].m_DecodeStep * data; 1003 m_pCompData[color].m_DecodeStep * data;
1004 src_bit_pos += m_bpc; 1004 src_bit_pos += m_bpc;
1005 } 1005 }
1006 if (TransMask()) { 1006 if (TransMask()) {
1007 FX_FLOAT k = 1.0f - color_values[3]; 1007 FX_FLOAT k = 1.0f - color_values[3];
1008 R = (1.0f - color_values[0]) * k; 1008 R = (1.0f - color_values[0]) * k;
1009 G = (1.0f - color_values[1]) * k; 1009 G = (1.0f - color_values[1]) * k;
1010 B = (1.0f - color_values[2]) * k; 1010 B = (1.0f - color_values[2]) * k;
(...skipping 15 matching lines...) Expand all
1026 return m_pCachedBitmap ? m_pCachedBitmap->GetBuffer() : nullptr; 1026 return m_pCachedBitmap ? m_pCachedBitmap->GetBuffer() : nullptr;
1027 } 1027 }
1028 1028
1029 const uint8_t* CPDF_DIBSource::GetScanline(int line) const { 1029 const uint8_t* CPDF_DIBSource::GetScanline(int line) const {
1030 if (m_bpc == 0) { 1030 if (m_bpc == 0) {
1031 return nullptr; 1031 return nullptr;
1032 } 1032 }
1033 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); 1033 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
1034 if (!src_pitch.IsValid()) 1034 if (!src_pitch.IsValid())
1035 return nullptr; 1035 return nullptr;
1036 FX_DWORD src_pitch_value = src_pitch.ValueOrDie(); 1036 uint32_t src_pitch_value = src_pitch.ValueOrDie();
1037 const uint8_t* pSrcLine = nullptr; 1037 const uint8_t* pSrcLine = nullptr;
1038 if (m_pCachedBitmap && src_pitch_value <= m_pCachedBitmap->GetPitch()) { 1038 if (m_pCachedBitmap && src_pitch_value <= m_pCachedBitmap->GetPitch()) {
1039 if (line >= m_pCachedBitmap->GetHeight()) { 1039 if (line >= m_pCachedBitmap->GetHeight()) {
1040 line = m_pCachedBitmap->GetHeight() - 1; 1040 line = m_pCachedBitmap->GetHeight() - 1;
1041 } 1041 }
1042 pSrcLine = m_pCachedBitmap->GetScanline(line); 1042 pSrcLine = m_pCachedBitmap->GetScanline(line);
1043 } else if (m_pDecoder) { 1043 } else if (m_pDecoder) {
1044 pSrcLine = m_pDecoder->GetScanline(line); 1044 pSrcLine = m_pDecoder->GetScanline(line);
1045 } else { 1045 } else {
1046 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch_value) { 1046 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch_value) {
1047 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch_value; 1047 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch_value;
1048 } 1048 }
1049 } 1049 }
1050 if (!pSrcLine) { 1050 if (!pSrcLine) {
1051 uint8_t* pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf; 1051 uint8_t* pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf;
1052 FXSYS_memset(pLineBuf, 0xFF, m_Pitch); 1052 FXSYS_memset(pLineBuf, 0xFF, m_Pitch);
1053 return pLineBuf; 1053 return pLineBuf;
1054 } 1054 }
1055 if (m_bpc * m_nComponents == 1) { 1055 if (m_bpc * m_nComponents == 1) {
1056 if (m_bImageMask && m_bDefaultDecode) { 1056 if (m_bImageMask && m_bDefaultDecode) {
1057 for (FX_DWORD i = 0; i < src_pitch_value; i++) { 1057 for (uint32_t i = 0; i < src_pitch_value; i++) {
1058 m_pLineBuf[i] = ~pSrcLine[i]; 1058 m_pLineBuf[i] = ~pSrcLine[i];
1059 } 1059 }
1060 } else if (m_bColorKey) { 1060 } else if (m_bColorKey) {
1061 FX_DWORD reset_argb, set_argb; 1061 uint32_t reset_argb, set_argb;
1062 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000; 1062 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000;
1063 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF; 1063 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF;
1064 if (m_pCompData[0].m_ColorKeyMin == 0) { 1064 if (m_pCompData[0].m_ColorKeyMin == 0) {
1065 reset_argb = 0; 1065 reset_argb = 0;
1066 } 1066 }
1067 if (m_pCompData[0].m_ColorKeyMax == 1) { 1067 if (m_pCompData[0].m_ColorKeyMax == 1) {
1068 set_argb = 0; 1068 set_argb = 0;
1069 } 1069 }
1070 set_argb = FXARGB_TODIB(set_argb); 1070 set_argb = FXARGB_TODIB(set_argb);
1071 reset_argb = FXARGB_TODIB(reset_argb); 1071 reset_argb = FXARGB_TODIB(reset_argb);
1072 FX_DWORD* dest_scan = reinterpret_cast<FX_DWORD*>(m_pMaskedLine); 1072 uint32_t* dest_scan = reinterpret_cast<uint32_t*>(m_pMaskedLine);
1073 for (int col = 0; col < m_Width; col++) { 1073 for (int col = 0; col < m_Width; col++) {
1074 if (pSrcLine[col / 8] & (1 << (7 - col % 8))) { 1074 if (pSrcLine[col / 8] & (1 << (7 - col % 8))) {
1075 *dest_scan = set_argb; 1075 *dest_scan = set_argb;
1076 } else { 1076 } else {
1077 *dest_scan = reset_argb; 1077 *dest_scan = reset_argb;
1078 } 1078 }
1079 dest_scan++; 1079 dest_scan++;
1080 } 1080 }
1081 return m_pMaskedLine; 1081 return m_pMaskedLine;
1082 } else { 1082 } else {
1083 FXSYS_memcpy(m_pLineBuf, pSrcLine, src_pitch_value); 1083 FXSYS_memcpy(m_pLineBuf, pSrcLine, src_pitch_value);
1084 } 1084 }
1085 return m_pLineBuf; 1085 return m_pLineBuf;
1086 } 1086 }
1087 if (m_bpc * m_nComponents <= 8) { 1087 if (m_bpc * m_nComponents <= 8) {
1088 if (m_bpc == 8) { 1088 if (m_bpc == 8) {
1089 FXSYS_memcpy(m_pLineBuf, pSrcLine, src_pitch_value); 1089 FXSYS_memcpy(m_pLineBuf, pSrcLine, src_pitch_value);
1090 } else { 1090 } else {
1091 uint64_t src_bit_pos = 0; 1091 uint64_t src_bit_pos = 0;
1092 for (int col = 0; col < m_Width; col++) { 1092 for (int col = 0; col < m_Width; col++) {
1093 unsigned int color_index = 0; 1093 unsigned int color_index = 0;
1094 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1094 for (uint32_t color = 0; color < m_nComponents; color++) {
1095 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc); 1095 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc);
1096 color_index |= data << (color * m_bpc); 1096 color_index |= data << (color * m_bpc);
1097 src_bit_pos += m_bpc; 1097 src_bit_pos += m_bpc;
1098 } 1098 }
1099 m_pLineBuf[col] = color_index; 1099 m_pLineBuf[col] = color_index;
1100 } 1100 }
1101 } 1101 }
1102 if (m_bColorKey) { 1102 if (m_bColorKey) {
1103 uint8_t* pDestPixel = m_pMaskedLine; 1103 uint8_t* pDestPixel = m_pMaskedLine;
1104 const uint8_t* pSrcPixel = m_pLineBuf; 1104 const uint8_t* pSrcPixel = m_pLineBuf;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 int dest_bpp, 1168 int dest_bpp,
1169 int dest_width, 1169 int dest_width,
1170 FX_BOOL bFlipX, 1170 FX_BOOL bFlipX,
1171 int clip_left, 1171 int clip_left,
1172 int clip_width) const { 1172 int clip_width) const {
1173 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || 1173 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 ||
1174 clip_left < 0 || clip_width <= 0) { 1174 clip_left < 0 || clip_width <= 0) {
1175 return; 1175 return;
1176 } 1176 }
1177 1177
1178 FX_DWORD src_width = m_Width; 1178 uint32_t src_width = m_Width;
1179 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); 1179 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
1180 if (!pitch.IsValid()) 1180 if (!pitch.IsValid())
1181 return; 1181 return;
1182 1182
1183 const uint8_t* pSrcLine = nullptr; 1183 const uint8_t* pSrcLine = nullptr;
1184 if (m_pCachedBitmap) { 1184 if (m_pCachedBitmap) {
1185 pSrcLine = m_pCachedBitmap->GetScanline(line); 1185 pSrcLine = m_pCachedBitmap->GetScanline(line);
1186 } else if (m_pDecoder) { 1186 } else if (m_pDecoder) {
1187 pSrcLine = m_pDecoder->GetScanline(line); 1187 pSrcLine = m_pDecoder->GetScanline(line);
1188 } else { 1188 } else {
1189 FX_DWORD src_pitch = pitch.ValueOrDie(); 1189 uint32_t src_pitch = pitch.ValueOrDie();
1190 pitch *= (line + 1); 1190 pitch *= (line + 1);
1191 if (!pitch.IsValid()) { 1191 if (!pitch.IsValid()) {
1192 return; 1192 return;
1193 } 1193 }
1194 1194
1195 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) { 1195 if (m_pStreamAcc->GetSize() >= pitch.ValueOrDie()) {
1196 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch; 1196 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch;
1197 } 1197 }
1198 } 1198 }
1199 int orig_Bpp = m_bpc * m_nComponents / 8; 1199 int orig_Bpp = m_bpc * m_nComponents / 8;
(...skipping 17 matching lines...) Expand all
1217 DownSampleScanline8Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan, 1217 DownSampleScanline8Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan,
1218 dest_width, bFlipX, clip_left, clip_width); 1218 dest_width, bFlipX, clip_left, clip_width);
1219 } else { 1219 } else {
1220 DownSampleScanline32Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan, 1220 DownSampleScanline32Bit(orig_Bpp, dest_Bpp, src_width, pSrcLine, dest_scan,
1221 dest_width, bFlipX, clip_left, clip_width); 1221 dest_width, bFlipX, clip_left, clip_width);
1222 } 1222 }
1223 } 1223 }
1224 1224
1225 void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp, 1225 void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp,
1226 int dest_Bpp, 1226 int dest_Bpp,
1227 FX_DWORD src_width, 1227 uint32_t src_width,
1228 const uint8_t* pSrcLine, 1228 const uint8_t* pSrcLine,
1229 uint8_t* dest_scan, 1229 uint8_t* dest_scan,
1230 int dest_width, 1230 int dest_width,
1231 FX_BOOL bFlipX, 1231 FX_BOOL bFlipX,
1232 int clip_left, 1232 int clip_left,
1233 int clip_width) const { 1233 int clip_width) const {
1234 FX_DWORD set_argb = (FX_DWORD)-1; 1234 uint32_t set_argb = (uint32_t)-1;
1235 FX_DWORD reset_argb = 0; 1235 uint32_t reset_argb = 0;
1236 if (m_bImageMask) { 1236 if (m_bImageMask) {
1237 if (m_bDefaultDecode) { 1237 if (m_bDefaultDecode) {
1238 set_argb = 0; 1238 set_argb = 0;
1239 reset_argb = (FX_DWORD)-1; 1239 reset_argb = (uint32_t)-1;
1240 } 1240 }
1241 } else if (m_bColorKey) { 1241 } else if (m_bColorKey) {
1242 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000; 1242 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000;
1243 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF; 1243 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF;
1244 if (m_pCompData[0].m_ColorKeyMin == 0) { 1244 if (m_pCompData[0].m_ColorKeyMin == 0) {
1245 reset_argb = 0; 1245 reset_argb = 0;
1246 } 1246 }
1247 if (m_pCompData[0].m_ColorKeyMax == 1) { 1247 if (m_pCompData[0].m_ColorKeyMax == 1) {
1248 set_argb = 0; 1248 set_argb = 0;
1249 } 1249 }
1250 set_argb = FXARGB_TODIB(set_argb); 1250 set_argb = FXARGB_TODIB(set_argb);
1251 reset_argb = FXARGB_TODIB(reset_argb); 1251 reset_argb = FXARGB_TODIB(reset_argb);
1252 FX_DWORD* dest_scan_dword = reinterpret_cast<FX_DWORD*>(dest_scan); 1252 uint32_t* dest_scan_dword = reinterpret_cast<uint32_t*>(dest_scan);
1253 for (int i = 0; i < clip_width; i++) { 1253 for (int i = 0; i < clip_width; i++) {
1254 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1254 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1255 if (bFlipX) { 1255 if (bFlipX) {
1256 src_x = src_width - src_x - 1; 1256 src_x = src_width - src_x - 1;
1257 } 1257 }
1258 src_x %= src_width; 1258 src_x %= src_width;
1259 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1259 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
1260 dest_scan_dword[i] = set_argb; 1260 dest_scan_dword[i] = set_argb;
1261 } else { 1261 } else {
1262 dest_scan_dword[i] = reset_argb; 1262 dest_scan_dword[i] = reset_argb;
1263 } 1263 }
1264 } 1264 }
1265 return; 1265 return;
1266 } else { 1266 } else {
1267 if (dest_Bpp == 1) { 1267 if (dest_Bpp == 1) {
1268 } else if (m_pPalette) { 1268 } else if (m_pPalette) {
1269 reset_argb = m_pPalette[0]; 1269 reset_argb = m_pPalette[0];
1270 set_argb = m_pPalette[1]; 1270 set_argb = m_pPalette[1];
1271 } 1271 }
1272 } 1272 }
1273 for (int i = 0; i < clip_width; i++) { 1273 for (int i = 0; i < clip_width; i++) {
1274 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1274 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1275 if (bFlipX) { 1275 if (bFlipX) {
1276 src_x = src_width - src_x - 1; 1276 src_x = src_width - src_x - 1;
1277 } 1277 }
1278 src_x %= src_width; 1278 src_x %= src_width;
1279 int dest_pos = i * dest_Bpp; 1279 int dest_pos = i * dest_Bpp;
1280 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1280 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
1281 if (dest_Bpp == 1) { 1281 if (dest_Bpp == 1) {
1282 dest_scan[dest_pos] = static_cast<uint8_t>(set_argb); 1282 dest_scan[dest_pos] = static_cast<uint8_t>(set_argb);
1283 } else if (dest_Bpp == 3) { 1283 } else if (dest_Bpp == 3) {
1284 dest_scan[dest_pos] = FXARGB_B(set_argb); 1284 dest_scan[dest_pos] = FXARGB_B(set_argb);
1285 dest_scan[dest_pos + 1] = FXARGB_G(set_argb); 1285 dest_scan[dest_pos + 1] = FXARGB_G(set_argb);
1286 dest_scan[dest_pos + 2] = FXARGB_R(set_argb); 1286 dest_scan[dest_pos + 2] = FXARGB_R(set_argb);
1287 } else { 1287 } else {
1288 *reinterpret_cast<FX_DWORD*>(dest_scan + dest_pos) = set_argb; 1288 *reinterpret_cast<uint32_t*>(dest_scan + dest_pos) = set_argb;
1289 } 1289 }
1290 } else { 1290 } else {
1291 if (dest_Bpp == 1) { 1291 if (dest_Bpp == 1) {
1292 dest_scan[dest_pos] = static_cast<uint8_t>(reset_argb); 1292 dest_scan[dest_pos] = static_cast<uint8_t>(reset_argb);
1293 } else if (dest_Bpp == 3) { 1293 } else if (dest_Bpp == 3) {
1294 dest_scan[dest_pos] = FXARGB_B(reset_argb); 1294 dest_scan[dest_pos] = FXARGB_B(reset_argb);
1295 dest_scan[dest_pos + 1] = FXARGB_G(reset_argb); 1295 dest_scan[dest_pos + 1] = FXARGB_G(reset_argb);
1296 dest_scan[dest_pos + 2] = FXARGB_R(reset_argb); 1296 dest_scan[dest_pos + 2] = FXARGB_R(reset_argb);
1297 } else { 1297 } else {
1298 *reinterpret_cast<FX_DWORD*>(dest_scan + dest_pos) = reset_argb; 1298 *reinterpret_cast<uint32_t*>(dest_scan + dest_pos) = reset_argb;
1299 } 1299 }
1300 } 1300 }
1301 } 1301 }
1302 } 1302 }
1303 1303
1304 void CPDF_DIBSource::DownSampleScanline8Bit(int orig_Bpp, 1304 void CPDF_DIBSource::DownSampleScanline8Bit(int orig_Bpp,
1305 int dest_Bpp, 1305 int dest_Bpp,
1306 FX_DWORD src_width, 1306 uint32_t src_width,
1307 const uint8_t* pSrcLine, 1307 const uint8_t* pSrcLine,
1308 uint8_t* dest_scan, 1308 uint8_t* dest_scan,
1309 int dest_width, 1309 int dest_width,
1310 FX_BOOL bFlipX, 1310 FX_BOOL bFlipX,
1311 int clip_left, 1311 int clip_left,
1312 int clip_width) const { 1312 int clip_width) const {
1313 if (m_bpc < 8) { 1313 if (m_bpc < 8) {
1314 uint64_t src_bit_pos = 0; 1314 uint64_t src_bit_pos = 0;
1315 for (FX_DWORD col = 0; col < src_width; col++) { 1315 for (uint32_t col = 0; col < src_width; col++) {
1316 unsigned int color_index = 0; 1316 unsigned int color_index = 0;
1317 for (FX_DWORD color = 0; color < m_nComponents; color++) { 1317 for (uint32_t color = 0; color < m_nComponents; color++) {
1318 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc); 1318 unsigned int data = GetBits8(pSrcLine, src_bit_pos, m_bpc);
1319 color_index |= data << (color * m_bpc); 1319 color_index |= data << (color * m_bpc);
1320 src_bit_pos += m_bpc; 1320 src_bit_pos += m_bpc;
1321 } 1321 }
1322 m_pLineBuf[col] = color_index; 1322 m_pLineBuf[col] = color_index;
1323 } 1323 }
1324 pSrcLine = m_pLineBuf; 1324 pSrcLine = m_pLineBuf;
1325 } 1325 }
1326 if (m_bColorKey) { 1326 if (m_bColorKey) {
1327 for (int i = 0; i < clip_width; i++) { 1327 for (int i = 0; i < clip_width; i++) {
1328 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1328 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1329 if (bFlipX) { 1329 if (bFlipX) {
1330 src_x = src_width - src_x - 1; 1330 src_x = src_width - src_x - 1;
1331 } 1331 }
1332 src_x %= src_width; 1332 src_x %= src_width;
1333 uint8_t* pDestPixel = dest_scan + i * 4; 1333 uint8_t* pDestPixel = dest_scan + i * 4;
1334 uint8_t index = pSrcLine[src_x]; 1334 uint8_t index = pSrcLine[src_x];
1335 if (m_pPalette) { 1335 if (m_pPalette) {
1336 *pDestPixel++ = FXARGB_B(m_pPalette[index]); 1336 *pDestPixel++ = FXARGB_B(m_pPalette[index]);
1337 *pDestPixel++ = FXARGB_G(m_pPalette[index]); 1337 *pDestPixel++ = FXARGB_G(m_pPalette[index]);
1338 *pDestPixel++ = FXARGB_R(m_pPalette[index]); 1338 *pDestPixel++ = FXARGB_R(m_pPalette[index]);
1339 } else { 1339 } else {
1340 *pDestPixel++ = index; 1340 *pDestPixel++ = index;
1341 *pDestPixel++ = index; 1341 *pDestPixel++ = index;
1342 *pDestPixel++ = index; 1342 *pDestPixel++ = index;
1343 } 1343 }
1344 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || 1344 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin ||
1345 index > m_pCompData[0].m_ColorKeyMax) 1345 index > m_pCompData[0].m_ColorKeyMax)
1346 ? 0xFF 1346 ? 0xFF
1347 : 0; 1347 : 0;
1348 } 1348 }
1349 return; 1349 return;
1350 } 1350 }
1351 for (int i = 0; i < clip_width; i++) { 1351 for (int i = 0; i < clip_width; i++) {
1352 FX_DWORD src_x = (clip_left + i) * src_width / dest_width; 1352 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1353 if (bFlipX) { 1353 if (bFlipX) {
1354 src_x = src_width - src_x - 1; 1354 src_x = src_width - src_x - 1;
1355 } 1355 }
1356 src_x %= src_width; 1356 src_x %= src_width;
1357 uint8_t index = pSrcLine[src_x]; 1357 uint8_t index = pSrcLine[src_x];
1358 if (dest_Bpp == 1) { 1358 if (dest_Bpp == 1) {
1359 dest_scan[i] = index; 1359 dest_scan[i] = index;
1360 } else { 1360 } else {
1361 int dest_pos = i * dest_Bpp; 1361 int dest_pos = i * dest_Bpp;
1362 FX_ARGB argb = m_pPalette[index]; 1362 FX_ARGB argb = m_pPalette[index];
1363 dest_scan[dest_pos] = FXARGB_B(argb); 1363 dest_scan[dest_pos] = FXARGB_B(argb);
1364 dest_scan[dest_pos + 1] = FXARGB_G(argb); 1364 dest_scan[dest_pos + 1] = FXARGB_G(argb);
1365 dest_scan[dest_pos + 2] = FXARGB_R(argb); 1365 dest_scan[dest_pos + 2] = FXARGB_R(argb);
1366 } 1366 }
1367 } 1367 }
1368 } 1368 }
1369 1369
1370 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp, 1370 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp,
1371 int dest_Bpp, 1371 int dest_Bpp,
1372 FX_DWORD src_width, 1372 uint32_t src_width,
1373 const uint8_t* pSrcLine, 1373 const uint8_t* pSrcLine,
1374 uint8_t* dest_scan, 1374 uint8_t* dest_scan,
1375 int dest_width, 1375 int dest_width,
1376 FX_BOOL bFlipX, 1376 FX_BOOL bFlipX,
1377 int clip_left, 1377 int clip_left,
1378 int clip_width) const { 1378 int clip_width) const {
1379 // last_src_x used to store the last seen src_x position which should be 1379 // last_src_x used to store the last seen src_x position which should be
1380 // in [0, src_width). Set the initial value to be an invalid src_x value. 1380 // in [0, src_width). Set the initial value to be an invalid src_x value.
1381 FX_DWORD last_src_x = src_width; 1381 uint32_t last_src_x = src_width;
1382 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF); 1382 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF);
1383 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); 1383 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1);
1384 for (int i = 0; i < clip_width; i++) { 1384 for (int i = 0; i < clip_width; i++) {
1385 int dest_x = clip_left + i; 1385 int dest_x = clip_left + i;
1386 FX_DWORD src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * 1386 uint32_t src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) *
1387 (int64_t)src_width / dest_width; 1387 (int64_t)src_width / dest_width;
1388 src_x %= src_width; 1388 src_x %= src_width;
1389 1389
1390 uint8_t* pDestPixel = dest_scan + i * dest_Bpp; 1390 uint8_t* pDestPixel = dest_scan + i * dest_Bpp;
1391 FX_ARGB argb; 1391 FX_ARGB argb;
1392 if (src_x == last_src_x) { 1392 if (src_x == last_src_x) {
1393 argb = last_argb; 1393 argb = last_argb;
1394 } else { 1394 } else {
1395 CFX_FixedBufGrow<uint8_t, 128> extracted_components(m_nComponents); 1395 CFX_FixedBufGrow<uint8_t, 128> extracted_components(m_nComponents);
1396 const uint8_t* pSrcPixel = nullptr; 1396 const uint8_t* pSrcPixel = nullptr;
1397 if (m_bpc % 8 != 0) { 1397 if (m_bpc % 8 != 0) {
1398 // No need to check for 32-bit overflow, as |src_x| is bounded by 1398 // No need to check for 32-bit overflow, as |src_x| is bounded by
1399 // |src_width| and DownSampleScanline() already checked for overflow 1399 // |src_width| and DownSampleScanline() already checked for overflow
1400 // with the pitch calculation. 1400 // with the pitch calculation.
1401 size_t num_bits = src_x * m_bpc * m_nComponents; 1401 size_t num_bits = src_x * m_bpc * m_nComponents;
1402 uint64_t src_bit_pos = num_bits % 8; 1402 uint64_t src_bit_pos = num_bits % 8;
1403 pSrcPixel = pSrcLine + num_bits / 8; 1403 pSrcPixel = pSrcLine + num_bits / 8;
1404 for (FX_DWORD j = 0; j < m_nComponents; ++j) { 1404 for (uint32_t j = 0; j < m_nComponents; ++j) {
1405 extracted_components[j] = static_cast<uint8_t>( 1405 extracted_components[j] = static_cast<uint8_t>(
1406 GetBits8(pSrcPixel, src_bit_pos, m_bpc) * unit_To8Bpc); 1406 GetBits8(pSrcPixel, src_bit_pos, m_bpc) * unit_To8Bpc);
1407 src_bit_pos += m_bpc; 1407 src_bit_pos += m_bpc;
1408 } 1408 }
1409 pSrcPixel = extracted_components; 1409 pSrcPixel = extracted_components;
1410 } else { 1410 } else {
1411 pSrcPixel = pSrcLine + src_x * orig_Bpp; 1411 pSrcPixel = pSrcLine + src_x * orig_Bpp;
1412 if (m_bpc == 16) { 1412 if (m_bpc == 16) {
1413 for (FX_DWORD j = 0; j < m_nComponents; ++j) 1413 for (uint32_t j = 0; j < m_nComponents; ++j)
1414 extracted_components[j] = pSrcPixel[j * 2]; 1414 extracted_components[j] = pSrcPixel[j * 2];
1415 pSrcPixel = extracted_components; 1415 pSrcPixel = extracted_components;
1416 } 1416 }
1417 } 1417 }
1418 1418
1419 if (m_pColorSpace) { 1419 if (m_pColorSpace) {
1420 uint8_t color[4]; 1420 uint8_t color[4];
1421 const FX_BOOL bTransMask = TransMask(); 1421 const FX_BOOL bTransMask = TransMask();
1422 if (m_bDefaultDecode) { 1422 if (m_bDefaultDecode) {
1423 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0, 1423 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0,
1424 bTransMask); 1424 bTransMask);
1425 } else { 1425 } else {
1426 for (FX_DWORD j = 0; j < m_nComponents; ++j) { 1426 for (uint32_t j = 0; j < m_nComponents; ++j) {
1427 FX_FLOAT component_value = 1427 FX_FLOAT component_value =
1428 static_cast<FX_FLOAT>(extracted_components[j]); 1428 static_cast<FX_FLOAT>(extracted_components[j]);
1429 int color_value = static_cast<int>( 1429 int color_value = static_cast<int>(
1430 (m_pCompData[j].m_DecodeMin + 1430 (m_pCompData[j].m_DecodeMin +
1431 m_pCompData[j].m_DecodeStep * component_value) * 1431 m_pCompData[j].m_DecodeStep * component_value) *
1432 255.0f + 1432 255.0f +
1433 0.5f); 1433 0.5f);
1434 extracted_components[j] = 1434 extracted_components[j] =
1435 color_value > 255 ? 255 : (color_value < 0 ? 0 : color_value); 1435 color_value > 255 ? 255 : (color_value < 0 ? 0 : color_value);
1436 } 1436 }
(...skipping 16 matching lines...) Expand all
1453 ? 0xFF 1453 ? 0xFF
1454 : 0; 1454 : 0;
1455 } 1455 }
1456 argb &= 0xFFFFFF; 1456 argb &= 0xFFFFFF;
1457 argb |= alpha << 24; 1457 argb |= alpha << 24;
1458 } 1458 }
1459 last_src_x = src_x; 1459 last_src_x = src_x;
1460 last_argb = argb; 1460 last_argb = argb;
1461 } 1461 }
1462 if (dest_Bpp == 4) { 1462 if (dest_Bpp == 4) {
1463 *reinterpret_cast<FX_DWORD*>(pDestPixel) = FXARGB_TODIB(argb); 1463 *reinterpret_cast<uint32_t*>(pDestPixel) = FXARGB_TODIB(argb);
1464 } else { 1464 } else {
1465 *pDestPixel++ = FXARGB_B(argb); 1465 *pDestPixel++ = FXARGB_B(argb);
1466 *pDestPixel++ = FXARGB_G(argb); 1466 *pDestPixel++ = FXARGB_G(argb);
1467 *pDestPixel = FXARGB_R(argb); 1467 *pDestPixel = FXARGB_R(argb);
1468 } 1468 }
1469 } 1469 }
1470 } 1470 }
1471 1471
1472 FX_BOOL CPDF_DIBSource::TransMask() const { 1472 FX_BOOL CPDF_DIBSource::TransMask() const {
1473 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && 1473 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK &&
(...skipping 19 matching lines...) Expand all
1493 m_pCache = nullptr; 1493 m_pCache = nullptr;
1494 m_pImage = nullptr; 1494 m_pImage = nullptr;
1495 } 1495 }
1496 1496
1497 CPDF_ImageLoaderHandle::~CPDF_ImageLoaderHandle() {} 1497 CPDF_ImageLoaderHandle::~CPDF_ImageLoaderHandle() {}
1498 1498
1499 FX_BOOL CPDF_ImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader, 1499 FX_BOOL CPDF_ImageLoaderHandle::Start(CPDF_ImageLoader* pImageLoader,
1500 const CPDF_ImageObject* pImage, 1500 const CPDF_ImageObject* pImage,
1501 CPDF_PageRenderCache* pCache, 1501 CPDF_PageRenderCache* pCache,
1502 FX_BOOL bStdCS, 1502 FX_BOOL bStdCS,
1503 FX_DWORD GroupFamily, 1503 uint32_t GroupFamily,
1504 FX_BOOL bLoadMask, 1504 FX_BOOL bLoadMask,
1505 CPDF_RenderStatus* pRenderStatus, 1505 CPDF_RenderStatus* pRenderStatus,
1506 int32_t nDownsampleWidth, 1506 int32_t nDownsampleWidth,
1507 int32_t nDownsampleHeight) { 1507 int32_t nDownsampleHeight) {
1508 m_pImageLoader = pImageLoader; 1508 m_pImageLoader = pImageLoader;
1509 m_pCache = pCache; 1509 m_pCache = pCache;
1510 m_pImage = const_cast<CPDF_ImageObject*>(pImage); 1510 m_pImage = const_cast<CPDF_ImageObject*>(pImage);
1511 m_nDownsampleWidth = nDownsampleWidth; 1511 m_nDownsampleWidth = nDownsampleWidth;
1512 m_nDownsampleHeight = nDownsampleHeight; 1512 m_nDownsampleHeight = nDownsampleHeight;
1513 FX_BOOL ret; 1513 FX_BOOL ret;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor; 1558 m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor;
1559 } 1559 }
1560 } 1560 }
1561 return ret; 1561 return ret;
1562 } 1562 }
1563 1563
1564 FX_BOOL CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage, 1564 FX_BOOL CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
1565 CPDF_PageRenderCache* pCache, 1565 CPDF_PageRenderCache* pCache,
1566 CPDF_ImageLoaderHandle*& LoadHandle, 1566 CPDF_ImageLoaderHandle*& LoadHandle,
1567 FX_BOOL bStdCS, 1567 FX_BOOL bStdCS,
1568 FX_DWORD GroupFamily, 1568 uint32_t GroupFamily,
1569 FX_BOOL bLoadMask, 1569 FX_BOOL bLoadMask,
1570 CPDF_RenderStatus* pRenderStatus, 1570 CPDF_RenderStatus* pRenderStatus,
1571 int32_t nDownsampleWidth, 1571 int32_t nDownsampleWidth,
1572 int32_t nDownsampleHeight) { 1572 int32_t nDownsampleHeight) {
1573 m_nDownsampleWidth = nDownsampleWidth; 1573 m_nDownsampleWidth = nDownsampleWidth;
1574 m_nDownsampleHeight = nDownsampleHeight; 1574 m_nDownsampleHeight = nDownsampleHeight;
1575 LoadHandle = new CPDF_ImageLoaderHandle; 1575 LoadHandle = new CPDF_ImageLoaderHandle;
1576 return LoadHandle->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, 1576 return LoadHandle->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask,
1577 pRenderStatus, m_nDownsampleWidth, 1577 pRenderStatus, m_nDownsampleWidth,
1578 m_nDownsampleHeight); 1578 m_nDownsampleHeight);
1579 } 1579 }
1580 1580
1581 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, 1581 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle,
1582 IFX_Pause* pPause) { 1582 IFX_Pause* pPause) {
1583 return LoadHandle->Continue(pPause); 1583 return LoadHandle->Continue(pPause);
1584 } 1584 }
1585 1585
1586 CPDF_ImageLoader::~CPDF_ImageLoader() { 1586 CPDF_ImageLoader::~CPDF_ImageLoader() {
1587 if (!m_bCached) { 1587 if (!m_bCached) {
1588 delete m_pBitmap; 1588 delete m_pBitmap;
1589 delete m_pMask; 1589 delete m_pMask;
1590 } 1590 }
1591 } 1591 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render_image.cpp ('k') | core/fpdfapi/fpdf_render/fpdf_render_pattern.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698