Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / rescale.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #include "rescale.h"
22 #include "indexable.h"
23 #include "language.h"
24 #include "mwindow.h"
25
26 const char *Rescale::scale_types[] = {
27   N_("None"), N_("Scaled"), N_("Cropped"), N_("Filled"), N_("Horiz Edge"), N_("Vert Edge"),
28 };
29
30 Rescale::Rescale(int w, int h, double aspect)
31 {
32         this->w = w;
33         this->h = h;
34         this->aspect = aspect;
35 }
36
37 Rescale::Rescale(Indexable *in)
38 {
39         this->w = in->get_w();
40         this->h = in->get_h();
41         float aw, ah;
42         MWindow::create_aspect_ratio(aw, ah, this->w, this->h);
43         this->aspect = ah > 0 ? aw / ah : 1;
44 }
45
46 Rescale::~Rescale()
47 {
48 }
49
50 void Rescale::rescale(Rescale &out, int type,
51                 float &src_w,float &src_h, float &dst_w,float &dst_h)
52 {
53         int in_w = w, in_h = h;
54         int out_w = out.w, out_h = out.h;
55
56         src_w = in_w;  src_h = in_h;
57         dst_w = out_w; dst_h = out_h;
58         double r = out.aspect / aspect;
59
60         switch( type ) {
61         case cropped:
62                 if( r < 1 )
63                         src_w = in_w * r;
64                 else
65                         src_h = in_h / r;
66                 break;
67         case filled:
68                 if( r < 1 )
69                         dst_h = out_h * r;
70                 else
71                         dst_w = out_w / r;
72                 break;
73         case horiz_edge:
74                 if( r < 1 )
75                         dst_h = out_h * r;
76                 else
77                         src_h = in_h / r;
78                 break;
79         case vert_edge:
80                 if( r < 1 )
81                         src_w = in_w * r;
82                 else
83                         dst_w = out_w / r;
84                 break;
85         default:
86                 break;
87         }
88 }
89