Skip to content

Commit

Permalink
testing: better testing coverage of null image reader/writer
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
lgritz committed Dec 29, 2024
1 parent 42fd804 commit 6aaf25a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
29 changes: 13 additions & 16 deletions src/null.imageio/nullimageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class NullOutput final : public ImageOutput {
NullOutput() {}
~NullOutput() override {}
const char* format_name(void) const override { return "null"; }
int supports(string_view /*feature*/) const override { return true; }
int supports(string_view feature) const override
{
return feature != "rectangles";
}
bool open(const std::string& /*name*/, const ImageSpec& spec,
OpenMode /*mode*/) override
{
Expand Down Expand Up @@ -316,10 +319,10 @@ NullInput::open(const std::string& name, ImageSpec& newspec,
}
}

m_value.resize(m_topspec.pixel_bytes()); // default fills with 0's
if (fvalue.size()) {
// Convert float to the native type
fvalue.resize(m_topspec.nchannels, 0.0f);
m_value.resize(m_topspec.pixel_bytes());
convert_pixel_values(TypeFloat, fvalue.data(), m_topspec.format,
m_value.data(), m_topspec.nchannels);
}
Expand Down Expand Up @@ -365,13 +368,10 @@ bool
NullInput::read_native_scanline(int /*subimage*/, int /*miplevel*/, int /*y*/,
int /*z*/, void* data)
{
if (m_value.size()) {
size_t s = m_spec.pixel_bytes();
for (int x = 0; x < m_spec.width; ++x)
memcpy((char*)data + s * x, m_value.data(), s);
} else {
memset(data, 0, m_spec.scanline_bytes());
}
size_t s = m_spec.pixel_bytes();
OIIO_DASSERT(m_value.size() == s);
for (int x = 0; x < m_spec.width; ++x)
memcpy((char*)data + s * x, m_value.data(), s);
return true;
}

Expand All @@ -381,13 +381,10 @@ bool
NullInput::read_native_tile(int /*subimage*/, int /*miplevel*/, int /*x*/,
int /*y*/, int /*z*/, void* data)
{
if (m_value.size()) {
size_t s = m_spec.pixel_bytes();
for (size_t x = 0, e = m_spec.tile_pixels(); x < e; ++x)
memcpy((char*)data + s * x, m_value.data(), s);
} else {
memset(data, 0, m_spec.tile_bytes());
}
size_t s = m_spec.pixel_bytes();
OIIO_DASSERT(m_value.size() == s);
for (size_t x = 0, e = m_spec.tile_pixels(); x < e; ++x)
memcpy((char*)data + s * x, m_value.data(), s);
return true;
}

Expand Down
36 changes: 36 additions & 0 deletions testsuite/null/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,39 @@ foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1 : 640 x 480, 3 cha
Constant: Yes
Constant Color: 64.00 128.00 255.00 (of 255)
Monochrome: No
Reading foo.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1
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
MIP-map levels: 128x128 64x64 32x32 16x16 8x8 4x4 2x2 1x1
channel list: R, G, B
tile size: 64 x 64
textureformat: "Plain Texture"
wrapmodes: "black,black"
Stats Min: 16384 32768 65535 (of 65535)
Stats Max: 16384 32768 65535 (of 65535)
Stats Avg: 16384.00 32768.00 65535.00 (of 65535)
Stats StdDev: 0.00 0.00 0.00 (of 65535)
Stats NanCount: 0 0 0
Stats InfCount: 0 0 0
Stats FiniteCount: 16384 16384 16384
Constant: Yes
Constant Color: 16384.00 32768.00 65535.00 (of 65535)
Monochrome: No
Reading foo.null?RES=128x128&CHANNELS=3&TYPE=uint8&a=1&b=2.5&c=foo&string e=bar
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
channel list: R, G, B
a: 1
b: 2.5
c: "foo"
e: "bar"
Stats Min: 0 0 0 (of 255)
Stats Max: 0 0 0 (of 255)
Stats Avg: 0.00 0.00 0.00 (of 255)
Stats StdDev: 0.00 0.00 0.00 (of 255)
Stats NanCount: 0 0 0
Stats InfCount: 0 0 0
Stats FiniteCount: 16384 16384 16384
Constant: Yes
Constant Color: 0.00 0.00 0.00 (of 255)
Monochrome: Yes
Writing out.null
Writing outtile.null
9 changes: 8 additions & 1 deletion testsuite/null/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
# https://github.com/AcademySoftwareFoundation/OpenImageIO


command += oiiotool ('-v -info -stats "foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1"')
command += oiiotool ('-v -info -stats ' +
'"foo.null?RES=640x480&CHANNELS=3&TYPE=uint8&PIXEL=0.25,0.5,1" ' +
'"foo.null?RES=128x128&CHANNELS=3&TILE=64x64&TEX=1&TYPE=uint16&PIXEL=0.25,0.5,1" '
)
command += oiiotool ('-v -info -stats ' +
'"foo.null?RES=128x128&CHANNELS=3&TYPE=uint8&a=1&b=2.5&c=foo&string e=bar" ' +
'-o out.null -o:tile=64 outtile.null'
)

0 comments on commit 6aaf25a

Please sign in to comment.