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/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 Loading... |
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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 int width, | 814 int width, |
815 int height, | 815 int height, |
816 const CFX_DIBSource* pSrcBitmap, | 816 const CFX_DIBSource* pSrcBitmap, |
817 int src_left, | 817 int src_left, |
818 int src_top, | 818 int src_top, |
819 uint32_t*& d_pal, | 819 uint32_t*& d_pal, |
820 void* pIccTransform) { | 820 void* pIccTransform) { |
821 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | 821 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
822 if (!CFX_GEModule::Get()->GetCodecModule() || | 822 if (!CFX_GEModule::Get()->GetCodecModule() || |
823 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | 823 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
824 pIccTransform = NULL; | 824 pIccTransform = nullptr; |
825 } | 825 } |
826 switch (dest_format) { | 826 switch (dest_format) { |
827 case FXDIB_Invalid: | 827 case FXDIB_Invalid: |
828 case FXDIB_1bppCmyk: | 828 case FXDIB_1bppCmyk: |
829 case FXDIB_1bppMask: | 829 case FXDIB_1bppMask: |
830 case FXDIB_1bppRgb: | 830 case FXDIB_1bppRgb: |
831 ASSERT(FALSE); | 831 ASSERT(FALSE); |
832 return FALSE; | 832 return FALSE; |
833 case FXDIB_8bppMask: { | 833 case FXDIB_8bppMask: { |
834 if ((src_format & 0xff) == 1) { | 834 if ((src_format & 0xff) == 1) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 } | 951 } |
952 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, | 952 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, |
953 const FX_RECT* pClip, | 953 const FX_RECT* pClip, |
954 void* pIccTransform) const { | 954 void* pIccTransform) const { |
955 if (dest_format == GetFormat() && !pIccTransform) { | 955 if (dest_format == GetFormat() && !pIccTransform) { |
956 return Clone(pClip); | 956 return Clone(pClip); |
957 } | 957 } |
958 if (pClip) { | 958 if (pClip) { |
959 CFX_DIBitmap* pClone = Clone(pClip); | 959 CFX_DIBitmap* pClone = Clone(pClip); |
960 if (!pClone) { | 960 if (!pClone) { |
961 return NULL; | 961 return nullptr; |
962 } | 962 } |
963 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { | 963 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { |
964 delete pClone; | 964 delete pClone; |
965 return NULL; | 965 return nullptr; |
966 } | 966 } |
967 return pClone; | 967 return pClone; |
968 } | 968 } |
969 CFX_DIBitmap* pClone = new CFX_DIBitmap; | 969 CFX_DIBitmap* pClone = new CFX_DIBitmap; |
970 if (!pClone->Create(m_Width, m_Height, dest_format)) { | 970 if (!pClone->Create(m_Width, m_Height, dest_format)) { |
971 delete pClone; | 971 delete pClone; |
972 return NULL; | 972 return nullptr; |
973 } | 973 } |
974 FX_BOOL ret = TRUE; | 974 FX_BOOL ret = TRUE; |
975 CFX_DIBitmap* pSrcAlpha = NULL; | 975 CFX_DIBitmap* pSrcAlpha = nullptr; |
976 if (HasAlpha()) { | 976 if (HasAlpha()) { |
977 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | 977 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; |
978 if (!pSrcAlpha) { | 978 if (!pSrcAlpha) { |
979 delete pClone; | 979 delete pClone; |
980 return NULL; | 980 return nullptr; |
981 } | 981 } |
982 } | 982 } |
983 if (dest_format & 0x0200) { | 983 if (dest_format & 0x0200) { |
984 if (dest_format == FXDIB_Argb) { | 984 if (dest_format == FXDIB_Argb) { |
985 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) | 985 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) |
986 : pClone->LoadChannel(FXDIB_Alpha, 0xff); | 986 : pClone->LoadChannel(FXDIB_Alpha, 0xff); |
987 } else { | 987 } else { |
988 ret = pClone->CopyAlphaMask(pSrcAlpha); | 988 ret = pClone->CopyAlphaMask(pSrcAlpha); |
989 } | 989 } |
990 } | 990 } |
991 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { | 991 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { |
992 delete pSrcAlpha; | 992 delete pSrcAlpha; |
993 pSrcAlpha = NULL; | 993 pSrcAlpha = nullptr; |
994 } | 994 } |
995 if (!ret) { | 995 if (!ret) { |
996 delete pClone; | 996 delete pClone; |
997 return NULL; | 997 return nullptr; |
998 } | 998 } |
999 uint32_t* pal_8bpp = NULL; | 999 uint32_t* pal_8bpp = nullptr; |
1000 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), | 1000 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), |
1001 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); | 1001 m_Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); |
1002 if (!ret) { | 1002 if (!ret) { |
1003 FX_Free(pal_8bpp); | 1003 FX_Free(pal_8bpp); |
1004 delete pClone; | 1004 delete pClone; |
1005 return NULL; | 1005 return nullptr; |
1006 } | 1006 } |
1007 if (pal_8bpp) { | 1007 if (pal_8bpp) { |
1008 pClone->CopyPalette(pal_8bpp); | 1008 pClone->CopyPalette(pal_8bpp); |
1009 FX_Free(pal_8bpp); | 1009 FX_Free(pal_8bpp); |
1010 pal_8bpp = NULL; | 1010 pal_8bpp = nullptr; |
1011 } | 1011 } |
1012 return pClone; | 1012 return pClone; |
1013 } | 1013 } |
1014 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, | 1014 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, |
1015 void* pIccTransform) { | 1015 void* pIccTransform) { |
1016 FXDIB_Format src_format = GetFormat(); | 1016 FXDIB_Format src_format = GetFormat(); |
1017 if (dest_format == src_format && !pIccTransform) { | 1017 if (dest_format == src_format && !pIccTransform) { |
1018 return TRUE; | 1018 return TRUE; |
1019 } | 1019 } |
1020 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && | 1020 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
(...skipping 12 matching lines...) Expand all Loading... |
1033 } | 1033 } |
1034 } | 1034 } |
1035 return TRUE; | 1035 return TRUE; |
1036 } | 1036 } |
1037 int dest_bpp = dest_format & 0xff; | 1037 int dest_bpp = dest_format & 0xff; |
1038 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; | 1038 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; |
1039 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); | 1039 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); |
1040 if (!dest_buf) { | 1040 if (!dest_buf) { |
1041 return FALSE; | 1041 return FALSE; |
1042 } | 1042 } |
1043 CFX_DIBitmap* pAlphaMask = NULL; | 1043 CFX_DIBitmap* pAlphaMask = nullptr; |
1044 if (dest_format == FXDIB_Argb) { | 1044 if (dest_format == FXDIB_Argb) { |
1045 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); | 1045 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); |
1046 if (m_pAlphaMask) { | 1046 if (m_pAlphaMask) { |
1047 for (int row = 0; row < m_Height; row++) { | 1047 for (int row = 0; row < m_Height; row++) { |
1048 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; | 1048 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; |
1049 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); | 1049 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); |
1050 for (int col = 0; col < m_Width; col++) { | 1050 for (int col = 0; col < m_Width; col++) { |
1051 *pDstScanline = *pSrcScanline++; | 1051 *pDstScanline = *pSrcScanline++; |
1052 pDstScanline += 4; | 1052 pDstScanline += 4; |
1053 } | 1053 } |
1054 } | 1054 } |
1055 } | 1055 } |
1056 } else if (dest_format & 0x0200) { | 1056 } else if (dest_format & 0x0200) { |
1057 if (src_format == FXDIB_Argb) { | 1057 if (src_format == FXDIB_Argb) { |
1058 pAlphaMask = GetAlphaMask(); | 1058 pAlphaMask = GetAlphaMask(); |
1059 if (!pAlphaMask) { | 1059 if (!pAlphaMask) { |
1060 FX_Free(dest_buf); | 1060 FX_Free(dest_buf); |
1061 return FALSE; | 1061 return FALSE; |
1062 } | 1062 } |
1063 } else { | 1063 } else { |
1064 if (!m_pAlphaMask) { | 1064 if (!m_pAlphaMask) { |
1065 if (!BuildAlphaMask()) { | 1065 if (!BuildAlphaMask()) { |
1066 FX_Free(dest_buf); | 1066 FX_Free(dest_buf); |
1067 return FALSE; | 1067 return FALSE; |
1068 } | 1068 } |
1069 pAlphaMask = m_pAlphaMask; | 1069 pAlphaMask = m_pAlphaMask; |
1070 m_pAlphaMask = NULL; | 1070 m_pAlphaMask = nullptr; |
1071 } else { | 1071 } else { |
1072 pAlphaMask = m_pAlphaMask; | 1072 pAlphaMask = m_pAlphaMask; |
1073 } | 1073 } |
1074 } | 1074 } |
1075 } | 1075 } |
1076 FX_BOOL ret = FALSE; | 1076 FX_BOOL ret = FALSE; |
1077 uint32_t* pal_8bpp = NULL; | 1077 uint32_t* pal_8bpp = nullptr; |
1078 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, | 1078 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, |
1079 this, 0, 0, pal_8bpp, pIccTransform); | 1079 this, 0, 0, pal_8bpp, pIccTransform); |
1080 if (!ret) { | 1080 if (!ret) { |
1081 FX_Free(pal_8bpp); | 1081 FX_Free(pal_8bpp); |
1082 if (pAlphaMask != m_pAlphaMask) { | 1082 if (pAlphaMask != m_pAlphaMask) { |
1083 delete pAlphaMask; | 1083 delete pAlphaMask; |
1084 } | 1084 } |
1085 FX_Free(dest_buf); | 1085 FX_Free(dest_buf); |
1086 return FALSE; | 1086 return FALSE; |
1087 } | 1087 } |
1088 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { | 1088 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { |
1089 delete m_pAlphaMask; | 1089 delete m_pAlphaMask; |
1090 } | 1090 } |
1091 m_pAlphaMask = pAlphaMask; | 1091 m_pAlphaMask = pAlphaMask; |
1092 FX_Free(m_pPalette); | 1092 FX_Free(m_pPalette); |
1093 m_pPalette = pal_8bpp; | 1093 m_pPalette = pal_8bpp; |
1094 if (!m_bExtBuf) { | 1094 if (!m_bExtBuf) { |
1095 FX_Free(m_pBuffer); | 1095 FX_Free(m_pBuffer); |
1096 } | 1096 } |
1097 m_bExtBuf = FALSE; | 1097 m_bExtBuf = FALSE; |
1098 m_pBuffer = dest_buf; | 1098 m_pBuffer = dest_buf; |
1099 m_bpp = (uint8_t)dest_format; | 1099 m_bpp = (uint8_t)dest_format; |
1100 m_AlphaFlag = (uint8_t)(dest_format >> 8); | 1100 m_AlphaFlag = (uint8_t)(dest_format >> 8); |
1101 m_Pitch = dest_pitch; | 1101 m_Pitch = dest_pitch; |
1102 return TRUE; | 1102 return TRUE; |
1103 } | 1103 } |
OLD | NEW |