Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: xfa/src/fxbarcode/src/BC_BufferedImageLuminanceSource.cpp

Issue 842043002: Organize barcode codes into modules. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/src/fxbarcode/src/BC_BinaryBitmap.cpp ('k') | xfa/src/fxbarcode/src/BC_C40Encoder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows:
7 /*
8 * Copyright 2009 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (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
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #include "barcode.h"
24 #include "include/BC_LuminanceSource.h"
25 #include "include/BC_BufferedImageLuminanceSource.h"
26 class CBC_Pause : public IFX_Pause
27 {
28 public:
29 virtual FX_BOOL NeedToPauseNow()
30 {
31 return TRUE;
32 }
33 };
34 static CFX_DIBitmap* CreateDIBSource(IFX_FileRead* fileread)
35 {
36 CFX_DIBitmap* bitmap = NULL;
37 CCodec_ModuleMgr* pCodecMgr = NULL;
38 ICodec_ProgressiveDecoder* pImageCodec = NULL;
39 pCodecMgr = CCodec_ModuleMgr::Create();
40 pImageCodec = pCodecMgr->CreateProgressiveDecoder();
41 FXCODEC_STATUS status = FXCODEC_STATUS_DECODE_FINISH;
42 status = pImageCodec->LoadImageInfo(fileread, FXCODEC_IMAGE_UNKNOWN);
43 if (status != FXCODEC_STATUS_FRAME_READY) {
44 return NULL;
45 }
46 bitmap = FX_NEW CFX_DIBitmap;
47 bitmap->Create(pImageCodec->GetWidth(), pImageCodec->GetHeight(), FXDIB_Argb );
48 bitmap->Clear(FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF));
49 CBC_Pause pause;
50 FX_INT32 frames;
51 status = pImageCodec->GetFrames(frames, &pause);
52 while (status == FXCODEC_STATUS_FRAME_TOBECONTINUE) {
53 status = pImageCodec->GetFrames(frames, &pause);
54 }
55 if (status != FXCODEC_STATUS_DECODE_READY) {
56 goto except;
57 }
58 status = pImageCodec->StartDecode(bitmap,
59 0,
60 0,
61 bitmap->GetWidth(),
62 bitmap->GetHeight(),
63 0,
64 FALSE);
65 if (status == FXCODEC_STATUS_ERR_PARAMS) {
66 goto except;
67 }
68 if (status != FXCODEC_STATUS_DECODE_TOBECONTINUE) {
69 goto except;
70 }
71 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
72 status = pImageCodec->ContinueDecode(&pause);
73 }
74 if (status != FXCODEC_STATUS_DECODE_FINISH) {
75 goto except;
76 }
77 if (pImageCodec) {
78 delete pImageCodec;
79 pImageCodec = NULL;
80 }
81 if (pCodecMgr) {
82 pCodecMgr->Destroy();
83 pCodecMgr = NULL;
84 }
85 return bitmap;
86 except:
87 if (pImageCodec) {
88 delete pImageCodec;
89 pImageCodec = NULL;
90 }
91 if (pCodecMgr) {
92 pCodecMgr->Destroy();
93 pCodecMgr = NULL;
94 }
95 if (bitmap) {
96 delete bitmap;
97 }
98 return NULL;
99 }
100 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource(const CFX_Wid eString &filename): CBC_LuminanceSource(0, 0), m_filename(filename)
101 {
102 m_height = 0;
103 m_width = 0;
104 m_bytesPerLine = 0;
105 m_top = 0;
106 m_left = 0;
107 }
108 void CBC_BufferedImageLuminanceSource::Init(FX_INT32 &e)
109 {
110 IFX_FileRead* fileread = FX_CreateFileRead(m_filename);
111 m_pBitmap = CreateDIBSource(fileread);
112 if (m_pBitmap == NULL) {
113 e = BCExceptionLoadFile;
114 return;
115 }
116 m_pBitmap->ConvertFormat(FXDIB_Argb);
117 m_height = m_pBitmap->GetHeight();
118 m_width = m_pBitmap->GetWidth();
119 m_rgbData.SetSize(m_height * m_width);
120 m_bytesPerLine = m_width * 4;
121 m_top = 0;
122 m_left = 0;
123 }
124 CBC_BufferedImageLuminanceSource::CBC_BufferedImageLuminanceSource(CFX_DIBitmap *pBitmap): CBC_LuminanceSource(0, 0)
125 {
126 m_pBitmap = pBitmap->Clone();
127 m_pBitmap->ConvertFormat(FXDIB_Argb);
128 m_height = m_pBitmap->GetHeight();
129 m_width = m_pBitmap->GetWidth();
130 m_rgbData.SetSize(m_height * m_width);
131 m_bytesPerLine = m_width * 4;
132 m_top = 0;
133 m_left = 0;
134 }
135 CBC_BufferedImageLuminanceSource::~CBC_BufferedImageLuminanceSource()
136 {
137 delete m_pBitmap;
138 m_pBitmap = NULL;
139 }
140 CFX_ByteArray *CBC_BufferedImageLuminanceSource::GetRow(FX_INT32 y, CFX_ByteArra y &row, FX_INT32 &e)
141 {
142 if (y < 0 || y >= m_height) {
143 e = BCExceptionRequestedRowIsOutSizeTheImage;
144 return NULL;
145 }
146 FX_INT32 width = m_width;
147 if(row.GetSize() == 0 || row.GetSize() < width) {
148 row.SetSize(width);
149 }
150 if(m_rgbData.GetSize() == 0 || m_rgbData.GetSize() < width) {
151 m_rgbData.SetSize(width);
152 }
153 FX_INT32* rowLine = (FX_INT32*)m_pBitmap->GetScanline(y);
154 FX_INT32 x;
155 for (x = 0; x < width; x++) {
156 FX_INT32 pixel = rowLine[x];
157 FX_INT32 luminance = (306 * ((pixel >> 16) & 0xFF) +
158 601 * ((pixel >> 8) & 0xFF) +
159 117 * (pixel & 0xFF)) >> 10;
160 row[x] = (FX_BYTE) luminance;
161 }
162 return &row;
163 }
164 CFX_ByteArray *CBC_BufferedImageLuminanceSource::GetMatrix()
165 {
166 CFX_ByteArray *matirx = FX_NEW CFX_ByteArray();
167 matirx->SetSize(m_bytesPerLine * m_height);
168 FX_INT32 *rgb = (FX_INT32*)m_pBitmap->GetBuffer();
169 FX_INT32 y;
170 for(y = 0; y < m_height; y++) {
171 FX_INT32 offset = y * m_width;
172 FX_INT32 x;
173 for(x = 0; x < m_width; x++) {
174 FX_INT32 pixel = rgb[offset + x];
175 FX_INT32 luminance = (306 * ((pixel >> 16) & 0xFF) +
176 601 * ((pixel >> 8) & 0xFF) +
177 117 * (pixel & 0xFF)) >> 10;
178 (*matirx)[offset + x] = (FX_BYTE) luminance;
179 }
180 }
181 return matirx;
182 }
183 FX_BOOL CBC_BufferedImageLuminanceSource::IsCropSupported()
184 {
185 return TRUE;
186 }
187 FX_BOOL CBC_BufferedImageLuminanceSource::IsRotateSupported()
188 {
189 return TRUE;
190 }
191 CBC_LuminanceSource *CBC_BufferedImageLuminanceSource::Crop(FX_INT32 left, FX_IN T32 top, FX_INT32 width, FX_INT32 height)
192 {
193 return NULL;
194 }
195 CBC_LuminanceSource *CBC_BufferedImageLuminanceSource::RotateCounterClockwise(FX _INT32 &e)
196 {
197 if (!IsRotateSupported()) {
198 e = BCExceptionRotateNotSupported;
199 return NULL;
200 }
201 FX_INT32 sourceWidth = m_width;
202 FX_INT32 sourceHeight = m_height;
203 return NULL;
204 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_BinaryBitmap.cpp ('k') | xfa/src/fxbarcode/src/BC_C40Encoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698