From f770266250c0ed2ecdd9cdbfd6381b95bc947ef9 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 27 Jun 2018 14:14:22 +0100 Subject: [PATCH] Fix bug in gray images with more than 8 bits --- app/ViewArea.cpp | 2 +- lib/CalypFrame.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/ViewArea.cpp b/app/ViewArea.cpp index ee06297..930fcd9 100644 --- a/app/ViewArea.cpp +++ b/app/ViewArea.cpp @@ -76,7 +76,7 @@ void ViewArea::setImage( CalypFrame* pcFrame ) m_uiPixelHalfScale = 1 << ( m_pcCurrFrame->getBitsPel() - 1 ); m_pcCurrFrame->fillRGBBuffer(); QImage qimg = QImage( m_pcCurrFrame->getRGBBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), - QImage::Format_RGB32 ); + QImage::Format_ARGB32 ); setImage( QPixmap::fromImage( qimg ) ); } diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index bd8cbf3..cf923ad 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -685,14 +685,17 @@ void CalypFrame::fillRGBBuffer() if( d->m_bHasRGBPel ) return; int shiftBits = d->m_uiBitsPel - 8; - unsigned int* pARGB = (unsigned int*)d->m_pcARGB32; + + // 4 bytes for A, R, G and B + uint32_t* pARGB = (uint32_t*)d->m_pcARGB32; if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY ) { ClpPel* pY = d->m_pppcInputPel[CLP_LUMA][0]; + unsigned char finalPel; for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ ) { - *pARGB++ = PEL_RGB( *pY, *pY, *pY ); - pY++; + finalPel = (*pY++) >> shiftBits; + *pARGB++ = PEL_RGB( finalPel, finalPel, finalPel ); } } else if( d->m_pcPelFormat->colorSpace == CLP_COLOR_RGB ) @@ -722,8 +725,8 @@ void CalypFrame::fillRGBBuffer() ClpPel* pU; ClpPel* pV; int iY, iU, iV, iR, iG, iB; - unsigned int* pARGBLine = pARGB; - unsigned int* pARGB; + uint32_t* pARGBLine = pARGB; + uint32_t* pARGBAux; unsigned int y, x; int i, j; @@ -734,7 +737,7 @@ void CalypFrame::fillRGBBuffer() pY = pLineY; pU = pLineU; pV = pLineV; - pARGB = pARGBLine; + pARGBAux = pARGBLine; for( x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) { iU = *pU++; @@ -746,7 +749,7 @@ void CalypFrame::fillRGBBuffer() iY = *pY++; iY >>= shiftBits; YUV2RGB( iY, iU, iV, iR, iG, iB ); - *pARGB++ = PEL_RGB( iR, iG, iB ); + *pARGBAux++ = PEL_RGB( iR, iG, iB ); } } pLineY += d->m_uiWidth;