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

Side by Side Diff: core/fxge/dib/fx_dib_convert.cpp

Issue 2149903002: Use smart pointers for various Jbig2 decoding contexts (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 5 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/fxcodec/include/fx_codec.h" 7 #include "core/fxcodec/include/fx_codec.h"
8 #include "core/fxge/include/fx_dib.h" 8 #include "core/fxge/include/fx_dib.h"
9 #include "core/fxge/include/fx_ge.h" 9 #include "core/fxge/include/fx_ge.h"
10 10
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 642 }
643 643
644 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, 644 FX_BOOL ConvertBuffer(FXDIB_Format dest_format,
645 uint8_t* dest_buf, 645 uint8_t* dest_buf,
646 int dest_pitch, 646 int dest_pitch,
647 int width, 647 int width,
648 int height, 648 int height,
649 const CFX_DIBSource* pSrcBitmap, 649 const CFX_DIBSource* pSrcBitmap,
650 int src_left, 650 int src_left,
651 int src_top, 651 int src_top,
652 uint32_t*& d_pal) { 652 std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
653 FXDIB_Format src_format = pSrcBitmap->GetFormat(); 653 FXDIB_Format src_format = pSrcBitmap->GetFormat();
654 switch (dest_format) { 654 switch (dest_format) {
655 case FXDIB_Invalid: 655 case FXDIB_Invalid:
656 case FXDIB_1bppCmyk: 656 case FXDIB_1bppCmyk:
657 case FXDIB_1bppMask: 657 case FXDIB_1bppMask:
658 case FXDIB_1bppRgb: 658 case FXDIB_1bppRgb:
659 ASSERT(FALSE); 659 ASSERT(FALSE);
660 return FALSE; 660 return FALSE;
661 case FXDIB_8bppMask: { 661 case FXDIB_8bppMask: {
662 if ((src_format & 0xff) == 1) { 662 if ((src_format & 0xff) == 1) {
(...skipping 15 matching lines...) Expand all
678 if ((src_format & 0xff) >= 24) { 678 if ((src_format & 0xff) >= 24) {
679 return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height, 679 return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
680 pSrcBitmap, src_left, src_top); 680 pSrcBitmap, src_left, src_top);
681 } 681 }
682 return FALSE; 682 return FALSE;
683 } 683 }
684 case FXDIB_8bppRgb: 684 case FXDIB_8bppRgb:
685 case FXDIB_8bppRgba: { 685 case FXDIB_8bppRgba: {
686 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { 686 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) {
687 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, 687 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
688 height, pSrcBitmap, src_left, src_top, d_pal); 688 height, pSrcBitmap, src_left, src_top, p_pal);
689 } 689 }
690 d_pal = FX_Alloc(uint32_t, 256); 690 p_pal->reset(FX_Alloc(uint32_t, 256));
691 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && 691 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) &&
692 pSrcBitmap->GetPalette()) { 692 pSrcBitmap->GetPalette()) {
693 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, 693 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
694 pSrcBitmap, src_left, src_top, d_pal); 694 pSrcBitmap, src_left, src_top,
695 p_pal->get());
695 } 696 }
696 if ((src_format & 0xff) >= 24) { 697 if ((src_format & 0xff) >= 24) {
697 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height, 698 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
698 pSrcBitmap, src_left, src_top, d_pal); 699 pSrcBitmap, src_left, src_top,
700 p_pal->get());
699 } 701 }
700 return FALSE; 702 return FALSE;
701 } 703 }
702 case FXDIB_Rgb: 704 case FXDIB_Rgb:
703 case FXDIB_Rgba: { 705 case FXDIB_Rgba: {
704 if ((src_format & 0xff) == 1) { 706 if ((src_format & 0xff) == 1) {
705 if (pSrcBitmap->GetPalette()) { 707 if (pSrcBitmap->GetPalette()) {
706 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, 708 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
707 width, height, pSrcBitmap, src_left, 709 width, height, pSrcBitmap, src_left,
708 src_top); 710 src_top);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 ret = pClone->CopyAlphaMask(pSrcAlpha); 795 ret = pClone->CopyAlphaMask(pSrcAlpha);
794 } 796 }
795 } 797 }
796 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { 798 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
797 delete pSrcAlpha; 799 delete pSrcAlpha;
798 pSrcAlpha = nullptr; 800 pSrcAlpha = nullptr;
799 } 801 }
800 if (!ret) 802 if (!ret)
801 return nullptr; 803 return nullptr;
802 804
803 uint32_t* pal_8bpp = nullptr; 805 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
804 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), 806 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
805 m_Width, m_Height, this, 0, 0, pal_8bpp)) { 807 m_Width, m_Height, this, 0, 0, &pal_8bpp)) {
806 FX_Free(pal_8bpp);
807 return nullptr; 808 return nullptr;
808 } 809 }
809 if (pal_8bpp) { 810 if (pal_8bpp)
810 pClone->CopyPalette(pal_8bpp); 811 pClone->CopyPalette(pal_8bpp.get());
811 FX_Free(pal_8bpp);
812 }
813 return pClone.release(); 812 return pClone.release();
814 } 813 }
815 814
816 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { 815 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
817 FXDIB_Format src_format = GetFormat(); 816 FXDIB_Format src_format = GetFormat();
818 if (dest_format == src_format) 817 if (dest_format == src_format)
819 return TRUE; 818 return TRUE;
820 819
821 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && 820 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
822 !m_pPalette) { 821 !m_pPalette) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 return FALSE; 866 return FALSE;
868 } 867 }
869 pAlphaMask = m_pAlphaMask; 868 pAlphaMask = m_pAlphaMask;
870 m_pAlphaMask = nullptr; 869 m_pAlphaMask = nullptr;
871 } else { 870 } else {
872 pAlphaMask = m_pAlphaMask; 871 pAlphaMask = m_pAlphaMask;
873 } 872 }
874 } 873 }
875 } 874 }
876 FX_BOOL ret = FALSE; 875 FX_BOOL ret = FALSE;
877 uint32_t* pal_8bpp = nullptr; 876 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
878 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, 877 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
879 this, 0, 0, pal_8bpp); 878 this, 0, 0, &pal_8bpp);
880 if (!ret) { 879 if (!ret) {
881 FX_Free(pal_8bpp); 880 if (pAlphaMask != m_pAlphaMask)
882 if (pAlphaMask != m_pAlphaMask) {
883 delete pAlphaMask; 881 delete pAlphaMask;
884 }
885 FX_Free(dest_buf); 882 FX_Free(dest_buf);
886 return FALSE; 883 return FALSE;
887 } 884 }
888 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { 885 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) {
889 delete m_pAlphaMask; 886 delete m_pAlphaMask;
890 } 887 }
891 m_pAlphaMask = pAlphaMask; 888 m_pAlphaMask = pAlphaMask;
892 FX_Free(m_pPalette); 889 m_pPalette.reset(pal_8bpp.release());
Lei Zhang 2016/07/18 23:55:10 std::move?
Wei Li 2016/07/19 21:21:29 Done.
893 m_pPalette = pal_8bpp;
894 if (!m_bExtBuf) { 890 if (!m_bExtBuf) {
895 FX_Free(m_pBuffer); 891 FX_Free(m_pBuffer);
896 } 892 }
897 m_bExtBuf = FALSE; 893 m_bExtBuf = FALSE;
898 m_pBuffer = dest_buf; 894 m_pBuffer = dest_buf;
899 m_bpp = (uint8_t)dest_format; 895 m_bpp = (uint8_t)dest_format;
900 m_AlphaFlag = (uint8_t)(dest_format >> 8); 896 m_AlphaFlag = (uint8_t)(dest_format >> 8);
901 m_Pitch = dest_pitch; 897 m_Pitch = dest_pitch;
902 return TRUE; 898 return TRUE;
903 } 899 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698