rustup.
This commit is contained in:
parent
9fe75964ab
commit
068707d312
|
@ -457,7 +457,7 @@ impl Bits {
|
||||||
#[unstable]
|
#[unstable]
|
||||||
pub fn push_byte_data(&mut self, data: &[u8]) -> QrResult<()> {
|
pub fn push_byte_data(&mut self, data: &[u8]) -> QrResult<()> {
|
||||||
try!(self.push_header(Mode::Byte, data.len()));
|
try!(self.push_header(Mode::Byte, data.len()));
|
||||||
for b in data.iter() {
|
for b in data {
|
||||||
self.push_number(8, *b as u16);
|
self.push_number(8, *b as u16);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -754,7 +754,7 @@ mod finish_tests {
|
||||||
|
|
||||||
impl Bits {
|
impl Bits {
|
||||||
/// Push a segmented data to the bits, and then terminate it.
|
/// Push a segmented data to the bits, and then terminate it.
|
||||||
pub fn push_segments<I>(&mut self, data: &[u8], mut segments_iter: I) -> QrResult<()>
|
pub fn push_segments<I>(&mut self, data: &[u8], segments_iter: I) -> QrResult<()>
|
||||||
where I: Iterator<Item=Segment>
|
where I: Iterator<Item=Segment>
|
||||||
{
|
{
|
||||||
for segment in segments_iter {
|
for segment in segments_iter {
|
||||||
|
@ -823,8 +823,8 @@ mod encode_tests {
|
||||||
/// This method will not consider any Micro QR code versions.
|
/// This method will not consider any Micro QR code versions.
|
||||||
pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult<Bits> {
|
pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult<Bits> {
|
||||||
let segments = Parser::new(data).collect::<Vec<Segment>>();
|
let segments = Parser::new(data).collect::<Vec<Segment>>();
|
||||||
for version in [Version::Normal(9), Version::Normal(26), Version::Normal(40)].iter() {
|
for version in &[Version::Normal(9), Version::Normal(26), Version::Normal(40)] {
|
||||||
let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::<Vec<Segment>>();
|
let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::<Vec<_>>();
|
||||||
let total_len = total_encoded_len(&*opt_segments, *version);
|
let total_len = total_encoded_len(&*opt_segments, *version);
|
||||||
let data_capacity = version.fetch(ec_level, &DATA_LENGTHS).unwrap();
|
let data_capacity = version.fetch(ec_level, &DATA_LENGTHS).unwrap();
|
||||||
if total_len <= data_capacity {
|
if total_len <= data_capacity {
|
||||||
|
|
|
@ -111,9 +111,9 @@ impl Canvas {
|
||||||
fn to_debug_str(&self) -> String {
|
fn to_debug_str(&self) -> String {
|
||||||
let width = self.width;
|
let width = self.width;
|
||||||
let mut res = String::with_capacity((width * (width + 1)) as usize);
|
let mut res = String::with_capacity((width * (width + 1)) as usize);
|
||||||
for y in (0 .. width) {
|
for y in 0 .. width {
|
||||||
res.push('\n');
|
res.push('\n');
|
||||||
for x in (0 .. width) {
|
for x in 0 .. width {
|
||||||
res.push(match self.get(x, y) {
|
res.push(match self.get(x, y) {
|
||||||
Module::Empty => '?',
|
Module::Empty => '?',
|
||||||
Module::Light => '.',
|
Module::Light => '.',
|
||||||
|
@ -626,7 +626,7 @@ impl Canvas {
|
||||||
coords: &[(i16, i16)]) {
|
coords: &[(i16, i16)]) {
|
||||||
let zero: N = Int::zero();
|
let zero: N = Int::zero();
|
||||||
let mut mask: N = !(!zero >> 1);
|
let mut mask: N = !(!zero >> 1);
|
||||||
for &(x, y) in coords.iter() {
|
for &(x, y) in coords {
|
||||||
let color = if (mask & number) == zero { off_color } else { on_color };
|
let color = if (mask & number) == zero { off_color } else { on_color };
|
||||||
self.put(x, y, color);
|
self.put(x, y, color);
|
||||||
mask = mask >> 1;
|
mask = mask >> 1;
|
||||||
|
@ -1428,8 +1428,8 @@ impl Canvas {
|
||||||
/// patterns.
|
/// patterns.
|
||||||
pub fn apply_mask(&mut self, pattern: MaskPattern) {
|
pub fn apply_mask(&mut self, pattern: MaskPattern) {
|
||||||
let mask_fn = get_mask_function(pattern);
|
let mask_fn = get_mask_function(pattern);
|
||||||
for x in (0 .. self.width) {
|
for x in 0 .. self.width {
|
||||||
for y in (0 .. self.width) {
|
for y in 0 .. self.width {
|
||||||
let module = self.get_mut(x, y);
|
let module = self.get_mut(x, y);
|
||||||
*module = module.mask(mask_fn(x, y));
|
*module = module.mask(mask_fn(x, y));
|
||||||
}
|
}
|
||||||
|
@ -1587,14 +1587,14 @@ impl Canvas {
|
||||||
fn compute_adjacent_penalty_score(&self, is_horizontal: bool) -> u16 {
|
fn compute_adjacent_penalty_score(&self, is_horizontal: bool) -> u16 {
|
||||||
let mut total_score = 0;
|
let mut total_score = 0;
|
||||||
|
|
||||||
for i in (0 .. self.width) {
|
for i in 0 .. self.width {
|
||||||
let map_fn = |&:j| if is_horizontal {
|
let map_fn = |&:j| if is_horizontal {
|
||||||
self.get(j, i)
|
self.get(j, i)
|
||||||
} else {
|
} else {
|
||||||
self.get(i, j)
|
self.get(i, j)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut colors = (0 .. self.width).map(map_fn)
|
let colors = (0 .. self.width).map(map_fn)
|
||||||
.chain(Some(Module::Empty).into_iter());
|
.chain(Some(Module::Empty).into_iter());
|
||||||
let mut last_color = Module::Empty;
|
let mut last_color = Module::Empty;
|
||||||
let mut consecutive_len = 1u16;
|
let mut consecutive_len = 1u16;
|
||||||
|
@ -1623,8 +1623,8 @@ impl Canvas {
|
||||||
fn compute_block_penalty_score(&self) -> u16 {
|
fn compute_block_penalty_score(&self) -> u16 {
|
||||||
let mut total_score = 0;
|
let mut total_score = 0;
|
||||||
|
|
||||||
for i in (0 .. self.width-1) {
|
for i in 0 .. self.width-1 {
|
||||||
for j in (0 .. self.width-1) {
|
for j in 0 .. self.width-1 {
|
||||||
let this = self.get(i, j);
|
let this = self.get(i, j);
|
||||||
let right = self.get(i+1, j);
|
let right = self.get(i+1, j);
|
||||||
let bottom = self.get(i, j+1);
|
let bottom = self.get(i, j+1);
|
||||||
|
@ -1651,8 +1651,8 @@ impl Canvas {
|
||||||
|
|
||||||
let mut total_score = 0;
|
let mut total_score = 0;
|
||||||
|
|
||||||
for i in (0 .. self.width) {
|
for i in 0 .. self.width {
|
||||||
for j in (0 .. self.width-6) {
|
for j in 0 .. self.width-6 {
|
||||||
// TODO a ref to a closure should be enough?
|
// TODO a ref to a closure should be enough?
|
||||||
let get: Box<Fn(i16) -> Module> = if is_horizontal {
|
let get: Box<Fn(i16) -> Module> = if is_horizontal {
|
||||||
Box::new(|&: k: i16| self.get(k, i))
|
Box::new(|&: k: i16| self.get(k, i))
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub fn create_error_correction_code(data: &[u8], ec_code_size: usize) -> Vec<u8>
|
||||||
let data_len = data.len();
|
let data_len = data.len();
|
||||||
let log_den = GENERATOR_POLYNOMIALS[ec_code_size];
|
let log_den = GENERATOR_POLYNOMIALS[ec_code_size];
|
||||||
|
|
||||||
for i in (0 .. data_len) {
|
for i in 0 .. data_len {
|
||||||
let lead_coeff = res[i] as usize;
|
let lead_coeff = res[i] as usize;
|
||||||
if lead_coeff == 0 {
|
if lead_coeff == 0 {
|
||||||
continue;
|
continue;
|
||||||
|
@ -76,8 +76,8 @@ mod ec_tests {
|
||||||
fn interleave<T: Copy, V: Deref<Target=[T]>>(blocks: &Vec<V>) -> Vec<T> {
|
fn interleave<T: Copy, V: Deref<Target=[T]>>(blocks: &Vec<V>) -> Vec<T> {
|
||||||
let last_block_len = blocks.last().unwrap().len();
|
let last_block_len = blocks.last().unwrap().len();
|
||||||
let mut res = Vec::with_capacity(last_block_len * blocks.len());
|
let mut res = Vec::with_capacity(last_block_len * blocks.len());
|
||||||
for i in (0 .. last_block_len) {
|
for i in 0 .. last_block_len {
|
||||||
for t in blocks.iter() {
|
for t in blocks {
|
||||||
if i < t.len() {
|
if i < t.len() {
|
||||||
res.push(t[i]);
|
res.push(t[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
//! match code {
|
//! match code {
|
||||||
//! Err(err) => panic!("Failed to encode the QR code: {:?}", err),
|
//! Err(err) => panic!("Failed to encode the QR code: {:?}", err),
|
||||||
//! Ok(code) => {
|
//! Ok(code) => {
|
||||||
//! for y in (0 .. code.width()) {
|
//! for y in 0 .. code.width() {
|
||||||
//! for x in (0 .. code.width()) {
|
//! for x in 0 .. code.width() {
|
||||||
//! let color = if code[(x, y)] { "black" } else { "white" };
|
//! let color = if code[(x, y)] { "black" } else { "white" };
|
||||||
//! // render color at position (x, y)
|
//! // render color at position (x, y)
|
||||||
//! }
|
//! }
|
||||||
|
@ -164,9 +164,9 @@ impl QrCode {
|
||||||
let width = self.width;
|
let width = self.width;
|
||||||
let mut k = 0;
|
let mut k = 0;
|
||||||
let mut res = String::with_capacity(width * (width + 1));
|
let mut res = String::with_capacity(width * (width + 1));
|
||||||
for _ in (0 .. width) {
|
for _ in 0 .. width {
|
||||||
res.push('\n');
|
res.push('\n');
|
||||||
for _ in (0 .. width) {
|
for _ in 0 .. width {
|
||||||
res.push(if self.content[k] { on_char } else { off_char });
|
res.push(if self.content[k] { on_char } else { off_char });
|
||||||
k += 1;
|
k += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue