1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
49 #include "cvvidtypes.h"
51 #include <X11/Intrinsic.h>
52 #include <X11/StringDefs.h>
53 #include <X11/Shell.h>
54 #include <X11/Xaw/Paned.h>
55 #include <X11/Xaw/Scrollbar.h>
56 #include <X11/Xaw/Label.h>
57 #include <X11/Xaw/Toggle.h>
60 ////////////////////////////////////////////////////////////////////////////////
61 extern Widget cvvTopLevelWidget;
62 static int select_res = 1;
63 static int select_format = 0;
75 CameraDescription descr;
99 Widget format_yuv420p;
101 Widget label_brightness;
102 Widget label_contrast;
123 CameraDescription descr;
140 static void updatevalues(VideoWidget *vf);
142 static void on_apply( Widget w, VideoWidget* data )
144 cvcamSetProperty(data->n, "set_video_format", &data->vf);
145 XtVaSetValues( w, XtNstate, False, 0 );
149 static void on_cancel( Widget w, VideoWidget* data )
151 XtDestroyWidget( data->dialog );
155 static void on_ok( Widget w, VideoWidget* data )
158 on_cancel( w, data );
161 static void on_track( Widget w, Tracker* data, float* percent )
164 __u16 value = (__u16)(*percent * 0xFFFF);
165 *(data->value) = value;
166 sprintf( s, "%d", value );
167 XtVaSetValues( data->w, XtNlabel, s, 0 );
170 static void set_float( Widget w, char* name, float value )
174 if (sizeof(float) > sizeof(XtArgVal))
175 XtSetArg(args[0], name, &value);
183 XtSetArg(args[0], name, foo.xt);
185 XtSetValues(w,args,1);
188 static void on_24( Widget w, VideoWidget* v )
191 XtVaGetValues( w, XtNstate, &state, 0 );
194 v->vf.picture.palette = VIDEO_PALETTE_RGB24;
197 static void on_32( Widget w, VideoWidget* v )
200 XtVaGetValues( w, XtNstate, &state, 0 );
203 v->vf.picture.palette = VIDEO_PALETTE_RGB32;
206 static void on_yuv420p( Widget w, VideoWidget* v )
209 XtVaGetValues( w, XtNstate, &state, 0 );
212 v->vf.picture.palette = VIDEO_PALETTE_YUV420P;
215 static void on_min( Widget w, VideoWidget* v )
218 XtVaGetValues( w, XtNstate, &state, 0 );
221 v->vf.width = v->min_w;
222 v->vf.height = v->min_h;
225 static void on_mid( Widget w, VideoWidget* v )
228 XtVaGetValues( w, XtNstate, &state, 0 );
231 v->vf.width = v->mid_w;
232 v->vf.height = v->mid_h;
235 static void on_max( Widget w, VideoWidget* v )
238 XtVaGetValues( w, XtNstate, &state, 0 );
241 v->vf.width = v->max_w;
242 v->vf.height = v->max_h;
245 static void updatevalues(VideoWidget *vf)
250 cvcamGetProperty(camera, "set_video_format", &vf->vf);
251 if( vf->vf.width == vf->descr.minwidth )
252 XtVaSetValues( vf->res_min, XtNstate, True, 0 );
253 else if( vf->vf.width == vf->descr.maxwidth )
254 XtVaSetValues( vf->res_max, XtNstate, True, 0 );
256 XtVaSetValues( vf->res_middle, XtNstate, True, 0 );
258 switch( vf->vf.picture.palette )
260 case VIDEO_PALETTE_RGB24:
261 XtVaSetValues( vf->format_24, XtNstate, True, 0 );
263 case VIDEO_PALETTE_RGB32:
264 XtVaSetValues( vf->format_32, XtNstate, True, 0 );
266 case VIDEO_PALETTE_YUV420P:
267 XtVaSetValues( vf->format_yuv420p, XtNstate, True, 0 );
270 XtDestroyWidget( vf->dialog );
272 printf( "supported only RGB24, RGB32 & YUV420P formats\n" );
276 set_float( vf->br_w, XtNtopOfThumb, (float)vf->vf.picture.brightness / 0xFFFF );
277 percent = (float)vf->vf.picture.brightness / 0xFFFF;
278 vf->br.value = &vf->vf.picture.brightness;
279 on_track(vf->br_w, &vf->br, &percent );
281 set_float( vf->con_w, XtNtopOfThumb, (float)vf->vf.picture.contrast / 0xFFFF );
282 percent = (float)vf->vf.picture.contrast / 0xFFFF;
283 vf->con.value = &vf->vf.picture.contrast;
284 on_track(vf->con_w, &vf->con, &percent );
286 set_float( vf->col_w, XtNtopOfThumb, (float)vf->vf.picture.colour / 0xFFFF );
287 percent = (float)vf->vf.picture.colour / 0xFFFF;
288 vf->col.value = &vf->vf.picture.colour;
289 on_track(vf->col_w, &vf->col, &percent );
291 set_float( vf->h_w, XtNtopOfThumb, (float)vf->vf.picture.hue / 0xFFFF );
292 percent = (float)vf->vf.picture.hue / 0xFFFF;
293 vf->hue.value = &vf->vf.picture.hue;
294 on_track(vf->h_w, &vf->hue, &percent );
297 void icvVideoVideoPPDialog(int camera)
302 VideoWidget* vf = (VideoWidget*)malloc( sizeof(*vf) );
304 cvcamGetProperty(camera, "description", &vf->descr);
306 snprintf( title, 100, "%s, %s (%s): Video format", vf->descr.device, vf->descr.DeviceDescription, vf->descr.ChannelDescription );
307 // snprintf( title, 100, "%d", camera);
310 /* Creating main dialog window */
311 vf->dialog = XtVaAppCreateShell( title, "video", topLevelShellWidgetClass,
312 XtDisplay( /*(void*)*/cvvTopLevelWidget ),
313 XtNminWidth, 10, XtNminHeight, 10,
315 /* Creating main paned window... It will parent for all smaller elements */
316 vf->paned = XtVaCreateManagedWidget( "CvVisual_paned", panedWidgetClass, vf->dialog,
318 /* Resolution elements */
319 vf->label_res = XtVaCreateManagedWidget( "resolution", labelWidgetClass, vf->paned,
321 XtNlabel, "camera resolution",
322 XtNjustify, XtJustifyCenter, 0 );
324 vf->paned_res = XtVaCreateManagedWidget( "resolution_res", panedWidgetClass, vf->paned,
326 XtNorientation, XtorientHorizontal,
329 sprintf( title, "%dx%d", vf->descr.minwidth, vf->descr.minheight );
330 vf->res_min = XtVaCreateManagedWidget( "res min", toggleWidgetClass, vf->paned_res,
333 XtNradioData, &select_res,
335 XtAddCallback( vf->res_min, "callback", (XtCallbackProc)on_min, vf );
336 vf->min_w = vf->descr.minwidth;
337 vf->min_h = vf->descr.minheight;
339 vf->res_middle = XtVaCreateManagedWidget( "res middle", toggleWidgetClass, vf->paned_res,
342 XtNradioData, &select_res,
343 XtNradioGroup, vf->res_min,
345 XtAddCallback( vf->res_middle, "callback", (XtCallbackProc)on_mid, vf );
349 sprintf( title, "%dx%d", vf->descr.maxwidth, vf->descr.maxheight );
350 vf->res_max = XtVaCreateManagedWidget( "res max", toggleWidgetClass, vf->paned_res,
353 XtNradioData, &select_res,
354 XtNradioGroup, vf->res_min,
356 XtAddCallback( vf->res_max, "callback", (XtCallbackProc)on_max, vf );
357 vf->max_w = vf->descr.maxwidth;
358 vf->max_h = vf->descr.maxheight;
360 /* Video format elements */
361 vf->label_format = XtVaCreateManagedWidget( "format", labelWidgetClass, vf->paned,
363 XtNlabel, "data format",
364 XtNjustify, XtJustifyCenter, 0 );
366 vf->paned_format = XtVaCreateManagedWidget( "format", panedWidgetClass, vf->paned,
368 XtNorientation, XtorientHorizontal,
371 vf->format_24 = XtVaCreateManagedWidget( "bpp24", toggleWidgetClass, vf->paned_format,
374 XtNradioData, &select_format,
376 XtAddCallback( vf->format_24, "callback", (XtCallbackProc)on_24, vf );
378 vf->format_32 = XtVaCreateManagedWidget( "bpp32", toggleWidgetClass, vf->paned_format,
381 XtNradioData, &select_format,
382 XtNradioGroup, vf->format_24,
384 XtAddCallback( vf->format_32, "callback", (XtCallbackProc)on_32, vf );
386 vf->format_yuv420p = XtVaCreateManagedWidget( "yuv420p", toggleWidgetClass, vf->paned_format,
389 XtNradioData, &select_format,
390 XtNradioGroup, vf->format_24,
392 XtAddCallback( vf->format_yuv420p, "callback", (XtCallbackProc)on_yuv420p, vf );
394 /* Brightness, contrast, color & hue elements */
396 vf->label_brightness = XtVaCreateManagedWidget( "brigthness", labelWidgetClass, vf->paned,
398 XtNlabel, "brigthness",
399 XtNjustify, XtJustifyCenter, 0 );
400 vf->brightness_w = XtVaCreateManagedWidget( "brigthness", labelWidgetClass, vf->paned,
402 XtNjustify, XtJustifyCenter, 0 );
403 vf->br.w = vf->brightness_w;
404 vf->br_w = XtVaCreateManagedWidget( "br", scrollbarWidgetClass, vf->paned,
406 XtNorientation, XtorientHorizontal, 0 );
407 XtAddCallback( vf->br_w, "jumpProc", (XtCallbackProc)on_track, &vf->br );
410 vf->label_contrast = XtVaCreateManagedWidget( "contrast", labelWidgetClass, vf->paned,
412 XtNlabel, "contrast",
413 XtNjustify, XtJustifyCenter, 0 );
414 vf->contrast_w = XtVaCreateManagedWidget( "brigthness", labelWidgetClass, vf->paned,
416 XtNjustify, XtJustifyCenter, 0 );
417 vf->con.w = vf->contrast_w;
418 vf->con_w = XtVaCreateManagedWidget( "con", scrollbarWidgetClass, vf->paned,
420 XtNorientation, XtorientHorizontal, 0 );
421 XtAddCallback( vf->con_w, "jumpProc", (XtCallbackProc)on_track, &vf->con );
424 vf->label_color = XtVaCreateManagedWidget( "color", labelWidgetClass, vf->paned,
427 XtNjustify, XtJustifyCenter, 0 );
428 vf->color_w = XtVaCreateManagedWidget( "brigthness", labelWidgetClass, vf->paned,
430 XtNjustify, XtJustifyCenter, 0 );
431 vf->col.w = vf->color_w;
432 vf->col_w = XtVaCreateManagedWidget( "col", scrollbarWidgetClass, vf->paned,
434 XtNorientation, XtorientHorizontal, 0 );
435 XtAddCallback( vf->col_w, "jumpProc", (XtCallbackProc)on_track, &vf->col );
438 vf->label_hue = XtVaCreateManagedWidget( "hue", labelWidgetClass, vf->paned,
441 XtNjustify, XtJustifyCenter, 0 );
442 vf->hue_w = XtVaCreateManagedWidget( "brigthness", labelWidgetClass, vf->paned,
444 XtNjustify, XtJustifyCenter, 0 );
445 vf->hue.w = vf->hue_w;
446 vf->h_w = XtVaCreateManagedWidget( "h", scrollbarWidgetClass, vf->paned,
448 XtNorientation, XtorientHorizontal, 0 );
449 XtAddCallback( vf->h_w, "jumpProc", (XtCallbackProc)on_track, &vf->hue );
454 vf->buttons = XtVaCreateManagedWidget( "buttons", panedWidgetClass, vf->paned,
456 XtNorientation, XtorientHorizontal,
459 vf->b_ok = XtVaCreateManagedWidget( "b_ok", toggleWidgetClass, vf->buttons,
464 XtAddCallback( vf->b_ok, XtNcallback, (XtCallbackProc)on_ok, (void*)vf );
466 vf->b_apply = XtVaCreateManagedWidget( "b_apply", toggleWidgetClass, vf->buttons,
471 XtAddCallback( vf->b_apply, XtNcallback, (XtCallbackProc)on_apply, (void*)vf );
473 vf->b_cancel = XtVaCreateManagedWidget( "b_cancel", toggleWidgetClass, vf->buttons,
478 XtAddCallback( vf->b_cancel, XtNcallback, (XtCallbackProc)on_cancel, (void*)vf );
481 XtRealizeWidget( vf->dialog );
484 /* fixating window size */
487 XtVaGetValues( vf->dialog, XtNwidth, &width, XtNheight, &height, 0 );
488 XtVaSetValues( vf->dialog, XtNminWidth, width, XtNminHeight, height,
489 XtNmaxWidth, width, XtNmaxHeight, height, 0 );
493 ////////////////////////////////////////////////////////////////////////////////
494 static void on_enable( Widget w, CameraWidget* data )
497 XtVaGetValues( w, XtNstate, &status, 0 );
498 data->enable = status;
501 static void on_render( Widget w, CameraWidget* data )
504 XtVaGetValues( w, XtNstate, &status, 0 );
505 data->render = status;
508 static void on_cam_apply( Widget w, CameraWidget* data )
510 cvcamSetProperty( data->n, "enable", &data->enable );
511 cvcamSetProperty( data->n, "render", &data->render );
512 XtVaSetValues( w, XtNstate, False, 0 );
515 static void on_cam_cancel( Widget w, CameraWidget* data )
517 XtDestroyWidget( data->dialog );
521 static void on_cam_ok( Widget w, CameraWidget* data )
523 on_cam_apply( w, data );
524 on_cam_cancel( w, data );
527 void icvVideoCameraPPDialog(int camera)
533 CameraWidget* vf = (CameraWidget*)malloc( sizeof(*vf) );
534 cvcamGetProperty(camera, "description", &vf->descr);
535 snprintf( title, 100, "%s, %s (%s): Camera options", vf->descr.device, vf->descr.DeviceDescription, vf->descr.ChannelDescription );
538 /* Creating main dialog window */
539 vf->dialog = XtVaAppCreateShell( title, "camera", topLevelShellWidgetClass,
540 XtDisplay( cvvTopLevelWidget ),
541 XtNminWidth, 10, XtNminHeight, 10,
543 /* Creating main paned window... It will parent for all smaller elements */
544 vf->paned = XtVaCreateManagedWidget( "CvCamera_paned", panedWidgetClass, vf->dialog,
546 /* Resolution elements */
547 sprintf( title, "%s on %s", vf->descr.DeviceDescription, vf->descr.device );
548 vf->label = XtVaCreateManagedWidget( "desriprion", labelWidgetClass, vf->paned,
551 XtNjustify, XtJustifyCenter, 0 );
553 cvcamGetProperty(camera, "enable", &res);
554 vf->enable_w = XtVaCreateManagedWidget( "enable", toggleWidgetClass, vf->paned,
557 XtNradioData, &select_res,
560 XtAddCallback( vf->enable_w, "callback", (XtCallbackProc)on_enable, vf );
562 cvcamGetProperty(camera, "render", &res);
563 vf->render_w = XtVaCreateManagedWidget( "render", toggleWidgetClass, vf->paned,
566 XtNradioData, &select_res,
569 XtAddCallback( vf->render_w, "callback", (XtCallbackProc)on_render, vf );
572 vf->buttons = XtVaCreateManagedWidget( "buttons", panedWidgetClass, vf->paned,
574 XtNorientation, XtorientHorizontal,
577 vf->b_ok = XtVaCreateManagedWidget( "b_ok", toggleWidgetClass, vf->buttons,
582 XtAddCallback( vf->b_ok, XtNcallback, (XtCallbackProc)on_cam_ok, (void*)vf );
584 vf->b_apply = XtVaCreateManagedWidget( "b_apply", toggleWidgetClass, vf->buttons,
589 XtAddCallback( vf->b_apply, XtNcallback, (XtCallbackProc)on_cam_apply, (void*)vf );
591 vf->b_cancel = XtVaCreateManagedWidget( "b_cancel", toggleWidgetClass, vf->buttons,
596 XtAddCallback( vf->b_cancel, XtNcallback, (XtCallbackProc)on_cam_cancel, (void*)vf );
597 XtRealizeWidget( vf->dialog );
602 /* fixating window size */
605 XtVaGetValues( vf->dialog, XtNwidth, &width, XtNheight, &height, 0 );
606 XtVaSetValues( vf->dialog, XtNminWidth, width, XtNminHeight, height,
607 XtNmaxWidth, width, XtNmaxHeight, height, 0 );