Merge pull request #69 from dlbeer/fix/c99
Refactored some c99 features
This commit is contained in:
commit
cbf911edf0
1 changed files with 6 additions and 6 deletions
|
@ -180,9 +180,8 @@ static uint8_t otsu(const struct quirc *q)
|
||||||
int numPixels = q->w * q->h;
|
int numPixels = q->w * q->h;
|
||||||
|
|
||||||
// Calculate histogram
|
// Calculate histogram
|
||||||
const int HISTOGRAM_SIZE = 256;
|
unsigned int histogram[UINT8_MAX + 1];
|
||||||
unsigned int histogram[HISTOGRAM_SIZE];
|
(void)memset(histogram, 0, sizeof(histogram));
|
||||||
memset(histogram, 0, (HISTOGRAM_SIZE) * sizeof(unsigned int));
|
|
||||||
uint8_t* ptr = q->image;
|
uint8_t* ptr = q->image;
|
||||||
int length = numPixels;
|
int length = numPixels;
|
||||||
while (length--) {
|
while (length--) {
|
||||||
|
@ -191,8 +190,9 @@ static uint8_t otsu(const struct quirc *q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate weighted sum of histogram values
|
// Calculate weighted sum of histogram values
|
||||||
int sum = 0;
|
unsigned int sum = 0;
|
||||||
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
|
unsigned int i = 0;
|
||||||
|
for (i = 0; i <= UINT8_MAX; ++i) {
|
||||||
sum += i * histogram[i];
|
sum += i * histogram[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ static uint8_t otsu(const struct quirc *q)
|
||||||
int q1 = 0;
|
int q1 = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
uint8_t threshold = 0;
|
uint8_t threshold = 0;
|
||||||
for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
|
for (i = 0; i <= UINT8_MAX; ++i) {
|
||||||
// Weighted background
|
// Weighted background
|
||||||
q1 += histogram[i];
|
q1 += histogram[i];
|
||||||
if (q1 == 0)
|
if (q1 == 0)
|
||||||
|
|
Loading…
Reference in a new issue