Alex 'AdUser' Z
11 years ago
7 changed files with 83 additions and 39 deletions
@ -0,0 +1,11 @@
|
||||
all: test-bitmap |
||||
|
||||
%.o: %.c |
||||
gcc -O0 -Wall -Wextra -pedantic -ggdb $< -o $@
|
||||
|
||||
test-bitmap: test-bitmap.c bitmap.c |
||||
gcc -Wall -Wextra -pedantic -g -ggdb test-bitmap.c bitmap.c -o test-bitmap
|
||||
|
||||
clean: |
||||
rm -f *.o
|
||||
rm -f test-bitmap
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Library General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA |
||||
*/ |
||||
|
||||
#include "main.h" |
||||
#include "bitmap.h" |
||||
|
||||
int bitmap_compare(bitmap *a, bitmap *b) |
||||
{ |
||||
uint16_t row = 0; |
||||
uint16_t bit = 0; |
||||
size_t cnt = 0; |
||||
|
||||
for (row = 0; row < 16; row++) { |
||||
bit = 1 << 15; |
||||
while (bit) { |
||||
cnt += !!(((*a)[row] & bit) ^ ((*b)[row] & bit)); |
||||
bit >>= 1; |
||||
} |
||||
} |
||||
|
||||
return cnt; |
||||
} |
@ -0,0 +1,3 @@
|
||||
typedef uint16_t bitmap[16]; |
||||
|
||||
int bitmap_compare(bitmap *a, bitmap *b); |
@ -1,6 +1 @@
|
||||
#define SAMPLE_SIZE sizeof(uint16_t) |
||||
|
||||
typedef uint16_t image_bitmap[16]; |
||||
|
||||
int bitmap_compare(image_bitmap * const a, image_bitmap * const b); |
||||
int image_load(void); |
||||
|
@ -1,17 +0,0 @@
|
||||
#include "main.h" |
||||
#include "image.h" |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
int i = 0; |
||||
image_bitmap a, b; |
||||
|
||||
for (i = 0; i < 16; i++) { |
||||
a[i] = 0x0000; |
||||
b[i] = 0xFFFF; |
||||
} |
||||
|
||||
printf("%u\n", bitmap_compare(&a, &b)); |
||||
|
||||
return 1; |
||||
} |
@ -0,0 +1,34 @@
|
||||
#include "main.h" |
||||
#include "bitmap.h" |
||||
|
||||
int |
||||
main(int argc, char **argv) |
||||
{ |
||||
bitmap a, b; |
||||
|
||||
memset (&a, 0x00, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0x00, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 0); |
||||
|
||||
memset (&a, 0xFE, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0xFF, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 32); |
||||
|
||||
memset (&a, 0x00, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0x55, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 128); |
||||
|
||||
memset (&a, 0x00, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0xAA, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 128); |
||||
|
||||
memset (&a, 0xAA, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0x55, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 256); |
||||
|
||||
memset (&a, 0x00, 16 * sizeof(uint16_t)); |
||||
memset (&b, 0xFF, 16 * sizeof(uint16_t)); |
||||
assert(bitmap_compare(&a, &b) == 256); |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue