// static bool PortableFloatMapIO::write( const std::string& filename, Array2DReadView< Vector4f > image ) { int w = image.width(); int h = image.height(); // use "wb" binary mode to ensure that on Windows, // newlines in the header are written out as '\n' FILE* pFile = fopen( filename.c_str(), "wb" ); if( pFile == nullptr ) { return false; } // write header int nCharsWritten = fprintf( pFile, "PF4\n%d %d\n-1\n", w, h ); if( nCharsWritten < 0 ) { fclose( pFile ); return false; } // All at once. if( image.packed() ) { fwrite( image.rowPointer( 0 ), sizeof( Vector4f ), image.numElements(), pFile ); } // Row by Row. else if( image.elementsArePacked() ) { for( int y = 0; y < h; ++y ) { fwrite( image.rowPointer( y ), sizeof( Vector4f ), image.width(), pFile ); } } // Element by element. else { for( int y = 0; y < h; ++y ) { for( int x = 0; x < w; ++x ) { fwrite( image.elementPointer( { x, y } ), sizeof( Vector4f ), 1, pFile ); } } } fclose( pFile ); return true; }
bool GLTextureRectangle::set( Array2DReadView< uint8x2 > srcData, GLImageFormat srcFormat, const Vector2i& dstOffset ) { if( srcFormat != GLImageFormat::RG ) { return false; } if( !srcData.packed() ) { return false; } const GLPixelType srcType = GLPixelType::UNSIGNED_BYTE; return set2D( srcData.pointer(), srcData.size(), srcFormat, srcType, dstOffset ); }
bool GLTextureRectangle::set( Array2DReadView< Vector4f > srcData, GLImageFormat srcFormat, const Vector2i& dstOffset ) { if( srcFormat != GLImageFormat::RGBA && srcFormat != GLImageFormat::BGRA ) { return false; } if( !srcData.packed() ) { return false; } const GLPixelType srcType = GLPixelType::FLOAT; return set2D( srcData.pointer(), srcData.size(), srcFormat, srcType, dstOffset ); }
// static bool PNGIO::write( const std::string& filename, Array2DReadView< uint8x4 > image ) { Array2D< uint8x4 > tmpImage; const uint8_t* srcPointer; if( !image.packed() ) { tmpImage.resize( image.size() ); copy< uint8x4 >( image, tmpImage ); srcPointer = reinterpret_cast< const uint8_t* >( tmpImage.pointer() ); } else { srcPointer = reinterpret_cast< const uint8_t* >( image.pointer() ); } unsigned int errVal = lodepng::encode( filename, srcPointer, image.width(), image.height(), LCT_RGBA ); bool succeeded = ( errVal == 0 ); return succeeded; }