00001 #ifndef __DISPLAYRESCREEN_H__
00002 #define __DISPLAYRESCREEN_H__
00003
00004 #include <vector>
00005 #include <map>
00006 #include <algorithm>
00007
00008 #include <QString>
00009
00010 #include <stdint.h>
00011
00012 #include "mythuiexp.h"
00013
00014 class DisplayResScreen;
00015
00016 typedef std::vector<DisplayResScreen> DisplayResVector;
00017 typedef DisplayResVector::iterator DisplayResVectorIt;
00018 typedef DisplayResVector::const_iterator DisplayResVectorCIt;
00019
00020 typedef std::map<uint64_t, DisplayResScreen> DisplayResMap;
00021 typedef DisplayResMap::iterator DisplayResMapIt;
00022 typedef DisplayResMap::const_iterator DisplayResMapCIt;
00023
00024 class MUI_PUBLIC DisplayResScreen
00025 {
00026 public:
00027
00028 DisplayResScreen()
00029 : width(0), height(0), width_mm(0), height_mm(0), aspect(-1.0),
00030 custom(false) {;}
00031 DisplayResScreen(int w, int h, int mw, int mh,
00032 double aspectRatio, double refreshRate);
00033 DisplayResScreen(int w, int h, int mw, int mh,
00034 const std::vector<double>& refreshRates);
00035 DisplayResScreen(int w, int h, int mw, int mh,
00036 const std::vector<double>& refreshRates,
00037 const std::map<double, short>& realrates);
00038 DisplayResScreen(int w, int h, int mw, int mh,
00039 const double* refreshRates, uint rr_length);
00040 DisplayResScreen(int w, int h, int mw, int mh,
00041 const short* refreshRates, uint rr_length);
00042 DisplayResScreen(const QString &str);
00043 inline void Init();
00044
00045
00046 int Width() const { return width; }
00047 int Height() const { return height; }
00048 int Width_mm() const { return width_mm; }
00049 int Height_mm() const { return height_mm; }
00050 bool Custom() const { return custom; }
00051
00052 inline double AspectRatio() const;
00053 inline double RefreshRate() const;
00054 const std::vector<double>& RefreshRates() const { return refreshRates; }
00055
00056
00057 void SetAspectRatio(double a);
00058 void AddRefreshRate(double rr)
00059 {
00060 refreshRates.push_back(rr);
00061 std::sort(refreshRates.begin(), refreshRates.end());
00062 }
00063 void ClearRefreshRates(void) { refreshRates.clear(); }
00064 void SetCustom(bool b) { custom = b; }
00065
00066
00067 std::map<double, short> realRates;
00068
00069
00070 QString toString() const;
00071 inline bool operator < (const DisplayResScreen& b) const;
00072 inline bool operator == (const DisplayResScreen &b) const;
00073
00074
00075 static QStringList Convert(const DisplayResVector& dsr);
00076 static DisplayResVector Convert(const QStringList& slist);
00077 static int FindBestMatch(const DisplayResVector& dsr,
00078 const DisplayResScreen& d,
00079 double& target_rate);
00080 static inline uint64_t CalcKey(int w, int h, double rate);
00081 static bool compare_rates(double f1, double f2, double precision = 0.01);
00082 static uint64_t FindBestScreen(const DisplayResMap& resmap,
00083 int iwidth, int iheight, double frate);
00084
00085 private:
00086 int width, height;
00087 int width_mm, height_mm;
00088 double aspect;
00089 std::vector<double> refreshRates;
00090 bool custom;
00091 };
00092
00093 inline void DisplayResScreen::Init()
00094 {
00095 width = height = width_mm = height_mm = 0;
00096 aspect = -1.0;
00097 }
00098
00099 inline double DisplayResScreen::AspectRatio() const
00100 {
00101 if (aspect<=0.0)
00102 {
00103 if (0 == height_mm)
00104 return 1.0;
00105 return ((double)(width_mm))/((double)(height_mm));
00106 }
00107 return aspect;
00108 }
00109
00110 inline double DisplayResScreen::RefreshRate() const
00111 {
00112 if (refreshRates.size() >= 1)
00113 return refreshRates[0];
00114 else return 0.0;
00115 }
00116
00117 inline bool DisplayResScreen::operator < (const DisplayResScreen& b) const
00118 {
00119 if (width < b.width)
00120 return true;
00121 if (height < b.height)
00122 return true;
00123 return false;
00124 }
00125
00126 inline bool DisplayResScreen::operator == (const DisplayResScreen &b) const
00127 {
00128 return width == b.width && height == b.height;
00129 }
00130
00131 inline uint64_t DisplayResScreen::CalcKey(int w, int h, double rate)
00132 {
00133 uint64_t irate = (uint64_t) (rate * 1000.0);
00134 return ((uint64_t)w << 34) | ((uint64_t)h << 18) | irate;
00135 }
00136
00137 #endif // __DISPLAYRESCREEN_H__