diff options
author | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
commit | 9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch) | |
tree | c97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp | |
parent | 780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff) | |
download | pdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz |
XFA: clang-format all pdfium code.
No behavior change.
Generated by:
find . -name '*.cpp' -o -name '*.h' | \
grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \
xargs ../../buildtools/mac/clang-format -i
Then manually merged https://codereview.chromium.org/1269223002/
See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion.
BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp')
-rw-r--r-- | xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp | 250 |
1 files changed, 125 insertions, 125 deletions
diff --git a/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp index 5976d450d9..88b0c43828 100644 --- a/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp +++ b/xfa/src/fxbarcode/common/BC_GlobalHistogramBinarizer.cpp @@ -29,141 +29,141 @@ const int32_t LUMINANCE_BITS = 5;
const int32_t LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
const int32_t LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
-CBC_GlobalHistogramBinarizer::CBC_GlobalHistogramBinarizer(CBC_LuminanceSource *source): CBC_Binarizer(source)
-{
-}
-CBC_GlobalHistogramBinarizer::~CBC_GlobalHistogramBinarizer()
-{
-}
-CBC_CommonBitArray *CBC_GlobalHistogramBinarizer::GetBlackRow(int32_t y, CBC_CommonBitArray *row, int32_t &e)
-{
- CBC_LuminanceSource *source = GetLuminanceSource();
- int32_t width = source->GetWidth();
- CBC_AutoPtr<CBC_CommonBitArray> result(FX_NEW CBC_CommonBitArray(width));
- InitArrays(width);
- CFX_ByteArray *localLuminances = source->GetRow(y, m_luminance, e);
- if (e != BCExceptionNO) {
- return result.release();
- }
- CFX_Int32Array localBuckets;
- localBuckets.Copy(m_buckets);
- int32_t x;
- for (x = 0; x < width; x++) {
- int32_t pixel = (*localLuminances)[x] & 0xff;
- localBuckets[pixel >> LUMINANCE_SHIFT]++;
- }
- int32_t blackPoint = EstimateBlackPoint(localBuckets, e);
- if (e != BCExceptionNO) {
- return result.release();
- }
- int32_t left = (*localLuminances)[0] & 0xff;
- int32_t center = (*localLuminances)[1] & 0xff;
- for (x = 1; x < width - 1; x++) {
- int32_t right = (*localLuminances)[x + 1] & 0xff;
- int32_t luminance = ((center << 2) - left - right) >> 1;
- if (luminance < blackPoint) {
- result->Set(x);
- }
- left = center;
- center = right;
+CBC_GlobalHistogramBinarizer::CBC_GlobalHistogramBinarizer(
+ CBC_LuminanceSource* source)
+ : CBC_Binarizer(source) {}
+CBC_GlobalHistogramBinarizer::~CBC_GlobalHistogramBinarizer() {}
+CBC_CommonBitArray* CBC_GlobalHistogramBinarizer::GetBlackRow(
+ int32_t y,
+ CBC_CommonBitArray* row,
+ int32_t& e) {
+ CBC_LuminanceSource* source = GetLuminanceSource();
+ int32_t width = source->GetWidth();
+ CBC_AutoPtr<CBC_CommonBitArray> result(FX_NEW CBC_CommonBitArray(width));
+ InitArrays(width);
+ CFX_ByteArray* localLuminances = source->GetRow(y, m_luminance, e);
+ if (e != BCExceptionNO) {
+ return result.release();
+ }
+ CFX_Int32Array localBuckets;
+ localBuckets.Copy(m_buckets);
+ int32_t x;
+ for (x = 0; x < width; x++) {
+ int32_t pixel = (*localLuminances)[x] & 0xff;
+ localBuckets[pixel >> LUMINANCE_SHIFT]++;
+ }
+ int32_t blackPoint = EstimateBlackPoint(localBuckets, e);
+ if (e != BCExceptionNO) {
+ return result.release();
+ }
+ int32_t left = (*localLuminances)[0] & 0xff;
+ int32_t center = (*localLuminances)[1] & 0xff;
+ for (x = 1; x < width - 1; x++) {
+ int32_t right = (*localLuminances)[x + 1] & 0xff;
+ int32_t luminance = ((center << 2) - left - right) >> 1;
+ if (luminance < blackPoint) {
+ result->Set(x);
}
- return result.release();
+ left = center;
+ center = right;
+ }
+ return result.release();
}
-CBC_CommonBitMatrix *CBC_GlobalHistogramBinarizer::GetBlackMatrix(int32_t &e)
-{
- CBC_LuminanceSource *source = GetLuminanceSource();
- int32_t width = source->GetWidth();
- int32_t height = source->GetHeight();
- CBC_CommonBitMatrix *BitMatrixTemp = FX_NEW CBC_CommonBitMatrix();
- BitMatrixTemp->Init(width, height);
- CBC_AutoPtr<CBC_CommonBitMatrix> matrix(BitMatrixTemp);
- InitArrays(width);
- CFX_Int32Array localBuckets;
- localBuckets.Copy(m_buckets);
- int32_t y;
- for (y = 1; y < 5; y++) {
- int32_t row = height * y / 5;
- CFX_ByteArray *localLuminances = source->GetRow(row, m_luminance, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- int32_t right = (width << 2) / 5;
- int32_t x;
- for (x = width / 5; x < right; x++) {
- int32_t pixel = (*localLuminances)[x] & 0xff;
- localBuckets[pixel >> LUMINANCE_SHIFT]++;
- }
- }
- int32_t blackPoint = EstimateBlackPoint(localBuckets, e);
+CBC_CommonBitMatrix* CBC_GlobalHistogramBinarizer::GetBlackMatrix(int32_t& e) {
+ CBC_LuminanceSource* source = GetLuminanceSource();
+ int32_t width = source->GetWidth();
+ int32_t height = source->GetHeight();
+ CBC_CommonBitMatrix* BitMatrixTemp = FX_NEW CBC_CommonBitMatrix();
+ BitMatrixTemp->Init(width, height);
+ CBC_AutoPtr<CBC_CommonBitMatrix> matrix(BitMatrixTemp);
+ InitArrays(width);
+ CFX_Int32Array localBuckets;
+ localBuckets.Copy(m_buckets);
+ int32_t y;
+ for (y = 1; y < 5; y++) {
+ int32_t row = height * y / 5;
+ CFX_ByteArray* localLuminances = source->GetRow(row, m_luminance, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CBC_AutoPtr<CFX_ByteArray> localLuminances(source->GetMatrix());
- for (y = 0; y < height; y++) {
- int32_t offset = y * width;
- for (int32_t x = 0; x < width; x++) {
- int32_t pixel = (*localLuminances)[offset + x] & 0xff;
- if (pixel < blackPoint) {
- matrix->Set(x, y);
- }
- }
- }
- return matrix.release();
-}
-void CBC_GlobalHistogramBinarizer::InitArrays(int32_t luminanceSize)
-{
- if(m_luminance.GetSize() < luminanceSize) {
- m_luminance.SetSize(luminanceSize);
+ int32_t right = (width << 2) / 5;
+ int32_t x;
+ for (x = width / 5; x < right; x++) {
+ int32_t pixel = (*localLuminances)[x] & 0xff;
+ localBuckets[pixel >> LUMINANCE_SHIFT]++;
}
- if(m_buckets.GetSize() <= 0) {
- m_buckets.SetSize(LUMINANCE_BUCKETS);
- } else {
- int32_t x;
- for(x = 0; x < LUMINANCE_BUCKETS; x++) {
- m_buckets[x] = 0;
- }
+ }
+ int32_t blackPoint = EstimateBlackPoint(localBuckets, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ CBC_AutoPtr<CFX_ByteArray> localLuminances(source->GetMatrix());
+ for (y = 0; y < height; y++) {
+ int32_t offset = y * width;
+ for (int32_t x = 0; x < width; x++) {
+ int32_t pixel = (*localLuminances)[offset + x] & 0xff;
+ if (pixel < blackPoint) {
+ matrix->Set(x, y);
+ }
}
+ }
+ return matrix.release();
}
-int32_t CBC_GlobalHistogramBinarizer::EstimateBlackPoint(CFX_Int32Array &buckets, int32_t &e)
-{
- int32_t numBuckets = buckets.GetSize();
- int32_t maxBucketCount = 0;
- int32_t firstPeak = 0;
- int32_t firstPeakSize = 0;
+void CBC_GlobalHistogramBinarizer::InitArrays(int32_t luminanceSize) {
+ if (m_luminance.GetSize() < luminanceSize) {
+ m_luminance.SetSize(luminanceSize);
+ }
+ if (m_buckets.GetSize() <= 0) {
+ m_buckets.SetSize(LUMINANCE_BUCKETS);
+ } else {
int32_t x;
- for (x = 0; x < numBuckets; x++) {
- if (buckets[x] > firstPeakSize) {
- firstPeak = x;
- firstPeakSize = buckets[x];
- }
- if (buckets[x] > maxBucketCount) {
- maxBucketCount = buckets[x];
- }
+ for (x = 0; x < LUMINANCE_BUCKETS; x++) {
+ m_buckets[x] = 0;
}
- int32_t secondPeak = 0;
- int32_t secondPeakScore = 0;
- for (x = 0; x < numBuckets; x++) {
- int32_t distanceToBiggest = x - firstPeak;
- int32_t score = buckets[x] * distanceToBiggest * distanceToBiggest;
- if (score > secondPeakScore) {
- secondPeak = x;
- secondPeakScore = score;
- }
+ }
+}
+int32_t CBC_GlobalHistogramBinarizer::EstimateBlackPoint(
+ CFX_Int32Array& buckets,
+ int32_t& e) {
+ int32_t numBuckets = buckets.GetSize();
+ int32_t maxBucketCount = 0;
+ int32_t firstPeak = 0;
+ int32_t firstPeakSize = 0;
+ int32_t x;
+ for (x = 0; x < numBuckets; x++) {
+ if (buckets[x] > firstPeakSize) {
+ firstPeak = x;
+ firstPeakSize = buckets[x];
}
- if (firstPeak > secondPeak) {
- int32_t temp = firstPeak;
- firstPeak = secondPeak;
- secondPeak = temp;
+ if (buckets[x] > maxBucketCount) {
+ maxBucketCount = buckets[x];
}
- if (secondPeak - firstPeak <= numBuckets >> 4) {
- e = BCExceptionRead;
- return 0;
+ }
+ int32_t secondPeak = 0;
+ int32_t secondPeakScore = 0;
+ for (x = 0; x < numBuckets; x++) {
+ int32_t distanceToBiggest = x - firstPeak;
+ int32_t score = buckets[x] * distanceToBiggest * distanceToBiggest;
+ if (score > secondPeakScore) {
+ secondPeak = x;
+ secondPeakScore = score;
}
- int32_t bestValley = secondPeak - 1;
- int32_t bestValleyScore = -1;
- for (x = secondPeak - 1; x > firstPeak; x--) {
- int32_t fromFirst = x - firstPeak;
- int32_t score = fromFirst * fromFirst * (secondPeak - x) * (maxBucketCount - buckets[x]);
- if (score > bestValleyScore) {
- bestValley = x;
- bestValleyScore = score;
- }
+ }
+ if (firstPeak > secondPeak) {
+ int32_t temp = firstPeak;
+ firstPeak = secondPeak;
+ secondPeak = temp;
+ }
+ if (secondPeak - firstPeak <= numBuckets >> 4) {
+ e = BCExceptionRead;
+ return 0;
+ }
+ int32_t bestValley = secondPeak - 1;
+ int32_t bestValleyScore = -1;
+ for (x = secondPeak - 1; x > firstPeak; x--) {
+ int32_t fromFirst = x - firstPeak;
+ int32_t score = fromFirst * fromFirst * (secondPeak - x) *
+ (maxBucketCount - buckets[x]);
+ if (score > bestValleyScore) {
+ bestValley = x;
+ bestValleyScore = score;
}
- return bestValley << LUMINANCE_SHIFT;
+ }
+ return bestValley << LUMINANCE_SHIFT;
}
|