Skip to main content

rxing/pdf417/encoder/
barcode_row.rs

1/*
2 * Copyright 2011 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * @author Jacob Haynes
19 */
20pub struct BarcodeRow {
21    row: Vec<u8>,
22    //A tacker for position in the bar
23    currentLocation: usize,
24}
25
26impl BarcodeRow {
27    /**
28     * Creates a Barcode row of the width
29     */
30    pub fn new(width: usize) -> Self {
31        Self {
32            row: vec![0; width],
33            currentLocation: 0,
34        }
35    }
36
37    /**
38     * Sets a specific location in the bar
39     *
40     * @param x The location in the bar
41     * @param value Black if true, white if false;
42     */
43    pub fn set<T: Into<u8>>(&mut self, x: usize, value: T) {
44        self.row[x] = value.into()
45    }
46
47    /**
48     * @param black A boolean which is true if the bar black false if it is white
49     * @param width How many spots wide the bar is.
50     */
51    pub fn addBar(&mut self, black: bool, width: usize) {
52        for _ii in 0..width {
53            // for (int ii = 0; ii < width; ii++) {
54            self.set(self.currentLocation, black);
55            self.currentLocation += 1;
56        }
57    }
58
59    /**
60     * This function scales the row
61     *
62     * @param scale How much you want the image to be scaled, must be greater than or equal to 1.
63     * @return the scaled row
64     */
65    pub fn getScaledRow(&self, scale: usize) -> Vec<u8> {
66        let mut output = vec![0; self.row.len() * scale];
67        for (i, row) in output.iter_mut().enumerate() {
68            *row = self.row[i / scale];
69        }
70
71        output
72    }
73}