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.

121 lines
4.6KB

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