Skip to content

Commit 2e74769

Browse files
jessey-gitssh4net
authored andcommitted
cleanup: remove left over tile emulation code for various formats (AcademySoftwareFoundation#5029)
Since the OpenImageIO 2.5 series, when calls to `check_open` were added, any format that did not declare support for "tiles" would immediately fail to open. But many of the formats which attempted to emulate tiles, by buffering the contents and writing it all as scanlines at the end, were not updated. All of the tile emulation code for these formats is effectively dead-code and untested. Remove the tile emulation code from these formats. An example of what the failure currently looks like: ```python >>> out = oiio.ImageOutput.create("test.png") >>> spec = oiio.ImageSpec(64, 64, 3, 'uint8') >>> spec.tile_width = 64 >>> out.open("test.png", spec) False >>> out.geterror() 'png does not support tiled images' ``` No tests were impacted. Signed-off-by: Jesse Yurkovich <jesse.y@gmail.com> Signed-off-by: Vlad <shaamaan@gmail.com>
1 parent c3891f0 commit 2e74769

10 files changed

Lines changed: 11 additions & 312 deletions

File tree

src/bmp.imageio/bmpoutput.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class BmpOutput final : public ImageOutput {
2727
bool close(void) override;
2828
bool write_scanline(int y, int z, TypeDesc format, const void* data,
2929
stride_t xstride) override;
30-
bool write_tile(int x, int y, int z, TypeDesc format, const void* data,
31-
stride_t xstride, stride_t ystride,
32-
stride_t zstride) override;
3330

3431
private:
3532
int64_t m_padded_scanline_size;
@@ -38,7 +35,6 @@ class BmpOutput final : public ImageOutput {
3835
bmp_pvt::DibInformationHeader m_dib_header;
3936
int64_t m_image_start;
4037
unsigned int m_dither;
41-
std::vector<unsigned char> m_tilebuffer;
4238
std::vector<unsigned char> m_scratch;
4339
std::vector<unsigned char> m_buf; // more tmp space for write_scanline
4440

@@ -110,11 +106,6 @@ BmpOutput::open(const std::string& name, const ImageSpec& spec, OpenMode mode)
110106

111107
m_image_start = iotell();
112108

113-
// If user asked for tiles -- which this format doesn't support, emulate
114-
// it by buffering the whole image.
115-
if (m_spec.tile_width && m_spec.tile_height)
116-
m_tilebuffer.resize(m_spec.image_bytes());
117-
118109
return true;
119110
}
120111

@@ -157,23 +148,6 @@ BmpOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
157148
}
158149

159150

160-
161-
bool
162-
BmpOutput::write_tile(int x, int y, int z, TypeDesc format, const void* data,
163-
stride_t xstride, stride_t ystride, stride_t zstride)
164-
{
165-
if (!ioproxy_opened()) {
166-
errorfmt("write_tile called but file is not open.");
167-
return false;
168-
}
169-
170-
// Emulate tiles by buffering the whole image
171-
return copy_tile_to_image_buffer(x, y, z, format, data, xstride, ystride,
172-
zstride, m_tilebuffer.data());
173-
}
174-
175-
176-
177151
bool
178152
BmpOutput::close(void)
179153
{
@@ -182,17 +156,8 @@ BmpOutput::close(void)
182156
return true;
183157
}
184158

185-
bool ok = true;
186-
if (m_spec.tile_width && m_tilebuffer.size()) {
187-
// Handle tile emulation -- output the buffered pixels
188-
OIIO_DASSERT(m_tilebuffer.size());
189-
ok &= write_scanlines(m_spec.y, m_spec.y + m_spec.height, 0,
190-
m_spec.format, m_tilebuffer.data());
191-
std::vector<unsigned char>().swap(m_tilebuffer);
192-
}
193-
194159
init();
195-
return ok;
160+
return true;
196161
}
197162

198163

