Skip to content

Commit 9f0c41c

Browse files
lgritzscott-wilson
authored andcommitted
testing: better testing coverage of null image reader/writer (AcademySoftwareFoundation#4578)
This improves the mediocre testing line coverage in nullimageio.cpp from 50% to 95%. * Test writing * Test reading of tiled and MIP-mapped null images * Test setting and reading of attributes * Simplify some code * Along the way, identified and fixed a nullimage bug -- it was answering that it supported "rectangles" but had no write_rectangle method. Testing works! Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Scott Wilson <[email protected]>
1 parent 1a04714 commit 9f0c41c

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

src/null.imageio/nullimageio.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class NullOutput final : public ImageOutput {
2424
NullOutput() {}
2525
~NullOutput() override {}
2626
const char* format_name(void) const override { return "null"; }
27-
int supports(string_view /*feature*/) const override { return true; }
27+
int supports(string_view feature) const override
28+
{
29+
return feature != "rectangles";
30+
}
2831
bool open(const std::string& /*name*/, const ImageSpec& spec,
2932
OpenMode /*mode*/) override
3033
{
@@ -316,10 +319,10 @@ NullInput::open(const std::string& name, ImageSpec& newspec,
316319
}
317320
}
318321

322+
m_value.resize(m_topspec.pixel_bytes()); // default fills with 0's
319323
if (fvalue.size()) {
320324
// Convert float to the native type
321325
fvalue.resize(m_topspec.nchannels, 0.0f);
322-
m_value.resize(m_topspec.pixel_bytes());
323326
convert_pixel_values(TypeFloat, fvalue.data(), m_topspec.format,
324327
m_value.data(), m_topspec.nchannels);
325328
}
@@ -365,13 +368,10 @@ bool
365368
NullInput::read_native_scanline(int /*subimage*/, int /*miplevel*/, int /*y*/,
366369
int /*z*/, void* data)
367370
{
368-
if (m_value.size()) {
369-
size_t s = m_spec.pixel_bytes();
370-
for (int x = 0; x < m_spec.width; ++x)
371-
memcpy((char*)data + s * x, m_value.data(), s);
372-
} else {
373-
memset(data, 0, m_spec.scanline_bytes());
374-
}
371+
size_t s = m_spec.pixel_bytes();
372+
OIIO_DASSERT(m_value.size() == s);
373+
for (int x = 0; x < m_spec.width; ++x)
374+
memcpy((char*)data + s * x, m_value.data(), s);
375375
return true;
376376
}
377377

@@ -381,13 +381,10 @@ bool
381381
NullInput::read_native_tile(int /*subimage*/, int /*miplevel*/, int /*x*/,
382382
int /*y*/, int /*z*/, void* data)
383383
{
384-
if (m_value.size()) {
385-
size_t s = m_spec.pixel_bytes();
386-
for (size_t x = 0, e = m_spec.tile_pixels(); x < e; ++x)
387-
memcpy((char*)data + s * x, m_value.data(), s);
388-
} else {
389-
memset(data, 0, m_spec.tile_bytes());
390-
}
384+
size_t s = m_spec.pixel_bytes();
385+
OIIO_DASSERT(m_value.size() == s);
386+
for (size_t x = 0, e = m_spec.tile_pixels(); x < e; ++x)
387+
memcpy((char*)data + s * x, m_value.data(), s);
391388
return true;
392389
}
393390

testsuite/null/ref/out.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
Reading foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1
2-
foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1 : 640 x 480, 3 channel, uint8 null
1+
Reading foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1&a=1&b=2.5&c=foo&string d=bar&e=float 3&f="baz"
2+
foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1&a=1&b=2.5&c=foo&string d=bar&e=float 3&f="baz" : 640 x 480, 3 channel, uint8 null
33
channel list: R, G, B
4+
a: 1
5+
b: 2.5
6+
c: "foo"
7+
d: "bar"
8+
e: 3
9+
f: "baz"
410
Stats Min: 64 128 255 (of 255)
511
Stats Max: 64 128 255 (of 255)
612
Stats Avg: 64.00 128.00 255.00 (of 255)
@@ -11,3 +17,22 @@ foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1 : 640 x 480, 3 cha
1117
Constant: Yes
1218
Constant Color: 64.00 128.00 255.00 (of 255)
1319
Monochrome: No
20+
Writing out.null
21+
Reading bar.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1
22+
bar.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1 : 128 x 128, 3 channel, uint16 null
23+
MIP-map levels: 128x128 64x64 32x32 16x16 8x8 4x4 2x2 1x1
24+
channel list: R, G, B
25+
tile size: 64 x 64
26+
textureformat: "Plain Texture"
27+
wrapmodes: "black,black"
28+
Stats Min: 16384 32768 65535 (of 65535)
29+
Stats Max: 16384 32768 65535 (of 65535)
30+
Stats Avg: 16384.00 32768.00 65535.00 (of 65535)
31+
Stats StdDev: 0.00 0.00 0.00 (of 65535)
32+
Stats NanCount: 0 0 0
33+
Stats InfCount: 0 0 0
34+
Stats FiniteCount: 16384 16384 16384
35+
Constant: Yes
36+
Constant Color: 16384.00 32768.00 65535.00 (of 65535)
37+
Monochrome: No
38+
Writing outtile.null

testsuite/null/run.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
# https://github.com/AcademySoftwareFoundation/OpenImageIO
66

77

8-
command += oiiotool ('-v -info -stats "foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1"')
8+
# Read and write null scanline and a tiled mipmap image
9+
command += oiiotool ('-v -info -stats ' +
10+
'"foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1&a=1&b=2.5&c=foo&string d=bar&e=float 3&f=\\\"baz\\\"" ' +
11+
'-o out.null ' +
12+
'"bar.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1" ' +
13+
'-o:tile=64x64 outtile.null'
14+
)

0 commit comments

Comments
 (0)