Browse Source

* chg database fmt

master
Alex 'AdUser' Z 10 years ago
parent
commit
b5fee767e0
  1. 10
      src/database.c
  2. 51
      src/database.h
  3. 8
      src/util.c

10
src/database.c

@ -42,6 +42,8 @@
return -1; \ return -1; \
} }
const char *imdb_hdr_fmt = "IMDB v%02u, CAPS: %s;";
int db_open(db_t *db, const char *path) int db_open(db_t *db, const char *path)
{ {
int init = 0; int init = 0;
@ -70,7 +72,7 @@ int db_open(db_t *db, const char *path)
if (init) { if (init) {
memset(buf, 0x0, IMDB_REC_LEN); memset(buf, 0x0, IMDB_REC_LEN);
snprintf((char *) buf, IMDB_REC_LEN, "DB of image fingerprints (vers %d)", IMDB_VERSION); snprintf((char *) buf, IMDB_REC_LEN, imdb_hdr_fmt, IMDB_VERSION, "M-R");
DB_SEEK(db, 0); DB_SEEK(db, 0);
DB_WRITE(db, buf, IMDB_REC_LEN); DB_WRITE(db, buf, IMDB_REC_LEN);
@ -213,11 +215,11 @@ int db_search(db_t *db, rec_t *sample, float tresh, match_t **matches)
while (db_rd_blk(db, &blk) > 0) { while (db_rd_blk(db, &blk) > 0) {
p = blk.data; p = blk.data;
for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) { for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) {
t = p + OFF_USED; t = p + REC_OFF_RU;
if (*t == 0x0) continue; if (*t == 0x0) continue;
t = p + OFF_BITMAP; t = p + REC_OFF_BM;
diff = (float) bitmap_compare(t, sample->data + OFF_BITMAP); diff = (float) bitmap_compare(t, sample->data + REC_OFF_BM);
diff /= BITMAP_BITS; diff /= BITMAP_BITS;
if (diff > tresh) continue; if (diff > tresh) continue;

51
src/database.h

@ -2,7 +2,7 @@
#define HAS_DATABASE_H 1 #define HAS_DATABASE_H 1
#define IMDB_REC_LEN 48 #define IMDB_REC_LEN 48
#define IMDB_VERSION 1 #define IMDB_VERSION 2
#define OPEN_FLAGS O_CREAT | O_RDWR #define OPEN_FLAGS O_CREAT | O_RDWR
typedef struct { typedef struct {
@ -18,21 +18,44 @@ typedef struct {
} block_t; } block_t;
/** /**
pos len || description Database header format - fixed length, 48 bytes
- 0 1 -- record is used
- 1 1 -- must be zero 0-15 : "IMDB vXX, CAPS: "
- 2 32 -- bitmap, each 2 bytes is row of monochrome image 16x16 16-23 : capabilities, terminated with ';'
- 33 1 -- level of color R__ 24-48 : padding with null's
- 34 1 -- level of color _G_ */
- 35 1 -- level of color __B
- 36 11 -- must be zero #define CAP_OFF_BITMAP 0
#define CAP_OFF_COLORS 1
#define CAP_OFF_RATIO 2
/* 3 used, 5 reserved */
/**
Database record format - fixed length, 48 bytes
# | off | len | description
---+-----+-----+-------------------------------------------------------
1 | 0 | 1 | record is used
2 | 1 | 1 | overall level of color: R--
3 | 2 | 1 | overall level of color: -G-
4 | 3 | 1 | overall level of color: --B
5 | 4 | 2 | image width
6 | 6 | 2 | image height
- | 8 | 8 | reserved for future use
7 | 16 | 32 | bitmap, each 2 bytes is row of monochrome image 16x16
field | 12345 6 + 7
map | XRGBWWHH________MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
sect | [ 0-15 ][ 16-31 ][ 32-48 ]
*/ */
#define OFF_USED 0 #define REC_OFF_RU 0 /* record is used */
#define OFF_BITMAP 2 #define REC_OFF_CR 1 /* color level: red */
#define OFF_COLORR 33 #define REC_OFF_CG 2 /* color level: green */
#define OFF_COLORG 34 #define REC_OFF_CB 3 /* color level: blue */
#define OFF_COLORB 35 #define REC_OFF_IW 4 /* image width */
#define REC_OFF_IH 6 /* image height */
#define REC_OFF_BM 16 /* image bitmap */
typedef struct { typedef struct {
uint64_t num; uint64_t num;

8
src/util.c

@ -78,7 +78,7 @@ int db_usage_map(db_t *db, unsigned short int cols)
while (db_rd_blk(db, &blk) > 0) { while (db_rd_blk(db, &blk) > 0) {
p = blk.data; p = blk.data;
for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) { for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) {
t = p + OFF_USED; t = p + REC_OFF_RU;
buf[j] = (*t == 0xFF) ? '1' : '0'; buf[j] = (*t == 0xFF) ? '1' : '0';
if (j++ < cols) if (j++ < cols)
continue; continue;
@ -111,7 +111,7 @@ int rec_bitmap(db_t *db, rec_t *sample)
} }
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
row = *(((uint16_t *) (&sample->data[OFF_BITMAP])) + i); row = *(((uint16_t *) (&sample->data[REC_OFF_BM])) + i);
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
putchar((row & 1) == 1 ? '1' : '0'); putchar((row & 1) == 1 ? '1' : '0');
row >>= 1; row >>= 1;
@ -156,13 +156,13 @@ int rec_diff(db_t *db, unsigned long a, unsigned long b, unsigned short int show
} }
if (showmap == 0) { if (showmap == 0) {
diff = (float) bitmap_compare(&src.data[OFF_BITMAP], &dst.data[OFF_BITMAP]); diff = (float) bitmap_compare(&src.data[REC_OFF_BM], &dst.data[REC_OFF_BM]);
diff /= BITMAP_BITS; diff /= BITMAP_BITS;
printf("%.2f%%\n", diff * 100); printf("%.2f%%\n", diff * 100);
return 0; return 0;
} }
bitmap_diffmap(&map[0], src.data + OFF_BITMAP, dst.data + OFF_BITMAP); bitmap_diffmap(&map[0], src.data + REC_OFF_BM, dst.data + REC_OFF_BM);
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
row = *(((uint16_t *) map) + i); row = *(((uint16_t *) map) + i);

Loading…
Cancel
Save