📄 dialogs.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include <tcl.h>
#include <tk.h>
#include <pthread.h>
#include <stdio.h>
#include <assert.h>
#include "dialogs.h"
#include "cvcam.h"
#include "cvvidtypes.h"
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/Scrollbar.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Toggle.h>
#include <stdlib.h>
#include "highgui.h"
////////////////////////////////////////////////////////////////////////////////
extern Widget cvvTopLevelWidget;
static int select_res = 1;
static int select_format = 0;
typedef struct
{
__u16* value;
Widget w;
} Tracker;
typedef struct
{
int n;
VideoFormat vf;
CameraDescription descr;
Tracker br;
Tracker con;
Tracker col;
Tracker hue;
int min_w;
int min_h;
int mid_w;
int mid_h;
int max_w;
int max_h;
Widget dialog;
Widget paned;
Widget label_res;
Widget paned_res;
Widget label_format;
Widget paned_format;
Widget res_min;
Widget res_middle;
Widget res_max;
Widget format_24;
Widget format_32;
Widget format_yuv420p;
Widget label_brightness;
Widget label_contrast;
Widget label_color;
Widget label_hue;
Widget brightness_w;
Widget contrast_w;
Widget color_w;
Widget hue_w;
Widget br_w;
Widget con_w;
Widget col_w;
Widget h_w;
Widget buttons;
Widget b_ok;
Widget b_apply;
Widget b_cancel;
} VideoWidget;
typedef struct
{
int n;
CameraDescription descr;
int enable;
int render;
Widget dialog;
Widget label;
Widget paned;
Widget enable_w;
Widget render_w;
Widget buttons;
Widget b_ok;
Widget b_apply;
Widget b_cancel;
} CameraWidget;
static void updatevalues(VideoWidget *vf);
static void on_apply( Widget w, VideoWidget* data )
{
cvcamSetProperty(data->n, "set_video_format", &data->vf);
XtVaSetValues( w, XtNstate, False, 0 );
updatevalues(data);
}
static void on_cancel( Widget w, VideoWidget* data )
{
XtDestroyWidget( data->dialog );
free( data );
}
static void on_ok( Widget w, VideoWidget* data )
{
on_apply( w, data );
on_cancel( w, data );
}
static void on_track( Widget w, Tracker* data, float* percent )
{
char s[100];
__u16 value = (__u16)(*percent * 0xFFFF);
*(data->value) = value;
sprintf( s, "%d", value );
XtVaSetValues( data->w, XtNlabel, s, 0 );
}
static void set_float( Widget w, char* name, float value )
{
Arg args[1];
if (sizeof(float) > sizeof(XtArgVal))
XtSetArg(args[0], name, &value);
else
{
union {
XtArgVal xt;
float fp;
} foo;
foo.fp = value;
XtSetArg(args[0], name, foo.xt);
}
XtSetValues(w,args,1);
}
static void on_24( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.picture.palette = VIDEO_PALETTE_RGB24;
}
static void on_32( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.picture.palette = VIDEO_PALETTE_RGB32;
}
static void on_yuv420p( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.picture.palette = VIDEO_PALETTE_YUV420P;
}
static void on_min( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.width = v->min_w;
v->vf.height = v->min_h;
}
static void on_mid( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.width = v->mid_w;
v->vf.height = v->mid_h;
}
static void on_max( Widget w, VideoWidget* v )
{
int state = 1;
XtVaGetValues( w, XtNstate, &state, 0 );
if( !state )
return;
v->vf.width = v->max_w;
v->vf.height = v->max_h;
}
static void updatevalues(VideoWidget *vf)
{
int camera = vf->n;
float percent;
cvcamGetProperty(camera, "set_video_format", &vf->vf);
if( vf->vf.width == vf->descr.minwidth )
XtVaSetValues( vf->res_min, XtNstate, True, 0 );
else if( vf->vf.width == vf->descr.maxwidth )
XtVaSetValues( vf->res_max, XtNstate, True, 0 );
else
XtVaSetValues( vf->res_middle, XtNstate, True, 0 );
switch( vf->vf.picture.palette )
{
case VIDEO_PALETTE_RGB24:
XtVaSetValues( vf->format_24, XtNstate, True, 0 );
break;
case VIDEO_PALETTE_RGB32:
XtVaSetValues( vf->format_32, XtNstate, True, 0 );
break;
case VIDEO_PALETTE_YUV420P:
XtVaSetValues( vf->format_yuv420p, XtNstate, True, 0 );
break;
default:
XtDestroyWidget( vf->dialog );
free( vf );
printf( "supported only RGB24, RGB32 & YUV420P formats\n" );
return;
}
set_float( vf->br_w, XtNtopOfThumb, (float)vf->vf.picture.brightness / 0xFFFF );
percent = (float)vf->vf.picture.brightness / 0xFFFF;
vf->br.value = &vf->vf.picture.brightness;
on_track(vf->br_w, &vf->br, &percent );
set_float( vf->con_w, XtNtopOfThumb, (float)vf->vf.picture.contrast / 0xFFFF );
percent = (float)vf->vf.picture.contrast / 0xFFFF;
vf->con.value = &vf->vf.picture.contrast;
on_track(vf->con_w, &vf->con, &percent );
set_float( vf->col_w, XtNtopOfThumb, (float)vf->vf.picture.colour / 0xFFFF );
percent = (float)vf->vf.picture.colour / 0xFFFF;
vf->col.value = &vf->vf.picture.colour;
on_track(vf->col_w, &vf->col, &percent );
set_float( vf->h_w, XtNtopOfThumb, (float)vf->vf.picture.hue / 0xFFFF );
percent = (float)vf->vf.picture.hue / 0xFFFF;
vf->hue.value = &vf->vf.picture.hue;
on_track(vf->h_w, &vf->hue, &percent );
}
void icvVideoVideoPPDialog(int camera)
{
char title[100];
VideoWidget* vf = (VideoWidget*)malloc( sizeof(*vf) );
vf->n = camera;
cvcamGetProperty(camera, "description", &vf->descr);
snprintf( title, 100, "%s, %s (%s): Video format", vf->descr.device, vf->descr.DeviceDescription, vf->descr.ChannelDescription );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -