Skip to content

Commit 198c112

Browse files
committed
cleanup: convert more old errorf() to errorfmt()
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent c76824b commit 198c112

File tree

27 files changed

+203
-218
lines changed

27 files changed

+203
-218
lines changed

src/dds.imageio/ddsinput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ DDSInput::open(const std::string& name, ImageSpec& newspec)
480480
&& m_dds.flags & DDS_DEPTH))
481481
|| (m_dds.caps.flags2 & DDS_CAPS2_CUBEMAP
482482
&& !(m_dds.caps.flags1 & DDS_CAPS1_COMPLEX))) {
483-
errorf("Invalid DDS header, possibly corrupt file");
483+
errorfmt("Invalid DDS header, possibly corrupt file");
484484
return false;
485485
}
486486

@@ -493,7 +493,7 @@ DDSInput::open(const std::string& name, ImageSpec& newspec)
493493
&& !(m_dds.fmt.flags
494494
& (DDS_PF_RGB | DDS_PF_LUMINANCE | DDS_PF_ALPHA
495495
| DDS_PF_ALPHAONLY)))) {
496-
errorf("Image with no data");
496+
errorfmt("Image with no data");
497497
return false;
498498
}
499499

src/dicom.imageio/dicominput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ DICOMInput::seek_subimage(int subimage, int miplevel)
157157
m_subimage = 0;
158158
if (m_img->getStatus() != EIS_Normal) {
159159
m_img.reset();
160-
errorf("Unable to open DICOM file %s", m_filename);
160+
errorfmt("Unable to open DICOM file {}", m_filename);
161161
return false;
162162
}
163163
m_framecount = m_img->getFrameCount();
164164
m_firstframe = m_img->getFirstFrame();
165165
}
166166

167167
if (subimage >= m_firstframe + m_framecount) {
168-
errorf("Unable to seek to subimage %d", subimage);
168+
errorfmt("Unable to seek to subimage {}", subimage);
169169
return false;
170170
}
171171

@@ -174,7 +174,7 @@ DICOMInput::seek_subimage(int subimage, int miplevel)
174174
m_img->processNextFrames(1);
175175
if (m_img->getStatus() != EIS_Normal) {
176176
m_img.reset();
177-
errorf("Unable to seek to subimage %d", subimage);
177+
errorfmt("Unable to seek to subimage {}", subimage);
178178
return false;
179179
}
180180
++m_subimage;

src/dpx.imageio/dpxinput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ DPXInput::open(const std::string& name, ImageSpec& newspec)
139139

140140
m_stream = new InStream(ioproxy());
141141
if (!m_stream) {
142-
errorf("Could not open file \"%s\"", name);
142+
errorfmt("Could not open file \"{}\"", name);
143143
return false;
144144
}
145145

