1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "imagedimensions.h"
21 #include "rtengine.h"
22 
PreviewProps(int _x,int _y,int _width,int _height,int _skip)23 PreviewProps::PreviewProps(int _x, int _y, int _width, int _height, int _skip) :
24     x(_x),
25     y(_y),
26     width(_width),
27     height(_height),
28     skip(_skip)
29 {
30 }
31 
getX() const32 int PreviewProps::getX() const
33 {
34     return x;
35 }
36 
getY() const37 int PreviewProps::getY() const
38 {
39     return y;
40 }
41 
getWidth() const42 int PreviewProps::getWidth() const
43 {
44     return width;
45 }
46 
getHeight() const47 int PreviewProps::getHeight() const
48 {
49     return height;
50 }
51 
getSkip() const52 int PreviewProps::getSkip() const
53 {
54     return skip;
55 }
56 
ImageDimensions()57 ImageDimensions::ImageDimensions() :
58     width(-1),
59     height(-1)
60 {
61 }
62 
transform(const PreviewProps & pp,int tran,int & sx1,int & sy1,int & sx2,int & sy2) const63 void ImageDimensions::transform(const PreviewProps& pp, int tran, int& sx1, int& sy1, int& sx2, int& sy2) const
64 {
65     int sw = width;
66     int sh = height;
67 
68     if ((tran & TR_ROT) == TR_R90 || (tran & TR_ROT) == TR_R270) {
69         std::swap(sw, sh);
70     }
71 
72     int ppx = pp.getX();
73     int ppy = pp.getY();
74 
75     if (tran & TR_HFLIP) {
76         ppx = sw - pp.getX() - pp.getWidth();
77     }
78 
79     if (tran & TR_VFLIP) {
80         ppy = sh - pp.getY() - pp.getHeight();
81     }
82 
83     sx1 = ppx;
84     sy1 = ppy;
85     sx2 = ppx + pp.getWidth();
86     sy2 = ppy + pp.getHeight();
87 
88     if ((tran & TR_ROT) == TR_R180) {
89         sx1 = width - ppx - pp.getWidth();
90         sy1 = height - ppy - pp.getHeight();
91         sx2 = sx1 + pp.getWidth();
92         sy2 = sy1 + pp.getHeight();
93     } else if ((tran & TR_ROT) == TR_R90) {
94         sx1 = ppy;
95         sy1 = height - ppx - pp.getWidth();
96         sx2 = sx1 + pp.getHeight();
97         sy2 = sy1 + pp.getWidth();
98     } else if ((tran & TR_ROT) == TR_R270) {
99         sx1 = width - ppy - pp.getHeight();
100         sy1 = ppx;
101         sx2 = sx1 + pp.getHeight();
102         sy2 = sy1 + pp.getWidth();
103     }
104 
105     if (sx1 < 0) {
106         sx1 = 0;
107     }
108 
109     if (sy1 < 0) {
110         sy1 = 0;
111     }
112 }
113 
114