mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
port relevant parts of r1937 to C++
git-svn-id: https://zxing.googlecode.com/svn/trunk@1962 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ccf08aabe8
commit
9558d83d71
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* Binarizer.cpp
|
||||
* zxing
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* Result.cpp
|
||||
* zxing
|
||||
|
|
|
@ -73,7 +73,7 @@ void BitArray::setBulk(size_t i, unsigned int newBits) {
|
|||
|
||||
void BitArray::setRange(int start, int end) {
|
||||
if (end < start) {
|
||||
throw new IllegalArgumentException("invalid call to BitArray::setRange");
|
||||
throw IllegalArgumentException("invalid call to BitArray::setRange");
|
||||
}
|
||||
if (end == start) {
|
||||
return;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* DetectorResult.cpp
|
||||
* zxing
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* GlobalHistogramBinarizer.cpp
|
||||
* zxing
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* HybridBinarizer.cpp
|
||||
* zxing
|
||||
|
@ -31,7 +32,7 @@ static const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
|
|||
static const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
|
||||
|
||||
HybridBinarizer::HybridBinarizer(Ref<LuminanceSource> source) :
|
||||
GlobalHistogramBinarizer(source), cached_matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) {
|
||||
GlobalHistogramBinarizer(source), matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,40 +40,43 @@ HybridBinarizer::~HybridBinarizer() {
|
|||
}
|
||||
|
||||
|
||||
Ref<BitMatrix> HybridBinarizer::getBlackMatrix() {
|
||||
binarizeEntireImage();
|
||||
return cached_matrix_;
|
||||
}
|
||||
|
||||
Ref<Binarizer> HybridBinarizer::createBinarizer(Ref<LuminanceSource> source) {
|
||||
return Ref<Binarizer> (new HybridBinarizer(source));
|
||||
}
|
||||
|
||||
void HybridBinarizer::binarizeEntireImage() {
|
||||
if (cached_matrix_ == NULL) {
|
||||
Ref<LuminanceSource> source = getLuminanceSource();
|
||||
if (source->getWidth() >= MINIMUM_DIMENSION && source->getHeight() >= MINIMUM_DIMENSION) {
|
||||
unsigned char* luminances = source->getMatrix();
|
||||
int width = source->getWidth();
|
||||
int height = source->getHeight();
|
||||
Ref<BitMatrix> HybridBinarizer::getBlackMatrix() {
|
||||
// Calculates the final BitMatrix once for all requests. This could be called once from the
|
||||
// constructor instead, but there are some advantages to doing it lazily, such as making
|
||||
// profiling easier, and not doing heavy lifting when callers don't expect it.
|
||||
if (matrix_) {
|
||||
return matrix_;
|
||||
}
|
||||
LuminanceSource& source = *getLuminanceSource();
|
||||
if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) {
|
||||
unsigned char* luminances = source.getMatrix();
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
int subWidth = width >> 3;
|
||||
if (width & 0x07) {
|
||||
if ((width & 0x07) != 0) {
|
||||
subWidth++;
|
||||
}
|
||||
int subHeight = height >> 3;
|
||||
if (height & 0x07) {
|
||||
if ((height & 0x07) != 0) {
|
||||
subHeight++;
|
||||
}
|
||||
int *blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);
|
||||
cached_matrix_.reset(new BitMatrix(width,height));
|
||||
calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, cached_matrix_);
|
||||
int* blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);
|
||||
|
||||
Ref<BitMatrix> newMatrix (new BitMatrix(width, height));
|
||||
calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix);
|
||||
matrix_ = newMatrix;
|
||||
|
||||
delete [] blackPoints;
|
||||
delete [] luminances;
|
||||
} else {
|
||||
// If the image is too small, fall back to the global histogram approach.
|
||||
cached_matrix_.reset(GlobalHistogramBinarizer::getBlackMatrix());
|
||||
}
|
||||
matrix_ = GlobalHistogramBinarizer::getBlackMatrix();
|
||||
}
|
||||
return matrix_;
|
||||
}
|
||||
|
||||
void HybridBinarizer::calculateThresholdForBlock(unsigned char* luminances, int subWidth, int subHeight,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
#ifndef __HYBRIDBINARIZER_H__
|
||||
#define __HYBRIDBINARIZER_H__
|
||||
/*
|
||||
|
@ -29,7 +30,7 @@ namespace zxing {
|
|||
|
||||
class HybridBinarizer : public GlobalHistogramBinarizer {
|
||||
private:
|
||||
Ref<BitMatrix> cached_matrix_;
|
||||
Ref<BitMatrix> matrix_;
|
||||
Ref<BitArray> cached_row_;
|
||||
int cached_row_num_;
|
||||
|
||||
|
@ -40,7 +41,6 @@ namespace zxing {
|
|||
virtual Ref<BitMatrix> getBlackMatrix();
|
||||
Ref<Binarizer> createBinarizer(Ref<LuminanceSource> source);
|
||||
private:
|
||||
void binarizeEntireImage();
|
||||
// We'll be using one-D arrays because C++ can't dynamically allocate 2D arrays
|
||||
int* calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight,
|
||||
int width, int height);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* Detector.cpp
|
||||
* zxing
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
#ifndef __DETECTOR_H__
|
||||
#define __DETECTOR_H__
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* OneDReader.cpp
|
||||
* ZXing
|
||||
|
|
Loading…
Reference in a new issue