Skip to content

Commit

Permalink
api: move OIIO::pvt::error and log_time into the exposed OIIO namespa…
Browse files Browse the repository at this point in the history
…ce (#4362)

This is needed for the related OpenCV-related PR

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Aug 7, 2024
1 parent 3cb2acf commit d249036
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/iff.imageio/noproxy-iff_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class IffInput final : public ImageInput {
try {
close();
} catch (const std::exception& e) {
OIIO::pvt::errorfmt("{}", e.what());
OIIO::errorfmt("{}", e.what());
}
}
const char* format_name(void) const override { return "iff"; }
Expand Down Expand Up @@ -228,7 +228,7 @@ class IffOutput final : public ImageOutput {
try {
close();
} catch (const std::exception& e) {
OIIO::pvt::errorfmt("{}", e.what());
OIIO::errorfmt("{}", e.what());
}
}
const char* format_name(void) const override { return "iff"; }
Expand Down
16 changes: 16 additions & 0 deletions src/include/OpenImageIO/imageio.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OIIO_NAMESPACE_BEGIN

class DeepData;
class ImageBuf;
class Timer;


/// Type we use for stride lengths between pixels, scanlines, or image
Expand Down Expand Up @@ -3363,7 +3364,22 @@ void debugfmt (const char* fmt, Args&&... args)
Strutil::debug(fmt, std::forward<Args>(args)...);
}

namespace pvt {
// For internal use - use errorfmt() below for a nicer interface.
OIIO_API void append_error(string_view message);
}

/// error logging (mostly for OIIO internals) with `std::format` conventions.
template<typename... Args>
inline void errorfmt(const char* fmt, Args&&... args)
{
pvt::append_error(string_view(Strutil::fmt::format(fmt, args...)));
}

/// Internal function to log time recorded by an OIIO::timer(). It will only
/// trigger a read of the time if the "log_times" attribute is set or the
/// OPENIMAGEIO_LOG_TIMES env variable is set.
OIIO_API void log_time(string_view key, const Timer& timer, int count = 1);

// to force correct linkage on some systems
OIIO_API void _ImageIO_force_link ();
Expand Down
4 changes: 3 additions & 1 deletion src/include/OpenImageIO/strutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ using old::format;
#endif


// format_to comes from fmt library
// More things we wrap from fmt library
using ::fmt::format_args;
using ::fmt::make_format_args;
using ::fmt::format_to;
using ::fmt::format_to_n;

Expand Down
18 changes: 0 additions & 18 deletions src/include/imageio_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ font_list();



// For internal use - use error() below for a nicer interface.
void
append_error(string_view message);

/// Use errorfmt() privately only. Formatting notation is like std::format.
template<typename... Args>
inline void
errorfmt(const char* fmt, const Args&... args)
{
append_error(Strutil::fmt::format(fmt, args...));
}

