commit b0b737bac612cb7c8c65f2e8dfeadb3c74f824d0 Author: Alex 'AdUser' Z Date: Wed Mar 12 20:56:30 2014 +1100 + sources diff --git a/src/image.c b/src/image.c new file mode 100644 index 0000000..ba9afa8 --- /dev/null +++ b/src/image.c @@ -0,0 +1,42 @@ +/* + * 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 "image.h" + +#include + +int bitmap_compare(image_bitmap * const a, image_bitmap * const 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; +} + +int image_load(void) +{ + return 1; +} diff --git a/src/image.h b/src/image.h new file mode 100644 index 0000000..a991cb2 --- /dev/null +++ b/src/image.h @@ -0,0 +1,6 @@ +#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); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..34e2956 --- /dev/null +++ b/src/main.c @@ -0,0 +1,34 @@ +/* + * 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 + +#define DB_BLOCKSIZE 256 * 1024 + +GDBM_FILE dbf; + +int db_open(char *samples, char *files) +{ + dbf = gdbm_open(samples, DB_BLOCKSIZE, GDBM_WRCREAT, 0644, 0); + + if (!dbf) { + printf("Can't open database: %s\n", gdbm_strerror(gdbm_errno)); + return 0; + } + + return 1; +} diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..5d26eee --- /dev/null +++ b/src/main.h @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern int db_open(char *samples, char *files); +extern int db_close(void); + +extern int image_add(uint64_t, char *path); +extern int image_del(uint64_t); +extern int image_exists(uint64_t); +/*extern int image_find(uint64_t, rec_t **data, size_t limit);*/ diff --git a/src/test-image.c b/src/test-image.c new file mode 100644 index 0000000..f6a61b0 --- /dev/null +++ b/src/test-image.c @@ -0,0 +1,17 @@ +#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; +}