@@ -264,6 +264,7 @@ static void validateCinema(const std::string& arg, uint16_t profile, grk_cparame
264264 parameters->numgbits = (profile == GRK_PROFILE_CINEMA_2K) ? 1 : 2 ;
265265}
266266
267+ template <typename T>
267268static grk_image* loadInputImage (const char * filename, grk_cparameters* parameters)
268269{
269270 grk_image* image = nullptr ;
@@ -278,47 +279,47 @@ static grk_image* loadInputImage(const char* filename, grk_cparameters* paramete
278279 switch (fmt)
279280 {
280281 case GRK_FMT_PGX: {
281- PGXFormat<int32_t > pgx;
282+ PGXFormat<T > pgx;
282283 image = pgx.readImage (filename, parameters);
283284 }
284285 break ;
285286 case GRK_FMT_PXM: {
286- PNMFormat<int32_t > pnm (false );
287+ PNMFormat<T > pnm (false );
287288 image = pnm.readImage (filename, parameters);
288289 }
289290 break ;
290291 case GRK_FMT_BMP: {
291- BMPFormat<int32_t > bmp;
292+ BMPFormat<T > bmp;
292293 image = bmp.readImage (filename, parameters);
293294 }
294295 break ;
295296#ifdef GROK_HAVE_LIBTIFF
296297 case GRK_FMT_TIF: {
297- TIFFFormat<int32_t > tif;
298+ TIFFFormat<T > tif;
298299 image = tif.readImage (filename, parameters);
299300 }
300301 break ;
301302#endif
302303 case GRK_FMT_RAW: {
303- RAWFormat<int32_t > raw (true );
304+ RAWFormat<T > raw (true );
304305 image = raw.readImage (filename, parameters);
305306 }
306307 break ;
307308 case GRK_FMT_RAWL: {
308- RAWFormat<int32_t > raw (false );
309+ RAWFormat<T > raw (false );
309310 image = raw.readImage (filename, parameters);
310311 }
311312 break ;
312313#ifdef GROK_HAVE_LIBPNG
313314 case GRK_FMT_PNG: {
314- PNGFormat<int32_t > png;
315+ PNGFormat<T > png;
315316 image = png.readImage (filename, parameters);
316317 }
317318 break ;
318319#endif
319320#ifdef GROK_HAVE_LIBJPEG
320321 case GRK_FMT_JPG: {
321- JPEGFormat<int32_t > jpeg;
322+ JPEGFormat<T > jpeg;
322323 image = jpeg.readImage (filename, parameters);
323324 }
324325 break ;
@@ -400,7 +401,8 @@ int GrkCompress::main(int argc, const char** argv, grk_image* in_image, grk_stre
400401 initParams.parameters .rate_control_algorithm = rate_control_algorithm;
401402 initParams.parameters .decod_format = GRK_FMT_UNK;
402403
403- grk_image* image = loadInputImage (filePath.string ().c_str (), &initParams.parameters );
404+ grk_image* image =
405+ loadInputImage<int32_t >(filePath.string ().c_str (), &initParams.parameters );
404406 if (!image)
405407 {
406408 spdlog::warn (" Skipping unreadable file: {}" , filePath.filename ().string ());
@@ -2070,102 +2072,11 @@ static uint64_t pluginCompressCallback(grk_plugin_compress_user_callback_info* i
20702072 }
20712073 }
20722074 /* decode the source image */
2073- switch (info->compressor_parameters ->decod_format )
2075+ image = loadInputImage<int32_t >(info->input_file_name , info->compressor_parameters );
2076+ if (!image)
20742077 {
2075- case GRK_FMT_PGX: {
2076- PGXFormat<int32_t > pgx;
2077- image = pgx.readImage (info->input_file_name , info->compressor_parameters );
2078- if (!image)
2079- {
2080- spdlog::error (" Unable to load pgx file" );
2081- goto cleanup;
2082- }
2083- }
2084- break ;
2085-
2086- case GRK_FMT_PXM: {
2087- PNMFormat<int32_t > pnm (false );
2088- image = pnm.readImage (info->input_file_name , info->compressor_parameters );
2089- if (!image)
2090- {
2091- spdlog::error (" Unable to load pnm file" );
2092- goto cleanup;
2093- }
2094- }
2095- break ;
2096-
2097- case GRK_FMT_BMP: {
2098- BMPFormat<int32_t > bmp;
2099- image = bmp.readImage (info->input_file_name , info->compressor_parameters );
2100- if (!image)
2101- {
2102- spdlog::error (" Unable to load bmp file" );
2103- goto cleanup;
2104- }
2105- }
2106- break ;
2107-
2108- #ifdef GROK_HAVE_LIBTIFF
2109- case GRK_FMT_TIF: {
2110- TIFFFormat<int32_t > tif;
2111- image = tif.readImage (info->input_file_name , info->compressor_parameters );
2112- if (!image)
2113- goto cleanup;
2114- }
2115- break ;
2116- #endif /* GROK_HAVE_LIBTIFF */
2117-
2118- case GRK_FMT_RAW: {
2119- RAWFormat<int32_t > raw (true );
2120- image = raw.readImage (info->input_file_name , info->compressor_parameters );
2121- if (!image)
2122- {
2123- spdlog::error (" Unable to load raw file" );
2124- goto cleanup;
2125- }
2126- }
2127- break ;
2128-
2129- case GRK_FMT_RAWL: {
2130- RAWFormat<int32_t > raw (false );
2131- image = raw.readImage (info->input_file_name , info->compressor_parameters );
2132- if (!image)
2133- {
2134- spdlog::error (" Unable to load raw file" );
2135- goto cleanup;
2136- }
2137- }
2138- break ;
2139-
2140- #ifdef GROK_HAVE_LIBPNG
2141- case GRK_FMT_PNG: {
2142- PNGFormat<int32_t > png;
2143- image = png.readImage (info->input_file_name , info->compressor_parameters );
2144- if (!image)
2145- {
2146- spdlog::error (" Unable to load png file" );
2147- goto cleanup;
2148- }
2149- }
2150- break ;
2151- #endif /* GROK_HAVE_LIBPNG */
2152-
2153- #ifdef GROK_HAVE_LIBJPEG
2154- case GRK_FMT_JPG: {
2155- JPEGFormat<int32_t > jpeg;
2156- image = jpeg.readImage (info->input_file_name , info->compressor_parameters );
2157- if (!image)
2158- {
2159- spdlog::error (" Unable to load jpeg file" );
2160- goto cleanup;
2161- }
2162- }
2163- break ;
2164- #endif /* GROK_HAVE_LIBPNG */
2165- default :
2166- spdlog::error (" Input file format {} is not supported" ,
2167- convertFileFmtToString (info->compressor_parameters ->decod_format ));
2168- goto cleanup;
2078+ spdlog::error (" Unable to load input file" );
2079+ goto cleanup;
21692080 }
21702081
21712082 /* Can happen if input file is TIFF or PNG
0 commit comments