Browse Source

+ sources

master
Alex 'AdUser' Z 11 years ago
commit
b0b737bac6
  1. 42
      src/image.c
  2. 6
      src/image.h
  3. 34
      src/main.c
  4. 21
      src/main.h
  5. 17
      src/test-image.c

42
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 <gd.h>
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;
}

6
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);

34
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 <gdbm.h>
#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;
}

21
src/main.h

@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
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);*/

17
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;
}
Loading…
Cancel
Save