Panda3D
imageResize.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file imageResize.I
10  * @author drose
11  * @date 2003-03-13
12  */
13 
14 /**
15  *
16  */
17 INLINE ImageResize::SizeRequest::
18 SizeRequest() {
19  _type = RT_none;
20 }
21 
22 /**
23  * Returns the type of the size request, or RT_none if the request has not
24  * been specified.
25  */
26 INLINE ImageResize::RequestType ImageResize::SizeRequest::
27 get_type() const {
28  return _type;
29 }
30 
31 /**
32  * Sets the size request to store an explicit pixel size.
33  */
34 INLINE void ImageResize::SizeRequest::
35 set_pixel_size(int pixel_size) {
36  _type = RT_pixel_size;
37  _e._pixel_size = pixel_size;
38 }
39 
40 /**
41  * Returns the explicit pixel size stored within the size request.
42  */
43 INLINE int ImageResize::SizeRequest::
44 get_pixel_size() const {
45  nassertr(_type == RT_pixel_size, 0);
46  return _e._pixel_size;
47 }
48 
49 /**
50  * Returns the explicit pixel size stored within the size request, or if a
51  * ratio has been stored, returns the computed pixel size based on the
52  * original size.
53  */
54 INLINE int ImageResize::SizeRequest::
55 get_pixel_size(int orig_pixel_size) const {
56  switch (_type) {
57  case RT_pixel_size:
58  return _e._pixel_size;
59  case RT_ratio:
60  return (int)(_e._ratio * orig_pixel_size + 0.5);
61  default:
62  return orig_pixel_size;
63  }
64 }
65 
66 /**
67  * Sets the size request to store a specific ratio.
68  */
69 INLINE void ImageResize::SizeRequest::
70 set_ratio(double ratio) {
71  _type = RT_ratio;
72  _e._ratio = ratio;
73 }
74 
75 /**
76  * Returns the specific ratio stored within the size request.
77  */
78 INLINE double ImageResize::SizeRequest::
79 get_ratio() const {
80  nassertr(_type == RT_ratio, 0);
81  return _e._ratio;
82 }
83 
84 /**
85  * Returns the specific ratio stored within the size request, or if a pixel
86  * size has been stored, returns the computed ratio based on the original
87  * size.
88  */
89 INLINE double ImageResize::SizeRequest::
90 get_ratio(int orig_pixel_size) const {
91  switch (_type) {
92  case RT_ratio:
93  return _e._ratio;
94  case RT_pixel_size:
95  return (double)_e._pixel_size / (double)orig_pixel_size;
96  default:
97  return 1.0;
98  }
99 }