Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_ScaledImage.h 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /**
  21. An image that will be resampled before it is drawn.
  22. A plain Image only stores plain pixels, but does not store any information
  23. about how these pixels correspond to points. This means that if the image's
  24. dimensions are interpreted as points, then the image will be blurry when
  25. drawn on high resolution displays. If the image's dimensions are instead
  26. interpreted as corresponding to exact pixel positions, then the logical
  27. size of the image will change depending on the scale factor of the screen
  28. used to draw it.
  29. The ScaledImage class is designed to store an image alongside a scale
  30. factor that informs a renderer how to convert between the image's pixels
  31. and points.
  32. */
  33. class JUCE_API ScaledImage
  34. {
  35. public:
  36. /** Creates a ScaledImage with an invalid image and unity scale.
  37. */
  38. ScaledImage() = default;
  39. /** Creates a ScaledImage from an Image, where the dimensions of the image
  40. in pixels are exactly equal to its dimensions in points.
  41. */
  42. explicit ScaledImage (const Image& imageIn)
  43. : ScaledImage (imageIn, 1.0) {}
  44. /** Creates a ScaledImage from an Image, using a custom scale factor.
  45. A scale of 1.0 means that the image's dimensions in pixels is equal to
  46. its dimensions in points.
  47. A scale of 2.0 means that the image contains 2 pixels per point in each
  48. direction.
  49. */
  50. ScaledImage (const Image& imageIn, double scaleIn)
  51. : image (imageIn), scaleFactor (scaleIn) {}
  52. /** Returns the image at its original dimensions. */
  53. Image getImage() const { return image; }
  54. /** Returns the image's scale. */
  55. double getScale() const { return scaleFactor; }
  56. /** Returns the bounds of this image expressed in points. */
  57. Rectangle<double> getScaledBounds() const { return image.getBounds().toDouble() / scaleFactor; }
  58. private:
  59. Image image;
  60. double scaleFactor = 1.0;
  61. };
  62. } // namespace juce