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