Panda3D

imageResize.I

00001 // Filename: imageResize.I
00002 // Created by:  drose (13Mar03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: ImageResize::SizeRequest::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE ImageResize::SizeRequest::
00022 SizeRequest() {
00023   _type = RT_none;
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: ImageResize::SizeRequest::get_type
00028 //       Access: Public
00029 //  Description: Returns the type of the size request, or RT_none if
00030 //               the request has not been specified.
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE ImageResize::RequestType ImageResize::SizeRequest::
00033 get_type() const {
00034   return _type;
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: ImageResize::SizeRequest::set_pixel_size
00039 //       Access: Public
00040 //  Description: Sets the size request to store an explicit pixel
00041 //               size.
00042 ////////////////////////////////////////////////////////////////////
00043 INLINE void ImageResize::SizeRequest::
00044 set_pixel_size(int pixel_size) {
00045   _type = RT_pixel_size;
00046   _e._pixel_size = pixel_size;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: ImageResize::SizeRequest::get_pixel_size
00051 //       Access: Public
00052 //  Description: Returns the explicit pixel size stored within the
00053 //               size request.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE int ImageResize::SizeRequest::
00056 get_pixel_size() const {
00057   nassertr(_type == RT_pixel_size, 0);
00058   return _e._pixel_size;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: ImageResize::SizeRequest::get_pixel_size
00063 //       Access: Public
00064 //  Description: Returns the explicit pixel size stored within the
00065 //               size request, or if a ratio has been stored, returns
00066 //               the computed pixel size based on the original size.
00067 ////////////////////////////////////////////////////////////////////
00068 INLINE int ImageResize::SizeRequest::
00069 get_pixel_size(int orig_pixel_size) const {
00070   switch (_type) {
00071   case RT_pixel_size:
00072     return _e._pixel_size;
00073   case RT_ratio:
00074     return (int)(_e._ratio * orig_pixel_size + 0.5);
00075   default:
00076     return orig_pixel_size;
00077   }
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: ImageResize::SizeRequest::set_ratio
00082 //       Access: Public
00083 //  Description: Sets the size request to store a specific ratio.
00084 ////////////////////////////////////////////////////////////////////
00085 INLINE void ImageResize::SizeRequest::
00086 set_ratio(double ratio) {
00087   _type = RT_ratio;
00088   _e._ratio = ratio;
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: ImageResize::SizeRequest::get_ratio
00093 //       Access: Public
00094 //  Description: Returns the specific ratio stored within the
00095 //               size request.
00096 ////////////////////////////////////////////////////////////////////
00097 INLINE double ImageResize::SizeRequest::
00098 get_ratio() const {
00099   nassertr(_type == RT_ratio, 0);
00100   return _e._ratio;
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: ImageResize::SizeRequest::get_ratio
00105 //       Access: Public
00106 //  Description: Returns the specific ratio stored within the
00107 //               size request, or if a pixel size has been stored,
00108 //               returns the computed ratio based on the original
00109 //               size.
00110 ////////////////////////////////////////////////////////////////////
00111 INLINE double ImageResize::SizeRequest::
00112 get_ratio(int orig_pixel_size) const {
00113   switch (_type) {
00114   case RT_ratio:
00115     return _e._ratio;
00116   case RT_pixel_size:
00117     return (double)_e._pixel_size / (double)orig_pixel_size;
00118   default:
00119     return 1.0;
00120   }
00121 }
 All Classes Functions Variables Enumerations