@@ -156,6 +156,9 @@ static const char *const mSupportedRasterFormats[] =
156
156
" GRASS" ,
157
157
" GTiff" ,
158
158
" HFA" ,
159
+ " JP2ECW" ,
160
+ " JP2KAK" ,
161
+ " JP2MrSID" ,
159
162
" JPEG2000" ,
160
163
" MrSID" ,
161
164
" SDTS" ,
@@ -201,8 +204,9 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
201
204
QStringList metadataTokens; // essentially the metadata string delimited by '='
202
205
203
206
QString catchallFilter; // for Any file(*.*), but also for those
204
- // drivers with no specific file
205
- // filter
207
+ // drivers with no specific file filter
208
+
209
+ GDALDriver *jp2Driver = NULL ; // first JPEG2000 driver found
206
210
207
211
// Grind through all the drivers and their respective metadata.
208
212
// We'll add a file filter for those drivers that have a file
@@ -279,6 +283,17 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
279
283
{
280
284
// XXX add check for SDTS; in that case we want (*CATD.DDF)
281
285
QString glob = " *." + myGdalDriverExtension;
286
+ // Add only the first JP2 driver found to the filter list (it's the one GDAL uses)
287
+ if (myGdalDriverDescription == " JPEG2000" ||
288
+ myGdalDriverDescription.startsWith (" JP2" )) // JP2ECW, JP2KAK, JP2MrSID
289
+ {
290
+ if (!jp2Driver)
291
+ {
292
+ jp2Driver = myGdalDriver; // first JP2 driver found
293
+ glob += " *.j2k" ; // add alternate extension
294
+ }
295
+ else break ; // skip if already found a JP2 driver
296
+ }
282
297
theFileFiltersString += myGdalDriverLongName + " (" + glob.lower () + " " + glob.upper () + " );;" ;
283
298
284
299
break ; // ... to next driver, if any.
@@ -324,16 +339,6 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
324
339
catchallFilter += QString (myGdalDriver->GetDescription ()) + " " ;
325
340
}
326
341
}
327
-
328
- // A number of drivers support JPEG 2000. Add it in for those.
329
- if ( myGdalDriverDescription.startsWith (" MrSID" )
330
- || myGdalDriverDescription.startsWith (" ECW" )
331
- || myGdalDriverDescription.startsWith (" JPEG2000" )
332
- || myGdalDriverDescription.startsWith (" JP2KAK" ) )
333
- {
334
- QString glob = " *.jp2 *.j2k" ;
335
- theFileFiltersString += " JPEG 2000 (" + glob.lower () + " " + glob.upper () + " );;" ;
336
- }
337
342
338
343
myGdalDriverExtension = myGdalDriverLongName = " " ; // reset for next driver
339
344
0 commit comments