} else {
row->clear();
}
-
+
//TODO(flyashi): cache this instead of allocating and deleting per row
unsigned char* row_pixels = NULL;
try {
- row_pixels = new unsigned char[width];
- getLuminanceSource()->getRow(y,row_pixels);
- for (int x = 0; x < width; x++) {
- histogram[row_pixels[x] >> LUMINANCE_SHIFT]++;
- }
- int blackPoint = estimate(histogram) << LUMINANCE_SHIFT;
-
-
- Ref<BitArray> array_ref(new BitArray(width));
- BitArray& array = *array_ref;
-
- int left = row_pixels[0];
- int center = row_pixels[1];
- for (int x = 1; x < width - 1; x++) {
- int right = row_pixels[x + 1];
- // A simple -1 4 -1 box filter with a weight of 2.
- int luminance = ((center << 2) - left - right) >> 1;
- if (luminance < blackPoint) {
- array.set(x);
- }
- left = center;
- center = right;
+ row_pixels = new unsigned char[width];
+ row_pixels = getLuminanceSource()->getRow(y, row_pixels);
+ for (int x = 0; x < width; x++) {
+ histogram[row_pixels[x] >> LUMINANCE_SHIFT]++;
+ }
+ int blackPoint = estimate(histogram) << LUMINANCE_SHIFT;
+
+ BitArray& array = *row;
+ int left = row_pixels[0];
+ int center = row_pixels[1];
+ for (int x = 1; x < width - 1; x++) {
+ int right = row_pixels[x + 1];
+ // A simple -1 4 -1 box filter with a weight of 2.
+ int luminance = ((center << 2) - left - right) >> 1;
+ if (luminance < blackPoint) {
+ array.set(x);
}
+ left = center;
+ center = right;
+ }
- cached_row_ = array_ref;
- cached_row_num_ = y;
- delete [] row_pixels;
- return array_ref;
+ cached_row_ = row;
+ cached_row_num_ = y;
+ delete [] row_pixels;
+ return row;
} catch (IllegalArgumentException const& iae) {
- // Cache the fact that this row failed.
- cached_row_ = NULL;
- cached_row_num_ = y;
- delete [] row_pixels;
- throw iae;
+ // Cache the fact that this row failed.
+ cached_row_ = NULL;
+ cached_row_num_ = y;
+ delete [] row_pixels;
+ throw iae;
}
}
}
} // namespace zxing
-
namespace zxing {
-GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
- int width, int height) : greyData_(greyData), dataWidth_(dataWidth), dataHeight_(dataHeight),
- left_(left), top_(top), width_(width), height_(height) {
+GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth,
+ int dataHeight, int left, int top, int width, int height) : greyData_(greyData),
+ dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width),
+ height_(height) {
if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
throw IllegalArgumentException("Crop rectangle does not fit within image data.");
}
unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
-
if (y < 0 || y >= this->getHeight()) {
throw IllegalArgumentException("Requested row is outside the image: " + y);
}
}
int offset = (y + top_) * dataWidth_ + left_;
memcpy(row, &greyData_[offset], width);
-
return row;
}
-
unsigned char* GreyscaleLuminanceSource::getMatrix() {
return greyData_;
}
Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
// Intentionally flip the left, top, width, and height arguments as needed. dataWidth and
// dataHeight are always kept unrotated.
- return Ref<LuminanceSource> (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_, dataHeight_,
- top_, left_, height_, width_));
+ return Ref<LuminanceSource> (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_,
+ dataHeight_, top_, left_, height_, width_));
}
-
} /* namespace */
-
int height_;
public:
- GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
- int width, int height);
+ GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left,
+ int top, int width, int height);
unsigned char* getRow(int y, unsigned char* row);
-
unsigned char* getMatrix();
bool isRotateSupported() const {
}
Ref<LuminanceSource> rotateCounterClockwise();
-
+
};
} /* namespace */
// Note that dataWidth and dataHeight are not reversed, as we need to be able to traverse the
// greyData correctly, which does not get rotated.
-GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight,
- int left, int top, int width, int height) : greyData_(greyData), dataWidth_(dataWidth), dataHeight_(dataHeight),
- left_(left), top_(top), width_(width), height_(height) {
+GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData,
+ int dataWidth, int dataHeight, int left, int top, int width, int height) : greyData_(greyData),
+ dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width),
+ height_(height) {
// Intentionally comparing to the opposite dimension since we're rotated.
if (left + width > dataHeight || top + height > dataWidth) {
int height_;
public:
- GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
- int width, int height);
+ GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight,
+ int left, int top, int width, int height);
unsigned char* getRow(int y, unsigned char* row);
-
unsigned char* getMatrix();
bool isRotateSupported() const {
}
};
-} /* namespace */
+} /* namespace */
#endif