src/dpx.imageio/dpxoutput.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class DPXOutput final : public ImageOutput {
4646
bool close() override;
4747
bool write_scanline(int y, int z, TypeDesc format, const void* data,
4848
stride_t xstride) override;
49-
bool write_tile(int x, int y, int z, TypeDesc format, const void* data,
50-
stride_t xstride, stride_t ystride,
51-
stride_t zstride) override;
5249

5350
private:
5451
OutStream* m_stream = nullptr;
@@ -69,7 +66,6 @@ class DPXOutput final : public ImageOutput {
6966
std::vector<ImageSpec> m_subimage_specs;
7067
bool m_write_pending; // subimage buffer needs to be written
7168
unsigned int m_dither;
72-
std::vector<unsigned char> m_tilebuffer;
7369

7470
// Initialize private members to pre-opened state
7571
void init(void)
@@ -417,11 +413,6 @@ DPXOutput::open(const std::string& name, const ImageSpec& userspec,
417413
? spec0.get_int_attribute("oiio:dither", 0)
418414
: 0;
419415

420-
// If user asked for tiles -- which this format doesn't support, emulate
421-
// it by buffering the whole image.
422-
if (spec0.tile_width && spec0.tile_height)
423-
m_tilebuffer.resize(spec0.image_bytes());
424-
425416
return prep_subimage(m_subimage, true);
426417
}
427418

@@ -593,16 +584,7 @@ DPXOutput::close()
593584
return true;
594585
}
595586

596-
bool ok = true;
597-
const ImageSpec& spec_s(m_subimage_specs[m_subimage]);
598-
if (spec_s.tile_width && m_tilebuffer.size()) {
599-
// Handle tile emulation -- output the buffered pixels
600-
ok &= write_scanlines(spec_s.y, spec_s.y + spec_s.height, 0,
601-
spec_s.format, &m_tilebuffer[0]);
602-
std::vector<unsigned char>().swap(m_tilebuffer);
603-
}
604-
605-
ok &= write_buffer();
587+
bool ok = write_buffer();
606588
m_dpx.Finish();
607589
init(); // Reset to initial state
608590
return ok;
@@ -644,22 +626,6 @@ DPXOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
644626

645627

646628

647-
bool
648-
DPXOutput::write_tile(int x, int y, int z, TypeDesc format, const void* data,
649-
stride_t xstride, stride_t ystride, stride_t zstride)
650-
{
651-
if (!is_opened()) {
652-
errorfmt("write_tile called but file is not open.");
653-
return false;
654-
}
655-
656-
// Emulate tiles by buffering the whole image
657-
return copy_tile_to_image_buffer(x, y, z, format, data, xstride, ystride,
658-
zstride, &m_tilebuffer[0]);
659-
}
660-
661-
662-
663629
dpx::Characteristic
664630
DPXOutput::get_characteristic_from_string(const std::string& str)
665631
{

src/hdr.imageio/hdroutput.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ class HdrOutput final : public ImageOutput {
2626
OpenMode mode) override;
2727
bool write_scanline(int y, int z, TypeDesc format, const void* data,
2828
stride_t xstride) override;
29-
bool write_tile(int x, int y, int z, TypeDesc format, const void* data,
30-
stride_t xstride, stride_t ystride,
31-
stride_t zstride) override;
3229
bool close() override;
3330

3431
private:
3532
std::vector<unsigned char> scratch;
36-
std::vector<unsigned char> m_tilebuffer;
3733

3834
void init(void) { ioproxy_clear(); }
3935

@@ -226,11 +222,6 @@ HdrOutput::open(const std::string& name, const ImageSpec& newspec,
226222
if (!iowritefmt("-Y {} +X {}\n", m_spec.height, m_spec.width))
227223
return false;
228224

229-
// If user asked for tiles -- which this format doesn't support, emulate
230-
// it by buffering the whole image.
231-
if (m_spec.tile_width && m_spec.tile_height)
232-
m_tilebuffer.resize(m_spec.image_bytes());
233-
234225
return true;
235226
}
236227

@@ -246,17 +237,6 @@ HdrOutput::write_scanline(int /*y*/, int /*z*/, TypeDesc format,
246237

247238

248239

249-
bool
250-
HdrOutput::write_tile(int x, int y, int z, TypeDesc format, const void* data,
251-
stride_t xstride, stride_t ystride, stride_t zstride)
252-
{
253-
// Emulate tiles by buffering the whole image
254-
return copy_tile_to_image_buffer(x, y, z, format, data, xstride, ystride,
255-
zstride, &m_tilebuffer[0]);
256-
}
257-
258-
259-
260240
bool
261241
HdrOutput::close()
262242
{
@@ -265,18 +245,9 @@ HdrOutput::close()
265245
return true;
266246
}
267247

268-
bool ok = true;
269-
if (m_spec.tile_width) {
270-
// We've been emulating tiles; now dump as scanlines.
271-
OIIO_ASSERT(m_tilebuffer.size());
272-
ok &= write_scanlines(m_spec.y, m_spec.y + m_spec.height, 0,
273-
m_spec.format, &m_tilebuffer[0]);
274-
std::vector<unsigned char>().swap(m_tilebuffer);
275-
}
276-
277248
init();
278249

279-
return ok;
250+
return true;
280251
}
281252

282253
OIIO_PLUGIN_NAMESPACE_END

src/ico.imageio/icooutput.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ class ICOOutput final : public ImageOutput {
3232
bool close() override;
3333
bool write_scanline(int y, int z, TypeDesc format, const void* data,
3434
stride_t xstride) override;
35-
bool write_tile(int x, int y, int z, TypeDesc format, const void* data,
36-
stride_t xstride, stride_t ystride,
37-
stride_t zstride) override;
3835

3936
private:
4037
std::string m_filename; ///< Stash the filename
@@ -47,7 +44,6 @@ class ICOOutput final : public ImageOutput {
4744
int m_and_slb; ///< AND mask scanline length in bytes
4845
int m_bpp; ///< Bits per pixel
4946
unsigned int m_dither;
50-
std::vector<unsigned char> m_tilebuffer;
5147

5248
png_structp m_png; ///< PNG read structure pointer
5349
png_infop m_info; ///< PNG image info structure pointer
@@ -361,11 +357,6 @@ ICOOutput::open(const std::string& name, const ImageSpec& userspec,
361357
fseek(m_file, m_offset + sizeof(bmi), SEEK_SET);
362358
}
363359

364-
// If user asked for tiles -- which this format doesn't support, emulate
365-
// it by buffering the whole image.
366-
if (m_spec.tile_width && m_spec.tile_height)
367-
m_tilebuffer.resize(m_spec.image_bytes());
368-
369360
return true;
370361
}
371362

@@ -392,15 +383,6 @@ ICOOutput::close()
392383
return true;
393384
}
394385

395-
bool ok = true;
396-
if (m_spec.tile_width) {
397-
// Handle tile emulation -- output the buffered pixels
398-
OIIO_ASSERT(m_tilebuffer.size());
399-
ok &= write_scanlines(m_spec.y, m_spec.y + m_spec.height, 0,
400-
m_spec.format, &m_tilebuffer[0]);
401-
std::vector<unsigned char>().swap(m_tilebuffer);
402-
}
403-
404386
if (m_png) {
405387
PNG_pvt::write_end(m_png, m_info);
406388
if (m_png || m_info)
@@ -411,7 +393,7 @@ ICOOutput::close()
411393
fclose(m_file);
412394
m_file = NULL;
413395
init(); // re-initialize
414-
return ok;
396+
return true;
415397
}
416398

417399

@@ -516,14 +498,4 @@ ICOOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
516498

517499

518500

519-
bool
520-
ICOOutput::write_tile(int x, int y, int z, TypeDesc format, const void* data,
521-
stride_t xstride, stride_t ystride, stride_t zstride)
522-
{
523-
// Emulate tiles by buffering the whole image
524-
return copy_tile_to_image_buffer(x, y, z, format, data, xstride, ystride,
525-
zstride, &m_tilebuffer[0]);
526-
}
527-
528-
529501
OIIO_PLUGIN_NAMESPACE_END

src/jpeg.imageio/jpegoutput.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class JpgOutput final : public ImageOutput {
4040
OpenMode mode = Create) override;
4141
bool write_scanline(int y, int z, TypeDesc format, const void* data,
4242
stride_t xstride) override;
43-
bool write_tile(int x, int y, int z, TypeDesc format, const void* data,
44-
stride_t xstride, stride_t ystride,
45-
stride_t zstride) override;
4643
bool close() override;
4744
bool copy_image(ImageInput* in) override;
4845

@@ -55,7 +52,7 @@ class JpgOutput final : public ImageOutput {
5552
struct jpeg_error_mgr c_jerr;
5653
jvirt_barray_ptr* m_copy_coeffs;
5754
struct jpeg_decompress_struct* m_copy_decompressor;
58-
std::vector<unsigned char> m_tilebuffer;
55+
5956
// m_outbuffer/m_outsize are used for jpeg-to-memory
6057
unsigned char* m_outbuffer = nullptr;
6158
#if OIIO_JPEG_LIB_VERSION >= 94
@@ -356,11 +353,6 @@ JpgOutput::open(const std::string& name, const ImageSpec& newspec,
356353

357354
m_dither = m_spec.get_int_attribute("oiio:dither", 0);
358355

359-
// If user asked for tiles -- which JPEG doesn't support, emulate it by
360-
// buffering the whole image.
361-
if (m_spec.tile_width && m_spec.tile_height)
362-
m_tilebuffer.resize(m_spec.image_bytes());
363-
364356
return true;
365357
}
366358

@@ -517,17 +509,6 @@ JpgOutput::write_scanline(int y, int z, TypeDesc format, const void* data,
517509

518510

519511

520-
bool
521-
JpgOutput::write_tile(int x, int y, int z, TypeDesc format, const void* data,
522-
stride_t xstride, stride_t ystride, stride_t zstride)
523-
{
524-
// Emulate tiles by buffering the whole image
525-
return copy_tile_to_image_buffer(x, y, z, format, data, xstride, ystride,
526-
zstride, &m_tilebuffer[0]);
527-
}
528-
529-
530-
531512
bool
532513
JpgOutput::close()
533514
{
@@ -536,16 +517,6 @@ JpgOutput::close()
536517
return true;
537518
}
538519

539-
bool ok = true;
540-
541-
if (m_spec.tile_width) {
542-
// We've been emulating tiles; now dump as scanlines.
543-
OIIO_DASSERT(m_tilebuffer.size());
544-
ok &= write_scanlines(m_spec.y, m_spec.y + m_spec.height, 0,
545-
m_spec.format, &m_tilebuffer[0]);
546-
std::vector<unsigned char>().swap(m_tilebuffer); // free it
547-
}
548-
549520
if (m_next_scanline < spec().height && m_copy_coeffs == NULL) {
550521
// But if we've only written some scanlines, write the rest to avoid
551522
// errors
@@ -578,7 +549,7 @@ JpgOutput::close()
578549
}
579550

580551
init();
581-
return ok;
552+
return true;
582553
}
583554

584555

0 commit comments

Comments
 (0)