// Make sure all plugins are inventoried. For internal use only.
void
catalog_all_plugins(std::string searchpath);
Expand Down Expand Up @@ -123,12 +111,6 @@ parallel_convert_from_float(const float* src, void* dst, size_t nvals,
OIIO_API bool
check_texture_metadata_sanity(ImageSpec& spec);

/// Internal function to log time recorded by an OIIO::timer(). It will only
/// trigger a read of the time if the "log_times" attribute is set or the
/// OPENIMAGEIO_LOG_TIMES env variable is set.
OIIO_API void
log_time(string_view key, const Timer& timer, int count = 1);

/// Get the timing report from log_time entries.
OIIO_API std::string
timing_report();
Expand Down
14 changes: 6 additions & 8 deletions src/libOpenImageIO/imagebufalgo_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,14 @@ ImageBufAlgo::to_OpenCV(cv::Mat& dst, const ImageBuf& src, ROI roi,
} else if (spec.format == TypeDesc(TypeDesc::DOUBLE)) {
dstFormat = CV_MAKETYPE(CV_64F, chans);
} else {
OIIO::pvt::errorfmt(
"to_OpenCV() doesn't know how to make a cv::Mat of {}",
spec.format);
OIIO::errorfmt("to_OpenCV() doesn't know how to make a cv::Mat of {}",
spec.format);
return false;
}
dst.create(roi.height(), roi.width(), dstFormat);
if (dst.empty()) {
OIIO::pvt::errorfmt(
"to_OpenCV() was unable to create cv::Mat of {}x{} {}", roi.width(),
roi.height(), dstSpecFormat);
OIIO::errorfmt("to_OpenCV() was unable to create cv::Mat of {}x{} {}",
roi.width(), roi.height(), dstSpecFormat);
return false;
}

Expand All @@ -189,7 +187,7 @@ ImageBufAlgo::to_OpenCV(cv::Mat& dst, const ImageBuf& src, ROI roi,
dst.ptr(), pixelsize, linestep, AutoStride);
bool converted = ImageBufAlgo::copy(cvib, src);
if (!converted) {
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"to_OpenCV() was unable to convert source {} to cv::Mat of {}",
spec.format, dstSpecFormat);
return false;
Expand All @@ -204,7 +202,7 @@ ImageBufAlgo::to_OpenCV(cv::Mat& dst, const ImageBuf& src, ROI roi,

return true;
#else
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"to_OpenCV() not supported -- no OpenCV support at compile time");
return false;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/imageinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ ImageInput::open(const std::string& filename, const ImageSpec* config,
// error, delete the ImageInput we allocated, and return NULL.
std::string err = in->geterror();
if (err.size())
OIIO::pvt::errorfmt("{}", err);
OIIO::errorfmt("{}", err);
in.reset();
}

Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ debug(string_view message)


void
pvt::log_time(string_view key, const Timer& timer, int count)
log_time(string_view key, const Timer& timer, int count)
{
timing_log(key, timer, count);
}
Expand Down
20 changes: 10 additions & 10 deletions src/libOpenImageIO/imageioplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
{
std::unique_ptr<ImageOutput> out;
if (filename.empty()) { // Can't even guess if no filename given
OIIO::pvt::errorfmt("ImageOutput::create() called with no filename");
OIIO::errorfmt("ImageOutput::create() called with no filename");
return out;
}

Expand Down Expand Up @@ -563,9 +563,9 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
const char* msg
= "ImageOutput::create() could not find any ImageOutput plugins! Perhaps you need to set OIIO_LIBRARY_PATH.\n";
Strutil::print(stderr, "{}", msg);
OIIO::pvt::errorfmt("{}", msg);
OIIO::errorfmt("{}", msg);
} else
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"OpenImageIO could not find a format writer for \"{}\". "
"Is it a file format that OpenImageIO doesn't know about?\n",
filename);
Expand All @@ -582,7 +582,7 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
}
if (out && ioproxy) {
if (!out->supports("ioproxy")) {
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"ImageOutput::create called with IOProxy, but format {} does not support IOProxy",
out->format_name());
out.reset();
Expand All @@ -609,7 +609,7 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
// Only check REST arguments if the file does not exist
if (!Filesystem::exists(filename)) {
if (!Strutil::get_rest_arguments(filename, filename_stripped, args)) {
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"ImageInput::create() called with malformed filename");
return in;
}
Expand All @@ -619,7 +619,7 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
filename_stripped = filename;

if (filename_stripped.empty()) { // Can't even guess if no filename given
OIIO::pvt::errorfmt("ImageInput::create() called with no filename");
OIIO::errorfmt("ImageInput::create() called with no filename");
return in;
}

Expand Down Expand Up @@ -770,18 +770,18 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
= "ImageInput::create() could not find any ImageInput plugins!\n"
" Perhaps you need to set OIIO_LIBRARY_PATH.\n";
Strutil::print(stderr, "{}", msg);
OIIO::pvt::errorfmt("{}", msg);
OIIO::errorfmt("{}", msg);
} else if (!specific_error.empty()) {
// Pass along any specific error message we got from our
// best guess of the format.
OIIO::pvt::errorfmt("{}", specific_error);
OIIO::errorfmt("{}", specific_error);
} else if (Filesystem::exists(filename))
pvt::errorfmt(
OIIO::errorfmt(
"OpenImageIO could not find a format reader for \"{}\". "
"Is it a file format that OpenImageIO doesn't know about?\n",
filename);
else
OIIO::pvt::errorfmt(
OIIO::errorfmt(
"Image \"{}\" does not exist. Also, it is not the name of an image format that OpenImageIO recognizes.\n",
filename);
OIIO_DASSERT(!in);
Expand Down
4 changes: 2 additions & 2 deletions src/libOpenImageIO/maketexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ write_mipmap(ImageBufAlgo::MakeTextureMode mode, std::shared_ptr<ImageBuf>& img,
std::ostream& outstream, double& stat_writetime,
double& stat_miptime, size_t& peak_mem)
{
using OIIO::pvt::errorfmt;
using OIIO::errorfmt;
using OIIO::Strutil::sync::print; // Be sure to use synchronized one
bool envlatlmode = (mode == ImageBufAlgo::MakeTxEnvLatl);
bool orig_was_overscan = (img->spec().x || img->spec().y || img->spec().z
Expand Down Expand Up @@ -981,7 +981,7 @@ make_texture_impl(ImageBufAlgo::MakeTextureMode mode, const ImageBuf* input,
std::string filename, std::string outputfilename,
const ImageSpec& _configspec, std::ostream* outstream_ptr)
{
using OIIO::pvt::errorfmt;
using OIIO::errorfmt;
using OIIO::Strutil::sync::print; // Be sure to use synchronized one
OIIO_ASSERT(mode >= 0 && mode < ImageBufAlgo::_MakeTxLast);
double stat_readtime = 0;
Expand Down

0 comments on commit d249036

Please sign in to comment.