X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fobject.c;h=7138aa954f703d7a1ee0d73b34660ff54c489db2;hb=e371dcc1cd2857036374dd9597705faed0427006;hp=0d6a146feb2a6cb70bd8a740f4277c3cc94edab0;hpb=44088b65c56a3051f4e31b2369927ff30c32d983;p=libucw.git diff --git a/images/object.c b/images/object.c index 0d6a146f..7138aa95 100644 --- a/images/object.c +++ b/images/object.c @@ -6,7 +6,7 @@ * This software may be freely distributed and used according to the terms */ -#define LOCAL_DEBUG +#undef LOCAL_DEBUG #include "sherlock/sherlock.h" #include "lib/base224.h" @@ -29,7 +29,7 @@ get_image_obj_info(struct image_obj_info *ioi, struct odes *o) DBG("Missing image info attribute"); return 0; } - byte color_space[MAX_ATTR_SIZE], thumb_format[MAX_ATTR_SIZE]; + byte color_space[16], thumb_format[16]; UNUSED uns cnt = sscanf(v, "%d%d%s%d%d%d%s", &ioi->cols, &ioi->rows, color_space, &ioi->colors, &ioi->thumb_cols, &ioi->thumb_rows, thumb_format); ASSERT(cnt == 7); @@ -48,11 +48,15 @@ get_image_obj_thumb(struct image_obj_info *ioi, struct odes *o, struct mempool * return 0; } uns count = 0; + uns max_len = 0; for (struct oattr *b = a; b; b = b->same) - count++; - byte buf[count * MAX_ATTR_SIZE], *b = buf; + { + count++; + max_len += strlen(b->val); + } + byte buf[max_len + 1], *b = buf; for (; a; a = a->same) - b += base224_decode(buf, a->val, strlen(a->val)); + b += base224_decode(b, a->val, strlen(a->val)); ASSERT(b != buf); ioi->thumb_data = mp_alloc(pool, ioi->thumb_size = b - buf); memcpy(ioi->thumb_data, buf, ioi->thumb_size); @@ -75,34 +79,32 @@ read_image_obj_thumb(struct image_obj_info *ioi, struct fastbuf *fb, struct imag if (!io->background_color.color_space) io->background_color = color_white; struct image *img; - if (!(img = image_io_read_data(io, 0))) + if (!(img = image_io_read_data(io, 1))) goto error; - ASSERT(img->cols == ioi->thumb_cols && img->rows == ioi->thumb_rows); DBG("Decompressed thumbnail: size=%ux%u", img->cols, img->rows); return img; error: DBG("Failed to decompress thumbnail: %s", io->thread->err_msg); - return NULL; + return NULL; } void put_image_obj_signature(struct odes *o, struct image_signature *sig) { - /* signatures should be short enough to fit one attribute */ - ASSERT(MAX_ATTR_SIZE > BASE224_ENC_LENGTH(sizeof(struct image_vector) + 4 + sig->len * sizeof(struct image_region))); - byte buf[MAX_ATTR_SIZE], *b = buf; - memcpy(b, &sig->vec, sizeof(struct image_vector)); - b += sizeof(struct image_vector); - *b++ = sig->len; - *b++ = sig->df; - *(u16 *)b++ = sig->dh; - for (uns i = 0; i < sig->len; i++) - { - memcpy(b, sig->reg + i, sizeof(struct image_region)); - b += sizeof(struct image_region); - } - uns len = b - buf; - byte b224[MAX_ATTR_SIZE]; - b224[base224_encode(b224, buf, len)] = 0; - obj_set_attr(o, 'H', b224); + /* signatures should be short enough to in a single attribute */ + uns size = image_signature_size(sig->len); + byte buf[BASE224_ENC_LENGTH(size) + 1]; + buf[base224_encode(buf, (byte *)sig, size)] = 0; + obj_set_attr(o, 'H', buf); +} + +uns +get_image_obj_signature(struct image_signature *sig, struct odes *o) +{ + byte *a = obj_find_aval(o, 'H'); + if (!a) + return 0; + UNUSED uns size = base224_decode((byte *)sig, a, strlen(a)); + ASSERT(size == image_signature_size(sig->len)); + return 1; }