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 "barcode.h" | 7 #include "barcode.h" |
8 #include "common/BC_CommonBitMatrix.h" | 8 #include "common/BC_CommonBitMatrix.h" |
9 #include "BC_Writer.h" | 9 #include "BC_Writer.h" |
10 #include "BC_TwoDimWriter.h" | 10 #include "BC_TwoDimWriter.h" |
11 CBC_TwoDimWriter::CBC_TwoDimWriter() | 11 CBC_TwoDimWriter::CBC_TwoDimWriter() |
12 { | 12 { |
13 m_iCorrectLevel = 1; | 13 m_iCorrectLevel = 1; |
14 m_bFixedSize = TRUE; | 14 m_bFixedSize = TRUE; |
15 m_output = NULL; | 15 m_output = NULL; |
16 } | 16 } |
17 CBC_TwoDimWriter::~CBC_TwoDimWriter() | 17 CBC_TwoDimWriter::~CBC_TwoDimWriter() |
18 { | 18 { |
19 if (m_output != NULL) { | 19 if (m_output != NULL) { |
20 delete m_output; | 20 delete m_output; |
21 m_output = NULL; | 21 m_output = NULL; |
22 } | 22 } |
23 } | 23 } |
24 void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Ma
trix* matrix) | 24 void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Ma
trix* matrix) |
25 { | 25 { |
26 CFX_GraphStateData stateData; | 26 CFX_GraphStateData stateData; |
27 CFX_PathData path; | 27 CFX_PathData path; |
28 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); | 28 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); |
29 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundC
olor, FXFILL_ALTERNATE); | 29 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundC
olor, FXFILL_ALTERNATE); |
30 FX_INT32 leftPos = 0; | 30 int32_t leftPos = 0; |
31 FX_INT32 topPos = 0; | 31 int32_t topPos = 0; |
32 if ( m_bFixedSize) { | 32 if ( m_bFixedSize) { |
33 leftPos = (m_Width - m_output->GetWidth()) / 2; | 33 leftPos = (m_Width - m_output->GetWidth()) / 2; |
34 topPos = (m_Height - m_output->GetHeight()) / 2; | 34 topPos = (m_Height - m_output->GetHeight()) / 2; |
35 } | 35 } |
36 CFX_Matrix matri = *matrix; | 36 CFX_Matrix matri = *matrix; |
37 if (m_Width < m_output->GetWidth() && m_Height < m_output->GetHeight()) { | 37 if (m_Width < m_output->GetWidth() && m_Height < m_output->GetHeight()) { |
38 CFX_Matrix matriScale((FX_FLOAT)m_Width / (FX_FLOAT)m_output->GetWidth()
, 0.0, 0.0, (FX_FLOAT)m_Height / (FX_FLOAT)m_output->GetHeight(), 0.0, 0.0); | 38 CFX_Matrix matriScale((FX_FLOAT)m_Width / (FX_FLOAT)m_output->GetWidth()
, 0.0, 0.0, (FX_FLOAT)m_Height / (FX_FLOAT)m_output->GetHeight(), 0.0, 0.0); |
39 matriScale.Concat(*matrix); | 39 matriScale.Concat(*matrix); |
40 matri = matriScale; | 40 matri = matriScale; |
41 } | 41 } |
42 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | 42 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
43 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | 43 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
44 CFX_PathData rect; | 44 CFX_PathData rect; |
45 rect.AppendRect((FX_FLOAT)leftPos + x, (FX_FLOAT)topPos + y, (FX_FLO
AT)(leftPos + x + 1), (FX_FLOAT)(topPos + y + 1)); | 45 rect.AppendRect((FX_FLOAT)leftPos + x, (FX_FLOAT)topPos + y, (FX_FLO
AT)(leftPos + x + 1), (FX_FLOAT)(topPos + y + 1)); |
46 CFX_GraphStateData stateData; | 46 CFX_GraphStateData stateData; |
47 if(m_output->Get(x, y)) { | 47 if(m_output->Get(x, y)) { |
48 device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFIL
L_WINDING); | 48 device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFIL
L_WINDING); |
49 } | 49 } |
50 } | 50 } |
51 } | 51 } |
52 } | 52 } |
53 void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_INT32& e
) | 53 void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, int32_t& e) |
54 { | 54 { |
55 if (m_bFixedSize) { | 55 if (m_bFixedSize) { |
56 pOutBitmap = CreateDIBitmap(m_Width, m_Height); | 56 pOutBitmap = CreateDIBitmap(m_Width, m_Height); |
57 } else { | 57 } else { |
58 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight())
; | 58 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight())
; |
59 } | 59 } |
60 if (!pOutBitmap) { | 60 if (!pOutBitmap) { |
61 e = BCExceptionFailToCreateBitmap; | 61 e = BCExceptionFailToCreateBitmap; |
62 return; | 62 return; |
63 } | 63 } |
64 pOutBitmap->Clear(m_backgroundColor); | 64 pOutBitmap->Clear(m_backgroundColor); |
65 FX_INT32 leftPos = 0; | 65 int32_t leftPos = 0; |
66 FX_INT32 topPos = 0; | 66 int32_t topPos = 0; |
67 if ( m_bFixedSize) { | 67 if ( m_bFixedSize) { |
68 leftPos = (m_Width - m_output->GetWidth()) / 2; | 68 leftPos = (m_Width - m_output->GetWidth()) / 2; |
69 topPos = (m_Height - m_output->GetHeight()) / 2; | 69 topPos = (m_Height - m_output->GetHeight()) / 2; |
70 } | 70 } |
71 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | 71 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
72 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | 72 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
73 if (m_output->Get(x, y)) { | 73 if (m_output->Get(x, y)) { |
74 pOutBitmap->SetPixel(leftPos + x, topPos + y, m_barColor); | 74 pOutBitmap->SetPixel(leftPos + x, topPos + y, m_barColor); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 if (!m_bFixedSize) { | 78 if (!m_bFixedSize) { |
79 CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height)
; | 79 CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height)
; |
80 if (pOutBitmap) { | 80 if (pOutBitmap) { |
81 delete pOutBitmap; | 81 delete pOutBitmap; |
82 } | 82 } |
83 pOutBitmap = pStretchBitmap; | 83 pOutBitmap = pStretchBitmap; |
84 } | 84 } |
85 } | 85 } |
86 void CBC_TwoDimWriter::RenderResult(FX_BYTE *code, FX_INT32 codeWidth, FX_INT32
codeHeight, FX_INT32 &e) | 86 void CBC_TwoDimWriter::RenderResult(uint8_t *code, int32_t codeWidth, int32_t co
deHeight, int32_t &e) |
87 { | 87 { |
88 FX_INT32 inputWidth = codeWidth; | 88 int32_t inputWidth = codeWidth; |
89 FX_INT32 inputHeight = codeHeight; | 89 int32_t inputHeight = codeHeight; |
90 FX_INT32 tempWidth = inputWidth + (1 << 1); | 90 int32_t tempWidth = inputWidth + (1 << 1); |
91 FX_INT32 tempHeight = inputHeight + (1 << 1); | 91 int32_t tempHeight = inputHeight + (1 << 1); |
92 FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight); | 92 FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight); |
93 if (moduleHSize > 8) { | 93 if (moduleHSize > 8) { |
94 moduleHSize = 8; | 94 moduleHSize = 8; |
95 } else if (moduleHSize < 1) { | 95 } else if (moduleHSize < 1) { |
96 moduleHSize = 1; | 96 moduleHSize = 1; |
97 } | 97 } |
98 FX_INT32 outputWidth = (FX_INT32)FX_MAX(tempWidth * moduleHSize, tempWidth); | 98 int32_t outputWidth = (int32_t)FX_MAX(tempWidth * moduleHSize, tempWidth); |
99 FX_INT32 outputHeight = (FX_INT32)FX_MAX(tempHeight * moduleHSize, tempHeigh
t); | 99 int32_t outputHeight = (int32_t)FX_MAX(tempHeight * moduleHSize, tempHeight)
; |
100 FX_INT32 multiX = 1; | 100 int32_t multiX = 1; |
101 FX_INT32 multiY = 1; | 101 int32_t multiY = 1; |
102 if (m_bFixedSize) { | 102 if (m_bFixedSize) { |
103 if (m_Width < outputWidth || m_Height < outputHeight) { | 103 if (m_Width < outputWidth || m_Height < outputHeight) { |
104 e = BCExceptionBitmapSizeError; | 104 e = BCExceptionBitmapSizeError; |
105 return; | 105 return; |
106 } | 106 } |
107 } else { | 107 } else { |
108 if (m_Width > outputWidth || m_Height > outputHeight) { | 108 if (m_Width > outputWidth || m_Height > outputHeight) { |
109 outputWidth = (FX_INT32)(outputWidth * ceil ( (FX_FLOAT)m_Width / (F
X_FLOAT)outputWidth)); | 109 outputWidth = (int32_t)(outputWidth * ceil ( (FX_FLOAT)m_Width / (FX
_FLOAT)outputWidth)); |
110 outputHeight = (FX_INT32)(outputHeight * ceil ( (FX_FLOAT)m_Height /
(FX_FLOAT)outputHeight)); | 110 outputHeight = (int32_t)(outputHeight * ceil ( (FX_FLOAT)m_Height /
(FX_FLOAT)outputHeight)); |
111 } | 111 } |
112 } | 112 } |
113 multiX = (FX_INT32)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); | 113 multiX = (int32_t)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); |
114 multiY = (FX_INT32)ceil((FX_FLOAT)outputHeight / (FX_FLOAT) tempHeight); | 114 multiY = (int32_t)ceil((FX_FLOAT)outputHeight / (FX_FLOAT) tempHeight); |
115 if (m_bFixedSize) { | 115 if (m_bFixedSize) { |
116 multiX = FX_MIN(multiX, multiY); | 116 multiX = FX_MIN(multiX, multiY); |
117 multiY = multiX; | 117 multiY = multiX; |
118 } | 118 } |
119 FX_INT32 leftPadding = (outputWidth - (inputWidth * multiX)) / 2; | 119 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; |
120 FX_INT32 topPadding = (outputHeight - (inputHeight * multiY)) / 2; | 120 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; |
121 if (leftPadding < 0) { | 121 if (leftPadding < 0) { |
122 leftPadding = 0; | 122 leftPadding = 0; |
123 } | 123 } |
124 if (topPadding < 0) { | 124 if (topPadding < 0) { |
125 topPadding = 0; | 125 topPadding = 0; |
126 } | 126 } |
127 m_output = FX_NEW CBC_CommonBitMatrix; | 127 m_output = FX_NEW CBC_CommonBitMatrix; |
128 m_output->Init(outputWidth, outputHeight); | 128 m_output->Init(outputWidth, outputHeight); |
129 for (FX_INT32 inputY = 0, outputY = topPadding; (inputY < inputHeight) && (o
utputY < outputHeight - multiY); inputY++, outputY += multiY) { | 129 for (int32_t inputY = 0, outputY = topPadding; (inputY < inputHeight) && (ou
tputY < outputHeight - multiY); inputY++, outputY += multiY) { |
130 for (FX_INT32 inputX = 0, outputX = leftPadding; (inputX < inputWidth) &
& (outputX < outputWidth - multiX); inputX++, outputX += multiX) { | 130 for (int32_t inputX = 0, outputX = leftPadding; (inputX < inputWidth) &&
(outputX < outputWidth - multiX); inputX++, outputX += multiX) { |
131 if (code[inputX + inputY * inputWidth] == 1) { | 131 if (code[inputX + inputY * inputWidth] == 1) { |
132 m_output->SetRegion(outputX, outputY, multiX, multiY, e); | 132 m_output->SetRegion(outputX, outputY, multiX, multiY, e); |
133 BC_EXCEPTION_CHECK_ReturnVoid(e); | 133 BC_EXCEPTION_CHECK_ReturnVoid(e); |
134 } | 134 } |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
OLD | NEW |