void write( string const& fn, tImgViewLinear const& img ) { try { vector<uint8_t> buf; if( img.is_mono8() ) { buf.resize( offsetpixeldata8 + img.bytes() ); write_mono8( buf, img.size(), img.rows() ); } if( img.is_rgb() ) { uint32_t aligned_line_size = bmp_intern::align32( img.size().x() * sizeof( tBGR ) ); uint32_t filesize = header_size + aligned_line_size * img.size().y(); buf.resize( filesize ); write_rgb( buf, img.size(), img.rows() ); } if( img.is_rgba() ) { uint32_t aligned_line_size = bmp_intern::align32( img.size().x() * sizeof( tBGRA ) ); uint32_t filesize = header_size + aligned_line_size * img.size().y(); buf.resize( filesize ); write_rgba( buf, img.size(), img.rows() ); } bin_data::tWriteBin()( fn, buf ); } catch( bin_data::tBinWriteEx& ) { throw tImgWriteEx( bin_data::msg::write_file( fn ) ); } }