146146
m_dpx.SetInStream(m_stream);
147147
if (!m_dpx.ReadHeader()) {
148-
errorf("Could not read header");
148+
errorfmt("Could not read header");
149149
close();
150150
return false;
151151
}
@@ -203,7 +203,7 @@ DPXInput::seek_subimage(int subimage, int miplevel)
203203
break;
204204
case dpx::kFloat: typedesc = TypeDesc::FLOAT; break;
205205
case dpx::kDouble: typedesc = TypeDesc::DOUBLE; break;
206-
default: errorf("Invalid component data size"); return false;
206+
default: errorfmt("Invalid component data size"); return false;
207207
}
208208
m_spec = ImageSpec(m_dpx.header.Width(), m_dpx.header.Height(),
209209
m_dpx.header.ImageElementComponentCount(subimage),

src/dpx.imageio/dpxoutput.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ DPXOutput::open(const std::string& name, const ImageSpec& userspec,
399399

400400
// commit!
401401
if (!m_dpx.WriteHeader()) {
402-
errorf("Failed to write DPX header");
402+
errorfmt("Failed to write DPX header");
403403
close();
404404
return false;
405405
}
406406

407407
// write the user data
408408
if (user && user->datasize() > 0 && user->datasize() <= 1024 * 1024) {
409409
if (!m_dpx.WriteUserData((void*)user->data())) {
410-
errorf("Failed to write user data");
410+
errorfmt("Failed to write user data");
411411
close();
412412
return false;
413413
}
@@ -487,7 +487,7 @@ DPXOutput::prep_subimage(int s, bool allocate)
487487
if (spec_s.format == TypeDesc::UINT16) {
488488
m_bitdepth = spec_s.get_int_attribute("oiio:BitsPerSample", 16);
489489
if (m_bitdepth != 10 && m_bitdepth != 12 && m_bitdepth != 16) {
490-
errorf("Unsupported bit depth %d", m_bitdepth);
490+
errorfmt("Unsupported bit depth {}", m_bitdepth);
491491
return false;
492492
}
493493
}
@@ -536,7 +536,7 @@ DPXOutput::prep_subimage(int s, bool allocate)
536536
m_bytes = dpx::QueryNativeBufferSize(m_desc, m_datasize, spec_s.width,
537537
1);
538538
if (m_bytes == 0 && !m_rawcolor) {
539-
errorf("Unable to deliver native format data from source data");
539+
errorfmt("Unable to deliver native format data from source data");
540540
return false;
541541
} else if (m_bytes < 0) {
542542
// no need to allocate another buffer
@@ -571,8 +571,8 @@ DPXOutput::write_buffer()
571571
ok = m_dpx.WriteElement(m_subimage, m_buf.data(), m_datasize);
572572
if (!ok) {
573573
const char* err = strerror(errno);
574-
errorf("DPX write failed (%s)",
575-
(err && err[0]) ? err : "unknown error");
574+
errorfmt("DPX write failed ({})",
575+
(err && err[0]) ? err : "unknown error");
576576
}
577577
m_write_pending = false;
578578
}

src/fits.imageio/fitsinput.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ FitsInput::open(const std::string& name, ImageSpec& spec)
6262
// checking if the file exists and can be opened in READ mode
6363
m_fd = Filesystem::fopen(m_filename, "rb");
6464
if (!m_fd) {
65-
errorf("Could not open file \"%s\"", m_filename);
65+
errorfmt("Could not open file \"{}\"", m_filename);
6666
return false;
6767
}
6868

6969
// checking if the file is FITS file
7070
char magic[6] = { 0 };
7171
if (fread(magic, 1, 6, m_fd) != 6 || strncmp(magic, "SIMPLE", 6)) {
72-
errorf("%s isn't a FITS file", m_filename);
72+
errorfmt("{} isn't a FITS file", m_filename);
7373
close();
7474
return false;
7575
}
@@ -105,10 +105,10 @@ FitsInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
105105
size_t n = fread(&data_tmp[0], 1, m_spec.scanline_bytes(), m_fd);
106106
if (n != m_spec.scanline_bytes()) {
107107
if (feof(m_fd))
108-
errorf("Hit end of file unexpectedly (offset=%d, scanline %d)",
109-
ftell(m_fd), y);
108+
errorfmt("Hit end of file unexpectedly (offset={}, scanline {})",
109+
ftell(m_fd), y);
110110
else
111-
errorf("read error");
111+
errorfmt("read error");
112112
return false; // Read failed
113113
}
114114

@@ -215,9 +215,9 @@ FitsInput::read_fits_header(void)
215215
// we read whole header at once
216216
if (fread(&fits_header[0], 1, HEADER_SIZE, m_fd) != HEADER_SIZE) {
217217
if (feof(m_fd))
218-
errorf("Hit end of file unexpectedly (offset=%d)", ftell(m_fd));
218+
errorfmt("Hit end of file unexpectedly (offset={})", ftell(m_fd));
219219
else
220-
errorf("read error");
220+
errorfmt("read error");
221221
return false; // Read failed
222222
}
223223

@@ -299,7 +299,7 @@ FitsInput::read_fits_header(void)
299299
--m_naxes;
300300
}
301301
if (m_naxes < 0 || m_naxes > 4) {
302-
errorf("Number of data axes %d not supported", m_naxes);
302+
errorfmt("Number of data axes {} not supported", m_naxes);
303303
return false;
304304
}
305305
m_spec.nchannels = 1;
@@ -329,7 +329,7 @@ FitsInput::read_fits_header(void)
329329
m_spec.height = m_naxis[2];
330330
m_spec.depth = m_naxis[3];
331331
} else {
332-
errorf("Don't know now to read %d-channel FITS image", m_naxes);
332+
errorfmt("Don't know now to read {}-channel FITS image", m_naxes);
333333
return false;
334334
}
335335
m_spec.full_width = m_spec.width;
@@ -338,7 +338,7 @@ FitsInput::read_fits_header(void)
338338

339339
// if (m_spec.width < 1 || m_spec.height < 1 || m_spec.depth < 1 ||
340340
// m_spec.nchannels < 1) {
341-
// errorf("Don't know now to read empty (0 pixel) FITS image");
341+
// errorfmt("Don't know now to read empty (0 pixel) FITS image");
342342
// return false;
343343
// }
344344

src/gif.imageio/gifinput.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ GIFInput::read_subimage_data()
335335
colormap = m_gif_file->SColorMap->Colors;
336336
colormap_count = m_gif_file->SColorMap->ColorCount;
337337
} else {
338-
errorf("Neither local nor global colormap present.");
338+
errorfmt("Neither local nor global colormap present.");
339339
return false;
340340
}
341341

