ScalerFactory.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "ScalerFactory.hh"
  2. #include "RenderSettings.hh"
  3. #include "EnumSetting.hh"
  4. #include "IntegerSetting.hh"
  5. #include "Simple2xScaler.hh"
  6. #include "Simple3xScaler.hh"
  7. #include "SaI2xScaler.hh" // note: included even if MAX_SCALE_FACTOR == 1
  8. #include "SaI3xScaler.hh"
  9. #include "Scale2xScaler.hh"
  10. #include "Scale3xScaler.hh"
  11. #include "HQ2xScaler.hh"
  12. #include "HQ3xScaler.hh"
  13. #include "HQ2xLiteScaler.hh"
  14. #include "HQ3xLiteScaler.hh"
  15. #include "RGBTriplet3xScaler.hh"
  16. #include "MLAAScaler.hh"
  17. #include "Scaler1.hh"
  18. #include "unreachable.hh"
  19. #include "build-info.hh"
  20. #include <cstdint>
  21. #include <memory>
  22. using std::unique_ptr;
  23. namespace openmsx {
  24. template <class Pixel>
  25. unique_ptr<Scaler<Pixel>> ScalerFactory<Pixel>::createScaler(
  26. const PixelOperations<Pixel>& pixelOps, RenderSettings& renderSettings)
  27. {
  28. switch (renderSettings.getScaleFactor()) {
  29. #if (MIN_SCALE_FACTOR <= 1) && (MAX_SCALE_FACTOR >= 1)
  30. case 1:
  31. return std::make_unique<Scaler1<Pixel>>(pixelOps);
  32. #endif
  33. #if (MIN_SCALE_FACTOR <= 2) && (MAX_SCALE_FACTOR >= 2)
  34. case 2:
  35. switch (renderSettings.getScaleAlgorithm()) {
  36. case RenderSettings::SCALER_SIMPLE:
  37. return std::make_unique<Simple2xScaler<Pixel>>(
  38. pixelOps, renderSettings);
  39. case RenderSettings::SCALER_SAI:
  40. return std::make_unique<SaI2xScaler<Pixel>>(pixelOps);
  41. case RenderSettings::SCALER_SCALE:
  42. return std::make_unique<Scale2xScaler<Pixel>>(pixelOps);
  43. case RenderSettings::SCALER_HQ:
  44. return std::make_unique<HQ2xScaler<Pixel>>(pixelOps);
  45. case RenderSettings::SCALER_HQLITE:
  46. return std::make_unique<HQ2xLiteScaler<Pixel>>(pixelOps);
  47. case RenderSettings::SCALER_RGBTRIPLET:
  48. case RenderSettings::SCALER_TV: // fallback
  49. return std::make_unique<Simple2xScaler<Pixel>>(
  50. pixelOps, renderSettings);
  51. case RenderSettings::SCALER_MLAA:
  52. return std::make_unique<MLAAScaler<Pixel>>(640, pixelOps);
  53. default:
  54. UNREACHABLE;
  55. }
  56. #endif
  57. #if (MIN_SCALE_FACTOR <= 4) && (MAX_SCALE_FACTOR >= 3)
  58. case 3:
  59. case 4: // fallback
  60. switch (renderSettings.getScaleAlgorithm()) {
  61. case RenderSettings::SCALER_SIMPLE:
  62. return std::make_unique<Simple3xScaler<Pixel>>(
  63. pixelOps, renderSettings);
  64. case RenderSettings::SCALER_SAI:
  65. return std::make_unique<SaI3xScaler<Pixel>>(pixelOps);
  66. case RenderSettings::SCALER_SCALE:
  67. return std::make_unique<Scale3xScaler<Pixel>>(pixelOps);
  68. case RenderSettings::SCALER_HQ:
  69. return std::make_unique<HQ3xScaler<Pixel>>(pixelOps);
  70. case RenderSettings::SCALER_HQLITE:
  71. return std::make_unique<HQ3xLiteScaler<Pixel>>(pixelOps);
  72. case RenderSettings::SCALER_RGBTRIPLET:
  73. case RenderSettings::SCALER_TV: // fallback
  74. return std::make_unique<RGBTriplet3xScaler<Pixel>>(
  75. pixelOps, renderSettings);
  76. case RenderSettings::SCALER_MLAA:
  77. return std::make_unique<MLAAScaler<Pixel>>(960, pixelOps);
  78. default:
  79. UNREACHABLE;
  80. }
  81. #endif
  82. default:
  83. UNREACHABLE;
  84. }
  85. return nullptr; // avoid warning
  86. }
  87. // Force template instantiation.
  88. #if HAVE_16BPP
  89. template class ScalerFactory<uint16_t>;
  90. #endif
  91. #if HAVE_32BPP
  92. template class ScalerFactory<uint32_t>;
  93. #endif
  94. } // namespace openmsx