Merge pull request #69 from dlbeer/fix/c99

Refactored some c99 features
This commit is contained in:
Alexandre Perrin 2020-03-13 21:51:35 +01:00 committed by GitHub
commit cbf911edf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -180,9 +180,8 @@ static uint8_t otsu(const struct quirc *q)
int numPixels = q->w * q->h;
// Calculate histogram
const int HISTOGRAM_SIZE = 256;
unsigned int histogram[HISTOGRAM_SIZE];
memset(histogram, 0, (HISTOGRAM_SIZE) * sizeof(unsigned int));
unsigned int histogram[UINT8_MAX + 1];
(void)memset(histogram, 0, sizeof(histogram));
uint8_t* ptr = q->image;
int length = numPixels;
while (length--) {
@ -191,8 +190,9 @@ static uint8_t otsu(const struct quirc *q)
}
// Calculate weighted sum of histogram values
int sum = 0;
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
unsigned int sum = 0;
unsigned int i = 0;
for (i = 0; i <= UINT8_MAX; ++i) {
sum += i * histogram[i];
}
@ -201,7 +201,7 @@ static uint8_t otsu(const struct quirc *q)
int q1 = 0;
double max = 0;
uint8_t threshold = 0;
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
for (i = 0; i <= UINT8_MAX; ++i) {
// Weighted background
q1 += histogram[i];
if (q1 == 0)