@@ -472,13 +472,13 @@ GIFInput::report_last_error(void)
472472
// error was for *this* file. So if you're using giflib prior to
473473
// version 5, beware.
474474
#if GIFLIB_MAJOR >= 5
475-
errorf("%s", GifErrorString(m_gif_file->Error));
475+
errorfmt("{}", GifErrorString(m_gif_file->Error));
476476
#elif GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2
477477
spin_lock lock(gif_error_mutex);
478-
errorf("%s", GifErrorString());
478+
errorfmt("{}", GifErrorString());
479479
#else
480480
spin_lock lock(gif_error_mutex);
481-
errorf("GIF error %d", GifLastError());
481+
errorfmt("GIF error {}", GifLastError());
482482
#endif
483483
}
484484

src/heif.imageio/heifinput.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ HeifInput::open(const std::string& name, ImageSpec& newspec,
166166

167167
} catch (const heif::Error& err) {
168168
std::string e = err.get_message();
169-
errorf("%s", e.empty() ? "unknown exception" : e.c_str());
169+
errorfmt("{}", e.empty() ? "unknown exception" : e.c_str());
170170
return false;
171171
} catch (const std::exception& err) {
172172
std::string e = err.what();
173-
errorf("%s", e.empty() ? "unknown exception" : e.c_str());
173+
errorfmt("{}", e.empty() ? "unknown exception" : e.c_str());
174174
return false;
175175
}
176176

@@ -221,11 +221,11 @@ HeifInput::seek_subimage(int subimage, int miplevel)
221221
m_himage = m_ihandle.decode_image(heif_colorspace_RGB, chroma);
222222
} catch (const heif::Error& err) {
223223
std::string e = err.get_message();
224-
errorf("%s", e.empty() ? "unknown exception" : e.c_str());
224+
errorfmt("{}", e.empty() ? "unknown exception" : e.c_str());
225225
return false;
226226
} catch (const std::exception& err) {
227227
std::string e = err.what();
228-
errorf("%s", e.empty() ? "unknown exception" : e.c_str());
228+
errorfmt("{}", e.empty() ? "unknown exception" : e.c_str());
229229
return false;
230230
}
231231
#else
@@ -397,7 +397,7 @@ HeifInput::read_native_scanline(int subimage, int miplevel, int y, int /*z*/,
397397
const uint8_t* hdata = m_himage.get_plane(heif_channel_interleaved,
398398
&ystride);
399399
if (!hdata) {
400-
errorf("Unknown read error");
400+
errorfmt("Unknown read error");
401401
return false;
402402
}
403403
hdata += (y - m_spec.y) * ystride;

src/ico.imageio/icoinput.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ ICOInput::open(const std::string& name, ImageSpec& newspec,
138138
swap_endian(&m_ico.count);
139139
}
140140
if (m_ico.reserved != 0 || m_ico.type != 1) {
141-
errorf("File failed ICO header check");
141+
errorfmt("File failed ICO header check");
142142
return false;
143143
}
144144

@@ -199,15 +199,15 @@ ICOInput::seek_subimage(int subimage, int miplevel)
199199
if (temp[1] == 'P' && temp[2] == 'N' && temp[3] == 'G') {
200200
// standard PNG initialization
201201
if (png_sig_cmp((png_bytep)temp, 0, 7)) {
202-
errorf("Subimage failed PNG signature check");
202+
errorfmt("Subimage failed PNG signature check");
203203
return false;
204204
}
205205

206206
//std::cerr << "[ico] creating PNG read struct\n";
207207

208208
std::string s = PNG_pvt::create_read_struct(m_png, m_info, this);
209209
if (s.length()) {
210-
errorf("%s", s);
210+
errorfmt("{}", s);
211211
return false;
212212
}
213213

@@ -255,7 +255,7 @@ ICOInput::seek_subimage(int subimage, int miplevel)
255255
&& m_bpp != 8
256256
/*&& m_bpp != 16*/
257257
&& m_bpp != 24 && m_bpp != 32) {
258-
errorf("Unsupported image color depth, probably corrupt file");
258+
errorfmt("Unsupported image color depth, probably corrupt file");
259259
return false;
260260
}
261261
m_offset = subimg.ofs;
@@ -291,7 +291,7 @@ ICOInput::readimg()
291291
//std::cerr << "[ico] PNG buffer size = " << m_buf.size () << "\n";
292292

293293
if (s.length()) {
294-
errorf("%s", s);
294+
errorfmt("{}", s);
295295
return false;
296296
}
297297

src/iff.imageio/noproxy-iffinput.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ IffInput::open(const std::string& name, ImageSpec& spec)
6262

6363
m_fd = Filesystem::fopen(m_filename, "rb");
6464
if (!m_fd) {
65-
errorf("Could not open file \"%s\"", name);
65+
errorfmt("Could not open file \"{}\"", name);
6666
return false;
6767
}
6868

6969
// we read header of the file that we think is IFF file
7070
std::string err;
7171
if (!m_iff_header.read_header(m_fd, err)) {
72-
errorf("\"%s\": could not read iff header (%s)", m_filename,
73-
err.size() ? err : std::string("unknown"));
72+
errorfmt("\"{}\": could not read iff header ({})", m_filename,
73+
err.size() ? err : std::string("unknown"));
7474
close();
7575
return false;
7676
}
@@ -95,7 +95,7 @@ IffInput::open(const std::string& name, ImageSpec& spec)
9595
// only 1 subimage for IFF
9696
m_spec.tile_depth = 1;
9797
} else {
98-
errorf("\"%s\": wrong tile size", m_filename);
98+
errorfmt("\"{}\": wrong tile size", m_filename);
9999
close();
100100
return false;
101101
}
@@ -421,8 +421,8 @@ IffInput::readimg()
421421
}
422422

