summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@gmail.com>2014-02-27 23:49:05 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@gmail.com>2014-02-27 23:49:05 +0100
commita1b3038ab4a71ec9144ff1be487448a977b08604 (patch)
treee3a23535a24b87d92445bac9d0ab8ce3356b9f8f
parent361c0368d5e740bf7f4732c95f6f7d64aac0c9e3 (diff)
parent48c5a20936e0a1d3bcd480a1c2536ac77186eaf2 (diff)
downloaduca-a1b3038ab4a71ec9144ff1be487448a977b08604.tar.gz
uca-a1b3038ab4a71ec9144ff1be487448a977b08604.tar.bz2
uca-a1b3038ab4a71ec9144ff1be487448a977b08604.tar.xz
uca-a1b3038ab4a71ec9144ff1be487448a977b08604.zip
Merge pull request #33 from miq/mock_fix
Fix memory corruption if using ROIs
-rw-r--r--plugins/mock/CMakeLists.txt2
-rw-r--r--plugins/mock/uca-mock-camera.c29
2 files changed, 16 insertions, 15 deletions
diff --git a/plugins/mock/CMakeLists.txt b/plugins/mock/CMakeLists.txt
index d095fc5..11dd504 100644
--- a/plugins/mock/CMakeLists.txt
+++ b/plugins/mock/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6)
project(ucamock C)
set(UCA_CAMERA_NAME "mock")
-set(PLUGIN_VERSION "1.0.0")
+set(PLUGIN_VERSION "1.0.1")
set(PLUGIN_REVISION "1")
set(PLUGIN_REQUIRES "libuca >= 1.2.0")
set(PLUGIN_SUMMARY "Mock plugin for libuca")
diff --git a/plugins/mock/uca-mock-camera.c b/plugins/mock/uca-mock-camera.c
index b75882e..083c6c8 100644
--- a/plugins/mock/uca-mock-camera.c
+++ b/plugins/mock/uca-mock-camera.c
@@ -137,7 +137,7 @@ static const guint DIGIT_WIDTH = 4;
static const guint DIGIT_HEIGHT = 5;
static void
-print_number (gchar *buffer, guint number, guint x, guint y, guint width)
+print_number (guint8 *buffer, guint number, guint x, guint y, guint width)
{
for (int i = 0; i < DIGIT_WIDTH; i++) {
for (int j = 0; j < DIGIT_HEIGHT; j++) {
@@ -152,39 +152,40 @@ print_number (gchar *buffer, guint number, guint x, guint y, guint width)
}
static void
-print_current_frame (UcaMockCameraPrivate *priv, gchar *buffer)
+print_current_frame (UcaMockCameraPrivate *priv, guint8 *buffer)
{
guint number = priv->current_frame;
char default_line[priv->width];
guint divisor = 10000000;
int x = 1;
+ memset(buffer, 0, 15 * priv->roi_width);
while (divisor > 0) {
- print_number(buffer, number / divisor, x, 1, priv->width);
+ print_number(buffer, number / divisor, x, 1, priv->roi_width);
number = number % divisor;
divisor = divisor / 10;
x += DIGIT_WIDTH + 1;
}
- for (int p = 0; p < priv->width; p++) {
- default_line[p] = (char) ((p*256) / (priv->width));
+ for (int p = 0; p < priv->roi_width; p++) {
+ default_line[p] = (char) ((p*256) / (priv->roi_width));
}
- for (guint y = 16; y < priv->height; y++) {
- guint index = y * priv->width;
- memcpy (&buffer[index], &default_line[0], priv->width);
+ for (guint y = 16; y < priv->roi_height; y++) {
+ guint index = y * priv->roi_width;
+ memcpy (&buffer[index], &default_line[0], priv->roi_width);
}
-
+
#ifdef __CREATE_RANDOM_IMAGE_DATA__
//This block will fill a square at the center of the image with noraml
//distributed random data
const double mean = 128.0;
const double std = 32.0;
- for (guint y = (priv->height/3); y < ((priv->height*2)/3); y++) {
- guint row_start = y * priv->width;
+ for (guint y = (priv->roi_height / 3); y < ((priv->roi_height * 2) / 3); y++) {
+ guint row_start = y * priv->roi_width;
- for (guint i = (priv->width/3); i < ((priv->width*2)/3); i++) {
+ for (guint i = (priv->roi_width / 3); i < ((priv->roi_width * 2) / 3); i++) {
int index = row_start + i;
double u1 = g_rand_double (priv->rand);
double u2 = g_rand_double (priv->rand);
@@ -277,9 +278,9 @@ uca_mock_camera_grab (UcaCamera *camera, gpointer data, GError **error)
UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE (camera);
- g_memmove (data, priv->dummy_data, priv->roi_width * priv->roi_height);
- print_current_frame (priv, data);
+ print_current_frame (priv, priv->dummy_data);
priv->current_frame++;
+ g_memmove (data, priv->dummy_data, priv->roi_width * priv->roi_height);
return TRUE;
}