]> mj.ucw.cz Git - libucw.git/commitdiff
images/dup-cmp.c split in two files
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 8 Aug 2006 08:26:50 +0000 (10:26 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Tue, 8 Aug 2006 08:26:50 +0000 (10:26 +0200)
images/Makefile
images/dup-cmp.c
images/dup-cmp.h [deleted file]
images/dup-init.c [new file with mode: 0644]
images/duplicates.h [new file with mode: 0644]
images/image-dup-test.c

index 5c60744b4b74681253a435d29a191fa5a9926de6..97abc79bd2a4198e1aa4f5d40095367b9d987b9d 100644 (file)
@@ -4,7 +4,7 @@ DIRS+=images
 
 PROGS+=$(addprefix $(o)/images/,image-tool image-dup-test image-sim-test)
 
-LIBIMAGES_MODS=image scale color alpha io-main dup-cmp sig-dump sig-init sig-cmp object
+LIBIMAGES_MODS=image scale color alpha io-main dup-init dup-cmp sig-dump sig-init sig-cmp object
 
 LIBIMAGES_LIBS=-lm
 
index 35e1ec8e99d992b9be072502dee5c28f31cb0300..5d3650391127a4c17ca076df5ef948da7f25ef02 100644 (file)
  *
  *      This software may be freely distributed and used according to the terms
  *      of the GNU Lesser General Public License.
- *
- *
- *      FIXME:
- *      - many possible optimization
- *      - compare normalized pictures (brightness, ...)
- *      - a blur should help to deal with scaling errors
- *      - maybe better/slower last step
- *      - different thresholds for various transformations
- *      - do not test all transformations for symetric pictures
- *      - allocated memory could be easily decreased to about 1/3
- *        for aspect ratio threshold near one
  */
 
 #undef LOCAL_DEBUG
 
 #include "sherlock/sherlock.h"
 #include "lib/mempool.h"
+#include "lib/fastbuf.h"
 #include "images/images.h"
-#include "images/dup-cmp.h"
+#include "images/duplicates.h"
 
-#include "lib/mempool.h"
-#include "lib/fastbuf.h"
 #include <fcntl.h>
 
 static uns image_dup_ratio_threshold = 140;
 static uns image_dup_error_threshold = 800;
-static uns image_dup_tab_limit = 8;
-
-static inline byte *
-image_dup_block(struct image_dup *dup, uns tab_col, uns tab_row)
-{
-  return dup->tab_pixels + (dup->tab_row_size << tab_row) + (3 << (tab_row + tab_col));
-}
-
-static inline struct image *
-image_dup_subimage(struct image_thread *thread, struct image_dup *dup, struct image *block, uns tab_col, uns tab_row)
-{
-  return image_init_matrix(thread, block, image_dup_block(dup, tab_col, tab_row),
-      1 << tab_col, 1 << tab_row, 3 << tab_col, COLOR_SPACE_RGB);
-}
-
-static inline void
-pixels_average(byte *dest, byte *src1, byte *src2)
-{
-  dest[0] = ((uns)src1[0] + (uns)src2[0]) >> 1;
-  dest[1] = ((uns)src1[1] + (uns)src2[1]) >> 1;
-  dest[2] = ((uns)src1[2] + (uns)src2[2]) >> 1;
-}
-
-uns
-image_dup_estimate_size(uns cols, uns rows)
-{
-  uns tab_cols, tab_rows;
-  for (tab_cols = 0; (uns)(2 << tab_cols) < cols && tab_cols < image_dup_tab_limit; tab_cols++);
-  for (tab_rows = 0; (uns)(2 << tab_rows) < rows && tab_rows < image_dup_tab_limit; tab_rows++);
-  return sizeof(struct image) + cols * rows * 3 + sizeof(struct image_dup) + (12 << (tab_cols + tab_rows)) + 64;
-}
-
-uns
-image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *img, struct mempool *pool)
-{
-  DBG("image_dup_init()");
-
-  ASSERT((img->flags & IMAGE_PIXEL_FORMAT) == COLOR_SPACE_RGB);
-
-  dup->image = img;
-  for (dup->tab_cols = 0; (uns)(2 << dup->tab_cols) < img->cols && dup->tab_cols < image_dup_tab_limit; dup->tab_cols++);
-  for (dup->tab_rows = 0; (uns)(2 << dup->tab_rows) < img->rows && dup->tab_rows < image_dup_tab_limit; dup->tab_rows++);
-  dup->tab_pixels = mp_alloc(pool, dup->tab_size = (12 << (dup->tab_cols + dup->tab_rows)));
-  dup->tab_row_size = 6 << dup->tab_cols;
-
-  /* Scale original image to right bottom block */
-  {
-    struct image block;
-    if (!image_dup_subimage(thread, dup, &block, dup->tab_cols, dup->tab_rows))
-      return 0;
-    if (!image_scale(thread, &block, img))
-      return 0;
-  }
-
-  /* Complete bottom row */
-  for (uns i = dup->tab_cols; i--; )
-    {
-      byte *d = image_dup_block(dup, i, dup->tab_rows);
-      byte *s = image_dup_block(dup, i + 1, dup->tab_rows);
-      for (uns y = 0; y < (uns)(1 << dup->tab_rows); y++)
-       for (uns x = 0; x < (uns)(1 << i); x++)
-         {
-           pixels_average(d, s, s + 3);
-           d += 3;
-           s += 6;
-         }
-    }
-
-  /* Complete remaining blocks */
-  for (uns i = 0; i <= dup->tab_cols; i++)
-    {
-      uns line_size = (3 << i);
-      for (uns j = dup->tab_rows; j--; )
-        {
-          byte *d = image_dup_block(dup, i, j);
-          byte *s = image_dup_block(dup, i, j + 1);
-          for (uns y = 0; y < (uns)(1 << j); y++)
-            {
-              for (uns x = 0; x < (uns)(1 << i); x++)
-                {
-                 pixels_average(d, s, s + line_size);
-                 d += 3;
-                 s += 3;
-               }
-             s += line_size;
-           }
-        }
-    }
-
-  return 1;
-}
 
 static inline uns
 err (int a, int b)
