Skip to content

Commit

Permalink
Clean up some of the filter changes
Browse files Browse the repository at this point in the history
Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Jan 29, 2024
1 parent 9a1d926 commit 933b9a2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/include/OpenImageIO/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OIIO_UTIL_API Filter1D {
static const FilterDesc& get_filterdesc(int filternum);

protected:
float m_w;
const float m_w;
};


Expand Down Expand Up @@ -145,7 +145,7 @@ class OIIO_UTIL_API Filter2D {
static const FilterDesc& get_filterdesc(int filternum);

protected:
float m_w, m_h;
const float m_w, m_h;
};


Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/imagebufalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ ImageBufAlgo::make_kernel(string_view name, float width, float height,
spec.full_depth = spec.depth;
ImageBuf dst(spec);

std::unique_ptr<Filter2D> filter(Filter2D::create(name, width, height));
auto filter = Filter2D::create_shared(name, width, height);
if (filter) {
// Named continuous filter from filter.h
for (ImageBuf::Iterator<float> p(dst); !p.done(); ++p)
Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/imagebufalgo_xform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ ImageBufAlgo::st_warp(ImageBuf& dst, const ImageBuf& src, const ImageBuf& stbuf,
filter.width = 6.0f;
}
filter.filter(
Filter2D::create(filter.name, filter.width, filter.width));
Filter2D::create_shared(filter.name, filter.width, filter.width));
}

bool ok;
Expand Down
16 changes: 7 additions & 9 deletions src/libOpenImageIO/maketexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static spin_mutex maketx_mutex; // for anything that needs locking



static Filter2D*
static std::shared_ptr<const Filter2D>
setup_filter(const ImageSpec& dstspec, const ImageSpec& srcspec,
std::string filtername = std::string())
{
Expand All @@ -60,10 +60,10 @@ setup_filter(const ImageSpec& dstspec, const ImageSpec& srcspec,
FilterDesc d;
Filter2D::get_filterdesc(i, &d);
if (filtername == d.name)
return Filter2D::create(filtername, w * d.width, h * d.width);
return Filter2D::create_shared(filtername, w * d.width, h * d.width);
}

return NULL; // couldn't find a matching name
return {}; // couldn't find a matching name
}


Expand Down Expand Up @@ -797,8 +797,8 @@ write_mipmap(ImageBufAlgo::MakeTextureMode mode, std::shared_ptr<ImageBuf>& img,
envlatlmode,
allow_shift));
} else {
Filter2D* filter = setup_filter(small->spec(), img->spec(),
filtername);
auto filter = setup_filter(small->spec(), img->spec(),
filtername);
if (!filter) {
errorfmt("Could not make filter \"{}\"", filtername);
return false;
Expand Down Expand Up @@ -842,7 +842,6 @@ write_mipmap(ImageBufAlgo::MakeTextureMode mode, std::shared_ptr<ImageBuf>& img,
std::numeric_limits<float>::max(),
true);
}
Filter2D::destroy(filter);
}
}
if (clamp_half)
Expand Down Expand Up @@ -1748,14 +1747,13 @@ make_texture_impl(ImageBufAlgo::MakeTextureMode mode, const ImageBuf* input,
std::bind(resize_block, std::ref(*toplevel), std::cref(*src),
_1, envlatlmode, allow_shift != 0));
} else {
Filter2D* filter = setup_filter(toplevel->spec(), src->spec(),
resize_filter);
auto filter = setup_filter(toplevel->spec(), src->spec(),
resize_filter);
if (!filter) {
errorfmt("Could not make filter \"{}\"", resize_filter);
return false;
}
ImageBufAlgo::resize(*toplevel, *src, filter);
Filter2D::destroy(filter);
}
}
stat_resizetime += alltime.lap();
Expand Down
12 changes: 5 additions & 7 deletions src/libutil/filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ test_1d()
for (int i = 0, e = Filter1D::num_filters(); i < e; ++i) {
FilterDesc filtdesc;
Filter1D::get_filterdesc(i, &filtdesc);
Filter1D* f = Filter1D::create(filtdesc.name, filtdesc.width);
auto filter = Filter1D::create_shared(filtdesc.name, filtdesc.width);
auto f = filter.get();
// Graph it
float scale = normalize ? 1.0f / (*f)(0.0f) : 1.0f;
float color[3] = { 0.25f * (i & 3), 0.25f * ((i >> 2) & 3),
Expand All @@ -96,8 +97,6 @@ test_1d()

// Time it
bench(filtdesc.name, [=]() { DoNotOptimize((*f)(0.25f)); });

Filter1D::destroy(f);
}

graph.write("filters.tif");
Expand Down Expand Up @@ -127,8 +126,9 @@ test_2d()
for (int i = 0, e = Filter2D::num_filters(); i < e; ++i) {
FilterDesc filtdesc;
Filter2D::get_filterdesc(i, &filtdesc);
Filter2D* f = Filter2D::create(filtdesc.name, filtdesc.width,
filtdesc.width);
auto filter = Filter2D::create_shared(filtdesc.name, filtdesc.width,
filtdesc.width);
auto f = filter.get();
// Graph it
float scale = normalize ? 1.0f / (*f)(0.0f, 0.0f) : 1.0f;
float color[3] = { 0.25f * (i & 3), 0.25f * ((i >> 2) & 3),
Expand All @@ -150,8 +150,6 @@ test_2d()

// Time it
bench(filtdesc.name, [=]() { DoNotOptimize((*f)(0.25f, 0.25f)); });

Filter2D::destroy(f);
}

graph.write("filters2d.tif");
Expand Down

0 comments on commit 933b9a2

Please sign in to comment.