|
|
@ -47,7 +47,7 @@ int db_open(db_t *db, const char *path) |
|
|
|
int init = 0; |
|
|
|
int init = 0; |
|
|
|
ssize_t bytes = 0; |
|
|
|
ssize_t bytes = 0; |
|
|
|
struct stat st; |
|
|
|
struct stat st; |
|
|
|
char buf[REC_LEN] = "\0"; |
|
|
|
char buf[IMDB_REC_LEN] = "\0"; |
|
|
|
|
|
|
|
|
|
|
|
assert(db != NULL); |
|
|
|
assert(db != NULL); |
|
|
|
assert(path != NULL); |
|
|
|
assert(path != NULL); |
|
|
@ -69,12 +69,12 @@ int db_open(db_t *db, const char *path) |
|
|
|
db->path = path; |
|
|
|
db->path = path; |
|
|
|
|
|
|
|
|
|
|
|
if (init) { |
|
|
|
if (init) { |
|
|
|
memset(buf, 0x0, REC_LEN); |
|
|
|
memset(buf, 0x0, IMDB_REC_LEN); |
|
|
|
snprintf((char *) buf, REC_LEN, "DB of image fingerprints (vers %d)", DB_VERSION); |
|
|
|
snprintf((char *) buf, IMDB_REC_LEN, "DB of image fingerprints (vers %d)", IMDB_VERSION); |
|
|
|
DB_SEEK(db, 0); |
|
|
|
DB_SEEK(db, 0); |
|
|
|
DB_WRITE(db, buf, REC_LEN); |
|
|
|
DB_WRITE(db, buf, IMDB_REC_LEN); |
|
|
|
|
|
|
|
|
|
|
|
return bytes / REC_LEN; |
|
|
|
return bytes / IMDB_REC_LEN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -102,10 +102,10 @@ int db_rd_rec(db_t *db, rec_t *rec) |
|
|
|
assert(rec != NULL); |
|
|
|
assert(rec != NULL); |
|
|
|
assert(rec->num > 0); |
|
|
|
assert(rec->num > 0); |
|
|
|
|
|
|
|
|
|
|
|
DB_SEEK(db, rec->num * REC_LEN); |
|
|
|
DB_SEEK(db, rec->num * IMDB_REC_LEN); |
|
|
|
DB_READ(db, rec->data, REC_LEN); |
|
|
|
DB_READ(db, rec->data, IMDB_REC_LEN); |
|
|
|
|
|
|
|
|
|
|
|
return bytes / REC_LEN; |
|
|
|
return bytes / IMDB_REC_LEN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int db_wr_rec(db_t *db, rec_t *rec) |
|
|
|
int db_wr_rec(db_t *db, rec_t *rec) |
|
|
@ -116,10 +116,10 @@ int db_wr_rec(db_t *db, rec_t *rec) |
|
|
|
assert(rec != NULL); |
|
|
|
assert(rec != NULL); |
|
|
|
assert(rec->num > 0); |
|
|
|
assert(rec->num > 0); |
|
|
|
|
|
|
|
|
|
|
|
DB_SEEK(db, rec->num * REC_LEN); |
|
|
|
DB_SEEK(db, rec->num * IMDB_REC_LEN); |
|
|
|
DB_WRITE(db, rec->data, REC_LEN); |
|
|
|
DB_WRITE(db, rec->data, IMDB_REC_LEN); |
|
|
|
|
|
|
|
|
|
|
|
return bytes / REC_LEN; |
|
|
|
return bytes / IMDB_REC_LEN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int db_rd_blk(db_t *db, block_t *blk) |
|
|
|
int db_rd_blk(db_t *db, block_t *blk) |
|
|
@ -132,10 +132,10 @@ int db_rd_blk(db_t *db, block_t *blk) |
|
|
|
assert(blk->records > 0); |
|
|
|
assert(blk->records > 0); |
|
|
|
|
|
|
|
|
|
|
|
FREE(blk->data); |
|
|
|
FREE(blk->data); |
|
|
|
CALLOC(blk->data, blk->records, REC_LEN); |
|
|
|
CALLOC(blk->data, blk->records, IMDB_REC_LEN); |
|
|
|
DB_SEEK(db, blk->start * REC_LEN); |
|
|
|
DB_SEEK(db, blk->start * IMDB_REC_LEN); |
|
|
|
DB_READ(db, blk->data, blk->records * REC_LEN); |
|
|
|
DB_READ(db, blk->data, blk->records * IMDB_REC_LEN); |
|
|
|
blk->records = bytes / REC_LEN; |
|
|
|
blk->records = bytes / IMDB_REC_LEN; |
|
|
|
|
|
|
|
|
|
|
|
return blk->records; |
|
|
|
return blk->records; |
|
|
|
} |
|
|
|
} |
|
|
@ -153,9 +153,9 @@ int db_rd_list(db_t *db, rec_t *list, size_t list_len) |
|
|
|
|
|
|
|
|
|
|
|
r = list; |
|
|
|
r = list; |
|
|
|
for (i = 0; i < list_len; i++, r++) { |
|
|
|
for (i = 0; i < list_len; i++, r++) { |
|
|
|
DB_SEEK(db, r->num * REC_LEN); |
|
|
|
DB_SEEK(db, r->num * IMDB_REC_LEN); |
|
|
|
DB_READ(db, r->data, REC_LEN); |
|
|
|
DB_READ(db, r->data, IMDB_REC_LEN); |
|
|
|
if (bytes == REC_LEN) { processed++; } |
|
|
|
if (bytes == IMDB_REC_LEN) { processed++; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return processed; |
|
|
|
return processed; |
|
|
@ -174,9 +174,9 @@ int db_wr_list(db_t *db, rec_t *list, size_t list_len) |
|
|
|
|
|
|
|
|
|
|
|
r = list; |
|
|
|
r = list; |
|
|
|
for (i = 0; i < list_len; i++, r++) { |
|
|
|
for (i = 0; i < list_len; i++, r++) { |
|
|
|
DB_SEEK(db, r->num * REC_LEN); |
|
|
|
DB_SEEK(db, r->num * IMDB_REC_LEN); |
|
|
|
DB_WRITE(db, r->data, REC_LEN); |
|
|
|
DB_WRITE(db, r->data, IMDB_REC_LEN); |
|
|
|
if (bytes == REC_LEN) { processed++; } |
|
|
|
if (bytes == IMDB_REC_LEN) { processed++; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return processed; |
|
|
|
return processed; |
|
|
@ -212,7 +212,7 @@ int db_search(db_t *db, rec_t *sample, float tresh, match_t **matches) |
|
|
|
*matches = NULL; |
|
|
|
*matches = NULL; |
|
|
|
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 += REC_LEN) { |
|
|
|
for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) { |
|
|
|
t = p + OFF_USED; |
|
|
|
t = p + OFF_USED; |
|
|
|
if (*t == 0x0) continue; |
|
|
|
if (*t == 0x0) continue; |
|
|
|
|
|
|
|
|
|
|
|