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

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

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: s/NULL/nullptr/ Created 4 years, 6 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 uint8_t r; 74 uint8_t r;
75 uint8_t g; 75 uint8_t g;
76 uint8_t b; 76 uint8_t b;
77 _ColorDecode(color, r, g, b); 77 _ColorDecode(color, r, g, b);
78 dest_pal[row] = ((uint32_t)r << 16) | ((uint32_t)g << 8) | b | 0xff000000; 78 dest_pal[row] = ((uint32_t)r << 16) | ((uint32_t)g << 8) | b | 0xff000000;
79 aLut[lut_offset] = row; 79 aLut[lut_offset] = row;
80 } 80 }
81 } 81 }
82 82
83 CFX_Palette::CFX_Palette() { 83 CFX_Palette::CFX_Palette() {
84 m_pPalette = NULL; 84 m_pPalette = nullptr;
85 m_cLut = NULL; 85 m_cLut = nullptr;
86 m_aLut = NULL; 86 m_aLut = nullptr;
87 m_lut = 0; 87 m_lut = 0;
88 } 88 }
89 CFX_Palette::~CFX_Palette() { 89 CFX_Palette::~CFX_Palette() {
90 FX_Free(m_pPalette); 90 FX_Free(m_pPalette);
91 FX_Free(m_cLut); 91 FX_Free(m_cLut);
92 FX_Free(m_aLut); 92 FX_Free(m_aLut);
93 m_lut = 0; 93 m_lut = 0;
94 } 94 }
95 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) { 95 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) {
96 if (!pBitmap) { 96 if (!pBitmap) {
97 return FALSE; 97 return FALSE;
98 } 98 }
99 FX_Free(m_pPalette); 99 FX_Free(m_pPalette);
100 m_pPalette = FX_Alloc(uint32_t, 256); 100 m_pPalette = FX_Alloc(uint32_t, 256);
101 int bpp = pBitmap->GetBPP() / 8; 101 int bpp = pBitmap->GetBPP() / 8;
102 int width = pBitmap->GetWidth(); 102 int width = pBitmap->GetWidth();
103 int height = pBitmap->GetHeight(); 103 int height = pBitmap->GetHeight();
104 FX_Free(m_cLut); 104 FX_Free(m_cLut);
105 m_cLut = NULL; 105 m_cLut = nullptr;
106 FX_Free(m_aLut); 106 FX_Free(m_aLut);
107 m_aLut = NULL; 107 m_aLut = nullptr;
108 m_cLut = FX_Alloc(uint32_t, 4096); 108 m_cLut = FX_Alloc(uint32_t, 4096);
109 m_aLut = FX_Alloc(uint32_t, 4096); 109 m_aLut = FX_Alloc(uint32_t, 4096);
110 int row, col; 110 int row, col;
111 m_lut = 0; 111 m_lut = 0;
112 for (row = 0; row < height; row++) { 112 for (row = 0; row < height; row++) {
113 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row); 113 uint8_t* scan_line = (uint8_t*)pBitmap->GetScanline(row);
114 for (col = 0; col < width; col++) { 114 for (col = 0; col < width; col++) {
115 uint8_t* src_port = scan_line + col * bpp; 115 uint8_t* src_port = scan_line + col * bpp;
116 uint32_t b = src_port[0] & 0xf0; 116 uint32_t b = src_port[0] & 0xf0;
117 uint32_t g = src_port[1] & 0xf0; 117 uint32_t g = src_port[1] & 0xf0;
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 int width, 815 int width,
816 int height, 816 int height,
817 const CFX_DIBSource* pSrcBitmap, 817 const CFX_DIBSource* pSrcBitmap,
818 int src_left, 818 int src_left,
819 int src_top, 819 int src_top,
820 uint32_t*& d_pal, 820 uint32_t*& d_pal,
821 void* pIccTransform) { 821 void* pIccTransform) {
822 FXDIB_Format src_format = pSrcBitmap->GetFormat(); 822 FXDIB_Format src_format = pSrcBitmap->GetFormat();
823 if (!CFX_GEModule::Get()->GetCodecModule() || 823 if (!CFX_GEModule::Get()->GetCodecModule() ||
824 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { 824 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
825 pIccTransform = NULL; 825 pIccTransform = nullptr;
826 } 826 }
827 switch (dest_format) { 827 switch (dest_format) {
828 case FXDIB_Invalid: 828 case FXDIB_Invalid:
829 case FXDIB_1bppCmyk: 829 case FXDIB_1bppCmyk:
830 case FXDIB_1bppMask: 830 case FXDIB_1bppMask:
831 case FXDIB_1bppRgb: 831 case FXDIB_1bppRgb:
832 ASSERT(FALSE); 832 ASSERT(FALSE);
833 return FALSE; 833 return FALSE;
834 case FXDIB_8bppMask: { 834 case FXDIB_8bppMask: {
835 if ((src_format & 0xff) == 1) { 835 if ((src_format & 0xff) == 1) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 952 }
953 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, 953 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format,
954 const FX_RECT* pClip, 954 const FX_RECT* pClip,
955 void* pIccTransform) const { 955 void* pIccTransform) const {
956 if (dest_format == GetFormat() && !pIccTransform) { 956 if (dest_format == GetFormat() && !pIccTransform) {
957 return Clone(pClip); 957 return Clone(pClip);
958 } 958 }
959 if (pClip) { 959 if (pClip) {
960 CFX_DIBitmap* pClone = Clone(pClip); 960 CFX_DIBitmap* pClone = Clone(pClip);
961 if (!pClone) { 961 if (!pClone) {
962 return NULL; 962 return nullptr;
963 } 963 }
964 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { 964 if (!pClone->ConvertFormat(dest_format, pIccTransform)) {
965 delete pClone; 965 delete pClone;
966 return NULL; 966 return nullptr;
967 } 967 }
968 return pClone; 968 return pClone;
969 } 969 }
970 CFX_DIBitmap* pClone = new CFX_DIBitmap; 970 CFX_DIBitmap* pClone = new CFX_DIBitmap;
971 if (!pClone->Create(m_Width, m_Height, dest_format)) { 971 if (!pClone->Create(m_Width, m_Height, dest_format)) {
972 delete pClone; 972 delete pClone;
973 return NULL; 973 return nullptr;
974 } 974 }
975 FX_BOOL ret = TRUE; 975 FX_BOOL ret = TRUE;
976 CFX_DIBitmap* pSrcAlpha = NULL; 976 CFX_DIBitmap* pSrcAlpha = nullptr;
977 if (HasAlpha()) { 977 if (HasAlpha()) {
978 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; 978 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
979 if (!pSrcAlpha) { 979 if (!pSrcAlpha) {
980 delete pClone; 980 delete pClone;
981 return NULL; 981 return nullptr;
982 } 982 }
983 } 983 }
984 if (dest_format & 0x0200) { 984 if (dest_format & 0x0200) {
985 if (dest_format == FXDIB_Argb) { 985 if (dest_format == FXDIB_Argb) {
986 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) 986 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
987 : pClone->LoadChannel(FXDIB_Alpha, 0xff); 987 : pClone->LoadChannel(FXDIB_Alpha, 0xff);
988 } else { 988 } else {
989 ret = pClone->CopyAlphaMask(pSrcAlpha); 989 ret = pClone->CopyAlphaMask(pSrcAlpha);
990 } 990 }
991 } 991 }
992 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { 992 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
993 delete pSrcAlpha; 993 delete pSrcAlpha;
994 pSrcAlpha = NULL; 994 pSrcAlpha = nullptr;
995 } 995 }
996 if (!ret) { 996 if (!ret) {
997 delete pClone; 997 delete pClone;
998 return NULL; 998 return nullptr;
999 } 999 }
1000 uint32_t* pal_8bpp = NULL; 1000 uint32_t* pal_8bpp = nullptr;
1001 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), 1001 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
1002 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); 1002 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform);
1003 if (!ret) { 1003 if (!ret) {
1004 FX_Free(pal_8bpp); 1004 FX_Free(pal_8bpp);
1005 delete pClone; 1005 delete pClone;
1006 return NULL; 1006 return nullptr;
1007 } 1007 }
1008 if (pal_8bpp) { 1008 if (pal_8bpp) {
1009 pClone->CopyPalette(pal_8bpp); 1009 pClone->CopyPalette(pal_8bpp);
1010 FX_Free(pal_8bpp); 1010 FX_Free(pal_8bpp);
1011 pal_8bpp = NULL; 1011 pal_8bpp = nullptr;
1012 } 1012 }
1013 return pClone; 1013 return pClone;
1014 } 1014 }
1015 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, 1015 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format,
1016 void* pIccTransform) { 1016 void* pIccTransform) {
1017 FXDIB_Format src_format = GetFormat(); 1017 FXDIB_Format src_format = GetFormat();
1018 if (dest_format == src_format && !pIccTransform) { 1018 if (dest_format == src_format && !pIccTransform) {
1019 return TRUE; 1019 return TRUE;
1020 } 1020 }
1021 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && 1021 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
(...skipping 12 matching lines...) Expand all
1034 } 1034 }
1035 } 1035 }
1036 return TRUE; 1036 return TRUE;
1037 } 1037 }
1038 int dest_bpp = dest_format & 0xff; 1038 int dest_bpp = dest_format & 0xff;
1039 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; 1039 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
1040 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); 1040 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
1041 if (!dest_buf) { 1041 if (!dest_buf) {
1042 return FALSE; 1042 return FALSE;
1043 } 1043 }
1044 CFX_DIBitmap* pAlphaMask = NULL; 1044 CFX_DIBitmap* pAlphaMask = nullptr;
1045 if (dest_format == FXDIB_Argb) { 1045 if (dest_format == FXDIB_Argb) {
1046 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); 1046 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
1047 if (m_pAlphaMask) { 1047 if (m_pAlphaMask) {
1048 for (int row = 0; row < m_Height; row++) { 1048 for (int row = 0; row < m_Height; row++) {
1049 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; 1049 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3;
1050 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); 1050 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
1051 for (int col = 0; col < m_Width; col++) { 1051 for (int col = 0; col < m_Width; col++) {
1052 *pDstScanline = *pSrcScanline++; 1052 *pDstScanline = *pSrcScanline++;
1053 pDstScanline += 4; 1053 pDstScanline += 4;
1054 } 1054 }
1055 } 1055 }
1056 } 1056 }
1057 } else if (dest_format & 0x0200) { 1057 } else if (dest_format & 0x0200) {
1058 if (src_format == FXDIB_Argb) { 1058 if (src_format == FXDIB_Argb) {
1059 pAlphaMask = GetAlphaMask(); 1059 pAlphaMask = GetAlphaMask();
1060 if (!pAlphaMask) { 1060 if (!pAlphaMask) {
1061 FX_Free(dest_buf); 1061 FX_Free(dest_buf);
1062 return FALSE; 1062 return FALSE;
1063 } 1063 }
1064 } else { 1064 } else {
1065 if (!m_pAlphaMask) { 1065 if (!m_pAlphaMask) {
1066 if (!BuildAlphaMask()) { 1066 if (!BuildAlphaMask()) {
1067 FX_Free(dest_buf); 1067 FX_Free(dest_buf);
1068 return FALSE; 1068 return FALSE;
1069 } 1069 }
1070 pAlphaMask = m_pAlphaMask; 1070 pAlphaMask = m_pAlphaMask;
1071 m_pAlphaMask = NULL; 1071 m_pAlphaMask = nullptr;
1072 } else { 1072 } else {
1073 pAlphaMask = m_pAlphaMask; 1073 pAlphaMask = m_pAlphaMask;
1074 } 1074 }
1075 } 1075 }
1076 } 1076 }
1077 FX_BOOL ret = FALSE; 1077 FX_BOOL ret = FALSE;
1078 uint32_t* pal_8bpp = NULL; 1078 uint32_t* pal_8bpp = nullptr;
1079 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, 1079 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
1080 this, 0, 0, pal_8bpp, pIccTransform); 1080 this, 0, 0, pal_8bpp, pIccTransform);
1081 if (!ret) { 1081 if (!ret) {
1082 FX_Free(pal_8bpp); 1082 FX_Free(pal_8bpp);
1083 if (pAlphaMask != m_pAlphaMask) { 1083 if (pAlphaMask != m_pAlphaMask) {
1084 delete pAlphaMask; 1084 delete pAlphaMask;
1085 } 1085 }
1086 FX_Free(dest_buf); 1086 FX_Free(dest_buf);
1087 return FALSE; 1087 return FALSE;
1088 } 1088 }
1089 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { 1089 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) {
1090 delete m_pAlphaMask; 1090 delete m_pAlphaMask;
1091 } 1091 }
1092 m_pAlphaMask = pAlphaMask; 1092 m_pAlphaMask = pAlphaMask;
1093 FX_Free(m_pPalette); 1093 FX_Free(m_pPalette);
1094 m_pPalette = pal_8bpp; 1094 m_pPalette = pal_8bpp;
1095 if (!m_bExtBuf) { 1095 if (!m_bExtBuf) {
1096 FX_Free(m_pBuffer); 1096 FX_Free(m_pBuffer);
1097 } 1097 }
1098 m_bExtBuf = FALSE; 1098 m_bExtBuf = FALSE;
1099 m_pBuffer = dest_buf; 1099 m_pBuffer = dest_buf;
1100 m_bpp = (uint8_t)dest_format; 1100 m_bpp = (uint8_t)dest_format;
1101 m_AlphaFlag = (uint8_t)(dest_format >> 8); 1101 m_AlphaFlag = (uint8_t)(dest_format >> 8);
1102 m_Pitch = dest_pitch; 1102 m_Pitch = dest_pitch;
1103 return TRUE; 1103 return TRUE;
1104 } 1104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698