SDLImageScaler.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SDLImageScaler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../render/IImage.h"
  12. #include "../../lib/Rect.h"
  13. class SDLImageOptimizer : boost::noncopyable
  14. {
  15. SDL_Surface * surf = nullptr;
  16. SDL_Surface * output = nullptr;
  17. Rect virtualDimensions = Rect(0,0,0,0);
  18. public:
  19. SDLImageOptimizer(SDL_Surface * surf, const Rect & virtualDimensions);
  20. void optimizeSurface(SDL_Surface * formatSourceSurface);
  21. /// Aquires resulting surface and transfers surface ownership to the caller
  22. /// May return nullptr if input image was empty
  23. SDL_Surface * acquireResultSurface();
  24. /// Returns adjusted virtual dimensions of resulting surface
  25. const Rect & getResultDimensions() const;
  26. };
  27. /// Class that performs scaling of SDL surfaces
  28. /// Object construction MUST be performed while holding UI lock
  29. /// but task execution can be performed asynchronously if needed
  30. class SDLImageScaler : boost::noncopyable
  31. {
  32. SDL_Surface * intermediate = nullptr;
  33. SDL_Surface * ret = nullptr;
  34. Rect virtualDimensionsInput = Rect(0,0,0,0);
  35. Rect virtualDimensionsOutput = Rect(0,0,0,0);
  36. public:
  37. SDLImageScaler(SDL_Surface * surf);
  38. SDLImageScaler(SDL_Surface * surf, const Rect & virtualDimensions, bool optimizeImage);
  39. ~SDLImageScaler();
  40. /// Performs upscaling or downscaling to a requested dimensions
  41. /// Aspect ratio is NOT maintained.
  42. /// xbrz algorithm is not supported in this mode
  43. void scaleSurface(Point dimensions, EScalingAlgorithm algorithm);
  44. /// Performs upscaling by specified integral factor, potentially using xbrz algorithm if requested
  45. void scaleSurfaceIntegerFactor(int factor, EScalingAlgorithm algorithm);
  46. /// Aquires resulting surface and transfers surface ownership to the caller
  47. /// May return nullptr if input image was empty
  48. SDL_Surface * acquireResultSurface();
  49. /// Returns adjusted virtual dimensions of resulting surface
  50. const Rect & getResultDimensions() const;
  51. };