Skip to content

Commit d249036

Browse files
authored
api: move OIIO::pvt::error and log_time into the exposed OIIO namespace (#4362)
This is needed for the related OpenCV-related PR Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 3cb2acf commit d249036

9 files changed

Lines changed: 41 additions & 43 deletions

File tree

src/iff.imageio/noproxy-iff_pvt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class IffInput final : public ImageInput {
145145
try {
146146
close();
147147
} catch (const std::exception& e) {
148-
OIIO::pvt::errorfmt("{}", e.what());
148+
OIIO::errorfmt("{}", e.what());
149149
}
150150
}
151151
const char* format_name(void) const override { return "iff"; }
@@ -228,7 +228,7 @@ class IffOutput final : public ImageOutput {
228228
try {
229229
close();
230230
} catch (const std::exception& e) {
231-
OIIO::pvt::errorfmt("{}", e.what());
231+
OIIO::errorfmt("{}", e.what());
232232
}
233233
}
234234
const char* format_name(void) const override { return "iff"; }

src/include/OpenImageIO/imageio.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OIIO_NAMESPACE_BEGIN
4141

4242
class DeepData;
4343
class ImageBuf;
44+
class Timer;
4445

4546

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

3367+
namespace pvt {
3368+
// For internal use - use errorfmt() below for a nicer interface.
3369+
OIIO_API void append_error(string_view message);
3370+
}
3371+
3372+
/// error logging (mostly for OIIO internals) with `std::format` conventions.
3373+
template<typename... Args>
3374+
inline void errorfmt(const char* fmt, Args&&... args)
3375+
{
3376+
pvt::append_error(string_view(Strutil::fmt::format(fmt, args...)));
3377+
}
33663378

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

33683384
// to force correct linkage on some systems
33693385
OIIO_API void _ImageIO_force_link ();

src/include/OpenImageIO/strutil.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ using old::format;
152152
#endif
153153

154154

155-
// format_to comes from fmt library
155+
// More things we wrap from fmt library
156+
using ::fmt::format_args;
157+
using ::fmt::make_format_args;
156158
using ::fmt::format_to;
157159
using ::fmt::format_to_n;
158160

src/include/imageio_pvt.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ font_list();
6060

6161

6262

63-
// For internal use - use error() below for a nicer interface.
64-
void
65-
append_error(string_view message);
66-
67-
/// Use errorfmt() privately only. Formatting notation is like std::format.
68-
template<typename... Args>
69-
inline void
70-
errorfmt(const char* fmt, const Args&... args)
71-
{
72-
append_error(Strutil::fmt::format(fmt, args...));
73-
}
74-
7563
// Make sure all plugins are inventoried. For internal use only.
7664
void
7765
catalog_all_plugins(std::string searchpath);
@@ -123,12 +111,6 @@ parallel_convert_from_float(const float* src, void* dst, size_t nvals,
123111
OIIO_API bool
124112
check_texture_metadata_sanity(ImageSpec& spec);
125113

126-
/// Internal function to log time recorded by an OIIO::timer(). It will only
127-
/// trigger a read of the time if the "log_times" attribute is set or the
128-
/// OPENIMAGEIO_LOG_TIMES env variable is set.
129-
OIIO_API void
130-
log_time(string_view key, const Timer& timer, int count = 1);
131-
132114
/// Get the timing report from log_time entries.
133115
OIIO_API std::string
134116
timing_report();

src/libOpenImageIO/imagebufalgo_opencv.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,14 @@ ImageBufAlgo::to_OpenCV(cv::Mat& dst, const ImageBuf& src, ROI roi,
169169
} else if (spec.format == TypeDesc(TypeDesc::DOUBLE)) {
170170
dstFormat = CV_MAKETYPE(CV_64F, chans);
171171
} else {
172-
OIIO::pvt::errorfmt(
173-
"to_OpenCV() doesn't know how to make a cv::Mat of {}",
174-
spec.format);
172+
OIIO::errorfmt("to_OpenCV() doesn't know how to make a cv::Mat of {}",
173+
spec.format);
175174
return false;
176175
}
177176
dst.create(roi.height(), roi.width(), dstFormat);
178177
if (dst.empty()) {
179-
OIIO::pvt::errorfmt(
180-
"to_OpenCV() was unable to create cv::Mat of {}x{} {}", roi.width(),
181-
roi.height(), dstSpecFormat);
178+
OIIO::errorfmt("to_OpenCV() was unable to create cv::Mat of {}x{} {}",
179+
roi.width(), roi.height(), dstSpecFormat);
182180
return false;
183181
}
184182

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

205203
return true;
206204
#else
207-
OIIO::pvt::errorfmt(
205+
OIIO::errorfmt(
208206
"to_OpenCV() not supported -- no OpenCV support at compile time");
209207
return false;
210208
#endif

src/libOpenImageIO/imageinput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ImageInput::open(const std::string& filename, const ImageSpec* config,
164164
// error, delete the ImageInput we allocated, and return NULL.
165165
std::string err = in->geterror();
166166
if (err.size())
167-
OIIO::pvt::errorfmt("{}", err);
167+
OIIO::errorfmt("{}", err);
168168
in.reset();
169169
}
170170

src/libOpenImageIO/imageio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ debug(string_view message)
364364

365365

366366
void
367-
pvt::log_time(string_view key, const Timer& timer, int count)
367+
log_time(string_view key, const Timer& timer, int count)
368368
{
369369
timing_log(key, timer, count);
370370
}

src/libOpenImageIO/imageioplugin.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
526526
{
527527
std::unique_ptr<ImageOutput> out;
528528
if (filename.empty()) { // Can't even guess if no filename given
529-
OIIO::pvt::errorfmt("ImageOutput::create() called with no filename");
529+
OIIO::errorfmt("ImageOutput::create() called with no filename");
530530
return out;
531531
}
532532

@@ -563,9 +563,9 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
563563
const char* msg
564564
= "ImageOutput::create() could not find any ImageOutput plugins! Perhaps you need to set OIIO_LIBRARY_PATH.\n";
565565
Strutil::print(stderr, "{}", msg);
566-
OIIO::pvt::errorfmt("{}", msg);
566+
OIIO::errorfmt("{}", msg);
567567
} else
568-
OIIO::pvt::errorfmt(
568+
OIIO::errorfmt(
569569
"OpenImageIO could not find a format writer for \"{}\". "
570570
"Is it a file format that OpenImageIO doesn't know about?\n",
571571
filename);
@@ -582,7 +582,7 @@ ImageOutput::create(string_view filename, Filesystem::IOProxy* ioproxy,
582582
}
583583
if (out && ioproxy) {
584584
if (!out->supports("ioproxy")) {
585-
OIIO::pvt::errorfmt(
585+
OIIO::errorfmt(
586586
"ImageOutput::create called with IOProxy, but format {} does not support IOProxy",
587587
out->format_name());
588588
out.reset();
@@ -609,7 +609,7 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
609609
// Only check REST arguments if the file does not exist
610610
if (!Filesystem::exists(filename)) {
611611
if (!Strutil::get_rest_arguments(filename, filename_stripped, args)) {
612-
OIIO::pvt::errorfmt(
612+
OIIO::errorfmt(
613613
"ImageInput::create() called with malformed filename");
614614
return in;
615615
}
@@ -619,7 +619,7 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
619619
filename_stripped = filename;
620620

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

@@ -770,18 +770,18 @@ ImageInput::create(string_view filename, bool do_open, const ImageSpec* config,
770770
= "ImageInput::create() could not find any ImageInput plugins!\n"
771771
" Perhaps you need to set OIIO_LIBRARY_PATH.\n";
772772
Strutil::print(stderr, "{}", msg);
773-
OIIO::pvt::errorfmt("{}", msg);
773+
OIIO::errorfmt("{}", msg);
774774
} else if (!specific_error.empty()) {
775775
// Pass along any specific error message we got from our
776776
// best guess of the format.
777-
OIIO::pvt::errorfmt("{}", specific_error);
777+
OIIO::errorfmt("{}", specific_error);
778778
} else if (Filesystem::exists(filename))
779-
pvt::errorfmt(
779+
OIIO::errorfmt(
780780
"OpenImageIO could not find a format reader for \"{}\". "
781781
"Is it a file format that OpenImageIO doesn't know about?\n",
782782
filename);
783783
else
784-
OIIO::pvt::errorfmt(
784+
OIIO::errorfmt(
785785
"Image \"{}\" does not exist. Also, it is not the name of an image format that OpenImageIO recognizes.\n",
786786
filename);
787787
OIIO_DASSERT(!in);

src/libOpenImageIO/maketexture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ write_mipmap(ImageBufAlgo::MakeTextureMode mode, std::shared_ptr<ImageBuf>& img,
615615
std::ostream& outstream, double& stat_writetime,
616616
double& stat_miptime, size_t& peak_mem)
617617
{
618-
using OIIO::pvt::errorfmt;
618+
using OIIO::errorfmt;
619619
using OIIO::Strutil::sync::print; // Be sure to use synchronized one
620620
bool envlatlmode = (mode == ImageBufAlgo::MakeTxEnvLatl);
621621
bool orig_was_overscan = (img->spec().x || img->spec().y || img->spec().z
@@ -981,7 +981,7 @@ make_texture_impl(ImageBufAlgo::MakeTextureMode mode, const ImageBuf* input,
981981
std::string filename, std::string outputfilename,
982982
const ImageSpec& _configspec, std::ostream* outstream_ptr)
983983
{
984-
using OIIO::pvt::errorfmt;
984+
using OIIO::errorfmt;
985985
using OIIO::Strutil::sync::print; // Be sure to use synchronized one
986986
OIIO_ASSERT(mode >= 0 && mode < ImageBufAlgo::_MakeTxLast);
987987
double stat_readtime = 0;

0 commit comments

Comments
 (0)