| 1167 | } |
| 1168 | |
| 1169 | bool Image::saveToFile( const std::string& filepath, const SaveType& Format ) { |
| 1170 | bool Res = false; |
| 1171 | |
| 1172 | std::string fpath( FileSystem::fileRemoveFileName( filepath ) ); |
| 1173 | |
| 1174 | if ( !FileSystem::isDirectory( fpath ) ) |
| 1175 | FileSystem::makeDir( fpath ); |
| 1176 | |
| 1177 | if ( NULL != mPixels && 0 != mWidth && 0 != mHeight && 0 != mChannels ) { |
| 1178 | if ( SaveType::WEBP == Format ) { |
| 1179 | auto data = webpPacker( *this, mFormatConfiguration.webpSaveQuality(), |
| 1180 | mFormatConfiguration.webpSaveLossless(), |
| 1181 | mFormatConfiguration.webpCompressionMethod() ); |
| 1182 | if ( !data.empty() ) |
| 1183 | FileSystem::fileWrite( filepath, data ); |
| 1184 | } else if ( SaveType::JPG != Format ) { |
| 1185 | Res = 0 != ( SOIL_save_image( filepath.c_str(), (int)Format, (Int32)mWidth, |
| 1186 | (Int32)mHeight, mChannels, getPixelsPtr() ) ); |
| 1187 | } else { |
| 1188 | jpge::params params; |
| 1189 | params.m_quality = mFormatConfiguration.jpegSaveQuality(); |
| 1190 | Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), mWidth, mHeight, mChannels, |
| 1191 | getPixelsPtr(), params ); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return Res; |
| 1196 | } |
| 1197 | |
| 1198 | void Image::replaceColor( const Color& ColorKey, const Color& NewColor ) { |
| 1199 | unsigned int Pos = 0; |