| 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 } |
| 88 } else { | 91 } else { |
| 89 m_pBuffer = FX_Alloc(FX_BYTE, size); | 92 m_pBuffer = FX_Alloc(FX_BYTE, size); |
| 90 } | 93 } |
| 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 } | |
| 208 if(IsCmykImage()) { | 205 if(IsCmykImage()) { |
| 209 m_pPalette[0] = 0xff; | 206 m_pPalette[0] = 0xff; |
| 210 m_pPalette[1] = 0; | 207 m_pPalette[1] = 0; |
| 211 } else { | 208 } else { |
| 212 m_pPalette[0] = 0xff000000; | 209 m_pPalette[0] = 0xff000000; |
| 213 m_pPalette[1] = 0xffffffff; | 210 m_pPalette[1] = 0xffffffff; |
| 214 } | 211 } |
| 215 } else if (GetBPP() == 8) { | 212 } else if (GetBPP() == 8) { |
| 216 m_pPalette = FX_Alloc(FX_DWORD, 256); | 213 m_pPalette = FX_Alloc(FX_DWORD, 256); |
| 217 if (!m_pPalette) { | |
| 218 return; | |
| 219 } | |
| 220 if(IsCmykImage()) { | 214 if(IsCmykImage()) { |
| 221 for (int i = 0; i < 256; i ++) { | 215 for (int i = 0; i < 256; i ++) { |
| 222 m_pPalette[i] = 0xff - i; | 216 m_pPalette[i] = 0xff - i; |
| 223 } | 217 } |
| 224 } else { | 218 } else { |
| 225 for (int i = 0; i < 256; i ++) { | 219 for (int i = 0; i < 256; i ++) { |
| 226 m_pPalette[i] = 0xff000000 | (i * 0x10101); | 220 m_pPalette[i] = 0xff000000 | (i * 0x10101); |
| 227 } | 221 } |
| 228 } | 222 } |
| 229 } | 223 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (pSrc == NULL || GetBPP() > 8) { | 518 if (pSrc == NULL || GetBPP() > 8) { |
| 525 if (m_pPalette) { | 519 if (m_pPalette) { |
| 526 FX_Free(m_pPalette); | 520 FX_Free(m_pPalette); |
| 527 } | 521 } |
| 528 m_pPalette = NULL; | 522 m_pPalette = NULL; |
| 529 } else { | 523 } else { |
| 530 FX_DWORD pal_size = 1 << GetBPP(); | 524 FX_DWORD pal_size = 1 << GetBPP(); |
| 531 if (m_pPalette == NULL) { | 525 if (m_pPalette == NULL) { |
| 532 m_pPalette = FX_Alloc(FX_DWORD, pal_size); | 526 m_pPalette = FX_Alloc(FX_DWORD, pal_size); |
| 533 } | 527 } |
| 534 if (!m_pPalette) { | |
| 535 return; | |
| 536 } | |
| 537 if (pal_size > size) { | 528 if (pal_size > size) { |
| 538 pal_size = size; | 529 pal_size = size; |
| 539 } | 530 } |
| 540 FXSYS_memcpy32(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); | 531 FXSYS_memcpy32(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); |
| 541 } | 532 } |
| 542 } | 533 } |
| 543 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const | 534 void CFX_DIBSource::GetPalette(FX_DWORD* pal, int alpha) const |
| 544 { | 535 { |
| 545 ASSERT(GetBPP() <= 8 && !IsCmykImage()); | 536 ASSERT(GetBPP() <= 8 && !IsCmykImage()); |
| 546 if (GetBPP() == 1) { | 537 if (GetBPP() == 1) { |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 if (!m_pBitmap->Create(width, height, src_format)) { | 1672 if (!m_pBitmap->Create(width, height, src_format)) { |
| 1682 delete m_pBitmap; | 1673 delete m_pBitmap; |
| 1683 m_pBitmap = NULL; | 1674 m_pBitmap = NULL; |
| 1684 return FALSE; | 1675 return FALSE; |
| 1685 } | 1676 } |
| 1686 if (pSrcPalette) { | 1677 if (pSrcPalette) { |
| 1687 m_pBitmap->CopyPalette(pSrcPalette); | 1678 m_pBitmap->CopyPalette(pSrcPalette); |
| 1688 } | 1679 } |
| 1689 return TRUE; | 1680 return TRUE; |
| 1690 } | 1681 } |
| OLD | NEW |