Image2D::Image2D(Image2D const& _cpy) { SetText(_cpy.GetText()); m_fg = _cpy.GetForegroundColor(); m_bg = _cpy.GetBackgroundColor(); m_width = _cpy.GetWidth(); m_height = _cpy.GetHeight(); }
bool Image2DPngExporter::Export( const std::string& filename, const Image2D& image ) { FILE* file; png_structp write; png_infop info; png_bytepp rowBuf; uint width = image.GetWidth(); uint height = image.GetHeight(); unsigned char* buffer = (unsigned char*)&image.GetPixels()[0]; if( ( file = fopen( filename.c_str(), "wb" ) ) == 0 ) { return false; } // Creates structure. write = png_create_write_struct( PNG_LIBPNG_VER_STRING, (png_voidp)0, (png_error_ptr)0, (png_error_ptr)0 ); info = png_create_info_struct( write ); // Verify for errors. if( setjmp( png_jmpbuf( write ) ) ) { png_destroy_write_struct( &write, &info ); fclose( file ); return false; } // Write header. png_init_io( write, file ); png_set_IHDR( write, info, width, height, 8, _pngChannels[2], PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE ); png_write_info( write, info ); // Write image rowBuf = new png_bytep[height]; PixelType _type = yTE; int _pixelSize = pixelTypeSize[_type] * 3; int _lineSize = _pixelSize * width; // no padding for now for( int i = 0; i < (int)height; ++i ) { rowBuf[height-i-1] = &buffer[_lineSize*i]; } png_write_image( write, rowBuf ); // Clean up after the write, and free any memory allocated - REQUIRED png_write_end( write, info ); png_destroy_write_struct( &write, &info ); delete[] rowBuf; fclose( file ); return true; }