~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_guiChromaShift.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-12-15 17:13:20 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215171320-w79pvpehxx2fr217
Tags: 1:2.3.0-0.0ubuntu1
* Merge from debian-multimedia.org, remaining Ubuntu change:
  - desktop file,
  - no support for ccache and make -j.
* Closes Ubuntu: #69614.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          ADM_guiChromaShift.cpp  -  description
3
 
                             -------------------
4
 
    begin                : Sun Aug 24 2003
5
 
    copyright            : (C) 2002-2003 by mean
6
 
    email                : fixounet@free.fr
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
#include "config.h"
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
 
23
 
#include <gtk/gtk.h>
24
 
#include <time.h>
25
 
#include <sys/time.h>
26
 
 
27
 
 
28
 
#include "fourcc.h"
29
 
#include "avio.hxx"
30
 
#include "config.h"
31
 
#include "avi_vars.h"
32
 
#include <ADM_assert.h>
33
 
 
34
 
 
35
 
#include "ADM_editor/ADM_edit.hxx"
36
 
#include "ADM_video/ADM_genvideo.hxx"
37
 
#include "ADM_video/ADM_vidCommonFilter.h"
38
 
 
39
 
#include <gdk/gdkkeysyms.h>
40
 
#include <gtk/gtk.h>
41
 
 
42
 
 
43
 
#include <gdk/gdkkeysyms.h>
44
 
#include <gtk/gtk.h>
45
 
# include <math.h>
46
 
 
47
 
#include "callbacks.h"
48
 
#include "avi_vars.h"
49
 
#include "ADM_gui2/support.h"
50
 
#include "ADM_toolkit/toolkit_gtk.h"
51
 
#include "ADM_toolkit/toolkit_gtk_include.h"
52
 
#include "ADM_toolkit/toolkit.hxx"
53
 
#include "ADM_library/default.h"
54
 
 
55
 
 
56
 
#include "ADM_colorspace/ADM_rgb.h"
57
 
#include "ADM_video/ADM_vidChromaShift.h"
58
 
 
59
 
#include "ADM_toolkit/ADM_debugID.h"
60
 
#define MODULE_NAME MODULE_FILTER
61
 
#include "ADM_toolkit/ADM_debug.h"
62
 
 
63
 
 
64
 
 
65
 
#include "prototype.h"
66
 
 
67
 
