@@ -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
229249SoftimageInput::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
265276SoftimageInput::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
308319SoftimageInput::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
369380SoftimageInput::read_pixels_mixed_run_length (
370381 const softimage_pvt::ChannelPacket& curPacket, void * data)
371382{
0 commit comments