Skip to content

Commit 5c4320c

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

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

src/null.imageio/nullimageio.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ NullInput::open(const std::string& name, ImageSpec& newspec,
316316
}
317317
}
318318

319+
m_value.resize(m_topspec.pixel_bytes()); // default fills with 0's
319320
if (fvalue.size()) {
320321
// Convert float to the native type
321322
fvalue.resize(m_topspec.nchannels, 0.0f);
322-
m_value.resize(m_topspec.pixel_bytes());
323323
convert_pixel_values(TypeFloat, fvalue.data(), m_topspec.format,
324324
m_value.data(), m_topspec.nchannels);
325325
}
@@ -365,13 +365,10 @@ bool
365365
NullInput::read_native_scanline(int /*subimage*/, int /*miplevel*/, int /*y*/,
366366
int /*z*/, void* data)
367367
{
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-
}
368+
size_t s = m_spec.pixel_bytes();
369+
OIIO_DASSERT(m_value.size() == s);
370+
for (int x = 0; x < m_spec.width; ++x)
371+
memcpy((char*)data + s * x, m_value.data(), s);
375372
return true;
376373
}
377374

@@ -381,13 +378,10 @@ bool
381378
NullInput::read_native_tile(int /*subimage*/, int /*miplevel*/, int /*x*/,
382379
int /*y*/, int /*z*/, void* data)
383380
{
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-
}
381+
size_t s = m_spec.pixel_bytes();
382+
OIIO_DASSERT(m_value.size() == s);
383+
for (size_t x = 0, e = m_spec.tile_pixels(); x < e; ++x)
384+
memcpy((char*)data + s * x, m_value.data(), s);
391385
return true;
392386
}
393387

testsuite/null/ref/out.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,37 @@ 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&a=1&b=2.5&string c=foo
32+
foo.null?RES=128x128&CHANNELS=3&a=1&b=2.5&string c=foo : 128 x 128, 3 channel, float null
33+
channel list: R, G, B
34+
a: 1
35+
b: 2.5
36+
c: "foo"
37+
Stats Min: 0.000000 0.000000 0.000000 (float)
38+
Stats Max: 0.000000 0.000000 0.000000 (float)
39+
Stats Avg: 0.000000 0.000000 0.000000 (float)
40+
Stats StdDev: 0.000000 0.000000 0.000000 (float)
41+
Stats NanCount: 0 0 0
42+
Stats InfCount: 0 0 0
43+
Stats FiniteCount: 16384 16384 16384
44+
Constant: Yes
45+
Constant Color: 0.000000 0.000000 0.000000 (float)
46+
Monochrome: Yes
47+
Writing out.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&a=1&b=2.5&string c=foo" ' +
14+
'-o out.null'
15+
)

0 commit comments

Comments
 (0)