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 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2009 ZXing authors | 8 * Copyright 2009 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
| 23 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" |
23 #include "core/fxcodec/include/fx_codec.h" | 24 #include "core/fxcodec/include/fx_codec.h" |
24 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" | 25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" |
25 #include "xfa/fxbarcode/BC_LuminanceSource.h" | 26 #include "xfa/fxbarcode/BC_LuminanceSource.h" |
26 #include "xfa/fxbarcode/utils.h" | 27 #include "xfa/fxbarcode/utils.h" |
27 | 28 |
28 class CBC_Pause : public IFX_Pause { | 29 class CBC_Pause : public IFX_Pause { |
29 public: | 30 public: |
30 virtual FX_BOOL NeedToPauseNow() { return TRUE; } | 31 virtual FX_BOOL NeedToPauseNow() { return TRUE; } |
31 }; | 32 }; |
| 33 |
32 static CFX_DIBitmap* CreateDIBSource(IFX_FileRead* fileread) { | 34 static CFX_DIBitmap* CreateDIBSource(IFX_FileRead* fileread) { |
33 CFX_DIBitmap* bitmap = NULL; | 35 CFX_DIBitmap* bitmap = nullptr; |
34 CCodec_ModuleMgr* pCodecMgr = NULL; | 36 CCodec_ModuleMgr* pCodecMgr = nullptr; |
35 ICodec_ProgressiveDecoder* pImageCodec = NULL; | 37 CCodec_ProgressiveDecoder* pImageCodec = nullptr; |
36 pCodecMgr = new CCodec_ModuleMgr(); | 38 pCodecMgr = new CCodec_ModuleMgr(); |
37 pImageCodec = pCodecMgr->CreateProgressiveDecoder(); | 39 pImageCodec = pCodecMgr->CreateProgressiveDecoder(); |
38 FXCODEC_STATUS status = FXCODEC_STATUS_DECODE_FINISH; | 40 FXCODEC_STATUS status = FXCODEC_STATUS_DECODE_FINISH; |
39 status = pImageCodec->LoadImageInfo(fileread, FXCODEC_IMAGE_UNKNOWN, nullptr); | 41 status = pImageCodec->LoadImageInfo(fileread, FXCODEC_IMAGE_UNKNOWN, nullptr); |
40 if (status != FXCODEC_STATUS_FRAME_READY) { | 42 if (status != FXCODEC_STATUS_FRAME_READY) |
41 return NULL; | 43 return nullptr; |
42 } | 44 |
43 bitmap = new CFX_DIBitmap; | 45 bitmap = new CFX_DIBitmap; |
44 bitmap->Create(pImageCodec->GetWidth(), pImageCodec->GetHeight(), FXDIB_Argb); | 46 bitmap->Create(pImageCodec->GetWidth(), pImageCodec->GetHeight(), FXDIB_Argb); |
45 bitmap->Clear(FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF)); | 47 bitmap->Clear(FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF)); |
46 CBC_Pause pause; | 48 CBC_Pause pause; |
47 int32_t frames; | 49 int32_t frames; |
48 status = pImageCodec->GetFrames(frames, &pause); | 50 status = pImageCodec->GetFrames(frames, &pause); |
49 while (status == FXCODEC_STATUS_FRAME_TOBECONTINUE) { | 51 while (status == FXCODEC_STATUS_FRAME_TOBECONTINUE) { |
50 status = pImageCodec->GetFrames(frames, &pause); | 52 status = pImageCodec->GetFrames(frames, &pause); |
51 } | 53 } |
52 if (status != FXCODEC_STATUS_DECODE_READY) { | 54 if (status != FXCODEC_STATUS_DECODE_READY) { |
53 goto except; | 55 goto except; |
54 } | 56 } |
55 status = pImageCodec->StartDecode(bitmap, 0, 0, bitmap->GetWidth(), | 57 status = pImageCodec->StartDecode(bitmap, 0, 0, bitmap->GetWidth(), |
56 bitmap->GetHeight(), 0, FALSE); | 58 bitmap->GetHeight(), 0, FALSE); |
57 if (status == FXCODEC_STATUS_ERR_PARAMS) { | 59 if (status == FXCODEC_STATUS_ERR_PARAMS) { |
58 goto except; | 60 goto except; |
59 } | 61 } |
60 if (status != FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 62 if (status != FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
61 goto except; | 63 goto except; |
62 } | 64 } |
63 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 65 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
64 status = pImageCodec->ContinueDecode(&pause); | 66 status = pImageCodec->ContinueDecode(&pause); |
65 } | 67 } |
66 if (status != FXCODEC_STATUS_DECODE_FINISH) { | 68 if (status != FXCODEC_STATUS_DECODE_FINISH) { |
67 goto except; | 69 goto except; |
68 } | 70 } |
69 if (pImageCodec) { | 71 if (pImageCodec) { |
70 delete pImageCodec; | 72 delete pImageCodec; |
71 pImageCodec = NULL; | 73 pImageCodec = nullptr; |
72 } | 74 } |
73 delete pCodecMgr; | 75 delete pCodecMgr; |
74 pCodecMgr = NULL; | 76 pCodecMgr = nullptr; |
75 return bitmap; | 77 return bitmap; |
76 except: | 78 except: |
77 if (pImageCodec) { | 79 if (pImageCodec) { |
78 delete pImageCodec; | 80 delete pImageCodec; |
79 pImageCodec = NULL; | 81 pImageCodec = nullptr; |
80 } | 82 } |
81 delete pCodecMgr; | 83 delete pCodecMgr; |
82 pCodecMgr = NULL; | 84 pCodecMgr = nullptr; |
83 if (bitmap) { | 85 if (bitmap) { |
84 delete bitmap; | 86 delete bitmap; |
85 } | 87 } |
86 return NULL; | 88 return nullptr; |
87 } | 89 } |
| 90 |
88 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource( | 91 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource( |
89 const CFX_WideString& filename) | 92 const CFX_WideString& filename) |
90 : CBC_LuminanceSource(0, 0), m_filename(filename) { | 93 : CBC_LuminanceSource(0, 0), m_filename(filename) { |
91 m_height = 0; | 94 m_height = 0; |
92 m_width = 0; | 95 m_width = 0; |
93 m_bytesPerLine = 0; | 96 m_bytesPerLine = 0; |
94 m_top = 0; | 97 m_top = 0; |
95 m_left = 0; | 98 m_left = 0; |
96 } | 99 } |
| 100 |
97 void CBC_BufferedImageLuminanceSource::Init(int32_t& e) { | 101 void CBC_BufferedImageLuminanceSource::Init(int32_t& e) { |
98 IFX_FileRead* fileread = FX_CreateFileRead(m_filename); | 102 IFX_FileRead* fileread = FX_CreateFileRead(m_filename); |
99 m_pBitmap = CreateDIBSource(fileread); | 103 m_pBitmap = CreateDIBSource(fileread); |
100 if (m_pBitmap == NULL) { | 104 if (!m_pBitmap) { |
101 e = BCExceptionLoadFile; | 105 e = BCExceptionLoadFile; |
102 return; | 106 return; |
103 } | 107 } |
104 m_pBitmap->ConvertFormat(FXDIB_Argb); | 108 m_pBitmap->ConvertFormat(FXDIB_Argb); |
105 m_height = m_pBitmap->GetHeight(); | 109 m_height = m_pBitmap->GetHeight(); |
106 m_width = m_pBitmap->GetWidth(); | 110 m_width = m_pBitmap->GetWidth(); |
107 m_rgbData.SetSize(m_height * m_width); | 111 m_rgbData.SetSize(m_height * m_width); |
108 m_bytesPerLine = m_width * 4; | 112 m_bytesPerLine = m_width * 4; |
109 m_top = 0; | 113 m_top = 0; |
110 m_left = 0; | 114 m_left = 0; |
111 } | 115 } |
| 116 |
112 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource( | 117 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource( |
113 CFX_DIBitmap* pBitmap) | 118 CFX_DIBitmap* pBitmap) |
114 : CBC_LuminanceSource(0, 0) { | 119 : CBC_LuminanceSource(0, 0) { |
115 m_pBitmap = pBitmap->Clone(); | 120 m_pBitmap = pBitmap->Clone(); |
116 m_pBitmap->ConvertFormat(FXDIB_Argb); | 121 m_pBitmap->ConvertFormat(FXDIB_Argb); |
117 m_height = m_pBitmap->GetHeight(); | 122 m_height = m_pBitmap->GetHeight(); |
118 m_width = m_pBitmap->GetWidth(); | 123 m_width = m_pBitmap->GetWidth(); |
119 m_rgbData.SetSize(m_height * m_width); | 124 m_rgbData.SetSize(m_height * m_width); |
120 m_bytesPerLine = m_width * 4; | 125 m_bytesPerLine = m_width * 4; |
121 m_top = 0; | 126 m_top = 0; |
122 m_left = 0; | 127 m_left = 0; |
123 } | 128 } |
| 129 |
124 CBC_BufferedImageLuminanceSource::~CBC_BufferedImageLuminanceSource() { | 130 CBC_BufferedImageLuminanceSource::~CBC_BufferedImageLuminanceSource() { |
125 delete m_pBitmap; | 131 delete m_pBitmap; |
126 m_pBitmap = NULL; | |
127 } | 132 } |
| 133 |
128 CFX_ByteArray* CBC_BufferedImageLuminanceSource::GetRow(int32_t y, | 134 CFX_ByteArray* CBC_BufferedImageLuminanceSource::GetRow(int32_t y, |
129 CFX_ByteArray& row, | 135 CFX_ByteArray& row, |
130 int32_t& e) { | 136 int32_t& e) { |
131 if (y < 0 || y >= m_height) { | 137 if (y < 0 || y >= m_height) { |
132 e = BCExceptionRequestedRowIsOutSizeTheImage; | 138 e = BCExceptionRequestedRowIsOutSizeTheImage; |
133 return NULL; | 139 return nullptr; |
134 } | 140 } |
135 int32_t width = m_width; | 141 int32_t width = m_width; |
136 if (row.GetSize() == 0 || row.GetSize() < width) { | 142 if (row.GetSize() == 0 || row.GetSize() < width) { |
137 row.SetSize(width); | 143 row.SetSize(width); |
138 } | 144 } |
139 if (m_rgbData.GetSize() == 0 || m_rgbData.GetSize() < width) { | 145 if (m_rgbData.GetSize() == 0 || m_rgbData.GetSize() < width) { |
140 m_rgbData.SetSize(width); | 146 m_rgbData.SetSize(width); |
141 } | 147 } |
142 int32_t* rowLine = (int32_t*)m_pBitmap->GetScanline(y); | 148 int32_t* rowLine = (int32_t*)m_pBitmap->GetScanline(y); |
143 int32_t x; | 149 int32_t x; |
144 for (x = 0; x < width; x++) { | 150 for (x = 0; x < width; x++) { |
145 int32_t pixel = rowLine[x]; | 151 int32_t pixel = rowLine[x]; |
146 int32_t luminance = (306 * ((pixel >> 16) & 0xFF) + | 152 int32_t luminance = (306 * ((pixel >> 16) & 0xFF) + |
147 601 * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> | 153 601 * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> |
148 10; | 154 10; |
149 row[x] = (uint8_t)luminance; | 155 row[x] = (uint8_t)luminance; |
150 } | 156 } |
151 return &row; | 157 return &row; |
152 } | 158 } |
| 159 |
153 CFX_ByteArray* CBC_BufferedImageLuminanceSource::GetMatrix() { | 160 CFX_ByteArray* CBC_BufferedImageLuminanceSource::GetMatrix() { |
154 CFX_ByteArray* matirx = new CFX_ByteArray(); | 161 CFX_ByteArray* matirx = new CFX_ByteArray(); |
155 matirx->SetSize(m_bytesPerLine * m_height); | 162 matirx->SetSize(m_bytesPerLine * m_height); |
156 int32_t* rgb = (int32_t*)m_pBitmap->GetBuffer(); | 163 int32_t* rgb = (int32_t*)m_pBitmap->GetBuffer(); |
157 int32_t y; | 164 int32_t y; |
158 for (y = 0; y < m_height; y++) { | 165 for (y = 0; y < m_height; y++) { |
159 int32_t offset = y * m_width; | 166 int32_t offset = y * m_width; |
160 int32_t x; | 167 int32_t x; |
161 for (x = 0; x < m_width; x++) { | 168 for (x = 0; x < m_width; x++) { |
162 int32_t pixel = rgb[offset + x]; | 169 int32_t pixel = rgb[offset + x]; |
163 int32_t luminance = | 170 int32_t luminance = |
164 (306 * ((pixel >> 16) & 0xFF) + 601 * ((pixel >> 8) & 0xFF) + | 171 (306 * ((pixel >> 16) & 0xFF) + 601 * ((pixel >> 8) & 0xFF) + |
165 117 * (pixel & 0xFF)) >> | 172 117 * (pixel & 0xFF)) >> |
166 10; | 173 10; |
167 (*matirx)[offset + x] = (uint8_t)luminance; | 174 (*matirx)[offset + x] = (uint8_t)luminance; |
168 } | 175 } |
169 } | 176 } |
170 return matirx; | 177 return matirx; |
171 } | 178 } |
OLD | NEW |