00001 #ifndef __DISPLAYRESCREEN_H__
00002 #define __DISPLAYRESCREEN_H__
00003
00004 using namespace std;
00005
00006 #include <qstringlist.h>
00007 #include <vector>
00008 #include <map>
00009 #include <algorithm>
00010 #include "mythexp.h"
00011
00012 class MPUBLIC DisplayResScreen
00013 {
00014 public:
00015
00016 DisplayResScreen()
00017 : width(0), height(0), width_mm(0), height_mm(0), aspect(-1.0) {;}
00018 DisplayResScreen(int w, int h, int mw, int mh,
00019 double aspectRatio, short refreshRate);
00020 DisplayResScreen(int w, int h, int mw, int mh,
00021 const vector<short>& refreshRates);
00022 DisplayResScreen(int w, int h, int mw, int mh,
00023 const short* refreshRates, uint rr_length);
00024 DisplayResScreen(const QString &str);
00025 inline void Init();
00026
00027
00028 int Width() const { return width; }
00029 int Height() const { return height; }
00030 int Width_mm() const { return width_mm; }
00031 int Height_mm() const { return height_mm; }
00032 inline double AspectRatio() const;
00033 inline short RefreshRate() const;
00034 const vector<short>& RefreshRates() const { return refreshRates; }
00035
00036
00037 void SetAspectRatio(double a);
00038 void AddRefreshRate(short rr) {
00039 refreshRates.push_back(rr);
00040 sort(refreshRates.begin(), refreshRates.end());
00041 }
00042
00043
00044 QString toString() const;
00045 inline bool operator < (const DisplayResScreen& b) const;
00046 inline bool operator == (const DisplayResScreen &b) const;
00047
00048
00049 static QStringList Convert(const vector<DisplayResScreen>& dsr);
00050 static vector<DisplayResScreen> Convert(const QStringList& slist);
00051 static int FindBestMatch(const vector<DisplayResScreen>& dsr,
00052 const DisplayResScreen& d,
00053 short& target_rate);
00054 static inline int CalcKey(int w, int h, int rate);
00055
00056 private:
00057 int width, height;
00058 int width_mm, height_mm;
00059 double aspect;
00060 vector<short> refreshRates;
00061 };
00062
00063 typedef vector<DisplayResScreen> DisplayResVector;
00064 typedef DisplayResVector::iterator DisplayResVectorIt;
00065 typedef DisplayResVector::const_iterator DisplayResVectorCIt;
00066
00067 typedef map<uint, class DisplayResScreen> DisplayResMap;
00068 typedef DisplayResMap::iterator DisplayResMapIt;
00069 typedef DisplayResMap::const_iterator DisplayResMapCIt;
00070
00071 inline void DisplayResScreen::Init()
00072 {
00073 width = height = width_mm = height_mm = 0;
00074 aspect = -1.0;
00075 }
00076
00077 inline double DisplayResScreen::AspectRatio() const
00078 {
00079 if (aspect<=0.0)
00080 {
00081 if (0 == height_mm)
00082 return 1.0;
00083 return ((double)(width_mm))/((double)(height_mm));
00084 }
00085 return aspect;
00086 }
00087
00088 inline short DisplayResScreen::RefreshRate() const
00089 {
00090 if (refreshRates.size() >= 1)
00091 return refreshRates[0];
00092 else return 0;
00093 }
00094
00095 inline bool DisplayResScreen::operator < (const DisplayResScreen& b) const
00096 {
00097 if (width < b.width)
00098 return true;
00099 if (height < b.height)
00100 return true;
00101 return false;
00102 }
00103
00104 inline bool DisplayResScreen::operator == (const DisplayResScreen &b) const
00105 {
00106 return width == b.width && height == b.height;
00107 }
00108
00109 inline int DisplayResScreen::CalcKey(int w, int h, int rate)
00110 {
00111 return (w << 17) | (h << 3) | rate;
00112 }
00113
00114 #endif // __DISPLAYRESCREEN_H__