#define SPIN_GET(x,y) {y= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(lookup_widget(dialog,#x))) ;\
68
 
                                printf(#x":%d\n", y);}
69
 
 
70
 
#define SPIN_SET(x,y)  {gtk_spin_button_set_value(GTK_SPIN_BUTTON(lookup_widget(dialog,#x)),(gfloat)y) ; \
71
 
                                printf(#x":%d\n", y);}
72
 
 
73
 
 
74
 
static uint8_t *video_working,*video_rgb;
75
 
static  ADMImage *video_src;
76
 
static int32_t shift_u, shift_v;
77
 
static uint32_t ww,hh;
78
 
 
79
 
static GtkWidget *dialog;
80
 
static GtkWidget *create_ChromaShift( void );
81
 
static uint8_t DIA_getChromaShift( void );
82
 
static void chromadraw (GtkWidget *dialog,uint32_t w,uint32_t h );
83
 
static void read( void );
84
 
static void upload ( void );
85
 
static gboolean gui_draw( void );
86
 
static gboolean gui_update( void );
87
 
static void update(void);
88
 
 
89
 
static ColYuvRgb    *rgbConv=NULL;
90
 
uint8_t ADMVideoChromaShift::configure( AVDMGenericVideoStream *instream)
91
 
 
92
 
{
93
 
 
94
 
uint8_t ret=0;
95
 
uint32_t l,f;
96
 
 
97
 
                                                        video_working=NULL;
98
 
                                                        video_src=NULL;
99
 
 
100
 
                                 // Get info from previous filter
101
 
                                                        ww=_in->getInfo()->width;
102
 
                                                        hh= _in->getInfo()->height;
103
 
 
104
 
                                                        rgbConv=new ColYuvRgb(ww,hh);
105
 
                            rgbConv->reset(ww,hh);
106
 
                                                        
107
 
                                                        printf("\n Chromashift in : %lu  x %lu\n",ww,hh);
108
 
 
109
 
                                                        video_src=new ADMImage(ww,hh);// uint8_t [ww*hh*2];
110
 
                                                        ADM_assert(video_src);
111
 
                                                        video_working=new uint8_t [ww*hh*2];
112
 
                                                        ADM_assert(video_working);
113
 
 
114
 
                                                        video_rgb=new uint8_t [ww*hh*4];
115
 
                                                        ADM_assert(video_rgb);
116
 
 
117
 
 
118
 
                                                        // ask current frame from previous filter
119
 
                                                        ADM_assert(instream->getFrameNumberNoAlloc(curframe, &l,
120
 
                                                                                video_src,&f));
121
 
 
122
 
                                                        shift_u=_param->u;
123
 
                                                        shift_v=_param->v;
124
 
 
125
 
 
126
 
                                                        ret=DIA_getChromaShift();
127
 
                                                        if(ret)
128
 
                                                        {
129
 
                                                                _param->u=shift_u;
130
 
                                                                _param->v=shift_v;
131
 
                                                        }
132
 
 
133
 
                                                        delete [] video_working;
134
 
                                                        delete  video_src;
135
 
                                                        delete [] video_rgb;
136
 
                                                        video_working=NULL;
137
 
                                                        video_src=NULL;
138
 
                                                        delete rgbConv;
139
 
                                                        rgbConv=NULL;
140
 
 
141
 
                                        return ret;
142
 
}
143
 
 
144
 
uint8_t DIA_getChromaShift( void )
145
 
{
146
 
        uint8_t ret=0;
147
 
        dialog=create_ChromaShift();
148
 
 
149
 
        gtk_widget_set_usize(WID(drawingarea1), ww,hh);
150
 
        gtk_widget_show(dialog);
151
 
        upload();
152
 
         gtk_signal_connect(GTK_OBJECT(WID(drawingarea1)), "expose_event",
153
 
                       GTK_SIGNAL_FUNC(gui_draw),
154
 
                       NULL);
155
 
        gtk_signal_connect (GTK_OBJECT(WID( spinbutton_U)), "value_changed",
156
 
                    GTK_SIGNAL_FUNC (gui_update),
157
 
                    NULL);
158
 
        gtk_signal_connect (GTK_OBJECT(WID( spinbutton_V)), "value_changed",
159
 
                    GTK_SIGNAL_FUNC (gui_update),
160
 
                    NULL);
161
 
 
162
 
        update();
163
 
 
164
 
        int response;
165
 
        while( (response=gtk_dialog_run(GTK_DIALOG(dialog)))==GTK_RESPONSE_APPLY)
166
 
        {
167
 
                read();
168
 
                update();
169
 
        }
170
 
        if(response==GTK_RESPONSE_OK)
171
 
        {
172
 
                read();
173
 
                ret=1;
174
 
        }
175
 
 
176
 
        gtk_widget_destroy(dialog);
177
 
        dialog=NULL;
178
 
        return ret;
179
 
 
180
 
}
181
 
void read( void )
182
 
{
183
 
        SPIN_GET(spinbutton_U,shift_u);
184
 
        SPIN_GET(spinbutton_V,shift_v);
185
 
}
186
 
void upload ( void )
187
 
{
188
 
        SPIN_SET(spinbutton_U,shift_u);
189
 
        SPIN_SET(spinbutton_V,shift_v);
190
 
}
191
 
/*---------------------------------------------------------------------------
192
 
        Green-ify the displayed frame on cropped parts
193
 
*/
194
 
void update( void)
195
 
{
196
 
 
197
 
                // First copy Y
198
 
                memcpy(video_working,video_src->data,(ww*hh));
199
 
                // then shift u
200
 
 
201
 
                 ADMVideoChromaShift::shift(video_working+ww*hh,
202
 
                                                                video_src->data+ww*hh, ww>>1,hh>>1,shift_u);
203
 
                ADMVideoChromaShift::shift(video_working+((5*ww*hh)>>2),
204
 
                                                                video_src->data+((5*ww*hh)>>2), ww>>1,hh>>1,shift_v);
205
 
                if(shift_u)
206
 
                        ADMVideoChromaShift::fixup(video_working,ww,hh,shift_u*2);
207
 
                if(shift_v)
208
 
                        ADMVideoChromaShift::fixup(video_working,ww,hh,shift_v*2);
209
 
 
210
 
                //COL_yv12rgb(ww,hh,video_working,video_rgb);
211
 
                rgbConv->scale(video_working,video_rgb);
212
 
                chromadraw(dialog,ww,hh);
213
 
        //      printf("\n Updated..\n");
214
 
}
215
 
gboolean gui_update( void )
216
 
{
217
 
        //printf(" GUI !\n");
218
 
        read();
219
 
        update();
220
 
        return true;
221
 
}
222
 
 
223
 
/*---------------------------------------------------------------------------
224
 
        Actually draw the working frame on screen
225
 
*/
226
 
gboolean gui_draw( void )
227
 
{
228
 
        chromadraw(dialog,ww,hh);
229
 
        return true;
230
 
}
231
 
void chromadraw (GtkWidget *dialog,uint32_t w,uint32_t h )
232
 
{
233
 
        GtkWidget *draw;
234
 
        draw=WID(drawingarea1);
235
 
        GUI_RGBDisplay(video_rgb, w,h, (void *)draw);
236
 
}
237
 
/*----------------------------------------------------------------*/
238
 
GtkWidget               *create_ChromaShift (void)
239
 
{
240
 
  GtkWidget *ChromaShift;
241
 
  GtkWidget *dialog_vbox1;
242
 
  GtkWidget *vbox1;
243
 
  GtkWidget *table1;
244
 
  GtkWidget *label1;
245
 
  GtkWidget *label2;
246
 
  GtkObject *spinbutton_U_adj;
247
 
  GtkWidget *spinbutton_U;
248
 
  GtkObject *spinbutton_V_adj;
249
 
  GtkWidget *spinbutton_V;
250
 
  GtkWidget *drawingarea1;
251
 
  GtkWidget *dialog_action_area1;
252
 
  GtkWidget *cancelbutton1;
253
 
  GtkWidget *applybutton1;
254
 
  GtkWidget *okbutton1;
255
 
 
256
 
  ChromaShift = gtk_dialog_new ();
257
 
  gtk_window_set_title (GTK_WINDOW (ChromaShift), _("ChromaShift"));
258
 
 
259
 
  dialog_vbox1 = GTK_DIALOG (ChromaShift)->vbox;
260
 
  gtk_widget_show (dialog_vbox1);
261
 
 
262
 
  vbox1 = gtk_vbox_new (FALSE, 0);
263
 
  gtk_widget_show (vbox1);
264
 
  gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, TRUE, TRUE, 0);
265
 
 
266
 
  table1 = gtk_table_new (2, 2, FALSE);
267
 
  gtk_widget_show (table1);
268
 
  gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0);
269
 
 
270
 
  label1 = gtk_label_new (_("U Shift :"));
271
 
  gtk_widget_show (label1);
272
 
  gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
273
 
                    (GtkAttachOptions) (GTK_FILL),
274
 
                    (GtkAttachOptions) (0), 0, 0);
