Skip to content

Commit

Permalink
[imageCache] using resize from imageAlgo instead of downscaleImage fo…
Browse files Browse the repository at this point in the history
…r coherent behaviour
  • Loading branch information
mugulmd committed Dec 14, 2022
1 parent 54bea30 commit d1e4a7b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/aliceVision/image/caching.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Image.hpp"
#include "pixelTypes.hpp"
#include "io.hpp"
#include "resampling.hpp"
#include "imageAlgo.hpp"

#include <aliceVision/system/Logger.hpp>

Expand Down Expand Up @@ -375,7 +375,7 @@ void ImageCache::load(const CacheKey& key)

// apply downscale
int downscale = 1 << (key.halfSampleLevel - keyHighScale.halfSampleLevel);
downscaleImage<SamplerLinear, Image<TPix>>(*(valueHighScale.get<TPix>()), *img, downscale);
imageAlgo::resizeImage(downscale, *(valueHighScale.get<TPix>()), *img);

_info.nbLoadFromHigherScale++;
}
Expand All @@ -386,7 +386,10 @@ void ImageCache::load(const CacheKey& key)

// apply downscale
int downscale = 1 << key.halfSampleLevel;
downscaleImageInplace(*img, downscale);
if (downscale > 1)
{
imageAlgo::resizeImage(downscale, *img, *img);
}

_info.nbLoadFromDisk++;
}
Expand Down
32 changes: 32 additions & 0 deletions src/aliceVision/image/imageAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ void resizeImage(oiio::TypeDesc typeDesc,
oiio::ImageBufAlgo::resize(outBuf, inBuf, filter, filterSize, oiio::ROI::All());
}

void resizeImage(int downscale, const image::Image<unsigned char>& inImage,
image::Image<unsigned char>& outImage, const std::string& filter, float filterSize)
{
const int outWidth = inImage.Width() / downscale;
const int outHeight = inImage.Height() / downscale;
outImage.resize(outWidth, outHeight);
resizeImage(oiio::TypeDesc::UINT8, inImage.Width(), inImage.Height(), outWidth, outHeight, 1,
inImage.data(), outImage.data(), filter, filterSize);
}

void resizeImage(int downscale, const image::Image<float>& inImage,
image::Image<float>& outImage, const std::string& filter, float filterSize)
{
Expand All @@ -255,6 +265,17 @@ void resizeImage(int downscale, const image::Image<float>& inImage,
inImage.data(), outImage.data(), filter, filterSize);
}

void resizeImage(int downscale, const image::Image<image::RGBColor> &inImage,
image::Image<image::RGBColor> &outImage, const std::string &filter,
float filterSize)
{
const int outWidth = inImage.Width() / downscale;
const int outHeight = inImage.Height() / downscale;
outImage.resize(outWidth, outHeight);
resizeImage(oiio::TypeDesc::UINT8, inImage.Width(), inImage.Height(), outWidth, outHeight, 3,
inImage.data(), outImage.data(), filter, filterSize);
}

void resizeImage(int downscale, const image::Image<image::RGBfColor> &inImage,
image::Image<image::RGBfColor> &outImage, const std::string &filter,
float filterSize)
Expand All @@ -266,6 +287,17 @@ void resizeImage(int downscale, const image::Image<image::RGBfColor> &inImage,
inImage.data(), outImage.data(), filter, filterSize);
}

void resizeImage(int downscale, const image::Image<image::RGBAColor> &inImage,
image::Image<image::RGBAColor> &outImage, const std::string &filter,
float filterSize)
{
const int outWidth = inImage.Width() / downscale;
const int outHeight = inImage.Height() / downscale;
outImage.resize(outWidth, outHeight);
resizeImage(oiio::TypeDesc::UINT8, inImage.Width(), inImage.Height(), outWidth, outHeight, 4,
inImage.data(), outImage.data(), filter, filterSize);
}

void resizeImage(int downscale, const image::Image<image::RGBAfColor> &inImage,
image::Image<image::RGBAfColor> &outImage, const std::string &filter,
float filterSize)
Expand Down
9 changes: 9 additions & 0 deletions src/aliceVision/image/imageAlgo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ void colorconvert(oiio::ImageBuf& dst, const oiio::ImageBuf& src,
* See openImageIO documentation "ImageBufAlgo filtername"
* @param[in] filterSize The resize filter size
*/
void resizeImage(int downscale, const image::Image<unsigned char>& inImage,
image::Image<unsigned char>& outImage,
const std::string& filter = "", float filterSize = 0);
void resizeImage(int downscale, const image::Image<float>& inImage,
image::Image<float>& outImage,
const std::string& filter = "", float filterSize = 0);
void resizeImage(int downscale, const image::Image<image::RGBColor>& inImage,
image::Image<image::RGBColor>& outImage,
const std::string& filter = "", float filterSize = 0);
void resizeImage(int downscale, const image::Image<image::RGBfColor>& inImage,
image::Image<image::RGBfColor>& outImage,
const std::string& filter = "", float filterSize = 0);
void resizeImage(int downscale, const image::Image<image::RGBAColor>& inImage,
image::Image<image::RGBAColor>& outImage,
const std::string& filter = "", float filterSize = 0);
void resizeImage(int downscale, const image::Image<image::RGBAfColor>& inImage,
image::Image<image::RGBAfColor>& outImage,
const std::string& filter = "", float filterSize = 0);
Expand Down

0 comments on commit d1e4a7b

Please sign in to comment.