Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE ImageResize::SizeRequest::
18SizeRequest() {
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 */
26INLINE ImageResize::RequestType ImageResize::SizeRequest::
27get_type() const {
28 return _type;
29}
30
31/**
32 * Sets the size request to store an explicit pixel size.
33 */
34INLINE void ImageResize::SizeRequest::
35set_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 */
43INLINE int ImageResize::SizeRequest::
44get_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 */
54INLINE int ImageResize::SizeRequest::
55get_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 */
69INLINE void ImageResize::SizeRequest::
70set_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 */
78INLINE double ImageResize::SizeRequest::
79get_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 */
89INLINE double ImageResize::SizeRequest::
90get_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}