@@ -364,16 +364,19 @@ bool LoadOtherPicture(const fs::path& file, std::shared_ptr<CMemoryBitmap>& rpBi
364364 <bool Monochrome, typename PixelType, std::invocable<const PixelType&> auto GetColours>
365365 (const uchar* pSrc)
366366 {
367+
367368 std::atomic_int loopCtr = 0 ;
368369#pragma omp parallel for shared(loopCtr) default(shared) if(numberOfProcessors > 1)
369370 for (int row = 0 ; row < height; ++row)
370371 {
372+ constexpr uchar pixelSize{ sizeof (PixelType) };
371373 const auto * pPixel = reinterpret_cast <const PixelType*>(pSrc + row * bytes_per_line);
372374 for (int col = 0 ; col < width; ++col, ++pPixel)
373375 {
374376 if constexpr (Monochrome)
375377 {
376- const auto grey = static_cast <double >(*pPixel);
378+ auto grey = static_cast <double >(*pPixel);
379+ if constexpr (2 == pixelSize) grey /= scaleFactorInt16;
377380 pBitmap->SetPixel (col, row, grey);
378381 }
379382 else
@@ -588,29 +591,16 @@ bool ApplyGammaTransformation(QImage* pImage, BitmapClass<T>* pInBitmap, DSS::Ga
588591 auto pImageData = pImage->bits ();
589592 auto bytes_per_line = pImage->bytesPerLine ();
590593
591- if (QImage::Format_RGB32 == pImage->format ())
594+ QImage::Format format{ pImage->format () };
595+
596+ switch (format)
597+ {
598+ case QImage::Format::Format_Grayscale8:
592599 {
593600#pragma omp parallel for default(shared) schedule(dynamic, 50) if(Multitask::GetNrProcessors() > 1) // Returns 1 if multithreading disabled by user, otherwise # HW threads
594601 for (int j = 0 ; j < height; j++)
595602 {
596- QRgb* pOutPixel = reinterpret_cast <QRgb*>(pImageData + (j * bytes_per_line));
597- if constexpr (std::is_same_v<BitmapClass<T>, CColorBitmapT<T>>)
598- {
599- // Init iterators
600- T* pRed = pInBitmap->GetRedPixel (0 , j);
601- T* pGreen = pInBitmap->GetGreenPixel (0 , j);
602- T* pBlue = pInBitmap->GetBluePixel (0 , j);
603-
604- for (int i = 0 ; i < width; i++)
605- {
606- *pOutPixel++ = qRgb (gammatrans.getTransformation (*pRed / fMultiplier ),
607- gammatrans.getTransformation (*pGreen / fMultiplier ),
608- gammatrans.getTransformation (*pBlue / fMultiplier ));
609- pRed++;
610- pGreen++;
611- pBlue++;
612- }
613- }
603+ T* pOutPixel = reinterpret_cast <T*>(pImageData + (j * bytes_per_line));
614604 if constexpr (std::is_same_v<BitmapClass<T>, CGrayBitmapT<T>>)
615605 {
616606 // Init iterators
@@ -620,52 +610,120 @@ bool ApplyGammaTransformation(QImage* pImage, BitmapClass<T>* pInBitmap, DSS::Ga
620610 for (int i = 0 ; i < width; i++)
621611 {
622612 value = gammatrans.getTransformation (*pGray / fMultiplier );
623- *pOutPixel++ = qRgb ( value, value, value) ;
613+ *pOutPixel++ = value;
624614 pGray++;
625615 }
626616 }
627617 }
628618 bResult = true ;
629619 }
630- else // Must be RGB64
631- {
632- #pragma omp parallel for default(shared) schedule(dynamic, 50) if(Multitask::GetNrProcessors() > 1) // Returns 1 if multithreading disabled by user, otherwise # HW threads
633- for (int j = 0 ; j < height; j++)
620+ break ;
621+ case QImage::Format::Format_Grayscale16:
634622 {
635- QRgba64* pOutPixel = reinterpret_cast <QRgba64*>(pImageData + (j * bytes_per_line));
636- if constexpr (std::is_same_v<BitmapClass<T>, CColorBitmapT<T>> )
623+ # pragma omp parallel for default(shared) schedule(dynamic, 50) if(Multitask::GetNrProcessors() > 1) // Returns 1 if multithreading disabled by user, otherwise # HW threads
624+ for ( int j = 0 ; j < height; j++ )
637625 {
638- // Init iterators
639- T* pRed = pInBitmap->GetRedPixel (0 , j);
640- T* pGreen = pInBitmap->GetGreenPixel (0 , j);
641- T* pBlue = pInBitmap->GetBluePixel (0 , j);
626+ T* pOutPixel = reinterpret_cast <T*>(pImageData + (j * bytes_per_line));
627+ if constexpr (std::is_same_v<BitmapClass<T>, CGrayBitmapT<T>>)
628+ {
629+ // Init iterators
630+ const T* pGray = pInBitmap->GetGrayPixel (0 , j);
631+ uint16_t value = 0 ;
642632
643- for (int i = 0 ; i < width; i++)
633+ for (int i = 0 ; i < width; i++)
634+ {
635+ value = gammatrans.getTransformation16 (*pGray / fMultiplier );
636+ *pOutPixel++ = value;
637+ pGray++;
638+ }
639+ }
640+ }
641+ bResult = true ;
642+ }
643+ break ;
644+ case QImage::Format::Format_RGB32:
645+ {
646+ #pragma omp parallel for default(shared) schedule(dynamic, 50) if(Multitask::GetNrProcessors() > 1) // Returns 1 if multithreading disabled by user, otherwise # HW threads
647+ for (int j = 0 ; j < height; j++)
648+ {
649+ QRgb* pOutPixel = reinterpret_cast <QRgb*>(pImageData + (j * bytes_per_line));
650+ if constexpr (std::is_same_v<BitmapClass<T>, CColorBitmapT<T>>)
644651 {
645- *pOutPixel++ = QRgba64::fromRgba64 (gammatrans.getTransformation16 (*pRed / fMultiplier ),
646- gammatrans.getTransformation16 (*pGreen / fMultiplier ),
647- gammatrans.getTransformation16 (*pBlue / fMultiplier ),
648- std::numeric_limits<uint16_t >::max ());
649- pRed++;
650- pGreen++;
651- pBlue++;
652+ // Init iterators
653+ T* pRed = pInBitmap->GetRedPixel (0 , j);
654+ T* pGreen = pInBitmap->GetGreenPixel (0 , j);
655+ T* pBlue = pInBitmap->GetBluePixel (0 , j);
656+
657+ for (int i = 0 ; i < width; i++)
658+ {
659+ *pOutPixel++ = qRgb (gammatrans.getTransformation (*pRed / fMultiplier ),
660+ gammatrans.getTransformation (*pGreen / fMultiplier ),
661+ gammatrans.getTransformation (*pBlue / fMultiplier ));
662+ pRed++;
663+ pGreen++;
664+ pBlue++;
665+ }
666+ }
667+ if constexpr (std::is_same_v<BitmapClass<T>, CGrayBitmapT<T>>)
668+ {
669+ // Init iterators
670+ const T* pGray = pInBitmap->GetGrayPixel (0 , j);
671+ unsigned char value = 0 ;
672+
673+ for (int i = 0 ; i < width; i++)
674+ {
675+ value = gammatrans.getTransformation (*pGray / fMultiplier );
676+ *pOutPixel++ = qRgb (value, value, value);
677+ pGray++;
678+ }
652679 }
653680 }
654- if constexpr (std::is_same_v<BitmapClass<T>, CGrayBitmapT<T>>)
681+ bResult = true ;
682+ }
683+ break ;
684+ case QImage::Format::Format_RGBA64:
685+ {
686+ #pragma omp parallel for default(shared)schedule(dynamic, 50) if (Multitask::GetNrProcessors() > 1) // Returns 1 if multithreading disabled by user, otherwise # HW threads
687+ for (int j = 0 ; j < height; j++)
655688 {
656- // Init iterators
657- const T* pGray = pInBitmap->GetGrayPixel (0 , j);
658- unsigned char value = 0 ;
689+ QRgba64* pOutPixel = reinterpret_cast <QRgba64*>(pImageData + (j * bytes_per_line));
690+ if constexpr (std::is_same_v<BitmapClass<T>, CColorBitmapT<T>>)
691+ {
692+ // Init iterators
693+ T* pRed = pInBitmap->GetRedPixel (0 , j);
694+ T* pGreen = pInBitmap->GetGreenPixel (0 , j);
695+ T* pBlue = pInBitmap->GetBluePixel (0 , j);
659696
660- for (int i = 0 ; i < width; i++)
697+ for (int i = 0 ; i < width; i++)
698+ {
699+ *pOutPixel++ = QRgba64::fromRgba64 (gammatrans.getTransformation16 (*pRed / fMultiplier ),
700+ gammatrans.getTransformation16 (*pGreen / fMultiplier ),
701+ gammatrans.getTransformation16 (*pBlue / fMultiplier ),
702+ std::numeric_limits<uint16_t >::max ());
703+ pRed++;
704+ pGreen++;
705+ pBlue++;
706+ }
707+ }
708+ if constexpr (std::is_same_v<BitmapClass<T>, CGrayBitmapT<T>>)
661709 {
662- value = gammatrans.getTransformation16 (*pGray / fMultiplier );
663- *pOutPixel++ = qRgba64 (value, value, value, std::numeric_limits<uint16_t >::max ());
664- pGray++;
710+ // Init iterators
711+ const T* pGray = pInBitmap->GetGrayPixel (0 , j);
712+ uint16_t value = 0 ;
713+
714+ for (int i = 0 ; i < width; i++)
715+ {
716+ value = gammatrans.getTransformation16 (*pGray / fMultiplier );
717+ *pOutPixel++ = qRgba64 (value, value, value, std::numeric_limits<uint16_t >::max ());
718+ pGray++;
719+ }
665720 }
666721 }
722+ bResult = true ;
667723 }
668- bResult = true ;
724+ break ;
725+ default :
726+ break ;
669727 }
670728 }
671729 return bResult;
0 commit comments