summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMihael Koep <koep@schneide.com>2014-09-16 11:34:47 +0200
committerMihael Koep <koep@schneide.com>2014-09-17 09:45:13 +0200
commit718cb1e5d2059b5d88bfe34d8c8bcca6a4550249 (patch)
tree98ea988923811fbc431c55017ec48d3deb286bf1
parentf39be2686446c41a5fbf93eba7fb40ca99efcc3a (diff)
downloaduca-718cb1e5d2059b5d88bfe34d8c8bcca6a4550249.tar.gz
uca-718cb1e5d2059b5d88bfe34d8c8bcca6a4550249.tar.bz2
uca-718cb1e5d2059b5d88bfe34d8c8bcca6a4550249.tar.xz
uca-718cb1e5d2059b5d88bfe34d8c8bcca6a4550249.zip
Fix dexela software roi for multi-byte images
-rw-r--r--plugins/dexela/software-roi.c10
-rw-r--r--plugins/dexela/software-roi.h2
-rw-r--r--plugins/dexela/uca-dexela-camera.c2
-rw-r--r--test/test-software-roi.c54
4 files changed, 50 insertions, 18 deletions
diff --git a/plugins/dexela/software-roi.c b/plugins/dexela/software-roi.c
index 74baa96..6056dec 100644
--- a/plugins/dexela/software-roi.c
+++ b/plugins/dexela/software-roi.c
@@ -1,12 +1,12 @@
#include "software-roi.h"
#include <string.h>
-void apply_software_roi(const guchar* src, guint srcWidth, guchar* dest, guint x, guint y, guint roiWidth, guint roiHeight)
+void apply_software_roi(const guchar* src, guint srcWidth, guint bytesPerPixel, guchar* dest, guint x, guint y, guint roiWidth, guint roiHeight)
{
for (guint row = 0; row < roiHeight; row++) {
- guint rowOffset = srcWidth * (y + row);
- guint offset = rowOffset + x;
- memcpy(dest + row * roiWidth, src + offset, roiWidth);
+ guint roiWidthInBytes = roiWidth * bytesPerPixel;
+ guint rowOffset = srcWidth * bytesPerPixel * (y + row);
+ guint offset = rowOffset + x * bytesPerPixel;
+ memcpy(dest + row * roiWidthInBytes, src + offset, roiWidthInBytes);
}
}
-
diff --git a/plugins/dexela/software-roi.h b/plugins/dexela/software-roi.h
index e2916f0..3fb3b69 100644
--- a/plugins/dexela/software-roi.h
+++ b/plugins/dexela/software-roi.h
@@ -13,6 +13,6 @@
* @param roiWidth
* @param roiHeight
*/
-void apply_software_roi(const guchar* src, guint srcWidth, guchar* dest, guint x, guint y, guint roiWidth, guint roiHeight);
+void apply_software_roi(const guchar* src, guint srcWidth, guint bytesPerPixel, guchar* dest, guint x, guint y, guint roiWidth, guint roiHeight);
#endif // SOFTWAREROI_H
diff --git a/plugins/dexela/uca-dexela-camera.c b/plugins/dexela/uca-dexela-camera.c
index 9269457..5b9c524 100644
--- a/plugins/dexela/uca-dexela-camera.c
+++ b/plugins/dexela/uca-dexela-camera.c
@@ -353,7 +353,7 @@ static gboolean uca_dexela_camera_grab(UcaCamera *camera, gpointer data, GError
g_return_val_if_fail(UCA_IS_DEXELA_CAMERA(camera), FALSE);
UcaDexelaCameraPrivate *priv = UCA_DEXELA_CAMERA_GET_PRIVATE(camera);
guchar* fullFrame = dexela_grab();
- apply_software_roi(fullFrame, priv->width, data, priv->roi_x, priv->roi_y, priv->roi_width, priv->roi_height);
+ apply_software_roi(fullFrame, priv->width, priv->num_bytes, data, priv->roi_x, priv->roi_y, priv->roi_width, priv->roi_height);
return TRUE;
}
diff --git a/test/test-software-roi.c b/test/test-software-roi.c
index 2b628c5..08ab742 100644
--- a/test/test-software-roi.c
+++ b/test/test-software-roi.c
@@ -2,18 +2,34 @@
#include "software-roi.h"
static const guchar test_frame[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8,
- 0, 1, 2, 3, 4, 5, 6, 7, 8,
- 0, 1, 2, 3, 4, 5, 6, 7, 8,
- 0, 1, 2, 3, 4, 5, 6, 7, 8,
- 0, 1, 2, 3, 4, 5, 6, 7, 8,
+ 0, 10, 20, 30, 40, 50, 60, 70, 80,
+ 0, 11, 21, 31, 41, 51, 61, 71, 81,
+ 0, 12, 22, 32, 42, 52, 62, 72, 82,
+ 0, 13, 23, 33, 43, 53, 63, 73, 83,
+ 0, 14, 24, 34, 44, 54, 64, 74, 84,
};
static const guint test_frame_width = 9;
-
static guchar test_roi_2x1_5x3[] = {
- 2, 3, 4, 5, 6,
- 2, 3, 4, 5, 6,
- 2, 3, 4, 5, 6,
+ 21, 31, 41, 51, 61,
+ 22, 32, 42, 52, 62,
+ 23, 33, 43, 53, 63,
+};
+
+static const guchar test_frame16bit[] = {
+ 0, 0, 10, 10, 20, 20, 30, 30, 40, 40, 50, 50, 60, 60, 70, 70,
+ 1, 1, 11, 11, 21, 21, 31, 31, 41, 41, 51, 51, 61, 61, 71, 71,
+ 2, 2, 12, 12, 22, 22, 32, 32, 42, 42, 52, 52, 62, 62, 72, 72,
+ 3, 3, 13, 13, 23, 23, 33, 33, 43, 43, 53, 53, 63, 63, 73, 73,
+ 4, 4, 14, 14, 24, 24, 34, 34, 44, 44, 54, 54, 64, 64, 74, 74,
+ 5, 5, 15, 15, 25, 25, 35, 35, 45, 45, 55, 55, 65, 65, 75, 75,
+ 6, 6, 16, 16, 26, 26, 36, 36, 46, 46, 56, 56, 66, 66, 76, 76,
+};
+static const guint test_frame16bit_width = 8;
+static guchar test_roi16bit_3x3_5x3[] = {
+ 33, 33, 43, 43, 53, 53, 63, 63, 73, 73,
+ 34, 34, 44, 44, 54, 54, 64, 64, 74, 74,
+ 35, 35, 45, 45, 55, 55, 65, 65, 75, 75,
+ 36, 36, 46, 46, 56, 56, 66, 66, 76, 76,
};
void typical_roi_test(void)
@@ -24,7 +40,7 @@ void typical_roi_test(void)
guint roiHeight = 3;
guint roiSize = roiWidth * roiHeight;
guchar roiFrame[roiSize];
- apply_software_roi(test_frame, test_frame_width, roiFrame, roiX, roiY, roiWidth, roiHeight);
+ apply_software_roi(test_frame, test_frame_width, 1, roiFrame, roiX, roiY, roiWidth, roiHeight);
for (guint i = 0; i < roiSize; i++) {
g_assert_cmpint(test_roi_2x1_5x3[i], ==, roiFrame[i]);
}
@@ -38,16 +54,32 @@ void nrows_only_roi_test(void)
guint roiHeight = 3;
guint roiSize = roiWidth * roiHeight;
guchar roiFrame[roiSize];
- apply_software_roi(test_frame, test_frame_width, roiFrame, roiX, roiY, roiWidth, roiHeight);
+ apply_software_roi(test_frame, test_frame_width, 1, roiFrame, roiX, roiY, roiWidth, roiHeight);
for (guint i = 0; i < roiSize; i++) {
g_assert_cmpint(test_frame[i], ==, roiFrame[i]);
}
}
+void multibyte_image_test(void)
+{
+ guint roiX = 3;
+ guint roiY = 3;
+ guint roiWidth = 5;
+ guint roiHeight = 3;
+ guint bytesPerPixel = 2;
+ guint roiSize = roiWidth * bytesPerPixel * roiHeight;
+ guchar roiFrame[roiSize];
+ apply_software_roi(test_frame16bit, test_frame16bit_width, bytesPerPixel, roiFrame, roiX, roiY, roiWidth, roiHeight);
+ for (guint i = 0; i < roiSize; i++) {
+ g_assert_cmpint(test_roi16bit_3x3_5x3[i], ==, roiFrame[i]);
+ }
+}
+
int main(int argc, char** argv)
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/software-roi/apply-typical-roi", typical_roi_test);
g_test_add_func("/software-roi/apply-roi-nrows-only", nrows_only_roi_test);
+ g_test_add_func("/software-roi/apply-roi-multibyte-image", multibyte_image_test);
return g_test_run();
}