Skip to content

Commit 6aaf25a

Browse files
committed
testing: better testing coverage of null image reader/writer
* Test writing * Test reading of tiled and MIP-mapped null images * Test setting and reading of attributes This improves the poor testing line coverage in nullimageio.cpp. Signed-off-by: Larry Gritz <[email protected]>
1 parent 42fd804 commit 6aaf25a

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,39 @@ foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1 : 640 x 480, 3 cha
1111
Constant: Yes
1212
Constant Color: 64.00 128.00 255.00 (of 255)
1313
Monochrome: No
14+
Reading foo.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1
15+
foo.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1 : 128 x 128, 3 channel, uint16 null
16+
MIP-map levels: 128x128 64x64 32x32 16x16 8x8 4x4 2x2 1x1
17+
channel list: R, G, B
18+
tile size: 64 x 64
19+
textureformat: "Plain Texture"
20+
wrapmodes: "black,black"
21+
Stats Min: 16384 32768 65535 (of 65535)
22+
Stats Max: 16384 32768 65535 (of 65535)
23+
Stats Avg: 16384.00 32768.00 65535.00 (of 65535)
24+
Stats StdDev: 0.00 0.00 0.00 (of 65535)
25+
Stats NanCount: 0 0 0
26+
Stats InfCount: 0 0 0
27+
Stats FiniteCount: 16384 16384 16384
28+
Constant: Yes
29+
Constant Color: 16384.00 32768.00 65535.00 (of 65535)
30+
Monochrome: No
31+
Reading foo.null?RES=128x128&CHANNELS=3&TYPE=uint8&a=1&b=2.5&c=foo&string e=bar
32+
foo.null?RES=128x128&CHANNELS=3&TYPE=uint8&a=1&b=2.5&c=foo&string e=bar : 128 x 128, 3 channel, uint8 null
33+
channel list: R, G, B
34+
a: 1
35+
b: 2.5
36+
c: "foo"
37+
e: "bar"
38+
Stats Min: 0 0 0 (of 255)
39+
Stats Max: 0 0 0 (of 255)
40+
Stats Avg: 0.00 0.00 0.00 (of 255)
41+
Stats StdDev: 0.00 0.00 0.00 (of 255)
42+
Stats NanCount: 0 0 0
43+
Stats InfCount: 0 0 0
44+
Stats FiniteCount: 16384 16384 16384
45+
Constant: Yes
46+
Constant Color: 0.00 0.00 0.00 (of 255)
47+
Monochrome: Yes
48+
Writing out.null
49+
Writing outtile.null

testsuite/null/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
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+
command += oiiotool ('-v -info -stats ' +
9+
'"foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1" ' +
10+
'"foo.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1" '
11+
)
12+
command += oiiotool ('-v -info -stats ' +
13+
'"foo.null?RES=128x128&CHANNELS=3&TYPE=uint8&a=1&b=2.5&c=foo&string e=bar" ' +
14+
'-o out.null -o:tile=64 outtile.null'
15+
)

0 commit comments

Comments
 (0)