Solved Pointer to QByteArray as LPBYTE
-
I am attempting to provide color management for my Qt image viewing app using the library lcms2. I have everything working except pulling the icc profile from a jpeg file. I have extracted the icc segment in a QByteArray called iccBuf.
lcms2 has a function:
cmsOpenProfileFromMem(const void * MemPtr, cmsUInt32Number dwSize);"Opens an ICC profile which is entirely contained in a memory block. Useful for accessing embedded profiles. MemPtr must point to a buffer of at least dwSize bytes. This buffer must hold a full profile image. Memory must be contiguous."
I have seen code that supplies the MemPtr parameter as a LPBYTE but I cannot convert the QByteArray address to LPBYTE. I have tried:
reinterpret_cast<const void*>(&(iccBuf).data()[0])
and
(unsigned char*)G::iccBuf.data()but these do not work.
It appears I need to convert char* to uchar*
Any advice would be greatly permitted.
Thanks in advance!
-
Hi,
What exact error are you getting ?
-
@sgaist The function cmsOpenProfileFromMem is returning a nullptr indicating failure.
Snippet:
QByteArray iccBuf; // load iccBuf with file icc data segment quint32 iccLen = iccBuf.length(); LPBYTE buf = (unsigned char*)iccBuf.data(); hInProfile = cmsOpenProfileFromMem(iccData, iccLen); // output from qDebug: iccBuf.data() = 0x7ff61053e5c0 buf = 0x1a2811400c8
-
I've no documentation for cmsOpenProfileFromMem() but how should it suppose to work when you pass a pointer to data with a length of zero?
-
@christian-ehrlicher Apologies - I quickly threw together the use case. The variable iccLen is defined in the code as the length of iccBuf. I have tweaked the code above to show this.
-
@rory_1 said in Pointer to QByteArray as LPBYTE:
The variable iccLen is defined in the code as the length of iccBuf.
... which is still zero since you have an empty QByteArray
-
@christian-ehrlicher Yes I know. I was trying to state in my comments that I obtained the byte array and was continuing. I agree that was not clear. I have solved the issue - my test jpg file had a non-compliant embedded profile.
Many thanks for taking the time to help!