| 150 | /************************************************************************/ |
| 151 | |
| 152 | int msSaveImageGDAL( mapObj *map, imageObj *image, char *filename ) |
| 153 | |
| 154 | { |
| 155 | int bFileIsTemporary = MS_FALSE; |
| 156 | GDALDatasetH hMemDS, hOutputDS; |
| 157 | GDALDriverH hMemDriver, hOutputDriver; |
| 158 | int nBands = 1; |
| 159 | int iLine; |
| 160 | GByte *pabyAlphaLine = NULL; |
| 161 | char **papszOptions = NULL; |
| 162 | outputFormatObj *format = image->format; |
| 163 | rasterBufferObj rb; |
| 164 | GDALDataType eDataType = GDT_Byte; |
| 165 | |
| 166 | msGDALInitialize(); |
| 167 | memset(&rb,0,sizeof(rasterBufferObj)); |
| 168 | |
| 169 | /* -------------------------------------------------------------------- */ |
| 170 | /* Identify the proposed output driver. */ |
| 171 | /* -------------------------------------------------------------------- */ |
| 172 | msAcquireLock( TLOCK_GDAL ); |
| 173 | hOutputDriver = GDALGetDriverByName( format->driver+5 ); |
| 174 | if( hOutputDriver == NULL ) |
| 175 | { |
| 176 | msReleaseLock( TLOCK_GDAL ); |
| 177 | msSetError( MS_MISCERR, "Failed to find %s driver.", |
| 178 | "msSaveImageGDAL()", format->driver+5 ); |
| 179 | return MS_FAILURE; |
| 180 | } |
| 181 | |
| 182 | /* -------------------------------------------------------------------- */ |
| 183 | /* We will need to write the output to a temporary file and */ |
| 184 | /* then stream to stdout if no filename is passed. If the */ |
| 185 | /* driver supports virtualio then we hold the temporary file in */ |
| 186 | /* memory, otherwise we try to put it in a reasonable temporary */ |
| 187 | /* file location. */ |
| 188 | /* -------------------------------------------------------------------- */ |
| 189 | if( filename == NULL ) |
| 190 | { |
| 191 | const char *pszExtension = format->extension; |
| 192 | if( pszExtension == NULL ) |
| 193 | pszExtension = "img.tmp"; |
| 194 | |
| 195 | #ifdef GDAL_DCAP_VIRTUALIO |
| 196 | if( GDALGetMetadataItem( hOutputDriver, GDAL_DCAP_VIRTUALIO, NULL ) |
| 197 | != NULL ) |
| 198 | { |
| 199 | CleanVSIDir( "/vsimem/msout" ); |
| 200 | filename = msTmpFile(map, NULL, "/vsimem/msout/", pszExtension ); |
| 201 | } |
| 202 | #endif |
| 203 | if( filename == NULL && map != NULL) |
| 204 | filename = msTmpFile(map, map->mappath,NULL,pszExtension); |
| 205 | else if( filename == NULL ) |
| 206 | { |
| 207 | filename = msTmpFile(map, NULL, NULL, pszExtension ); |
| 208 | } |
| 209 |
no test coverage detected