Convert YCbCr to RGB
Moderator: Moderator Team
Convert YCbCr to RGB
I am trying to create a Windows DIB using createWindowsDIB. This works for LittleEndianImplicit, but not for JPEGLSLossless (as createWindowsDIB does not work if original YCbCr color model is retained).
How do I convert YCbCr to RGB?
(I have found the method DiYBRPixelTemplate< T1, T2 >::convert() in diybrpxt.h but I don´t manage how to use it.)
------------------------------------------------------
Here is my code:
STDMETHODIMP CDicomDataSet::CreateDIBFast(BYTE** pData, ULONG size, ULONG frame, SHORT bits, SHORT upsideDown, SHORT padding, ULONG* result)
{
DJDecoderRegistration::registerCodecs(); // register global JPEG decompression codecs
DJEncoderRegistration::registerCodecs(); // register global JPEG compression codecs
DcmRLEEncoderRegistration::registerCodecs(); // register RLE compression codec
DcmRLEDecoderRegistration::registerCodecs(); // register RLE decompression codec
DicomImage image(m_pData,m_pData->getOriginalXfer());
image.setMinMaxWindow();
InvertedPresentationFix(image);
*result = image.createWindowsDIB((void*&)(*pData),size, frame, bits, upsideDown, padding);
// deregister JPEG codecs
DJDecoderRegistration::cleanup();
DJEncoderRegistration::cleanup();
// deregister RLE codecs
DcmRLEDecoderRegistration::cleanup();
DcmRLEEncoderRegistration::cleanup();
return S_OK;
}
How do I convert YCbCr to RGB?
(I have found the method DiYBRPixelTemplate< T1, T2 >::convert() in diybrpxt.h but I don´t manage how to use it.)
------------------------------------------------------
Here is my code:
STDMETHODIMP CDicomDataSet::CreateDIBFast(BYTE** pData, ULONG size, ULONG frame, SHORT bits, SHORT upsideDown, SHORT padding, ULONG* result)
{
DJDecoderRegistration::registerCodecs(); // register global JPEG decompression codecs
DJEncoderRegistration::registerCodecs(); // register global JPEG compression codecs
DcmRLEEncoderRegistration::registerCodecs(); // register RLE compression codec
DcmRLEDecoderRegistration::registerCodecs(); // register RLE decompression codec
DicomImage image(m_pData,m_pData->getOriginalXfer());
image.setMinMaxWindow();
InvertedPresentationFix(image);
*result = image.createWindowsDIB((void*&)(*pData),size, frame, bits, upsideDown, padding);
// deregister JPEG codecs
DJDecoderRegistration::cleanup();
DJEncoderRegistration::cleanup();
// deregister RLE codecs
DcmRLEDecoderRegistration::cleanup();
DcmRLEEncoderRegistration::cleanup();
return S_OK;
}
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
-
- DCMTK Developer
- Posts: 2506
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
As I tried to explain in my previous posting: This is the default. So, if CIF_KeepYCbCrColorModel is not used in the DicomImage constructor, the internal representation is RGB (for color images) and createWindowsDIB() should work. Of course, you should always check whether the DICOM image could be processed at all (using getStatus()) and whether createWindowsDIB() was successful (see return value).
Btw, I don't think that it is a good idea to register and deregister the codecs for each images. This should be done only once for an application.
Btw, I don't think that it is a good idea to register and deregister the codecs for each images. This should be done only once for an application.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest