-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[image] New image cache #1310
Merged
Merged
[image] New image cache #1310
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
77b5497
[image] utility to log OIIO shared img cache info
mugulmd c3973ff
[image] image caching mechanism + sample application + unit test
mugulmd 43bdfe8
[image] add mutex for thread-safe code + option for multithread in sa…
mugulmd e0b2293
[imageCache] use mutable keyword for mutex
mugulmd 110aa18
[imageCache] support all pixel types for cached images
mugulmd d5901d3
[imageCache] usage statistics
mugulmd b0f70a2
[imageCache] load new image: use cached image with higher scale when …
mugulmd 23923db
[imageCache] include last write time of image on disk in cache key
mugulmd 3d1ab02
[imageCache] add unit tests
mugulmd ad287ea
[samples] add command-line arguments to image caching sample app
mugulmd 4f7f411
[imageCache] using resize from imageAlgo instead of downscaleImage fo…
mugulmd 972e47f
[image] downscaling dichotomy: image::downscaleImage for custom sampl…
mugulmd 9ebde4f
[imageCache] documented caching mechanism
mugulmd adc8e47
[imageCache] fix: use last write time when searching high res version…
mugulmd 1fffb23
[image] typo fixes
fabiencastan 25537c7
[image] add dedicated functions for rescaling in-place
mugulmd 61e7b6d
[imageCache] cosmetic change in member variable initialization
mugulmd 278e086
[image] linux build fix
fabiencastan 201c96b
[image] rename caching to imageCaching
mugulmd fad85f0
[image] using unsigned long long int type for memory size
mugulmd d9217aa
[imageCaching] use trace logs instead of debug logs
mugulmd f7e476e
[imageCaching] use MiB (mebibytes) instead of MB (megabytes)
mugulmd ed8cdae
minor cosmetic changes
mugulmd 5acb92a
[imageCaching] support all downscale levels instead of just powers of…
mugulmd 2a2436d
[image] renamed imageCaching to ImageCache
mugulmd 82c8c3f
[image] throw error when resizing image with downscale smaller than 1
mugulmd ef40139
[image] ImageCache: default downscale value
mugulmd 1e1c7cd
[image] imageCaching: update unit tests
mugulmd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// This file is part of the AliceVision project. | ||
// Copyright (c) 2022 AliceVision contributors. | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, | ||
// v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "ImageCache.hpp" | ||
|
||
#include <aliceVision/system/Logger.hpp> | ||
|
||
|
||
namespace aliceVision { | ||
namespace image { | ||
|
||
CacheValue::CacheValue() | ||
{ | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<unsigned char>> img) | ||
{ | ||
CacheValue value; | ||
value.imgUChar = img; | ||
return value; | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<float>> img) | ||
{ | ||
CacheValue value; | ||
value.imgFloat = img; | ||
return value; | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<RGBColor>> img) | ||
{ | ||
CacheValue value; | ||
value.imgRGB = img; | ||
return value; | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<RGBfColor>> img) | ||
{ | ||
CacheValue value; | ||
value.imgRGBf = img; | ||
return value; | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<RGBAColor>> img) | ||
{ | ||
CacheValue value; | ||
value.imgRGBA = img; | ||
return value; | ||
} | ||
|
||
CacheValue CacheValue::wrap(std::shared_ptr<Image<RGBAfColor>> img) | ||
{ | ||
CacheValue value; | ||
value.imgRGBAf = img; | ||
return value; | ||
} | ||
|
||
int CacheValue::useCount() const | ||
{ | ||
if (imgUChar) | ||
{ | ||
return imgUChar.use_count(); | ||
} | ||
if (imgFloat) | ||
{ | ||
return imgFloat.use_count(); | ||
} | ||
if (imgRGB) | ||
{ | ||
return imgRGB.use_count(); | ||
} | ||
if (imgRGBf) | ||
{ | ||
return imgRGBf.use_count(); | ||
} | ||
if (imgRGBA) | ||
{ | ||
return imgRGBA.use_count(); | ||
} | ||
if (imgRGBAf) | ||
{ | ||
return imgRGBAf.use_count(); | ||
} | ||
return 0; | ||
} | ||
|
||
unsigned long long int CacheValue::memorySize() const | ||
{ | ||
if (imgUChar) | ||
{ | ||
return imgUChar->MemorySize(); | ||
} | ||
if (imgFloat) | ||
{ | ||
return imgFloat->MemorySize(); | ||
} | ||
if (imgRGB) | ||
{ | ||
return imgRGB->MemorySize(); | ||
} | ||
if (imgRGBf) | ||
{ | ||
return imgRGBf->MemorySize(); | ||
} | ||
if (imgRGBA) | ||
{ | ||
return imgRGBA->MemorySize(); | ||
} | ||
if (imgRGBAf) | ||
{ | ||
return imgRGBAf->MemorySize(); | ||
} | ||
return 0; | ||
} | ||
|
||
ImageCache::ImageCache(float capacity_MiB, float maxSize_MiB, const ImageReadOptions& options) : | ||
_info(capacity_MiB, maxSize_MiB), | ||
_options(options) | ||
{ | ||
} | ||
|
||
ImageCache::~ImageCache() | ||
{ | ||
} | ||
|
||
std::string ImageCache::toString() const | ||
{ | ||
std::string description = "Image cache content (LRU to MRU): "; | ||
|
||
for (const CacheKey& key : _keys) | ||
{ | ||
std::string keyDesc = key.filename + | ||
", nbChannels: " + std::to_string(key.nbChannels) + | ||
", typeDesc: " + std::to_string(key.typeDesc) + | ||
", downscaleLevel: " + std::to_string(key.downscaleLevel) + | ||
", usages: " + std::to_string(_imagePtrs.at(key).useCount()) + | ||
", size: " + std::to_string(_imagePtrs.at(key).memorySize()); | ||
description += "\n * " + keyDesc; | ||
} | ||
|
||
std::string memUsageDesc = "\nMemory usage: " | ||
"\n * capacity: " + std::to_string(_info.capacity) + | ||
"\n * max size: " + std::to_string(_info.maxSize) + | ||
"\n * nb images: " + std::to_string(_info.nbImages) + | ||
"\n * content size: " + std::to_string(_info.contentSize); | ||
description += memUsageDesc; | ||
|
||
std::string statsDesc = "\nUsage statistics: " | ||
"\n * nb load from disk: " + std::to_string(_info.nbLoadFromDisk) + | ||
"\n * nb load from cache: " + std::to_string(_info.nbLoadFromCache) + | ||
"\n * nb remove unused: " + std::to_string(_info.nbRemoveUnused); | ||
description += statsDesc; | ||
|
||
return description; | ||
} | ||
|
||
} // namespace image | ||
} // namespace aliceVision |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a dedicated function to print in a human readable format, to print with MB, GB, etc depending on the values.