275
 
  gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
276
 
  gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
277
 
 
278
 
  label2 = gtk_label_new (_("V Shift :"));
279
 
  gtk_widget_show (label2);
280
 
  gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
281
 
                    (GtkAttachOptions) (GTK_FILL),
282
 
                    (GtkAttachOptions) (0), 0, 0);
283
 
  gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_LEFT);
284
 
  gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
285
 
 
286
 
  spinbutton_U_adj = gtk_adjustment_new (0, -32, 32, 1, 10, 10);
287
 
  spinbutton_U = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_U_adj), 1, 0);
288
 
  gtk_widget_show (spinbutton_U);
289
 
  gtk_table_attach (GTK_TABLE (table1), spinbutton_U, 1, 2, 0, 1,
290
 
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
291
 
                    (GtkAttachOptions) (0), 0, 0);
292
 
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton_U), TRUE);
293
 
 
294
 
  spinbutton_V_adj = gtk_adjustment_new (0, -32, 32, 1, 10, 10);
295
 
  spinbutton_V = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton_V_adj), 1, 0);
296
 
  gtk_widget_show (spinbutton_V);
297
 
  gtk_table_attach (GTK_TABLE (table1), spinbutton_V, 1, 2, 1, 2,
298
 
                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
299
 
                    (GtkAttachOptions) (0), 0, 0);
