@@ -495,20 +495,16 @@ detail::StreamPtr opjCreateBufferInputStream(detail::OpjMemoryBuffer* buf)
495
495
496
496
// ///////////////////// Jpeg2KOpjDecoder ///////////////////
497
497
498
- Jpeg2KOpjDecoder::Jpeg2KOpjDecoder ()
498
+ namespace detail {
499
+
500
+ Jpeg2KOpjDecoderBase::Jpeg2KOpjDecoderBase (OPJ_CODEC_FORMAT format)
501
+ : format_(format)
499
502
{
500
- static const unsigned char signature[] = { 0 , 0 , 0 , 0x0c , ' j' , ' P' , ' ' , ' ' , 13 , 10 , 0x87 , 10 };
501
- m_signature = String ((const char *)(signature), sizeof (signature));
502
503
m_buf_supported = true ;
503
504
}
504
505
505
506
506
- ImageDecoder Jpeg2KOpjDecoder::newDecoder () const
507
- {
508
- return makePtr<Jpeg2KOpjDecoder>();
509
- }
510
-
511
- bool Jpeg2KOpjDecoder::readHeader ()
507
+ bool Jpeg2KOpjDecoderBase::readHeader ()
512
508
{
513
509
if (!m_buf.empty ()) {
514
510
opjBuf_ = detail::OpjMemoryBuffer (m_buf);
@@ -521,7 +517,7 @@ bool Jpeg2KOpjDecoder::readHeader()
521
517
if (!stream_)
522
518
return false ;
523
519
524
- codec_.reset (opj_create_decompress (OPJ_CODEC_JP2 ));
520
+ codec_.reset (opj_create_decompress (format_ ));
525
521
if (!codec_)
526
522
return false ;
527
523
@@ -587,7 +583,7 @@ bool Jpeg2KOpjDecoder::readHeader()
587
583
return true ;
588
584
}
589
585
590
- bool Jpeg2KOpjDecoder ::readData ( Mat& img )
586
+ bool Jpeg2KOpjDecoderBase ::readData ( Mat& img )
591
587
{
592
588
using DecodeFunc = bool (*)(const opj_image_t &, cv::Mat&, uint8_t shift);
593
589
@@ -606,7 +602,9 @@ bool Jpeg2KOpjDecoder::readData( Mat& img )
606
602
switch (image_->color_space )
607
603
{
608
604
case OPJ_CLRSPC_UNKNOWN:
609
- CV_LOG_WARNING (NULL , " OpenJPEG2000: Image has unknown color space, SRGB is assumed" );
605
+ /* FALLTHRU */
606
+ case OPJ_CLRSPC_UNSPECIFIED:
607
+ CV_LOG_WARNING (NULL , " OpenJPEG2000: Image has unknown or unspecified color space, SRGB is assumed" );
610
608
/* FALLTHRU */
611
609
case OPJ_CLRSPC_SRGB:
612
610
decode = decodeSRGBData;
@@ -617,8 +615,6 @@ bool Jpeg2KOpjDecoder::readData( Mat& img )
617
615
case OPJ_CLRSPC_SYCC:
618
616
decode = decodeSYCCData;
619
617
break ;
620
- case OPJ_CLRSPC_UNSPECIFIED:
621
- CV_Error (Error::StsNotImplemented, " OpenJPEG2000: Image has unspecified color space" );
622
618
default :
623
619
CV_Error (Error::StsNotImplemented,
624
620
cv::format (" OpenJPEG2000: Unsupported color space conversion: %s -> %s" ,
@@ -654,6 +650,31 @@ bool Jpeg2KOpjDecoder::readData( Mat& img )
654
650
return decode (*image_, img, shift);
655
651
}
656
652
653
+ } // namespace detail
654
+
655
+ Jpeg2KJP2OpjDecoder::Jpeg2KJP2OpjDecoder ()
656
+ : Jpeg2KOpjDecoderBase(OPJ_CODEC_JP2)
657
+ {
658
+ static const unsigned char JP2Signature[] = { 0 , 0 , 0 , 0x0c , ' j' , ' P' , ' ' , ' ' , 13 , 10 , 0x87 , 10 };
659
+ m_signature = String ((const char *) JP2Signature, sizeof (JP2Signature));
660
+ }
661
+
662
+ ImageDecoder Jpeg2KJP2OpjDecoder::newDecoder () const
663
+ {
664
+ return makePtr<Jpeg2KJP2OpjDecoder>();
665
+ }
666
+
667
+ Jpeg2KJ2KOpjDecoder::Jpeg2KJ2KOpjDecoder ()
668
+ : Jpeg2KOpjDecoderBase(OPJ_CODEC_J2K)
669
+ {
670
+ static const unsigned char J2KSignature[] = { 0xff , 0x4f , 0xff , 0x51 };
671
+ m_signature = String ((const char *) J2KSignature, sizeof (J2KSignature));
672
+ }
673
+
674
+ ImageDecoder Jpeg2KJ2KOpjDecoder::newDecoder () const
675
+ {
676
+ return makePtr<Jpeg2KJ2KOpjDecoder>();
677
+ }
657
678
658
679
// ///////////////////// Jpeg2KOpjEncoder ///////////////////
659
680
0 commit comments