Skip to content

Commit

Permalink
set shape before offset to avoid offset oob
Browse files Browse the repository at this point in the history
  • Loading branch information
nclack committed Aug 14, 2023
1 parent c8ec599 commit 61d843f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/dcam.camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ aq_dcam_get_metadata__inner(const struct Dcam4Camera* self,
is_ok &= READ_PROP_META(
&metadata->readout_direction, DCAM_IDPROP_READOUT_DIRECTION, 1.0f);

is_ok &=
READ_PROP_META(&metadata->offset.x, DCAM_IDPROP_SUBARRAYHPOS, 1.0f);
is_ok &=
READ_PROP_META(&metadata->offset.y, DCAM_IDPROP_SUBARRAYVPOS, 1.0f);
is_ok &=
READ_PROP_META(&metadata->shape.x, DCAM_IDPROP_SUBARRAYHSIZE, 1.0f);
is_ok &=
READ_PROP_META(&metadata->shape.y, DCAM_IDPROP_SUBARRAYVSIZE, 1.0f);
is_ok &=
READ_PROP_META(&metadata->offset.x, DCAM_IDPROP_SUBARRAYHPOS, 1.0f);
is_ok &=
READ_PROP_META(&metadata->offset.y, DCAM_IDPROP_SUBARRAYVPOS, 1.0f);

#undef READ_PROP_META

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ else()
dcam-reset-on-fail
one-video-stream
set-output-trigger
set-roi
)

foreach(name ${tests})
Expand Down
88 changes: 88 additions & 0 deletions tests/set-roi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! Test: Runs through setting up acquiring from a sub-rectangle of the sensor
#include "acquire.h"
#include "device/hal/device.manager.h"
#include "device/props/components.h"
#include "logger.h"
#include <stdio.h>
#include <string.h>

#define L (aq_logger)
#define LOG(...) L(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#define ERR(...) L(1, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#define CHECK(e) \
do { \
if (!(e)) { \
ERR("Expression evaluated as false: " #e); \
goto Error; \
} \
} while (0)
#define DEVOK(e) CHECK(Device_Ok == (e))
#define OK(e) CHECK(AcquireStatus_Ok == (e))

#define countof(e) (sizeof(e) / sizeof(*(e)))

void
reporter(int is_error,
const char* file,
int line,
const char* function,
const char* msg)
{
fprintf(is_error ? stderr : stdout,
"%s%s(%d) - %s: %s\n",
is_error ? "ERROR " : "",
file,
line,
function,
msg);
}

int
setup(AcquireRuntime* runtime)
{
AcquireProperties props = {};

const DeviceManager* dm = 0;
CHECK(dm = acquire_device_manager(runtime));

#define SIZED(s) s, sizeof(s) - 1
DEVOK(device_manager_select(dm,
DeviceKind_Camera,
SIZED("Hamamatsu C15440-20UP.*"),
&props.video[0].camera.identifier));
DEVOK(device_manager_select(dm,
DeviceKind_Storage,
SIZED("Trash"),
&props.video[0].storage.identifier));
#undef SIZED

props.video[0].max_frame_count = 10;
props.video[0].camera.settings.shape = { .x = 1700, .y = 512 };
props.video[0].camera.settings.offset = { .x = 302, .y = 896 };
OK(acquire_configure(runtime, &props));
// Expect that the roi is what we intended.
CHECK(props.video[0].camera.settings.shape.x == 1700);
CHECK(props.video[0].camera.settings.shape.y == 512);
CHECK(props.video[0].camera.settings.offset.x == 302);
CHECK(props.video[0].camera.settings.offset.y == 896);
return 1;
Error:
return 0;
}

int
main()
{
int ecode = 0;
AcquireRuntime* runtime = 0;
CHECK(runtime = acquire_init(reporter));
CHECK(setup(runtime));
OK(acquire_start(runtime));
OK(acquire_stop(runtime));
Finalize:
acquire_shutdown(runtime);
return ecode;
Error:
ecode = 1;
goto Finalize;
}

0 comments on commit 61d843f

Please sign in to comment.