Int64 Header::writeTo (OStream &os, bool isTiled) const { // // Write a "magic number" to identify the file as an image file. // Write the current file format version number. // Xdr::write <StreamIO> (os, MAGIC); int version = isTiled ? makeTiled (EXR_VERSION) : EXR_VERSION; Xdr::write <StreamIO> (os, version); // // Write all attributes. If we have a preview image attribute, // keep track of its position in the file. // Int64 previewPosition = 0; const Attribute *preview = findTypedAttribute <PreviewImageAttribute> ("preview"); for (ConstIterator i = begin(); i != end(); ++i) { // // Write the attribute's name and type. // Xdr::write <StreamIO> (os, i.name()); Xdr::write <StreamIO> (os, i.attribute().typeName()); // // Write the size of the attribute value, // and the value itself. // StdOSStream oss; i.attribute().writeValueTo (oss, version); std::string s = oss.str(); Xdr::write <StreamIO> (os, (int) s.length()); if (&i.attribute() == preview) previewPosition = os.tellp(); os.write (s.data(), s.length()); } // // Write zero-length attribute name to mark the end of the header. // Xdr::write <StreamIO> (os, ""); return previewPosition; }
Int64 TileOffsets::writeTo (OStream &os) const { // // Write the tile offset table to the file, and // return the position of the start of the table // in the file. // Int64 pos = os.tellp(); if (pos == -1) Iex::throwErrnoExc ("Cannot determine current file position (%T)."); for (unsigned int l = 0; l < _offsets.size(); ++l) for (unsigned int dy = 0; dy < _offsets[l].size(); ++dy) for (unsigned int dx = 0; dx < _offsets[l][dy].size(); ++dx) Xdr::write <StreamIO> (os, _offsets[l][dy][dx]); return pos; }