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.

128 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. /**
  22. A global cache of images that have been loaded from files or memory.
  23. If you're loading an image and may need to use the image in more than one
  24. place, this is used to allow the same image to be shared rather than loading
  25. multiple copies into memory.
  26. Another advantage is that after images are released, they will be kept in
  27. memory for a few seconds before it is actually deleted, so if you're repeatedly
  28. loading/deleting the same image, it'll reduce the chances of having to reload it
  29. each time.
  30. @see Image, ImageFileFormat
  31. @tags{Graphics}
  32. */
  33. class JUCE_API ImageCache
  34. {
  35. public:
  36. //==============================================================================
  37. /** Loads an image from a file, (or just returns the image if it's already cached).
  38. If the cache already contains an image that was loaded from this file,
  39. that image will be returned. Otherwise, this method will try to load the
  40. file, add it to the cache, and return it.
  41. Remember that the image returned is shared, so drawing into it might
  42. affect other things that are using it! If you want to draw on it, first
  43. call Image::duplicateIfShared()
  44. @param file the file to try to load
  45. @returns the image, or null if it there was an error loading it
  46. @see getFromMemory, getFromCache, ImageFileFormat::loadFrom
  47. */
  48. static Image getFromFile (const File& file);
  49. /** Loads an image from an in-memory image file, (or just returns the image if it's already cached).
  50. If the cache already contains an image that was loaded from this block of memory,
  51. that image will be returned. Otherwise, this method will try to load the
  52. file, add it to the cache, and return it.
  53. Remember that the image returned is shared, so drawing into it might
  54. affect other things that are using it! If you want to draw on it, first
  55. call Image::duplicateIfShared()
  56. @param imageData the block of memory containing the image data
  57. @param dataSize the data size in bytes
  58. @returns the image, or an invalid image if it there was an error loading it
  59. @see getFromMemory, getFromCache, ImageFileFormat::loadFrom
  60. */
  61. static Image getFromMemory (const void* imageData, int dataSize);
  62. //==============================================================================
  63. /** Checks the cache for an image with a particular hashcode.
  64. If there's an image in the cache with this hashcode, it will be returned,
  65. otherwise it will return an invalid image.
  66. @param hashCode the hash code that was associated with the image by addImageToCache()
  67. @see addImageToCache
  68. */
  69. static Image getFromHashCode (int64 hashCode);
  70. /** Adds an image to the cache with a user-defined hash-code.
  71. The image passed-in will be referenced (not copied) by the cache, so it's probably
  72. a good idea not to draw into it after adding it, otherwise this will affect all
  73. instances of it that may be in use.
  74. @param image the image to add
  75. @param hashCode the hash-code to associate with it
  76. @see getFromHashCode
  77. */
  78. static void addImageToCache (const Image& image, int64 hashCode);
  79. /** Changes the amount of time before an unused image will be removed from the cache.
  80. By default this is about 5 seconds.
  81. */
  82. static void setCacheTimeout (int millisecs);
  83. /** Releases any images in the cache that aren't being referenced by active
  84. Image objects.
  85. */
  86. static void releaseUnusedImages();
  87. private:
  88. //==============================================================================
  89. struct Pimpl;
  90. friend struct Pimpl;
  91. ImageCache();
  92. ~ImageCache();
  93. JUCE_DECLARE_NON_COPYABLE (ImageCache)
  94. };
  95. } // namespace juce