diff --git a/images/dup-cmp.h b/images/dup-cmp.h
deleted file mode 100644 (file)
index bfb2448..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef _IMAGES_DUP_CMP_H
-#define _IMAGES_DUP_CMP_H
-
-struct image_dup {
-  struct image *image;
-  byte *tab_pixels;
-  u32 tab_cols;
-  u32 tab_rows;
-  u32 tab_row_size;
-  u32 tab_size;
-};
-
-#define IMAGE_DUP_TRANS_ID     0x01
-#define IMAGE_DUP_FLIP_X       0x02
-#define IMAGE_DUP_FLIP_Y       0x04
-#define IMAGE_DUP_ROT_180      0x08
-#define IMAGE_DUP_FLIP_BACK    0x10
-#define IMAGE_DUP_ROT_CCW      0x20
-#define IMAGE_DUP_ROT_CW       0x40
-#define IMAGE_DUP_FLIP_SLASH   0x80
-#define IMAGE_DUP_TRANS_ALL    0xff
-#define IMAGE_DUP_SCALE                0x100
-#define IMAGE_DUP_WANT_ALL     0x200
-
-uns image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *image, struct mempool *pool);
-uns image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags);
-uns image_dup_estimate_size(uns cols, uns rows);
-
-#endif
diff --git a/images/dup-init.c b/images/dup-init.c
new file mode 100644 (file)
index 0000000..da4b2be
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ *      Image Library -- Duplicates Comparison
+ *
+ *      (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/mempool.h"
+#include "lib/fastbuf.h"
+#include "images/images.h"
+#include "images/duplicates.h"
+
+#include <fcntl.h>
+
+static uns image_dup_tab_limit = 8;
+
+static inline struct image *
+image_dup_subimage(struct image_thread *thread, struct image_dup *dup, struct image *block, uns tab_col, uns tab_row)
+{
+  return image_init_matrix(thread, block, image_dup_block(dup, tab_col, tab_row),
+      1 << tab_col, 1 << tab_row, 3 << tab_col, COLOR_SPACE_RGB);
+}
+
+static inline void
+pixels_average(byte *dest, byte *src1, byte *src2)
+{
+  dest[0] = ((uns)src1[0] + (uns)src2[0]) >> 1;
+  dest[1] = ((uns)src1[1] + (uns)src2[1]) >> 1;
+  dest[2] = ((uns)src1[2] + (uns)src2[2]) >> 1;
+}
+
+uns
+image_dup_estimate_size(uns cols, uns rows)
+{
+  uns tab_cols, tab_rows;
+  for (tab_cols = 0; (uns)(2 << tab_cols) < cols && tab_cols < image_dup_tab_limit; tab_cols++);
+  for (tab_rows = 0; (uns)(2 << tab_rows) < rows && tab_rows < image_dup_tab_limit; tab_rows++);
+  return sizeof(struct image) + cols * rows * 3 + sizeof(struct image_dup) + (12 << (tab_cols + tab_rows)) + 64;
+}
+
+uns
+image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *img, struct mempool *pool)
+{
+  DBG("image_dup_init()");
+
+  ASSERT((img->flags & IMAGE_PIXEL_FORMAT) == COLOR_SPACE_RGB);
+
+  dup->image = img;
+  for (dup->tab_cols = 0; (uns)(2 << dup->tab_cols) < img->cols && dup->tab_cols < image_dup_tab_limit; dup->tab_cols++);
+  for (dup->tab_rows = 0; (uns)(2 << dup->tab_rows) < img->rows && dup->tab_rows < image_dup_tab_limit; dup->tab_rows++);
+  dup->tab_pixels = mp_alloc(pool, dup->tab_size = (12 << (dup->tab_cols + dup->tab_rows)));
+  dup->tab_row_size = 6 << dup->tab_cols;
+
+  /* Scale original image to right bottom block */
+  {
+    struct image block;
+    if (!image_dup_subimage(thread, dup, &block, dup->tab_cols, dup->tab_rows))
+      return 0;
+    if (!image_scale(thread, &block, img))
+      return 0;
+  }
+
+  /* Complete bottom row */
+  for (uns i = dup->tab_cols; i--; )
+    {
+      byte *d = image_dup_block(dup, i, dup->tab_rows);
+      byte *s = image_dup_block(dup, i + 1, dup->tab_rows);
+      for (uns y = 0; y < (uns)(1 << dup->tab_rows); y++)
+       for (uns x = 0; x < (uns)(1 << i); x++)
+         {
+           pixels_average(d, s, s + 3);
+           d += 3;
+           s += 6;
+         }
+    }
+
+  /* Complete remaining blocks */
+  for (uns i = 0; i <= dup->tab_cols; i++)
+    {
+      uns line_size = (3 << i);
+      for (uns j = dup->tab_rows; j--; )
+        {
+          byte *d = image_dup_block(dup, i, j);
+          byte *s = image_dup_block(dup, i, j + 1);
+          for (uns y = 0; y < (uns)(1 << j); y++)
+            {
+              for (uns x = 0; x < (uns)(1 << i); x++)
+                {
+                 pixels_average(d, s, s + line_size);
+                 d += 3;
+                 s += 3;
+               }
+             s += line_size;
+           }
+        }
+    }
+
+  return 1;
+}
diff --git a/images/duplicates.h b/images/duplicates.h
new file mode 100644 (file)
index 0000000..07db2af
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef _IMAGES_DUP_CMP_H
+#define _IMAGES_DUP_CMP_H
+
+struct image_dup {
+  struct image *image;
+  byte *tab_pixels;
+  u32 tab_cols;
+  u32 tab_rows;
+  u32 tab_row_size;
+  u32 tab_size;
+};
+
+#define IMAGE_DUP_TRANS_ID     0x01
+#define IMAGE_DUP_FLIP_X       0x02
+#define IMAGE_DUP_FLIP_Y       0x04
+#define IMAGE_DUP_ROT_180      0x08
+#define IMAGE_DUP_FLIP_BACK    0x10
+#define IMAGE_DUP_ROT_CCW      0x20
+#define IMAGE_DUP_ROT_CW       0x40
+#define IMAGE_DUP_FLIP_SLASH   0x80
+#define IMAGE_DUP_TRANS_ALL    0xff
+#define IMAGE_DUP_SCALE                0x100
+#define IMAGE_DUP_WANT_ALL     0x200
+
+/* dup-init.c */
+
+uns image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *image, struct mempool *pool);
+uns image_dup_estimate_size(uns cols, uns rows);
+
+/* dup-cmp.c */
+
+uns image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags);
+
+/* internals */
+
+static inline byte *
+image_dup_block(struct image_dup *dup, uns tab_col, uns tab_row)
+{
+  return dup->tab_pixels + (dup->tab_row_size << tab_row) + (3 << (tab_row + tab_col));
+}
+
+
+#endif
index e0d0558cad25ebecfba242de06711794d0106077..0d18ece08a1bd9ba4cdfff6c5ac9753213abfc2e 100644 (file)
@@ -12,7 +12,8 @@
 #include "lib/fastbuf.h"
 #include "images/images.h"
 #include "images/color.h"
-#include "images/dup-cmp.h"
+#include "images/duplicates.h"
+
 #include <stdlib.h>
 #include <fcntl.h>
 #include <errno.h>