423423
} else {
424-
errorf("\"%s\": unsupported number of bits per pixel for tile",
425-
m_filename);
424+
errorfmt("\"{}\": unsupported number of bits per pixel for tile",
425+
m_filename);
426426
return false;
427427
}
428428

src/iff.imageio/noproxy-iffoutput.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ IffOutput::open(const std::string& name, const ImageSpec& spec, OpenMode mode)
5858
// ...
5959

6060
if (mode != Create) {
61-
errorf("%s does not support subimages or MIP levels", format_name());
61+
errorfmt("{} does not support subimages or MIP levels", format_name());
6262
return false;
6363
}
6464

@@ -74,7 +74,7 @@ IffOutput::open(const std::string& name, const ImageSpec& spec, OpenMode mode)
7474

7575
m_fd = Filesystem::fopen(m_filename, "wb");
7676
if (!m_fd) {
77-
errorf("Could not open \"%s\"", m_filename);
77+
errorfmt("Could not open \"{}\"", m_filename);
7878
return false;
7979
}
8080

@@ -97,8 +97,8 @@ IffOutput::open(const std::string& name, const ImageSpec& spec, OpenMode mode)
9797
uint64_t xtiles = tile_width_size(m_spec.width);
9898
uint64_t ytiles = tile_height_size(m_spec.height);
9999
if (xtiles * ytiles >= (1 << 16)) { // The format can't store it!
100-
errorf(
101-
"Too high a resolution (%dx%d), exceeds maximum of 64k tiles in the image\n",
100+
errorfmt(
101+
"Too high a resolution ({}x{}), exceeds maximum of 64k tiles in the image\n",
102102
m_spec.width, m_spec.height);
103103
close();
104104
return false;
@@ -116,7 +116,7 @@ IffOutput::open(const std::string& name, const ImageSpec& spec, OpenMode mode)
116116
m_iff_header.date = m_spec.get_string_attribute("DateTime");
117117

118118
if (!write_header(m_iff_header)) {
119-
errorf("\"%s\": could not write iff header", m_filename);
119+
errorfmt("\"{}\": could not write iff header", m_filename);
120120
close();
121121
return false;
122122
}

0 commit comments

Comments
 (0)