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/include/fxge/fx_dib.h" | 7 #include "core/include/fxge/fx_dib.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 b = FXARGB_B(argb); | 35 b = FXARGB_B(argb); |
36 } | 36 } |
37 void ArgbDecode(FX_DWORD argb, int& a, FX_COLORREF& rgb) { | 37 void ArgbDecode(FX_DWORD argb, int& a, FX_COLORREF& rgb) { |
38 a = FXARGB_A(argb); | 38 a = FXARGB_A(argb); |
39 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); | 39 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); |
40 } | 40 } |
41 FX_DWORD ArgbEncode(int a, FX_COLORREF rgb) { | 41 FX_DWORD ArgbEncode(int a, FX_COLORREF rgb) { |
42 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), | 42 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), |
43 FXSYS_GetBValue(rgb)); | 43 FXSYS_GetBValue(rgb)); |
44 } | 44 } |
| 45 |
45 CFX_DIBSource::CFX_DIBSource() { | 46 CFX_DIBSource::CFX_DIBSource() { |
46 m_bpp = 0; | 47 m_bpp = 0; |
47 m_AlphaFlag = 0; | 48 m_AlphaFlag = 0; |
48 m_Width = m_Height = 0; | 49 m_Width = m_Height = 0; |
49 m_Pitch = 0; | 50 m_Pitch = 0; |
50 m_pPalette = NULL; | 51 m_pPalette = NULL; |
51 m_pAlphaMask = NULL; | 52 m_pAlphaMask = NULL; |
52 } | 53 } |
| 54 |
53 CFX_DIBSource::~CFX_DIBSource() { | 55 CFX_DIBSource::~CFX_DIBSource() { |
54 FX_Free(m_pPalette); | 56 FX_Free(m_pPalette); |
55 delete m_pAlphaMask; | 57 delete m_pAlphaMask; |
56 } | 58 } |
| 59 |
| 60 uint8_t* CFX_DIBSource::GetBuffer() const { |
| 61 return NULL; |
| 62 } |
| 63 |
| 64 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { |
| 65 return FALSE; |
| 66 } |
| 67 |
57 CFX_DIBitmap::CFX_DIBitmap() { | 68 CFX_DIBitmap::CFX_DIBitmap() { |
58 m_bExtBuf = FALSE; | 69 m_bExtBuf = FALSE; |
59 m_pBuffer = NULL; | 70 m_pBuffer = NULL; |
60 m_pPalette = NULL; | 71 m_pPalette = NULL; |
61 } | 72 } |
| 73 |
62 #define _MAX_OOM_LIMIT_ 12000000 | 74 #define _MAX_OOM_LIMIT_ 12000000 |
63 FX_BOOL CFX_DIBitmap::Create(int width, | 75 FX_BOOL CFX_DIBitmap::Create(int width, |
64 int height, | 76 int height, |
65 FXDIB_Format format, | 77 FXDIB_Format format, |
66 uint8_t* pBuffer, | 78 uint8_t* pBuffer, |
67 int pitch) { | 79 int pitch) { |
68 m_pBuffer = NULL; | 80 m_pBuffer = NULL; |
69 m_bpp = (uint8_t)format; | 81 m_bpp = (uint8_t)format; |
70 m_AlphaFlag = (uint8_t)(format >> 8); | 82 m_AlphaFlag = (uint8_t)(format >> 8); |
71 m_Width = m_Height = m_Pitch = 0; | 83 m_Width = m_Height = m_Pitch = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (!m_bExtBuf) { | 118 if (!m_bExtBuf) { |
107 FX_Free(m_pBuffer); | 119 FX_Free(m_pBuffer); |
108 m_pBuffer = NULL; | 120 m_pBuffer = NULL; |
109 m_Width = m_Height = m_Pitch = 0; | 121 m_Width = m_Height = m_Pitch = 0; |
110 return FALSE; | 122 return FALSE; |
111 } | 123 } |
112 } | 124 } |
113 } | 125 } |
114 return TRUE; | 126 return TRUE; |
115 } | 127 } |
| 128 |
116 FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) { | 129 FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) { |
117 if (m_pBuffer) { | 130 if (m_pBuffer) { |
118 return FALSE; | 131 return FALSE; |
119 } | 132 } |
120 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) { | 133 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) { |
121 return FALSE; | 134 return FALSE; |
122 } | 135 } |
123 CopyPalette(pSrc->GetPalette()); | 136 CopyPalette(pSrc->GetPalette()); |
124 CopyAlphaMask(pSrc->m_pAlphaMask); | 137 CopyAlphaMask(pSrc->m_pAlphaMask); |
125 for (int row = 0; row < pSrc->GetHeight(); row++) { | 138 for (int row = 0; row < pSrc->GetHeight(); row++) { |
126 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch); | 139 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch); |
127 } | 140 } |
128 return TRUE; | 141 return TRUE; |
129 } | 142 } |
| 143 |
130 CFX_DIBitmap::~CFX_DIBitmap() { | 144 CFX_DIBitmap::~CFX_DIBitmap() { |
131 if (!m_bExtBuf) { | 145 if (!m_bExtBuf) |
132 FX_Free(m_pBuffer); | 146 FX_Free(m_pBuffer); |
133 } | 147 |
134 m_pBuffer = NULL; | 148 m_pBuffer = nullptr; |
135 } | 149 } |
| 150 |
| 151 uint8_t* CFX_DIBitmap::GetBuffer() const { |
| 152 return m_pBuffer; |
| 153 } |
| 154 |
| 155 const uint8_t* CFX_DIBitmap::GetScanline(int line) const { |
| 156 return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr; |
| 157 } |
| 158 |
136 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { | 159 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { |
137 if (!m_bExtBuf) { | 160 if (!m_bExtBuf) |
138 FX_Free(m_pBuffer); | 161 FX_Free(m_pBuffer); |
139 } | 162 |
140 FX_Free(m_pPalette); | 163 FX_Free(m_pPalette); |
141 delete m_pAlphaMask; | 164 delete m_pAlphaMask; |
142 m_pBuffer = pSrcBitmap->m_pBuffer; | 165 m_pBuffer = pSrcBitmap->m_pBuffer; |
143 m_pPalette = pSrcBitmap->m_pPalette; | 166 m_pPalette = pSrcBitmap->m_pPalette; |
144 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; | 167 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; |
145 pSrcBitmap->m_pBuffer = NULL; | 168 pSrcBitmap->m_pBuffer = nullptr; |
146 pSrcBitmap->m_pPalette = NULL; | 169 pSrcBitmap->m_pPalette = nullptr; |
147 pSrcBitmap->m_pAlphaMask = NULL; | 170 pSrcBitmap->m_pAlphaMask = nullptr; |
148 m_bpp = pSrcBitmap->m_bpp; | 171 m_bpp = pSrcBitmap->m_bpp; |
149 m_bExtBuf = pSrcBitmap->m_bExtBuf; | 172 m_bExtBuf = pSrcBitmap->m_bExtBuf; |
150 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; | 173 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; |
151 m_Width = pSrcBitmap->m_Width; | 174 m_Width = pSrcBitmap->m_Width; |
152 m_Height = pSrcBitmap->m_Height; | 175 m_Height = pSrcBitmap->m_Height; |
153 m_Pitch = pSrcBitmap->m_Pitch; | 176 m_Pitch = pSrcBitmap->m_Pitch; |
154 } | 177 } |
| 178 |
155 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const { | 179 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const { |
156 FX_RECT rect(0, 0, m_Width, m_Height); | 180 FX_RECT rect(0, 0, m_Width, m_Height); |
157 if (pClip) { | 181 if (pClip) { |
158 rect.Intersect(*pClip); | 182 rect.Intersect(*pClip); |
159 if (rect.IsEmpty()) { | 183 if (rect.IsEmpty()) { |
160 return NULL; | 184 return NULL; |
161 } | 185 } |
162 } | 186 } |
163 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap; | 187 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap; |
164 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) { | 188 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) { |
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 if (!m_pBitmap->Create(width, height, src_format)) { | 1736 if (!m_pBitmap->Create(width, height, src_format)) { |
1713 delete m_pBitmap; | 1737 delete m_pBitmap; |
1714 m_pBitmap = NULL; | 1738 m_pBitmap = NULL; |
1715 return FALSE; | 1739 return FALSE; |
1716 } | 1740 } |
1717 if (pSrcPalette) { | 1741 if (pSrcPalette) { |
1718 m_pBitmap->CopyPalette(pSrcPalette); | 1742 m_pBitmap->CopyPalette(pSrcPalette); |
1719 } | 1743 } |
1720 return TRUE; | 1744 return TRUE; |
1721 } | 1745 } |
OLD | NEW |