]> mj.ucw.cz Git - libucw.git/commitdiff
safe signatures aligning in the indexer
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 12 Sep 2006 08:34:20 +0000 (10:34 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 12 Sep 2006 08:34:20 +0000 (10:34 +0200)
search server and struct image_cluster will follow

images/Makefile
images/sig-fb.c [new file with mode: 0644]
images/signature.h

index 8b7efbdd5c8842da108cb3cc3aa7be29b14ffad0..de7ea49b8a742cbbe4ed5618f64a9205bf980829 100644 (file)
@@ -15,7 +15,7 @@ PROGS+=$(o)/images/image-sim-test
 LIBIMAGES_MODS+=sig-cmp
 endif
 ifneq ($(CONFIG_IMAGES_DUP)$(CONFIG_IMAGES_SIM),)
-LIBIMAGES_MODS+=sig-dump sig-init sig-seg sig-txt
+LIBIMAGES_MODS+=sig-dump sig-fb sig-init sig-seg sig-txt
 endif
 
 LIBIMAGES_LIBS=-lm -lpthread
diff --git a/images/sig-fb.c b/images/sig-fb.c
new file mode 100644 (file)
index 0000000..75dcdeb
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *     Image Library -- Computation of image signatures
+ *
+ *     (c) 2006 Pavel Charvat <pchar@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#undef LOCAL_DEBUG
+
+#include "sherlock/sherlock.h"
+#include "lib/fastbuf.h"
+#include "images/images.h"
+#include "images/signature.h"
+
+uns
+image_signature_read(struct fastbuf *fb, struct image_signature *sig)
+{
+  uns size = image_signature_size(bpeekc(sig));
+  breadb(fb, sig, size);
+#ifndef CPU_ALLOW_UNALIGNED
+#define FIX_U16(x) PUT_U16(&(x), x)
+  FIX_U16(sig->dh);
+  struct image_region *reg = sig->reg;
+  for (uns i = 0; i < sig->len; i++, reg++)
+    {
+      for (uns j = 0; j < IMAGE_REG_H; j++)
+       FIX_U16(reg->h[j]);
+      FIX_U16(reg->wa);
+      FIX_U16(reg->wb);
+    }
+#undef FIX_U16  
+#endif
+  return size;
+}
+
+uns
+image_signature_write(struct fastbuf *fb, struct image_signature *sig)
+{
+  uns size = image_signature_size(sig->len);
+#ifdef CPU_ALLOW_UNALIGNED
+  bwrite(fb, sig, size);
+#else
+  struct image_signature tmp;
+  memcpy(tmp, sig, size);
+#define FIX_U16(x) do { x = GET_U16(&(x)); } while(0)
+  FIX_U16(tmp.dh);
+  struct image_region *reg = tmp.reg;
+  for (uns i = 0; i < tmp.len; i++, reg++)
+    {
+      for (uns j = 0; j < IMAGE_REG_H; j++)
+       FIX_U16(reg->h[j]);
+      FIX_U16(reg->wa);
+      FIX_U16(reg->wb);
+    }
+  bwrite(fb, &tmp, size);
+#undef FIX_U16
+#endif
+  return size;
+}
index e84c7f3164fbb01784fb9c527af634756f39b2d7..27bd2bb15ac693454a29d9463e452e8d9d749baf 100644 (file)
@@ -98,6 +98,33 @@ struct image_sig_data {
   u32 f[IMAGE_VEC_F];
 };
 
+/* sig-fb.c */
+
+#define IMAGE_VECTOR_SIZE (sizeof(struct image_vector))
+
+static inline uns
+image_vector_read(struct fastbuf *fb, struct image_vector *vec)
+{
+  breadb(fb, vec, sizeof(*vec));
+  return IMAGE_VECTOR_SIZE;
+}
+
+static inline uns
+image_vector_write(struct fastbuf *fb, struct image_vector *vec)
+{
+  bwrite(fb, vec, sizeof(*vec));
+  return IMAGE_VECTOR_SIZE;
+}
+
+static inline uns
+image_signature_peek_size(struct fastbuf *fb)
+{
+  return image_signature_size(bpeekc(fb));
+}
+
+uns image_signature_read(struct fastbuf *fb, struct image_signature *sig);
+uns image_signature_write(struct fastbuf *fb, struct image_signature *sig);
+
 /* sig-init.c */
 
 int compute_image_signature(struct image_thread *thread, struct image_signature *sig, struct image *image);