24 #include <core/exception.h> 26 #include <fvcams/leutron.h> 27 #include <fvutils/color/colorspaces.h> 46 LeutronCamera::LeutronCamera()
48 started = opened =
false;
51 cspace = YUV422_PACKED;
53 camera_name =
"PAL_S_CCIR";
58 LeutronCamera::~LeutronCamera()
67 camera_handle = HANDLE_INVALID;
73 if (DsyRecheckConnector() != I_NoError) {
74 throw Exception(
"LeutronCam: DsyRecheckConnector() failed");
77 LvCameraConnDlgInfo *info;
78 HANDLE conn_info_handle = NULL;
79 HGRABBER grabber_handle = HANDLE_INVALID;
81 if (DsyDetectCamera(&conn_info_handle) > 0) {
83 info = (LvCameraConnDlgInfo *)GlobalLock(conn_info_handle);
86 grabber = info[0].Grabber;
91 camera_id = info[0].CameraType;
94 LvCameraInfo cam_info;
95 for (
int i = 0; DsyEnumCameraType(i, &cam_info) == I_NoError; ++i) {
96 if ( strcmp(camera_name, cam_info.Name) == 0 ) {
98 camera_id = cam_info.Id;
102 if (camera_id == -1) {
104 camera_id = info[0].CameraType;
108 if (grabber == NULL) {
109 throw Exception(
"LeutronCam: grabber == NULL");
111 grabber_handle = info[0].hGrabber;
112 if (grabber_handle == HANDLE_INVALID) {
113 throw Exception(
"LeutronCam: grabber handle is invalid.");
115 if (info[0].hConn == HANDLE_INVALID) {
116 throw Exception(
"LeutronCam: connection handle is invalid.");
118 camera_handle = grabber->ConnectCamera(camera_id,
121 if ( camera_handle == HANDLE_INVALID ) {
122 throw Exception(
"LeutronCam: Could not connect the camera");
126 camera = grabber->GetCameraPtr(camera_handle);
127 camera->GetDescription(tmp,
sizeof(tmp));
131 GlobalFree(conn_info_handle);
133 if (grabber->ActivateCamera( camera_handle ) != DSY_I_NoError) {
134 throw Exception(
"LeutronCam: Could not activate camera");
137 LvSourceInfo src_info;
138 camera->GetSourceROI(&src_info);
142 if (camera->SetSourceROI( &src_info ) != DSY_I_NoError) {
146 width = src_info.MaxWidth;
147 height = src_info.MaxHeight;
148 scaled_width = width;
149 scaled_height = height;
156 if ( (scaled_width != width) || (scaled_height != height) ) {
158 scaled_buffer = (
unsigned char*)malloc(colorspace_buffer_size(YUV422_PACKED, scaled_width, scaled_height));
162 grabber->GetConnectionInfo( camera_handle, &roi );
163 roi.SetTargetBuffer( TgtBuffer_CPU );
164 roi.SetDIBMode( TRUE );
165 if (cspace != YUV422_PACKED) {
168 roi.SetColorFormat( ColF_YUV_422 );
169 roi.SetStartPosition( 0, 0 );
170 roi.SetDimension( scaled_width, scaled_height );
171 roi.SetMemoryWidth( width );
180 if (grabber->ActivateROI(camera_handle, &roi) != DSY_I_NoError) {
181 throw Exception(
"LeutronCam: Cannot activate ROI");
184 camera->Live( SY_None );
187 throw Exception(
"LeutronCam: Could not get lock on connection info.");
191 throw Exception(
"LeutronCam: Could not find any camera.");
198 LeutronCamera::start()
200 if ( started )
return;
202 throw Exception(
"LeutronCam: Trying to start closed cam!");
210 LeutronCamera::stop()
216 LeutronCamera::print_info()
221 LeutronCamera::capture()
226 LeutronCamera::flush()
231 LeutronCamera::buffer()
234 grabber->GetConnectionInfo(camera_handle, &roi);
236 if ( (scaled_width != width) || (scaled_height != height) ) {
237 unsigned char *r, *buf;
238 r = (
unsigned char*)roi.MemoryInfo.BaseAddress+roi.StartAddress;
240 for (
unsigned int i = 0; i < height; ++i) {
241 memcpy(buf, r, roi.GetPixelIncrement() * scaled_width);
242 buf += roi.GetPixelIncrement() * scaled_width;
243 r += roi.GetLineIncrement();
245 return scaled_buffer;
247 return (
unsigned char*) roi.MemoryInfo.BaseAddress+roi.StartAddress;
253 LeutronCamera::buffer_size()
255 return colorspace_buffer_size(YUV422_PACKED, 0, 0);
259 LeutronCamera::close()
262 if ( (scaled_width != width) || (scaled_height != height) ) {
272 LeutronCamera::dispose_buffer()
277 LeutronCamera::pixel_width()
282 throw Exception(
"LeutronCam: Camera not opened");
287 LeutronCamera::pixel_height()
290 return scaled_height;
292 throw Exception(
"LeutronCam: Camera not opened");
298 LeutronCamera::colorspace()
305 LeutronCamera::ready()
312 LeutronCamera::set_image_number(
unsigned int n)
Fawkes library namespace.
Base class for exceptions in Fawkes.