MCPcopy Create free account
hub / github.com/devilsen/CZXing / Encode

Method Encode

czxing/src/main/cpp/zxing/src/aztec/AZEncoder.cpp:165–302  ·  view source on GitHub ↗

* Encodes the given binary content as an Aztec symbol * * @param data input data string * @param minECCPercent minimal percentage of error check words (According to ISO/IEC 24778:2008, * a minimum of 23% + 3 words is recommended) * @param userSpecifiedLayers if non-zero, a user-specified value for the number of layers * @return Aztec symbol matrix with metadata */

Source from the content-addressed store, hash-verified

163* @return Aztec symbol matrix with metadata
164*/
165EncodeResult
166Encoder::Encode(const std::string& data, int minECCPercent, int userSpecifiedLayers)
167{
168 // High-level encode
169 BitArray bits = HighLevelEncoder::Encode(data);
170
171 // stuff bits and choose symbol size
172 int eccBits = bits.size() * minECCPercent / 100 + 11;
173 int totalSizeBits = bits.size() + eccBits;
174 bool compact;
175 int layers;
176 int totalBitsInLayer;
177 int wordSize;
178 BitArray stuffedBits;
179 if (userSpecifiedLayers != DEFAULT_AZTEC_LAYERS) {
180 compact = userSpecifiedLayers < 0;
181 layers = std::abs(userSpecifiedLayers);
182 if (layers > (compact ? MAX_NB_BITS_COMPACT : MAX_NB_BITS)) {
183 throw std::invalid_argument("Illegal value for layers: " + std::to_string(userSpecifiedLayers));
184 }
185 totalBitsInLayer = TotalBitsInLayer(layers, compact);
186 wordSize = WORD_SIZE[layers];
187 int usableBitsInLayers = totalBitsInLayer - (totalBitsInLayer % wordSize);
188 StuffBits(bits, wordSize, stuffedBits);
189 if (stuffedBits.size() + eccBits > usableBitsInLayers) {
190 throw std::invalid_argument("Data to large for user specified layer");
191 }
192 if (compact && stuffedBits.size() > wordSize * 64) {
193 // Compact format only allows 64 data words, though C4 can hold more words than that
194 throw std::invalid_argument("Data to large for user specified layer");
195 }
196 }
197 else {
198 wordSize = 0;
199 // We look at the possible table sizes in the order Compact1, Compact2, Compact3,
200 // Compact4, Normal4,... Normal(i) for i < 4 isn't typically used since Compact(i+1)
201 // is the same size, but has more data.
202 for (int i = 0; ; i++) {
203 if (i > MAX_NB_BITS) {
204 throw std::invalid_argument("Data too large for an Aztec code");
205 }
206 compact = i <= 3;
207 layers = compact ? i + 1 : i;
208 totalBitsInLayer = TotalBitsInLayer(layers, compact);
209 if (totalSizeBits > totalBitsInLayer) {
210 continue;
211 }
212 // [Re]stuff the bits if this is the first opportunity, or if the
213 // wordSize has changed
214 if (wordSize != WORD_SIZE[layers]) {
215 wordSize = WORD_SIZE[layers];
216 StuffBits(bits, wordSize, stuffedBits);
217 }
218 int usableBitsInLayers = totalBitsInLayer - (totalBitsInLayer % wordSize);
219 if (compact && stuffedBits.size() > wordSize * 64) {
220 // Compact format only allows 64 data words, though C4 can hold more words than that
221 continue;
222 }

Callers

nothing calls this directly

Calls 14

StuffBitsFunction · 0.85
GenerateCheckWordsFunction · 0.85
GenerateModeMessageFunction · 0.85
DrawModeMessageFunction · 0.85
DrawBullsEyeFunction · 0.85
TotalBitsInLayerFunction · 0.70
BitMatrixClass · 0.70
EncodeFunction · 0.50
absFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected