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