From f59507ce2a026ce3463fdb7cd00d293ea01f5e36 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 31 Dec 2022 11:56:14 -0600 Subject: [PATCH] add missing to_string methods in pdf417 --- Cargo.toml | 4 +- src/InvertedLuminanceSourceTestCase.java | 39 ------------------ src/pdf417/decoder/detection_result.rs | 40 ++++++++++++++++++- src/pdf417/decoder/detection_result_column.rs | 21 +++++++++- tests/common/pdf_417_multiimage_span.rs | 2 +- 5 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 src/InvertedLuminanceSourceTestCase.java diff --git a/Cargo.toml b/Cargo.toml index 848578c..54e4ecf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -regex = "1.6" +regex = "1.7.0" fancy-regex = "0.10" lazy_static = "1.4.0" encoding = "0.2" @@ -18,7 +18,7 @@ urlencoding = "2.1.2" uriparse = "0.6.4" chrono = "0.4" chrono-tz = "0.4" -image = {version = "0.24.3", optional = true} +image = {version = "0.24.5", optional = true} imageproc = {version = "0.23.0", optional = true} unicode-segmentation = "1.10.0" codepage-437 = "0.1.0" diff --git a/src/InvertedLuminanceSourceTestCase.java b/src/InvertedLuminanceSourceTestCase.java deleted file mode 100644 index 932a7e2..0000000 --- a/src/InvertedLuminanceSourceTestCase.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing; - -import org.junit.Assert; -import org.junit.Test; - -import java.awt.image.BufferedImage; - -/** - * Tests {@link InvertedLuminanceSource}. - */ -public final class InvertedLuminanceSourceTestCase extends Assert { - - @Test - public void testInverted() { - BufferedImage image = new BufferedImage(2, 1, BufferedImage.TYPE_INT_RGB); - image.setRGB(0, 0, 0xFFFFFF); - LuminanceSource source = new BufferedImageLuminanceSource(image); - assertArrayEquals(new byte[] { (byte) 0xFF, 0 }, source.getRow(0, null)); - LuminanceSource inverted = new InvertedLuminanceSource(source); - assertArrayEquals(new byte[] { 0, (byte) 0xFF }, inverted.getRow(0, null)); - } - -} diff --git a/src/pdf417/decoder/detection_result.rs b/src/pdf417/decoder/detection_result.rs index b9412db..0de9f89 100644 --- a/src/pdf417/decoder/detection_result.rs +++ b/src/pdf417/decoder/detection_result.rs @@ -648,7 +648,45 @@ impl DetectionRXingResult { impl Display for DetectionRXingResult { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - todo!() + let mut rowIndicatorColumn = &self.detectionRXingResultColumns[0]; + if rowIndicatorColumn.is_none() { + rowIndicatorColumn = &self.detectionRXingResultColumns[self.barcodeColumnCount + 1]; + } + // try (Formatter formatter = new Formatter()) { + for codewordsRow in 0..rowIndicatorColumn.as_ref().unwrap().getCodewords().len() { + // for (int codewordsRow = 0; codewordsRow < rowIndicatorColumn.getCodewords().length; codewordsRow++) { + write!(f, "CW {0:3}", codewordsRow)?; + // formatter.format("CW %3d:", codewordsRow); + for barcodeColumn in 0..self.barcodeColumnCount + 2 { + // for (int barcodeColumn = 0; barcodeColumn < barcodeColumnCount + 2; barcodeColumn++) { + if self.detectionRXingResultColumns[barcodeColumn].is_none() { + write!(f, "{}", " | ")?; + // formatter.format(" | "); + continue; + } + let codeword = self.detectionRXingResultColumns[barcodeColumn] + .as_ref() + .unwrap() + .getCodewords()[codewordsRow]; + if codeword.is_none() { + write!(f, "{}", " | ")?; + // formatter.format(" | "); + continue; + } + write!( + f, + " {}|{}", + codeword.as_ref().unwrap().getRowNumber(), + codeword.as_ref().unwrap().getValue() + )?; + // formatter.format(" %3d|%3d", codeword.getRowNumber(), codeword.getValue()); + } + // formatter.format("%n"); + write!(f, "{}", "\n")?; + } + // return formatter.toString(); + write!(f, "") + // } } } diff --git a/src/pdf417/decoder/detection_result_column.rs b/src/pdf417/decoder/detection_result_column.rs index f21f81c..7faddc5 100644 --- a/src/pdf417/decoder/detection_result_column.rs +++ b/src/pdf417/decoder/detection_result_column.rs @@ -127,9 +127,26 @@ impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn { impl Display for DetectionRXingResultColumn { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.isLeft.is_some() { - write!(f, "IsLeft: {} \n", self.isLeft.as_ref().unwrap()); + write!(f, "IsLeft: {} \n", self.isLeft.as_ref().unwrap())?; } - todo!() + let mut row = 0; + for codeword in &self.codewords { + // for (Codeword codeword : codewords) { + if codeword.is_none() { + write!(f, "{:3}: | \n", row)?; + row += 1; + continue; + } + write!( + f, + "{:3}: {:3}|{:3}\n", + row, + codeword.as_ref().unwrap().getRowNumber(), + codeword.as_ref().unwrap().getValue() + )?; + row += 1; + } + write!(f, "") } // @Override diff --git a/tests/common/pdf_417_multiimage_span.rs b/tests/common/pdf_417_multiimage_span.rs index fdc09f0..4f812ee 100644 --- a/tests/common/pdf_417_multiimage_span.rs +++ b/tests/common/pdf_417_multiimage_span.rs @@ -152,7 +152,7 @@ impl PDF417MultiImageSpanAbstractBlackBoxTest log::fine(format!("Starting Image Group {}", name)); let file_base_name = name; //testImageGroup.getKey(); - // let expectedText : String; + // let expectedText : String; let mut expected_text_file = test_base.clone().to_path_buf(); expected_text_file.push(file_base_name); expected_text_file.set_extension("txt");