Skip to content

Commit 22dfc1d

Browse files
committed
Merge pull request opencv#10051 from sturkmen72:upd_grfmt_gdal_cpp
2 parents 0a7c60b + e51a8e0 commit 22dfc1d

File tree

1 file changed

+7
-41
lines changed

1 file changed

+7
-41
lines changed

modules/imgcodecs/src/grfmt_gdal.cpp

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -104,66 +104,39 @@ int gdal2opencv( const GDALDataType& gdalType, const int& channels ){
104104

105105
/// UInt8
106106
case GDT_Byte:
107-
if( channels == 1 ){ return CV_8UC1; }
108-
if( channels == 3 ){ return CV_8UC3; }
109-
if( channels == 4 ){ return CV_8UC4; }
110-
else { return CV_8UC(channels); }
111-
return -1;
107+
return CV_8UC(channels);
112108

113109
/// UInt16
114110
case GDT_UInt16:
115-
if( channels == 1 ){ return CV_16UC1; }
116-
if( channels == 3 ){ return CV_16UC3; }
117-
if( channels == 4 ){ return CV_16UC4; }
118-
else { return CV_16UC(channels); }
119-
return -1;
111+
return CV_16UC(channels);
120112

121113
/// Int16
122114
case GDT_Int16:
123-
if( channels == 1 ){ return CV_16SC1; }
124-
if( channels == 3 ){ return CV_16SC3; }
125-
if( channels == 4 ){ return CV_16SC4; }
126-
else { return CV_16SC(channels); }
127-
return -1;
115+
return CV_16SC(channels);
128116

129117
/// UInt32
130118
case GDT_UInt32:
131119
case GDT_Int32:
132-
if( channels == 1 ){ return CV_32SC1; }
133-
if( channels == 3 ){ return CV_32SC3; }
134-
if( channels == 4 ){ return CV_32SC4; }
135-
else { return CV_32SC(channels); }
136-
return -1;
120+
return CV_32SC(channels);
137121

138122
case GDT_Float32:
139-
if( channels == 1 ){ return CV_32FC1; }
140-
if( channels == 3 ){ return CV_32FC3; }
141-
if( channels == 4 ){ return CV_32FC4; }
142-
else { return CV_32FC(channels); }
143-
return -1;
123+
return CV_32FC(channels);
144124

145125
case GDT_Float64:
146-
if( channels == 1 ){ return CV_64FC1; }
147-
if( channels == 3 ){ return CV_64FC3; }
148-
if( channels == 4 ){ return CV_64FC4; }
149-
else { return CV_64FC(channels); }
150-
return -1;
126+
return CV_64FC(channels);
151127

152128
default:
153129
std::cout << "Unknown GDAL Data Type" << std::endl;
154130
std::cout << "Type: " << GDALGetDataTypeName(gdalType) << std::endl;
155131
return -1;
156132
}
157-
158-
return -1;
159133
}
160134

161135
/**
162136
* GDAL Decoder Constructor
163137
*/
164138
GdalDecoder::GdalDecoder(){
165139

166-
167140
// set a dummy signature
168141
m_signature="0";
169142
for( size_t i=0; i<160; i++ ){
@@ -182,7 +155,6 @@ GdalDecoder::GdalDecoder(){
182155
*/
183156
GdalDecoder::~GdalDecoder(){
184157

185-
186158
if( m_dataset != NULL ){
187159
close();
188160
}
@@ -383,10 +355,7 @@ bool GdalDecoder::readData( Mat& img ){
383355

384356

385357
// make sure the image is the proper size
386-
if( img.size().height != m_height ){
387-
return false;
388-
}
389-
if( img.size().width != m_width ){
358+
if( img.size() != Size(m_width, m_height) ){
390359
return false;
391360
}
392361

@@ -398,7 +367,6 @@ bool GdalDecoder::readData( Mat& img ){
398367
// set the image to zero
399368
img = 0;
400369

401-
402370
// iterate over each raster band
403371
// note that OpenCV does bgr rather than rgb
404372
int nChannels = m_dataset->GetRasterCount();
@@ -452,8 +420,6 @@ bool GdalDecoder::readData( Mat& img ){
452420

453421
// delete our temp pointer
454422
delete [] scanline;
455-
456-
457423
}
458424

459425
return true;

0 commit comments

Comments
 (0)