Skip to content

Commit 534f990

Browse files
committed
testing: at long last, set up a softimage reading test
Also some very minor code cleanup that was helpful in setting up the test cases and getting better code coverage. Signed-off-by: Larry Gritz <[email protected]>
1 parent 7f2e8e6 commit 534f990

File tree

4 files changed

+83
-27
lines changed

4 files changed

+83
-27
lines changed

src/cmake/testing.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ macro (oiio_add_all_tests)
332332
oiio_add_tests (sgi
333333
ENABLEVAR ENABLE_SGI
334334
IMAGEDIR oiio-images)
335+
oiio_add_tests (softimage
336+
ENABLEVAR ENABLE_SOFTIMAGE
337+
IMAGEDIR oiio-images/softimage)
335338
oiio_add_tests (targa
336339
ENABLEVAR ENABLE_TARGA
337340
IMAGEDIR oiio-images)

src/softimage.imageio/softimageinput.cpp

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class SoftimageInput final : public ImageInput {
4242
read_pixels_mixed_run_length(const softimage_pvt::ChannelPacket& curPacket,
4343
void* data);
4444

45+
// Name for encoding
46+
const char* encoding_name(int encoding);
47+
4548
FILE* m_fd;
4649
softimage_pvt::PicFileHeader m_pic_header;
4750
std::vector<softimage_pvt::ChannelPacket> m_channel_packets;
@@ -108,6 +111,7 @@ SoftimageInput::open(const std::string& name, ImageSpec& spec)
108111
// Get the ChannelPackets
109112
ChannelPacket curPacket;
110113
int nchannels = 0;
114+
std::vector<std::string> encodings;
111115
do {
112116
// Read the next packet into curPacket and store it off
113117
if (fread(&curPacket, 1, sizeof(ChannelPacket), m_fd)
@@ -120,6 +124,7 @@ SoftimageInput::open(const std::string& name, ImageSpec& spec)
120124

121125
// Add the number of channels in this packet to nchannels
122126
nchannels += curPacket.channels().size();
127+
encodings.push_back(encoding_name(m_channel_packets.back().type));
123128
} while (curPacket.chained);
124129

125130
// Get the depth per pixel per channel
@@ -132,6 +137,8 @@ SoftimageInput::open(const std::string& name, ImageSpec& spec)
132137
chanType);
133138
m_spec.attribute("BitsPerSample", (int)curPacket.size);
134139

140+
m_spec.attribute("softimage:compression", Strutil::join(encodings, ","));
141+
135142
if (m_pic_header.comment[0] != 0) {
136143
char comment[80];
137144
Strutil::safe_strcpy(comment, m_pic_header.comment, 80);
@@ -225,43 +232,47 @@ SoftimageInput::close()
225232

226233

227234

228-
inline bool
235+
const char*
236+
SoftimageInput::encoding_name(int encoding)
237+
{
238+
switch (encoding & 0x3) {
239+
case UNCOMPRESSED: return "none";
240+
case PURE_RUN_LENGTH: return "rle";
241+
case MIXED_RUN_LENGTH: return "mixed-rle";
242+
default: return "unknown";
243+
}
244+
}
245+
246+
247+
248+
bool
229249
SoftimageInput::read_next_scanline(void* data)
230250
{
231251
// Each scanline is stored using one or more channel packets.
232252
// We go through each of those to pull the data
233253
for (auto& cp : m_channel_packets) {
234-
if (cp.type & UNCOMPRESSED) {
235-
if (!read_pixels_uncompressed(cp, data)) {
236-
errorfmt("Failed to read uncompressed pixel data from \"{}\"",
237-
m_filename);
238-
close();
239-
return false;
240-
}
241-
} else if (cp.type & PURE_RUN_LENGTH) {
242-
if (!read_pixels_pure_run_length(cp, data)) {
243-
errorfmt(
244-
"Failed to read pure run length encoded pixel data from \"{}\"",
245-
m_filename);
246-
close();
247-
return false;
248-
}
249-
} else if (cp.type & MIXED_RUN_LENGTH) {
250-
if (!read_pixels_mixed_run_length(cp, data)) {
251-
errorfmt(
252-
"Failed to read mixed run length encoded pixel data from \"{}\"",
253-
m_filename);
254-
close();
255-
return false;
256-
}
254+
bool ok = false;
255+
int type = int(cp.type) & 0x3;
256+
if (type == UNCOMPRESSED) {
257+
ok = read_pixels_uncompressed(cp, data);
258+
} else if (type == PURE_RUN_LENGTH) {
259+
ok = read_pixels_pure_run_length(cp, data);
260+
} else if (type == MIXED_RUN_LENGTH) {
261+
ok = read_pixels_mixed_run_length(cp, data);
262+
}
263+
if (!ok) {
264+
errorfmt("Failed to read channel packed type {:d} from \"{}\"",
265+
int(cp.type), m_filename);
266+
close();
267+
return false;
257268
}
258269
}
259270
return true;
260271
}
261272

262273

263274

264-
inline bool
275+
bool
265276
SoftimageInput::read_pixels_uncompressed(
266277
const softimage_pvt::ChannelPacket& curPacket, void* data)
267278
{
@@ -304,7 +315,7 @@ SoftimageInput::read_pixels_uncompressed(
304315

305316

306317

307-
inline bool
318+
bool
308319
SoftimageInput::read_pixels_pure_run_length(
309320
const softimage_pvt::ChannelPacket& curPacket, void* data)
310321
{
@@ -365,7 +376,7 @@ SoftimageInput::read_pixels_pure_run_length(
365376

366377

367378

368-
inline bool
379+
bool
369380
SoftimageInput::read_pixels_mixed_run_length(
370381
const softimage_pvt::ChannelPacket& curPacket, void* data)
371382
{

testsuite/softimage/ref/out.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Reading ../oiio-images/softimage/A4.pic
2+
../oiio-images/softimage/A4.pic : 64 x 64, 4 channel, uint8 softimage
3+
SHA-1: 6A9FFED68FE36B0DA8544C1A3CBD671F662F8142
4+
channel list: R, G, B, A
5+
BitsPerSample: 8
6+
ImageDescription: "Created by Houdini"
7+
softimage:compression: "mixed-rle,mixed-rle"
8+
Stats Min: 0 0 0 0 (of 255)
9+
Stats Max: 255 255 255 255 (of 255)
10+
Stats Avg: 2.29 2.29 2.29 2.29 (of 255)
11+
Stats StdDev: 21.26 21.26 21.26 21.26 (of 255)
12+
Stats NanCount: 0 0 0 0
13+
Stats InfCount: 0 0 0 0
14+
Stats FiniteCount: 4096 4096 4096 4096
15+
Constant: No
16+
Monochrome: Yes
17+
Reading ../oiio-images/softimage/astone64.pic
18+
../oiio-images/softimage/astone64.pic : 64 x 64, 3 channel, uint8 softimage
19+
SHA-1: 0FD57F8BBD941261055C65A64BBA294D9C21664F
20+
channel list: R, G, B
21+
BitsPerSample: 8
22+
ImageDescription: "ImageFX SoftImage Saver (Amiga)"
23+
softimage:compression: "none"
24+
Stats Min: 26 30 0 (of 255)
25+
Stats Max: 255 255 174 (of 255)
26+
Stats Avg: 154.83 158.82 68.19 (of 255)
27+
Stats StdDev: 37.89 37.86 29.05 (of 255)
28+
Stats NanCount: 0 0 0
29+
Stats InfCount: 0 0 0
30+
Stats FiniteCount: 4096 4096 4096
31+
Constant: No
32+
Monochrome: No

testsuite/softimage/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
files = [ "A4.pic", "astone64.pic" ]
8+
for f in files:
9+
command += info_command (OIIO_TESTSUITE_IMAGEDIR + "/" + f, extraargs="--stats")
10+

0 commit comments

Comments
 (0)