Credit Andrew - improve in-tree documentation
[goodguy/cinelerra.git] / cinelerra / rescale.C
1 #include "rescale.h"
2 #include "indexable.h"
3 #include "language.h"
4 #include "mwindow.h"
5
6 const char *Rescale::scale_types[] = {
7   N_("None"), N_("Scaled"), N_("Cropped"), N_("Filled"), N_("Horiz Edge"), N_("Vert Edge"),
8 };
9
10 Rescale::Rescale(int w, int h, double aspect)
11 {
12         this->w = w;
13         this->h = h;
14         this->aspect = aspect;
15 }
16
17 Rescale::Rescale(Indexable *in)
18 {
19         this->w = in->get_w();
20         this->h = in->get_h();
21         float aw, ah;
22         MWindow::create_aspect_ratio(aw, ah, this->w, this->h);
23         this->aspect = ah > 0 ? aw / ah : 1;
24 }
25
26 Rescale::~Rescale()
27 {
28 }
29
30 void Rescale::rescale(Rescale &out, int type,
31                 float &src_w,float &src_h, float &dst_w,float &dst_h)
32 {
33         int in_w = w, in_h = h;
34         int out_w = out.w, out_h = out.h;
35
36         src_w = in_w;  src_h = in_h;
37         dst_w = out_w; dst_h = out_h;
38         double r = out.aspect / aspect;
39
40         switch( type ) {
41         case cropped:
42                 if( r < 1 )
43                         src_w = in_w * r;
44                 else
45                         src_h = in_h / r;
46                 break;
47         case filled:
48                 if( r < 1 )
49                         dst_h = out_h * r;
50                 else
51                         dst_w = out_w / r;
52                 break;
53         case horiz_edge:
54                 if( r < 1 )
55                         dst_h = out_h * r;
56                 else
57                         src_h = in_h / r;
58                 break;
59         case vert_edge:
60                 if( r < 1 )
61                         src_w = in_w * r;
62                 else
63                         dst_w = out_w / r;
64                 break;
65         default:
66                 break;
67         }
68 }
69