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 "../../../include/fxge/fx_dib.h" | 7 #include "../../../include/fxge/fx_dib.h" |
8 #include "../../../include/fxge/fx_ge.h" | 8 #include "../../../include/fxge/fx_ge.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include "dib_int.h" | 10 #include "dib_int.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return FALSE; | 78 return FALSE; |
79 } | 79 } |
80 if (pBuffer) { | 80 if (pBuffer) { |
81 m_pBuffer = pBuffer; | 81 m_pBuffer = pBuffer; |
82 m_bExtBuf = TRUE; | 82 m_bExtBuf = TRUE; |
83 } else { | 83 } else { |
84 int size = pitch * height + 4; | 84 int size = pitch * height + 4; |
85 int oomlimit = _MAX_OOM_LIMIT_; | 85 int oomlimit = _MAX_OOM_LIMIT_; |
86 if (oomlimit >= 0 && size >= oomlimit) { | 86 if (oomlimit >= 0 && size >= oomlimit) { |
87 m_pBuffer = FX_TryAlloc(FX_BYTE, size); | 87 m_pBuffer = FX_TryAlloc(FX_BYTE, size); |
88 if (m_pBuffer == NULL) { | |
89 return FALSE; | |
90 } | |
91 } else { | 88 } else { |
92 m_pBuffer = FX_Alloc(FX_BYTE, size); | 89 m_pBuffer = FX_Alloc(FX_BYTE, size); |
93 } | 90 } |
| 91 if (m_pBuffer == NULL) { |
| 92 return FALSE; |
| 93 } |
94 } | 94 } |
95 m_Width = width; | 95 m_Width = width; |
96 m_Height = height; | 96 m_Height = height; |
97 m_Pitch = pitch; | 97 m_Pitch = pitch; |
98 if (HasAlpha() && format != FXDIB_Argb) { | 98 if (HasAlpha() && format != FXDIB_Argb) { |
99 FX_BOOL ret = TRUE; | 99 FX_BOOL ret = TRUE; |
100 ret = BuildAlphaMask(); | 100 ret = BuildAlphaMask(); |
101 if (!ret) { | 101 if (!ret) { |
102 if (!m_bExtBuf && m_pBuffer) { | 102 if (!m_bExtBuf && m_pBuffer) { |
103 FX_Free(m_pBuffer); | 103 FX_Free(m_pBuffer); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 return pNewBitmap; | 196 return pNewBitmap; |
197 } | 197 } |
198 void CFX_DIBSource::BuildPalette() | 198 void CFX_DIBSource::BuildPalette() |
199 { | 199 { |
200 if (m_pPalette) { | 200 if (m_pPalette) { |
201 return; | 201 return; |
202 } | 202 } |
203 if (GetBPP() == 1) { | 203 if (GetBPP() == 1) { |
204 m_pPalette = FX_Alloc(FX_DWORD, 2); | 204 m_pPalette = FX_Alloc(FX_DWORD, 2); |
| 205 if (!m_pPalette) { |
| 206 return; |
| 207 } |
205 if(IsCmykImage()) { | 208 if(IsCmykImage()) { |
206 m_pPalette[0] = 0xff; | 209 m_pPalette[0] = 0xff; |
207 m_pPalette[1] = 0; | 210 m_pPalette[1] = 0; |
208 } else { | 211 } else { |
209 m_pPalette[0] = 0xff000000; | 212 m_pPalette[0] = 0xff000000; |
210 m_pPalette[1] = 0xffffffff; | 213 m_pPalette[1] = 0xffffffff; |
211 } | 214 } |
212 } else if (GetBPP() == 8) { | 215 } else if (GetBPP() == 8) { |
213 m_pPalette = FX_Alloc(FX_DWORD, 256); | 216 m_pPalette = FX_Alloc(FX_DWORD, 256); |
| 217 if (!m_pPalette) { |
| 218 return; |
| 219 } |
214 if(IsCmykImage()) { | 220 if(IsCmykImage()) { |
215 for (int i = 0; i < 256; i ++) { | 221 for (int i = 0; i < 256; i ++) { |
216 m_pPalette[i] = 0xff - i; | 222 m_pPalette[i] = 0xff - i; |
217 } | 223 } |
218 } else { | 224 } else { |
219 for (int i = 0; i < 256; i ++) { | 225 for (int i = 0; i < 256; i ++) { |
220 m_pPalette[i] = 0xff000000 | (i * 0x10101); | 226 m_pPalette[i] = 0xff000000 | (i * 0x10101); |
221 } | 227 } |
222 } | 228 } |
223 } | 229 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 if (pSrc == NULL || GetBPP() > 8) { | 524 if (pSrc == NULL || GetBPP() > 8) { |
519 if (m_pPalette) { | 525 if (m_pPalette) { |
520 FX_Free(m_pPalette); | 526 FX_Free(m_pPalette); |
521 } | 527 } |
522 m_pPalette = NULL; | 528 m_pPalette = NULL; |
523 } else { | 529 } else { |
524 FX_DWORD pal_size = 1 << GetBPP(); | 530 FX_DWORD pal_size = 1 << GetBPP(); |
525 if (m_pPalette == NULL) { | 531 if (m_pPalette == NULL) { |
526 m_pPalette = FX_Alloc(FX_DWORD, pal_size); | 532 m_pPalette = FX_Alloc(FX_DWORD, pal_size); |
527 } | 533 } |
| 534 if (!m_pPalette) { |
| 535 return; |
| 536 } |
528 if (pal_size > size) { | 537 if (pal_size > size) { |
529 pal_size = size; | 538 pal_size = size; |
530 } | 539 } |
531 FXSYS_memcpy32(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); | 540 FXSYS_memcpy32(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); |
532 } | 541 } |
533 } | 542 } |
534 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const | 543 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const |
535 { | 544 { |
536 ASSERT(GetBPP() <= 8 && !IsCmykImage()); | 545 ASSERT(GetBPP() <= 8 && !IsCmykImage()); |
537 if (GetBPP() == 1) { | 546 if (GetBPP() == 1) { |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 if (!m_pBitmap->Create(width, height, src_format)) { | 1681 if (!m_pBitmap->Create(width, height, src_format)) { |
1673 delete m_pBitmap; | 1682 delete m_pBitmap; |
1674 m_pBitmap = NULL; | 1683 m_pBitmap = NULL; |
1675 return FALSE; | 1684 return FALSE; |
1676 } | 1685 } |
1677 if (pSrcPalette) { | 1686 if (pSrcPalette) { |
1678 m_pBitmap->CopyPalette(pSrcPalette); | 1687 m_pBitmap->CopyPalette(pSrcPalette); |
1679 } | 1688 } |
1680 return TRUE; | 1689 return TRUE; |
1681 } | 1690 } |
OLD | NEW |