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_ImageCache.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_IMAGECACHE_H_INCLUDED
  18. #define JUCE_IMAGECACHE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A global cache of images that have been loaded from files or memory.
  22. If you're loading an image and may need to use the image in more than one
  23. place, this is used to allow the same image to be shared rather than loading
  24. multiple copies into memory.
  25. Another advantage is that after images are released, they will be kept in
  26. memory for a few seconds before it is actually deleted, so if you're repeatedly
  27. loading/deleting the same image, it'll reduce the chances of having to reload it
  28. each time.
  29. @see Image, ImageFileFormat
  30. */
  31. class JUCE_API ImageCache
  32. {
  33. public:
  34. //==============================================================================
  35. /** Loads an image from a file, (or just returns the image if it's already cached).
  36. If the cache already contains an image that was loaded from this file,
  37. that image will be returned. Otherwise, this method will try to load the
  38. file, add it to the cache, and return it.
  39. Remember that the image returned is shared, so drawing into it might
  40. affect other things that are using it! If you want to draw on it, first
  41. call Image::duplicateIfShared()
  42. @param file the file to try to load
  43. @returns the image, or null if it there was an error loading it
  44. @see getFromMemory, getFromCache, ImageFileFormat::loadFrom
  45. */
  46. static Image getFromFile (const File& file);
  47. /** Loads an image from an in-memory image file, (or just returns the image if it's already cached).
  48. If the cache already contains an image that was loaded from this block of memory,
  49. that image will be returned. Otherwise, this method will try to load the
  50. file, add it to the cache, and return it.
  51. Remember that the image returned is shared, so drawing into it might
  52. affect other things that are using it! If you want to draw on it, first
  53. call Image::duplicateIfShared()
  54. @param imageData the block of memory containing the image data
  55. @param dataSize the data size in bytes
  56. @returns the image, or an invalid image if it there was an error loading it
  57. @see getFromMemory, getFromCache, ImageFileFormat::loadFrom
  58. */
  59. static Image getFromMemory (const void* imageData, int dataSize);
  60. //==============================================================================
  61. /** Checks the cache for an image with a particular hashcode.
  62. If there's an image in the cache with this hashcode, it will be returned,
  63. otherwise it will return an invalid image.
  64. @param hashCode the hash code that was associated with the image by addImageToCache()
  65. @see addImageToCache
  66. */
  67. static Image getFromHashCode (int64 hashCode);
  68. /** Adds an image to the cache with a user-defined hash-code.
  69. The image passed-in will be referenced (not copied) by the cache, so it's probably
  70. a good idea not to draw into it after adding it, otherwise this will affect all
  71. instances of it that may be in use.
  72. @param image the image to add
  73. @param hashCode the hash-code to associate with it
  74. @see getFromHashCode
  75. */
  76. static void addImageToCache (const Image& image, int64 hashCode);
  77. /** Changes the amount of time before an unused image will be removed from the cache.
  78. By default this is about 5 seconds.
  79. */
  80. static void setCacheTimeout (int millisecs);
  81. /** Releases any images in the cache that aren't being referenced by active
  82. Image objects.
  83. */
  84. static void releaseUnusedImages();
  85. private:
  86. //==============================================================================
  87. class Pimpl;
  88. friend class Pimpl;
  89. ImageCache();
  90. ~ImageCache();
  91. JUCE_DECLARE_NON_COPYABLE (ImageCache)
  92. };
  93. #endif // JUCE_IMAGECACHE_H_INCLUDED