int EXRFile::OpenOutputFile(const char* i_fileName) { m_file = fopen(i_fileName, "wb"); if (!m_file) { return IMF_ERROR_ERROR; } m_channelList = new ChannelList(*m_header->GetChannelList()); m_channelList->Sort(); m_header->GetAttribute("dataWindow", "box2i", (char*)&m_dataWindow[0]); m_header->GetAttribute("compression", "compression", (char*)&m_compression); int width = m_dataWindow[2] - m_dataWindow[0] + 1; size_t datasize = m_channelList->GetPixelSize() * width; if (m_compression == IMF_ZIP_COMPRESSION) { m_scanline_block = new ScanLineZipBlock( m_file, datasize, m_dataWindow[1]); } else { m_scanline_block = new ScanLineBlock( m_file, datasize, m_dataWindow[1]); } int height = m_dataWindow[3] - m_dataWindow[1] + 1; m_blocks = height / m_scanline_block->NumLinesInBlock(); m_blocks += height % m_scanline_block->NumLinesInBlock() > 0; m_offset_table = new uint64_t [m_blocks]; m_offset_table_counter = 0; WriteMagic(); WriteVersion(); WriteHeader(); WriteZerroOffsets(); return IMF_ERROR_NOERROR; }
int EXRFile::OpenOutputFile(const char* i_fileName) { m_file = fopen(i_fileName, "wb"); if (!m_file) { return IMF_ERROR_ERROR; } m_channelList = new ChannelList(*m_header->GetChannelList()); m_channelList->Sort(); m_header->GetAttribute("dataWindow", "box2i", (char*)&m_dataWindow[0]); m_header->GetAttribute("compression", "compression", (char*)&m_compression); /* TODO: Get and use length of the attribute */ char type[256]; const char* deepscanline = "deepscanline"; m_header->GetAttribute("type", "string", type); if (strncmp(type, deepscanline, strlen(deepscanline)) == 0) { m_dataType = IMF_DEEPSCANLINE; } else { m_dataType = IMF_SCANLINEIMAGE; } int width = m_dataWindow[2] - m_dataWindow[0] + 1; size_t datasize = m_channelList->GetPixelSize() * width; if( m_dataType == IMF_DEEPSCANLINE ) { if (m_compression == IMF_ZIPS_COMPRESSION) { m_scanline_block = new ScanLineDeepZipSBlock( m_file, width * sizeof(m_fb_sampleCount[0]), m_channelList->GetPixelSize(), m_dataWindow[1]); } else { m_scanline_block = new ScanLineDeepBlock( m_file, width * sizeof(m_fb_sampleCount[0]), m_channelList->GetPixelSize(), m_dataWindow[1]); } } else switch( m_compression ) { case IMF_ZIP_COMPRESSION: m_scanline_block = new ScanLineZipBlock( m_file, datasize, m_dataWindow[1], ScanLineZipBlock::kDefaultBlockSize); break; case IMF_ZIPS_COMPRESSION: m_scanline_block = new ScanLineZipBlock( m_file, datasize, m_dataWindow[1], 1); break; default: m_scanline_block = new ScanLineBlock( m_file, datasize, m_dataWindow[1]); } int height = m_dataWindow[3] - m_dataWindow[1] + 1; m_blocks = height / m_scanline_block->NumLinesInBlock(); m_blocks += height % m_scanline_block->NumLinesInBlock() > 0; m_offset_table = new uint64_t [m_blocks]; // Initialize table to 0, so that valgrind doesn't complain about writing it out to file before we initialize it for( int i = 0; i < m_blocks; i++ ) m_offset_table[i] = 0; m_offset_table_counter = 0; WriteMagic(); WriteVersion(); WriteHeader(); WriteZerroOffsets(); return IMF_ERROR_NOERROR; }