300
 
  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton_V), TRUE);
301
 
 
302
 
  drawingarea1 = gtk_drawing_area_new ();
303
 
  gtk_widget_show (drawingarea1);
304
 
  gtk_box_pack_start (GTK_BOX (vbox1), drawingarea1, TRUE, TRUE, 0);
305
 
  gtk_widget_set_size_request (drawingarea1, 512, 384);
306
 
 
307
 
  dialog_action_area1 = GTK_DIALOG (ChromaShift)->action_area;
308
 
  gtk_widget_show (dialog_action_area1);
309
 
  gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
310
 
 
311
 
  cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
312
 
  gtk_widget_show (cancelbutton1);
313
 
  gtk_dialog_add_action_widget (GTK_DIALOG (ChromaShift), cancelbutton1, GTK_RESPONSE_CANCEL);
314
 
  GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
315
 
 
316
 
  applybutton1 = gtk_button_new_from_stock ("gtk-apply");
317
 
  gtk_widget_show (applybutton1);
318
 
  gtk_dialog_add_action_widget (GTK_DIALOG (ChromaShift), applybutton1, GTK_RESPONSE_APPLY);
319
 
  GTK_WIDGET_SET_FLAGS (applybutton1, GTK_CAN_DEFAULT);
320
 
 
321
 
  okbutton1 = gtk_button_new_from_stock ("gtk-ok");
322
 
  gtk_widget_show (okbutton1);
323
 
  gtk_dialog_add_action_widget (GTK_DIALOG (ChromaShift), okbutton1, GTK_RESPONSE_OK);
324
 
  GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
325
 
 
326
 
  /* Store pointers to all widgets, for use by lookup_widget(). */
327
 
  GLADE_HOOKUP_OBJECT_NO_REF (ChromaShift, ChromaShift, "ChromaShift");
328
 
  GLADE_HOOKUP_OBJECT_NO_REF (ChromaShift, dialog_vbox1, "dialog_vbox1");
329
 
  GLADE_HOOKUP_OBJECT (ChromaShift, vbox1, "vbox1");
330
 
  GLADE_HOOKUP_OBJECT (ChromaShift, table1, "table1");
331
 
  GLADE_HOOKUP_OBJECT (ChromaShift, label1, "label1");
332
 
  GLADE_HOOKUP_OBJECT (ChromaShift, label2, "label2");
333
 
  GLADE_HOOKUP_OBJECT (ChromaShift, spinbutton_U, "spinbutton_U");
334
 
  GLADE_HOOKUP_OBJECT (ChromaShift, spinbutton_V, "spinbutton_V");
335
 
  GLADE_HOOKUP_OBJECT (ChromaShift, drawingarea1, "drawingarea1");
336
 
  GLADE_HOOKUP_OBJECT_NO_REF (ChromaShift, dialog_action_area1, "dialog_action_area1");
337
 
  GLADE_HOOKUP_OBJECT (ChromaShift, cancelbutton1, "cancelbutton1");
338
 
  GLADE_HOOKUP_OBJECT (ChromaShift, applybutton1, "applybutton1");
339
 
  GLADE_HOOKUP_OBJECT (ChromaShift, okbutton1, "okbutton1");
340
 
 
341
 
  return ChromaShift;
342
 
}
343
 
 
344