mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 03:30:34 +08:00
Merge pull request #18325 from alalek:issue_18166
This commit is contained in:
commit
9f69ca503a
@ -189,7 +189,19 @@ struct ImageCodecInitializer
|
||||
std::vector<ImageEncoder> encoders;
|
||||
};
|
||||
|
||||
static ImageCodecInitializer codecs;
|
||||
static
|
||||
ImageCodecInitializer& getCodecs()
|
||||
{
|
||||
#ifdef CV_CXX11
|
||||
static ImageCodecInitializer g_codecs;
|
||||
return g_codecs;
|
||||
#else
|
||||
// C++98 doesn't guarantee correctness of multi-threaded initialization of static global variables
|
||||
// (memory leak here is not critical, use C++11 to avoid that)
|
||||
static ImageCodecInitializer* g_codecs = new ImageCodecInitializer();
|
||||
return *g_codecs;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the decoders
|
||||
@ -203,6 +215,7 @@ static ImageDecoder findDecoder( const String& filename ) {
|
||||
size_t i, maxlen = 0;
|
||||
|
||||
/// iterate through list of registered codecs
|
||||
ImageCodecInitializer& codecs = getCodecs();
|
||||
for( i = 0; i < codecs.decoders.size(); i++ )
|
||||
{
|
||||
size_t len = codecs.decoders[i]->signatureLength();
|
||||
@ -240,6 +253,7 @@ static ImageDecoder findDecoder( const Mat& buf )
|
||||
if( buf.rows*buf.cols < 1 || !buf.isContinuous() )
|
||||
return ImageDecoder();
|
||||
|
||||
ImageCodecInitializer& codecs = getCodecs();
|
||||
for( i = 0; i < codecs.decoders.size(); i++ )
|
||||
{
|
||||
size_t len = codecs.decoders[i]->signatureLength();
|
||||
@ -272,6 +286,7 @@ static ImageEncoder findEncoder( const String& _ext )
|
||||
for( ext++; len < 128 && isalnum(ext[len]); len++ )
|
||||
;
|
||||
|
||||
ImageCodecInitializer& codecs = getCodecs();
|
||||
for( size_t i = 0; i < codecs.encoders.size(); i++ )
|
||||
{
|
||||
String description = codecs.encoders[i]->getDescription();
|
||||
|
Loading…
Reference in New Issue
Block a user