Skip to content

Commit 83b03d4

Browse files
lgritzscott-wilson
authored andcommitted
api: imagebuf.h add deprecation warnings to deprecated things (AcademySoftwareFoundation#4341)
* Add deprecation warnings to the varieties of ImageBuf constructor and `reset()` that don't take subimage and miplevel parameters. The equivalent is to just pass `0` for both of those parameters. The warned constructors have been marked as deprecated since OIIO 2.2. * The misspelled `ImageBuf::make_writeable()` has been given deprecation warnings. Since OIIO 2.2, the correct spelling is `make_writable`. * The `ImageBuf::error()` method that uses printf-style formatting now has deprecation warnings. Use `ImageBuf::errorfmt()` instead. * The `ImageBuf::interppixel_NDC_full()` method, which has been marked as deprecated since OIIO 1.5, now has deprecation warnings. Use `interppixel_NDC()` instead. Undeprecate the name+spec varieties of constructors. They were documented as deprecated but warnings were never added. In doing this set of changes, I realized that they were used for something useful after all -- it makes it easy to remember the name of a new buffer you're making not from a file, so you can later `write()` it without needing to know the filename at that time. I also added a new `set_name()` method to do it directly for times when you don't want to rely on the constructor or want to change the name. By the way, I'm being careful also to convert all the warned or marked deprecated functions to inline, if at all possible, so that in the future removing them will not be an ABI break. Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Scott Wilson <scott@propersquid.com>
1 parent 60ba3d5 commit 83b03d4

File tree

11 files changed

+110
-153
lines changed

11 files changed

+110
-153
lines changed

docs/Deprecations-3.0.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,27 @@ long-deprecated API facets. This document lists the deprecations and removals.
6767
severefmt, messagefmt, debugfmt, respectively, which all use the std::format
6868
notation.
6969

70+
## imagebuf.h
71+
72+
* Add deprecation warnings to the varieties of ImageBuf constructor and
73+
`reset()` that don't take subimage and miplevel parameters, which have been
74+
marked as deprecated since OIIO 2.2. The equivalent is to just pass `0` for
75+
both of those parameters.
76+
* The misspelled `ImageBuf::make_writeable()` has been given deprecation
77+
warnings. Since OIIO 2.2, we have used the correct spelling,
78+
`make_writable`.
79+
* The `ImageBuf::error()` method that uses printf-style formatting conventions
80+
now has deprecation warnings. Use `ImageBuf::errorfmt()` instead.
81+
* The `ImageBuf::interppixel_NDC_full()` method, which has been marked as
82+
deprecated since OIIO 1.5, now has deprecation warnings. Use
83+
`interppixel_NDC()` instead.
84+
7085
## missingmath.h
7186

7287
* This header has been removed entirely. It has was originally needed for
7388
pre-C++11 MSVS, but has been unused since OIIO 2.0 (other than transitively
7489
including fmath.h).
7590

76-
## parallel.h
77-
78-
* Removed several varieties of `parallel_for` functions where the task
79-
functions took a thread ID argument in addition to the range, which have
80-
been considered deprecated since OIIO 2.3. Please use task functions that do
81-
not take a thread ID parameter.
82-
8391
## paramlist.h
8492

8593
* Removed some ParamValue constructor variants that have been deprecated since
@@ -88,6 +96,13 @@ long-deprecated API facets. This document lists the deprecations and removals.
8896
behavior, please use the newer variety of constructors that instead use a
8997
"strong" type where you pass `ParamValue:Copy(bool)`.
9098

99+
## parallel.h
100+
101+
* Removed several varieties of `parallel_for` functions where the task
102+
functions took a thread ID argument in addition to the range, which have
103+
been considered deprecated since OIIO 2.3. Please use task functions that do
104+
not take a thread ID parameter.
105+
91106
## strutil.h
92107

93108
* Added deprecation warnings to all the old (printf-convention) string

src/idiff/idiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ read_input(const std::string& filename, ImageBuf& img, ImageCache* cache,
126126
&& img.miplevel() == miplevel)
127127
return true;
128128

129-
img.reset(filename, cache);
129+
img.reset(filename, 0, 0, cache);
130130
if (img.read(subimage, miplevel, false, TypeFloat))
131131
return true;
132132

src/include/OpenImageIO/imagebuf.h

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ class OIIO_API ImageBuf {
190190
const ImageSpec* config = nullptr,
191191
Filesystem::IOProxy* ioproxy = nullptr);
192192

193-
// Deprecated synonym for `ImageBuf(name, 0, 0, imagecache, nullptr)`.
194-
ImageBuf(string_view name, ImageCache* imagecache);
195-
196193
/// Construct a writable ImageBuf with the given specification
197194
/// (including resolution, data type, metadata, etc.). The ImageBuf will
198195
/// allocate and own its own pixel memory and will free that memory
@@ -219,10 +216,14 @@ class OIIO_API ImageBuf {
219216
explicit ImageBuf(const ImageSpec& spec,
220217
InitializePixels zero = InitializePixels::Yes);
221218

222-
// Deprecated/useless synonym for `ImageBuf(spec,zero)` but also gives
223-
// it an internal name.
219+
// Synonym for `ImageBuf(spec,zero)` but also gives it an internal name
220+
// that will be used if write() is called with an empty filename.
224221
ImageBuf(string_view name, const ImageSpec& spec,
225-
InitializePixels zero = InitializePixels::Yes);
222+
InitializePixels zero = InitializePixels::Yes)
223+
: ImageBuf(spec, zero)
224+
{
225+
set_name(name);
226+
}
226227

227228
/// Construct a writable ImageBuf that "wraps" existing pixel memory
228229
/// owned by the calling application. The ImageBuf does not own the
@@ -250,10 +251,6 @@ class OIIO_API ImageBuf {
250251
ImageBuf(const ImageSpec& spec, void* buffer, stride_t xstride = AutoStride,
251252
stride_t ystride = AutoStride, stride_t zstride = AutoStride);
252253

253-
// Deprecated/useless synonym for `ImageBuf(spec,buffer)` but also gives
254-
// it an internal name.
255-
ImageBuf(string_view name, const ImageSpec& spec, void* buffer);
256-
257254
/// Construct a copy of an ImageBuf.
258255
ImageBuf(const ImageBuf& src);
259256

@@ -269,9 +266,6 @@ class OIIO_API ImageBuf {
269266
/// `IBStorage::UNINITIALIZED`).
270267
void reset() { clear(); }
271268

272-
// Deprecated/useless synonym for `reset(name, 0, 0, imagecache, nullptr)`
273-
void reset(string_view name, ImageCache* imagecache);
274-
275269
/// Destroy any previous contents of the ImageBuf and re-initialize it
276270
/// as if newly constructed with the same arguments, as a read-only
277271
/// representation of an existing image file.
@@ -294,10 +288,13 @@ class OIIO_API ImageBuf {
294288
void reset(const ImageSpec& spec,
295289
InitializePixels zero = InitializePixels::Yes);
296290

297-
// Deprecated/useless synonym for `reset(spec, zero)` and also give it an
298-
// internal name.
291+
/// Synonym for `reset(spec, zero)` and also give it an internal name.
299292
void reset(string_view name, const ImageSpec& spec,
300-
InitializePixels zero = InitializePixels::Yes);
293+
InitializePixels zero = InitializePixels::Yes)
294+
{
295+
reset(spec, zero);
296+
set_name(name);
297+
}
301298

302299
/// Destroy any previous contents of the ImageBuf and re-initialize it
303300
/// as if newly constructed with the same arguments, to "wrap" existing
@@ -323,10 +320,6 @@ class OIIO_API ImageBuf {
323320
/// necessary), `false` if something went horribly wrong.
324321
bool make_writable(bool keep_cache_type = false);
325322

326-
// DEPRECATED(2.2): This is an alternate, and less common, spelling.
327-
// Let's standardize on "writable". We will eventually remove this.
328-
bool make_writeable(bool keep_cache_type = false);
329-
330323
/// @}
331324

332325

@@ -712,13 +705,6 @@ class OIIO_API ImageBuf {
712705
void interppixel_NDC(float s, float t, float* pixel,
713706
WrapMode wrap = WrapBlack) const;
714707

715-
#ifndef DOXYGEN_SHOULD_SKIP_THIS
716-
// DEPRECATED (1.5) synonym for interppixel_NDC.
717-
OIIO_DEPRECATED("use interppixel_NDC (1.5)")
718-
void interppixel_NDC_full(float s, float t, float* pixel,
719-
WrapMode wrap = WrapBlack) const;
720-
#endif
721-
722708
/// Bicubic interpolation at pixel coordinates (x,y).
723709
void interppixel_bicubic(float x, float y, float* pixel,
724710
WrapMode wrap = WrapBlack) const;
@@ -867,6 +853,10 @@ class OIIO_API ImageBuf {
867853
/// Return the name of the buffer as a ustring.
868854
ustring uname(void) const;
869855

856+
/// Set the name of the ImageBuf, will be used later as default
857+
/// filename if write() is called with an empty filename.
858+
void set_name(string_view name);
859+
870860
/// Return the name of the image file format of the file this ImageBuf
871861
/// refers to (for example `"openexr"`). Returns an empty string for an
872862
/// ImageBuf that was not constructed as a direct reference to a file.
@@ -1063,17 +1053,6 @@ class OIIO_API ImageBuf {
10631053
error(Strutil::fmt::format(fmt, args...));
10641054
}
10651055

1066-
/// Error reporting for ImageBuf: call this with Strutil::format
1067-
/// formatting conventions. It is not necessary to have the error
1068-
/// message contain a trailing newline. Beware, this is in transition,
1069-
/// is currently printf-like but will someday change to python-like!
1070-
template<typename... Args>
1071-
OIIO_FORMAT_DEPRECATED void error(const char* fmt,
1072-
const Args&... args) const
1073-
{
1074-
error(Strutil::format(fmt, args...));
1075-
}
1076-
10771056
/// Returns `true` if the ImageBuf has had an error and has an error
10781057
/// message ready to retrieve via `geterror()`.
10791058
bool has_error(void) const;
@@ -1168,6 +1147,54 @@ class OIIO_API ImageBuf {
11681147
/// Return the name corresponding to the wrap mode.
11691148
static ustring wrapmode_name(WrapMode wrap);
11701149

1150+
#if !defined(OIIO_DOXYGEN) && !defined(OIIO_INTERNAL)
1151+
// Deprecated things -- might be removed at any time
1152+
1153+
OIIO_DEPRECATED("Use `ImageBuf(name, 0, 0, imagecache, nullptr)` (2.2)")
1154+
ImageBuf(string_view name, ImageCache* imagecache)
1155+
: ImageBuf(name, 0, 0, imagecache)
1156+
{
1157+
}
1158+
1159+
OIIO_DEPRECATED(
1160+
"The name parameter is not used, use `ImageBuf(spec,buffer)` (2.2)")
1161+
ImageBuf(string_view name, const ImageSpec& spec, void* buffer)
1162+
: ImageBuf(spec, buffer)
1163+
{
1164+
}
1165+
1166+
OIIO_DEPRECATED("Use `reset(name, 0, 0, imagecache)` (2.2)")
1167+
void reset(string_view name, ImageCache* imagecache)
1168+
{
1169+
reset(name, 0, 0, imagecache);
1170+
}
1171+
1172+
OIIO_DEPRECATED("Use make_writable (2.2)")
1173+
bool make_writeable(bool keep_cache_type = false)
1174+
{
1175+
return make_writable(keep_cache_type);
1176+
}
1177+
1178+
OIIO_DEPRECATED("use interppixel_NDC (1.5)")
1179+
void interppixel_NDC_full(float s, float t, float* pixel,
1180+
WrapMode wrap = WrapBlack) const
1181+
{
1182+
const ImageSpec& spec(this->spec());
1183+
interppixel(static_cast<float>(spec.full_x)
1184+
+ s * static_cast<float>(spec.full_width),
1185+
static_cast<float>(spec.full_y)
1186+
+ t * static_cast<float>(spec.full_height),
1187+
pixel, wrap);
1188+
}
1189+
1190+
template<typename... Args>
1191+
OIIO_DEPRECATED("Use errorfmt")
1192+
void error(const char* fmt, const Args&... args) const
1193+
{
1194+
error(Strutil::old::format(fmt, args...));
1195+
}
1196+
#endif
1197+
11711198
friend class IteratorBase;
11721199

11731200
/// Base class for Iterator and ConstIterator -- this contains all the
@@ -1616,11 +1643,6 @@ class OIIO_API ImageBuf {
16161643
int& tilexend, bool& haderr, bool exists,
16171644
WrapMode wrap) const;
16181645

1619-
// DEPRECATED(2.4)
1620-
const void* retile(int x, int y, int z, pvt::ImageCacheTile*& tile,
1621-
int& tilexbegin, int& tileybegin, int& tilezbegin,
1622-
int& tilexend, bool exists, WrapMode wrap) const;
1623-
16241646
const void* blackpixel() const;
16251647

16261648
// Given x,y,z known to be outside the pixel data range, and a wrap

src/iv/ivimage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ IvImage::read_iv(int subimage, int miplevel, bool force, TypeDesc format,
7575
progress_callback_data);
7676

7777
if (m_image_valid && secondary_data && spec().format == TypeDesc::UINT8) {
78-
m_corrected_image.reset("", ImageSpec(spec().width, spec().height,
79-
std::min(spec().nchannels, 4),
80-
spec().format));
78+
m_corrected_image.reset(ImageSpec(spec().width, spec().height,
79+
std::min(spec().nchannels, 4),
80+
spec().format));
8181
} else {
8282
m_corrected_image.clear();
8383
}

0 commit comments

Comments
 (0)