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

« back to all changes in this revision

Viewing changes to avidemux/ADM_userInterfaces/ADM_QT4/ADM_dialog/Q_resizing.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2001 by mean
 
3
    email                : fixounet@free.fr
 
4
 ***************************************************************************/
 
5
 
 
6
/***************************************************************************
 
7
 *                                                                         *
 
8
 *   This program is free software; you can redistribute it and/or modify  *
 
9
 *   it under the terms of the GNU General Public License as published by  *
 
10
 *   the Free Software Foundation; either version 2 of the License, or     *
 
11
 *   (at your option) any later version.                                   *
 
12
 *                                                                         *
 
13
 ***************************************************************************/
 
14
#include "config.h"
 
15
 
 
16
#include <stdio.h>
 
17
#include <stdlib.h>
 
18
#include <math.h>
 
19
 
 
20
#define Ui_Dialog Ui_resizeDialog
 
21
#include "ui_resizing.h"
 
22
#undef Ui_Dialog
 
23
 
 
24
#include "default.h"
 
25
#include "avidemutils.h"
 
26
#include "avi_vars.h"
 
27
#include "ADM_osSupport/ADM_misc.h"
 
28
static double aspectRatio[2][3]={
 
29
                              {1.,0.888888,1.19}, // NTSC 1:1 4:3 16:9
 
30
                              {1.,1.066667,1.43} // PAL  1:1 4:3 16:9
 
31
                            };
 
32
#define aprintf printf
 
33
typedef struct resParam
 
34
{
 
35
    uint32_t width,height;
 
36
    uint32_t originalWidth,originalHeight;
 
37
    uint32_t fps1000;
 
38
    uint32_t algo;
 
39
    uint32_t pal;
 
40
}resParam;
 
41
 
 
42
class resizeWindow : public QDialog
 
43
 {
 
44
     Q_OBJECT
 
45
 protected : 
 
46
      resParam *_param;
 
47
 public:
 
48
     resizeWindow(resParam *param);
 
49
     Ui_resizeDialog ui;
 
50
 public slots:
 
51
      void gather(void);
 
52
      void update(int i);
 
53
 private slots:
 
54
   
 
55
 
 
56
 private:
 
57
     
 
58
 };
 
59
 
 
60
 
 
61
resizeWindow::resizeWindow(resParam *param)     : QDialog()
 
62
 {
 
63
     ui.setupUi(this);
 
64
     _param=param;
 
65
     ui.spinBoxWidth->setValue(_param->width);
 
66
     ui.spinBoxHeight->setValue(_param->height);
 
67
     ui.horizontalSlider->setValue(100);
 
68
     update(0);
 
69
     connect( ui.horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(update(int)));
 
70
 
 
71
 }
 
72
 void resizeWindow::gather(void)
 
73
 {
 
74
    _param->width=ui.spinBoxWidth->value();
 
75
    _param->height=ui.spinBoxHeight->value();
 
76
    _param->algo=ui.comboBoxAlgo->currentIndex();
 
77
 }
 
78
 
 
79
 void resizeWindow::update(int foo)
 
80
 {
 
81
 
 
82
  double percent;
 
83
  float x,y;
 
84
  float sr_mul,dst_mul;
 
85
 
 
86
 int32_t xx,yy;
 
87
 float erx,ery;
 
88
  int sar,dar;
 
89
 
 
90
  percent = ui.horizontalSlider->value();;
 
91
  sar=ui.comboBoxSource->currentIndex();
 
92
  dar=ui.comboBoxDestination->currentIndex();
 
93
  if(percent<10.0) percent=10.;
 
94
 
 
95
  aprintf("drag called : %f \n",percent);
 
96
  x=_param->originalWidth;
 
97
  y=_param->originalHeight;
 
98
  erx=0;
 
99
  ery=0;
 
100
  sr_mul=1.;
 
101
  if(sar)
 
102
        {  // source is 4/3 or 16/9
 
103
                        sr_mul=aspectRatio[_param->pal][sar];
 
104
 
 
105
        }
 
106
 
 
107
  dst_mul=1.;
 
108
  if(dar)
 
109
        {  // dst is 4/3 or 16/9
 
110
  
 
111
                        dst_mul=1/aspectRatio[_param->pal][dar];
 
112
        }
 
113
        aprintf("source mul %02.2f , dst mul : %02.2f\n",sr_mul,dst_mul);
 
114
        x=x*sr_mul*dst_mul;
 
115
        y=y;
 
116
  
 
117
        // normalize it to recover 100% width
 
118
        y=y/(x/_param->originalWidth);
 
119
        x=_param->originalWidth;
 
120
  
 
121
        aprintf("AR:x,y  : %03f %03f \n",x,y);
 
122
  
 
123
        percent/=100.;
 
124
        x=x*percent;
 
125
        y=y*percent;
 
126
  
 
127
  
 
128
        aprintf("AR x,y  : %03f %03f \n",x,y);
 
129
        xx=(uint32_t)floor(x+0.5);
 
130
        yy=(uint32_t)floor(y+0.5);
 
131
  
 
132
        if(xx&1) xx--;
 
133
        if(yy&1) yy--;
 
134
  
 
135
  
 
136
        if(ui.checkBoxRoundup->checkState())
 
137
        {
 
138
                int32_t ox=xx,oy=yy;
 
139
                xx=(xx +7) & 0xfffff0;
 
140
                yy=(yy +7) & 0xfffff0;
 
141
  
 
142
                erx=(xx-ox);
 
143
                erx=erx/xx;
 
144
                ery=(yy-oy);
 
145
                ery=ery/yy;
 
146
  
 
147
                aprintf("x: %d -> %d : err %f\n",ox,xx,erx);
 
148
                aprintf("y: %d -> %d : err %f\n",oy,yy,ery);
 
149
        }
 
150
  
 
151
        //
 
152
        ui.spinBoxWidth->setValue(xx);
 
153
        ui.spinBoxHeight->setValue(yy);
 
154
 
 
155
   
 
156
}
 
157
/**
 
158
    \fn DIA_resize
 
159
    \brief Handle resize dialo
 
160
*/
 
161
uint8_t DIA_resize(uint32_t *width,uint32_t *height,uint32_t *alg,uint32_t originalw, uint32_t originalh,uint32_t fps1000)
 
162
{
 
163
uint8_t r=0;
 
164
      resParam param={*width,*height,originalw,originalh,fps1000,*alg,0};
 
165
      //
 
166
      if(fps1000>24600 && fps1000<25400)
 
167
        {
 
168
                param.pal=1;
 
169
        }
 
170
       
 
171
 
 
172
     // Fetch info
 
173
     resizeWindow resizewindow(&param) ;
 
174
     ;
 
175
     if(resizewindow.exec()==QDialog::Accepted)
 
176
     {
 
177
       resizewindow.gather();
 
178
       *width=param.width;
 
179
       *height=param.height;
 
180
       *alg=param.algo;
 
181
       r=1;
 
182
     }
 
183
     return r;
 
184
}  
 
185
//********************************************
 
186
//EOF