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.

76 lines
2.6KB

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