mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
format aztec
This commit is contained in:
206
src/aztec.rs
206
src/aztec.rs
@@ -1,15 +1,19 @@
|
||||
pub mod decoder;
|
||||
pub mod decoder;
|
||||
pub mod detector;
|
||||
pub mod encoder;
|
||||
|
||||
use crate::{ResultPoint,BarcodeFormat,EncodeHintType,Writer,Reader,ReaderException,WriterException};
|
||||
use crate::common::{BitMatrix,DetectorResult,DecoderResult};
|
||||
use crate::{BarcodeFormat,BinaryBitmap,DecodeHintType,FormatException,NotFoundException,Reader,Result,ResultMetadataType,ResultPoint,ResultPointCallback};
|
||||
use crate::aztec::decoder::Decoder;
|
||||
use crate::aztec::detector::Detector;
|
||||
use crate::common::{BitMatrix, DecoderResult, DetectorResult};
|
||||
use crate::{
|
||||
BarcodeFormat, BinaryBitmap, DecodeHintType, FormatException, NotFoundException, Reader,
|
||||
Result, ResultMetadataType, ResultPoint, ResultPointCallback,
|
||||
};
|
||||
use crate::{
|
||||
BarcodeFormat, EncodeHintType, Reader, ReaderException, ResultPoint, Writer, WriterException,
|
||||
};
|
||||
|
||||
use crate::aztec::encoder::{AztecCode,Encoder};
|
||||
|
||||
use crate::aztec::encoder::{AztecCode, Encoder};
|
||||
|
||||
// AztecDetectorResult.java
|
||||
/**
|
||||
@@ -20,43 +24,53 @@ use crate::aztec::encoder::{AztecCode,Encoder};
|
||||
*/
|
||||
pub struct AztecDetectorResult {
|
||||
//super: DetectorResult;
|
||||
compact: bool,
|
||||
|
||||
compact: bool,
|
||||
nb_datablocks: i32,
|
||||
|
||||
nb_datablocks: i32,
|
||||
nb_layers: i32,
|
||||
|
||||
nb_layers: i32,
|
||||
bits: BitMatrix,
|
||||
|
||||
bits: BitMatrix,
|
||||
|
||||
points: Vec<ResultPoint>,
|
||||
points: Vec<ResultPoint>,
|
||||
}
|
||||
|
||||
impl DetectorResult for AztecDetectorResult {
|
||||
fn get_bits(&self) -> BitMatrix {
|
||||
fn get_bits(&self) -> BitMatrix {
|
||||
return self.bits;
|
||||
}
|
||||
|
||||
fn get_points(&self) -> Vec<ResultPoint> {
|
||||
fn get_points(&self) -> Vec<ResultPoint> {
|
||||
return self.points;
|
||||
}
|
||||
}
|
||||
|
||||
impl AztecDetectorResult {
|
||||
|
||||
pub fn new( bits: &BitMatrix, points: &Vec<ResultPoint>, compact: bool, nb_datablocks: i32, nb_layers: i32) -> Self {
|
||||
Self { compact: compact, nb_datablocks: nd_datablocks, nb_layers: nb_layers, bits: bits, points: points }
|
||||
pub fn new(
|
||||
bits: &BitMatrix,
|
||||
points: &Vec<ResultPoint>,
|
||||
compact: bool,
|
||||
nb_datablocks: i32,
|
||||
nb_layers: i32,
|
||||
) -> Self {
|
||||
Self {
|
||||
compact: compact,
|
||||
nb_datablocks: nd_datablocks,
|
||||
nb_layers: nb_layers,
|
||||
bits: bits,
|
||||
points: points,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_nb_layers(&self) -> i32 {
|
||||
pub fn get_nb_layers(&self) -> i32 {
|
||||
return self.nb_layers;
|
||||
}
|
||||
|
||||
pub fn get_nb_datablocks(&self) -> i32 {
|
||||
pub fn get_nb_datablocks(&self) -> i32 {
|
||||
return self.nb_datablocks;
|
||||
}
|
||||
|
||||
pub fn is_compact(&self) -> bool {
|
||||
pub fn is_compact(&self) -> bool {
|
||||
return self.compact;
|
||||
}
|
||||
}
|
||||
@@ -68,33 +82,35 @@ impl AztecDetectorResult {
|
||||
*
|
||||
* @author David Olivier
|
||||
*/
|
||||
pub struct AztecReader {
|
||||
}
|
||||
pub struct AztecReader {}
|
||||
|
||||
impl Reader for AztecReader {
|
||||
|
||||
/**
|
||||
* Locates and decodes a Data Matrix code in an image.
|
||||
*
|
||||
* @return a String representing the content encoded by the Data Matrix code
|
||||
* @throws NotFoundException if a Data Matrix code cannot be found
|
||||
* @throws FormatException if a Data Matrix code cannot be decoded
|
||||
*/
|
||||
/*fn decode(&self, image: &BinaryBitmap) -> /* throws NotFoundException, FormatException */Result<Result, Rc<Exception>> {
|
||||
* Locates and decodes a Data Matrix code in an image.
|
||||
*
|
||||
* @return a String representing the content encoded by the Data Matrix code
|
||||
* @throws NotFoundException if a Data Matrix code cannot be found
|
||||
* @throws FormatException if a Data Matrix code cannot be decoded
|
||||
*/
|
||||
/*fn decode(&self, image: &BinaryBitmap) -> /* throws NotFoundException, FormatException */Result<Result, Rc<Exception>> {
|
||||
return Ok(self.decode(image, null));
|
||||
}*/
|
||||
|
||||
fn decode(&self, image: &BinaryBitmap, hints: &Map<DecodeHintType, _>) -> Result<Result, ReaderException> {
|
||||
let not_found_exception: NotFoundException = null;
|
||||
let format_exception: FormatException = null;
|
||||
let detector: Detector = Detector::new(&image.get_black_matrix());
|
||||
let mut points: Vec<ResultPoint> = null;
|
||||
let decoder_result: DecoderResult = null;
|
||||
fn decode(
|
||||
&self,
|
||||
image: &BinaryBitmap,
|
||||
hints: &Map<DecodeHintType, _>,
|
||||
) -> Result<Result, ReaderException> {
|
||||
let not_found_exception: NotFoundException = null;
|
||||
let format_exception: FormatException = null;
|
||||
let detector: Detector = Detector::new(&image.get_black_matrix());
|
||||
let mut points: Vec<ResultPoint> = null;
|
||||
let decoder_result: DecoderResult = null;
|
||||
|
||||
let detector_result: AztecDetectorResult = detector.detect(Some(false))?;
|
||||
points = detector_result.get_points()?;
|
||||
decoder_result = Decoder::new().decode(detector_result);
|
||||
/*
|
||||
let detector_result: AztecDetectorResult = detector.detect(Some(false))?;
|
||||
points = detector_result.get_points()?;
|
||||
decoder_result = Decoder::new().decode(detector_result);
|
||||
/*
|
||||
let tryResult1 = 0;
|
||||
'try1: loop {
|
||||
{
|
||||
@@ -137,28 +153,39 @@ impl Reader for AztecReader {
|
||||
}
|
||||
*/
|
||||
if hints != null {
|
||||
let rpcb: ResultPointCallback = hints.get(DecodeHintType::NEED_RESULT_POINT_CALLBACK) as ResultPointCallback;
|
||||
let rpcb: ResultPointCallback =
|
||||
hints.get(DecodeHintType::NEED_RESULT_POINT_CALLBACK) as ResultPointCallback;
|
||||
if rpcb != null {
|
||||
for point in points {
|
||||
for point in points {
|
||||
rpcb.found_possible_result_point(&point);
|
||||
}
|
||||
}
|
||||
}
|
||||
let result: Result = Result::new(&decoder_result.get_text(), &decoder_result.get_raw_bytes(), &decoder_result.get_num_bits(), points, BarcodeFormat::AZTEC, &System::current_time_millis());
|
||||
let byte_segments: List<Vec<i8>> = decoder_result.get_byte_segments();
|
||||
let result: Result = Result::new(
|
||||
&decoder_result.get_text(),
|
||||
&decoder_result.get_raw_bytes(),
|
||||
&decoder_result.get_num_bits(),
|
||||
points,
|
||||
BarcodeFormat::AZTEC,
|
||||
&System::current_time_millis(),
|
||||
);
|
||||
let byte_segments: List<Vec<i8>> = decoder_result.get_byte_segments();
|
||||
if byte_segments != null {
|
||||
result.put_metadata(ResultMetadataType::BYTE_SEGMENTS, &byte_segments);
|
||||
}
|
||||
let ec_level: String = decoder_result.get_e_c_level();
|
||||
let ec_level: String = decoder_result.get_e_c_level();
|
||||
if ec_level != null {
|
||||
result.put_metadata(ResultMetadataType::ERROR_CORRECTION_LEVEL, &ec_level);
|
||||
}
|
||||
result.put_metadata(ResultMetadataType::SYMBOLOGY_IDENTIFIER, format!("]z{}", decoder_result.get_symbology_modifier()));
|
||||
result.put_metadata(
|
||||
ResultMetadataType::SYMBOLOGY_IDENTIFIER,
|
||||
format!("]z{}", decoder_result.get_symbology_modifier()),
|
||||
);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
fn reset(&self) {
|
||||
// do nothing
|
||||
fn reset(&self) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,30 +194,44 @@ impl Reader for AztecReader {
|
||||
/**
|
||||
* Renders an Aztec code as a {@link BitMatrix}.
|
||||
*/
|
||||
pub struct AztecWriter {
|
||||
}
|
||||
pub struct AztecWriter {}
|
||||
|
||||
impl Writer for AztecWriter {
|
||||
|
||||
fn encode(&self, contents: &String, format: &BarcodeFormat, width: i32, height: i32, hints: Option<&HashMap<EncodeHintType, _>>) -> BitMatrix {
|
||||
fn encode(
|
||||
&self,
|
||||
contents: &String,
|
||||
format: &BarcodeFormat,
|
||||
width: i32,
|
||||
height: i32,
|
||||
hints: Option<&HashMap<EncodeHintType, _>>,
|
||||
) -> BitMatrix {
|
||||
// Do not add any ECI code by default
|
||||
let mut charset: Charset = null;
|
||||
let ecc_percent: i32 = Encoder::DEFAULT_EC_PERCENT;
|
||||
let mut layers: i32 = Encoder::DEFAULT_AZTEC_LAYERS;
|
||||
let mut charset: Charset = null;
|
||||
let ecc_percent: i32 = Encoder::DEFAULT_EC_PERCENT;
|
||||
let mut layers: i32 = Encoder::DEFAULT_AZTEC_LAYERS;
|
||||
if hints != null {
|
||||
if hints.contains_key(EncodeHintType::CHARACTER_SET) {
|
||||
charset = Charset::for_name(&hints.get(EncodeHintType::CHARACTER_SET).to_string());
|
||||
}
|
||||
if hints.contains_key(EncodeHintType::ERROR_CORRECTION) {
|
||||
ecc_percent = Integer::parse_int(&hints.get(EncodeHintType::ERROR_CORRECTION).to_string());
|
||||
ecc_percent =
|
||||
Integer::parse_int(&hints.get(EncodeHintType::ERROR_CORRECTION).to_string());
|
||||
}
|
||||
if hints.contains_key(EncodeHintType::AZTEC_LAYERS) {
|
||||
layers = Integer::parse_int(&hints.get(EncodeHintType::AZTEC_LAYERS).to_string());
|
||||
}
|
||||
}
|
||||
return ::encode(&contents, format, width, height, &charset, ecc_percent, layers);
|
||||
return ::encode(
|
||||
&contents,
|
||||
format,
|
||||
width,
|
||||
height,
|
||||
&charset,
|
||||
ecc_percent,
|
||||
layers,
|
||||
);
|
||||
}
|
||||
/*
|
||||
/*
|
||||
fn encode( contents: &String, format: &BarcodeFormat, width: i32, height: i32, charset: &Charset, ecc_percent: i32, layers: i32) -> BitMatrix {
|
||||
if format != BarcodeFormat::AZTEC {
|
||||
return Err( IllegalArgumentException::new(format!("Can only encode AZTEC, but got {}", format)));
|
||||
@@ -198,16 +239,14 @@ impl Writer for AztecWriter {
|
||||
let aztec: AztecCode = Encoder::encode(&contents, ecc_percent, layers, &charset);
|
||||
return ::render_result(aztec, width, height);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl AztecWriter {
|
||||
fn render_result( code: &AztecCode, width: i32, height: i32) -> BitMatrix {
|
||||
fn render_result(code: &AztecCode, width: i32, height: i32) -> BitMatrix {
|
||||
let input: BitMatrix = code.get_matrix();
|
||||
if input == null {
|
||||
return Err( IllegalStateException::new());
|
||||
}
|
||||
if input == null {
|
||||
return Err(IllegalStateException::new());
|
||||
}
|
||||
let input_width: i32 = input.get_width();
|
||||
let input_height: i32 = input.get_height();
|
||||
let output_width: i32 = Math::max(width, input_width);
|
||||
@@ -218,30 +257,29 @@ impl AztecWriter {
|
||||
let output: BitMatrix = BitMatrix::new(output_width, output_height);
|
||||
{
|
||||
let input_y: i32 = 0;
|
||||
let output_y: i32 = top_padding;
|
||||
while input_y < input_height {
|
||||
{
|
||||
// Write the contents of this row of the barcode
|
||||
let output_y: i32 = top_padding;
|
||||
while input_y < input_height {
|
||||
{
|
||||
// Write the contents of this row of the barcode
|
||||
{
|
||||
let input_x: i32 = 0;
|
||||
let output_x: i32 = left_padding;
|
||||
while input_x < input_width {
|
||||
{
|
||||
if input.get(input_x, input_y) {
|
||||
output.set_region(output_x, output_y, multiple, multiple);
|
||||
}
|
||||
}
|
||||
input_x += 1;
|
||||
output_x += multiple;
|
||||
let output_x: i32 = left_padding;
|
||||
while input_x < input_width {
|
||||
{
|
||||
if input.get(input_x, input_y) {
|
||||
output.set_region(output_x, output_y, multiple, multiple);
|
||||
}
|
||||
}
|
||||
input_x += 1;
|
||||
output_x += multiple;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
input_y += 1;
|
||||
output_y += multiple;
|
||||
}
|
||||
input_y += 1;
|
||||
output_y += multiple;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user