* LuminanceSource.cpp
* zxing
*
- * Created by Ralf Kistner on 16/10/2009.
* Copyright 2008 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
unsigned char* matrix = new unsigned char[width * height];
unsigned char* row = new unsigned char[width];
for (int y = 0; y < height; y++) {
- getRow(y, row);
+ row = getRow(y, row);
memcpy(&matrix[y * width], row, width);
}
delete [] row;
virtual int getWidth() const = 0;
virtual int getHeight() const = 0;
+ // Callers take ownership of the returned memory and must call delete [] on it themselves.
virtual unsigned char* getRow(int y, unsigned char* row) = 0;
virtual unsigned char* getMatrix();
unsigned char* row_pixels = NULL;
try {
row_pixels = new unsigned char[width];
- row_pixels = getLuminanceSource()->getRow(y, row_pixels);
+ row_pixels = source.getRow(y, row_pixels);
for (int x = 0; x < width; x++) {
histogram[row_pixels[x] >> LUMINANCE_SHIFT]++;
}
int rownum = height * y / 5;
int right = (width << 2) / 5;
int sdf;
- getLuminanceSource()->getRow(rownum,row);
+ row = source.getRow(rownum, row);
for (int x = width / 5; x < right; x++) {
histogram[row[x] >> LUMINANCE_SHIFT]++;
sdf = histogram[row[x] >> LUMINANCE_SHIFT];
Ref<BitMatrix> matrix_ref(new BitMatrix(width, height));
BitMatrix& matrix = *matrix_ref;
for (int y = 0; y < height; y++) {
- getLuminanceSource()->getRow(y,row);
+ row = source.getRow(y, row);
for (int x = 0; x < width; x++) {
if (row[x] <= blackPoint)
matrix.set(x, y);
}
cached_matrix_ = matrix_ref;
-
delete [] row;
return matrix_ref;
}
}
unsigned char* GreyscaleLuminanceSource::getMatrix() {
+ if (left_ != 0 || top_ != 0 || dataWidth_ != width_ || dataHeight_ != height_) {
+ unsigned char* cropped = new unsigned char[width_ * height_];
+ for (int row = 0; row < height_; row++) {
+ memcpy(cropped + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_);
+ }
+ return cropped;
+ }
return greyData_;
}
cached_matrix_.reset(new BitMatrix(width,height));
calculateThresholdForBlock(luminances, subWidth, subHeight, width, blackPoints, cached_matrix_);
delete [] blackPoints;
+ delete [] luminances;
} else {
// If the image is too small, fall back to the global histogram approach.
cached_matrix_.reset(GlobalHistogramBinarizer::getBlackMatrix());