- bool OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount) {
- int numCounters = countersCount;//sizeof(counters) / sizeof(int);
- for (int i = 0; i < numCounters; i++) {
- counters[i] = 0;
- }
- int end = row->getSize();
- if (start >= end) {
- return false;
- }
- bool isWhite = !row->get(start);
- int counterPosition = 0;
- int i = start;
- while (i < end) {
- bool pixel = row->get(i);
- if (pixel ^ isWhite) { // that is, exactly one is true
- counters[counterPosition]++;
- } else {
- counterPosition++;
- if (counterPosition == numCounters) {
- break;
- } else {
- counters[counterPosition] = 1;
- isWhite ^= true; // isWhite = !isWhite;
- }
- }
- i++;
- }
- // If we read fully the last section of pixels and filled up our counters -- or filled
- // the last counter but ran off the side of the image, OK. Otherwise, a problem.
- if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
- return false;
- }
- return true;
- }
+ bool OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount) {
+ int numCounters = countersCount;//sizeof(counters) / sizeof(int);
+ for (int i = 0; i < numCounters; i++) {
+ counters[i] = 0;
+ }
+ int end = row->getSize();
+ if (start >= end) {
+ return false;
+ }
+ bool isWhite = !row->get(start);
+ int counterPosition = 0;
+ int i = start;
+ while (i < end) {
+ bool pixel = row->get(i);
+ if (pixel ^ isWhite) { // that is, exactly one is true
+ counters[counterPosition]++;
+ } else {
+ counterPosition++;
+ if (counterPosition == numCounters) {
+ break;
+ } else {
+ counters[counterPosition] = 1;
+ isWhite ^= true; // isWhite = !isWhite;
+ }
+ }
+ i++;
+ }
+ // If we read fully the last section of pixels and filled up our counters -- or filled
+ // the last counter but ran off the side of the image, OK. Otherwise, a problem.
+ if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
+ return false;
+ }
+ return true;
+ }