1 /***************************************************************************
2 DIA_crop.cpp - description
3 -------------------
4
5 GUI for cropping including autocrop
6 +Revisted the Gtk2 way
7 +Autocrop now in RGB space (more accurate)
8
9 begin : Fri May 3 2002
10 copyright : (C) 2002/2007 by mean
11 email : fixounet@free.fr
12 ***************************************************************************/
13
14 /***************************************************************************
15 * *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
20 * *
21 ***************************************************************************/
22 #include "Q_crop.h"
23 #include "ADM_toolkitQt.h"
24
25 //
26 // Video is in YV12 Colorspace
27 //
28 //
Ui_cropWindow(QWidget * parent,crop * param,ADM_coreVideoFilter * in)29 Ui_cropWindow::Ui_cropWindow(QWidget* parent, crop *param,ADM_coreVideoFilter *in) : QDialog(parent)
30 {
31 uint32_t width,height;
32 ui.setupUi(this);
33 lock=0;
34 // Allocate space for green-ised video
35 width=in->getInfo()->width;
36 height=in->getInfo()->height;
37
38 canvas=new ADM_QCanvas(ui.graphicsView,width,height);
39
40 myCrop=new flyCrop( this,width, height,in,canvas,ui.horizontalSlider);
41 myCrop->left=param->left;
42 myCrop->right=param->right;
43 myCrop->top=param->top;
44 myCrop->bottom=param->bottom;
45 myCrop->_cookie=&ui;
46 myCrop->addControl(ui.toolboxLayout);
47 myCrop->upload();
48 myCrop->sliderChanged();
49
50
51 connect( ui.horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(sliderUpdate(int)));
52 connect( ui.pushButtonAutoCrop,SIGNAL(clicked(bool)),this,SLOT(autoCrop(bool)));
53 connect( ui.pushButtonReset,SIGNAL(clicked(bool)),this,SLOT(reset(bool)));
54 #define SPINNER(x) connect( ui.spinBox##x,SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int)));
55 SPINNER(Left);
56 SPINNER(Right);
57 SPINNER(Top);
58 SPINNER(Bottom);
59
60 show();
61 myCrop->adjustCanvasPosition();
62 canvas->parentWidget()->setMinimumSize(30,30); // allow resizing both ways after the dialog has settled
63 }
sliderUpdate(int foo)64 void Ui_cropWindow::sliderUpdate(int foo)
65 {
66 myCrop->sliderChanged();
67 }
gather(crop * param)68 void Ui_cropWindow::gather(crop *param)
69 {
70 myCrop->download(true);
71 param->left=myCrop->left;
72 param->right=myCrop->right;
73 param->top=myCrop->top;
74 param->bottom=myCrop->bottom;
75 }
~Ui_cropWindow()76 Ui_cropWindow::~Ui_cropWindow()
77 {
78 if(myCrop) delete myCrop;
79 myCrop=NULL;
80 if(canvas) delete canvas;
81 canvas=NULL;
82 }
valueChanged(int f)83 void Ui_cropWindow::valueChanged( int f )
84 {
85 if(lock) return;
86 lock++;
87 myCrop->download();
88 myCrop->sameImage();
89 lock--;
90 }
91
autoCrop(bool f)92 void Ui_cropWindow::autoCrop( bool f )
93 {
94 lock++;
95 myCrop->autocrop();
96 lock--;
97 }
reset(bool f)98 void Ui_cropWindow::reset( bool f )
99 {
100 myCrop->left=0;
101 myCrop->right=0;
102 myCrop->bottom=0;
103 myCrop->top=0;
104 lock++;
105 myCrop->upload();
106 myCrop->sameImage();
107 lock--;
108 }
109
resizeEvent(QResizeEvent * event)110 void Ui_cropWindow::resizeEvent(QResizeEvent *event)
111 {
112 if(!canvas->height())
113 return;
114 uint32_t graphicsViewWidth = canvas->parentWidget()->width();
115 uint32_t graphicsViewHeight = canvas->parentWidget()->height();
116 myCrop->fitCanvasIntoView(graphicsViewWidth,graphicsViewHeight);
117 myCrop->adjustCanvasPosition();
118 }
119
120 //************************
upload(void)121 uint8_t flyCrop::upload(void)
122 {
123 Ui_cropDialog *w=(Ui_cropDialog *)_cookie;
124
125 w->spinBoxLeft->setValue(left);
126 w->spinBoxRight->setValue(right);
127 w->spinBoxTop->setValue(top);
128 w->spinBoxBottom->setValue(bottom);
129
130 return 1;
131 }
download(bool even)132 uint8_t flyCrop::download(bool even)
133 {
134 int reject=0;
135 Ui_cropDialog *w=(Ui_cropDialog *)_cookie;
136 #define SPIN_GET(x,y) x=w->spinBox##y->value();
137 SPIN_GET(left,Left);
138 SPIN_GET(right,Right);
139 SPIN_GET(top,Top);
140 SPIN_GET(bottom,Bottom);
141
142 printf("%d %d %d %d\n",left,right,top,bottom);
143
144 if((top+bottom)>_h)
145 {
146 top=bottom=0;
147 reject=1;
148 ADM_warning(" ** Rejected top bottom **\n");
149 }
150 if((left+right)>_w)
151 {
152 left=right=0;
153 reject=1;
154 ADM_warning(" ** Rejected left right **\n");
155 }
156 if(reject)
157 return upload();
158
159 if(even)
160 {
161 if((_w-left-right)&1)
162 {
163 if(left&1)
164 left&=0xfffe;
165 else if(right)
166 right--;
167 else if(left)
168 left--;
169 else
170 right++;
171 }
172 if((_h-top-bottom)&1)
173 {
174 if(top&1)
175 top&=0xfffe;
176 else if(bottom)
177 bottom--;
178 else if(top)
179 top--;
180 else
181 bottom++;
182 }
183 }
184 return 1;
185 }
186
187 /**
188 \fn DIA_getCropParams
189 \brief Handle crop dialog
190 */
DIA_getCropParams(const char * name,crop * param,ADM_coreVideoFilter * in)191 int DIA_getCropParams( const char *name,crop *param,ADM_coreVideoFilter *in)
192 {
193 uint8_t ret=0;
194
195 Ui_cropWindow dialog(qtLastRegisteredDialog(), param,in);
196 qtRegisterDialog(&dialog);
197
198 if(dialog.exec()==QDialog::Accepted)
199 {
200 dialog.gather(param);
201 ret=1;
202 }
203
204 qtUnregisterDialog(&dialog);
205
206 return ret;
207 }
208 //____________________________________
209 // EOF
210