Am 11.06.11 19:53 schrieb(en) Oliver Eichler:
The attached trivial fix solves the WMS issue for me, no idea if it has other harmful effects. The *really* clean (but *really* slow) way is probably to read all four bands and to construct qrgba() pixels.Right, I always have a bad feeling when accessing the bitmap buffer this way. But it's the only fast way.
To make things more robust, we could actually /calculate/ the real offset from a sample pixel. This fixes the endianess issue and would make the code immune against any changes within Qt and/or GDAL (see attached patch). The extra overhead should be negligible. More nitpicking: drop the assumption that a QRgb is 4 bytes, but use sizeof(), just if any compiler thinks an 'unsigned int' should be 64 bits... Best, Albrecht.
Index: src/CMapGeoTiff.cpp
===================================================================
--- src/CMapGeoTiff.cpp (Revision 2819)
+++ src/CMapGeoTiff.cpp (Arbeitskopie)
@@ -308,6 +308,7 @@ void CMapGeoTiff::draw()
QVector<quint8> buffer(w*h);
img.fill(qRgba(255,255,255,255));
+ QRgb testPix = qRgba(GCI_RedBand, GCI_GreenBand, GCI_BlueBand, GCI_AlphaBand);
for(int b = 1; b <= rasterBandCount; ++b)
{
@@ -319,21 +320,15 @@ void CMapGeoTiff::draw()
if(!err)
{
- int offset;
- switch(pBand->GetColorInterpretation())
- {
- case GCI_RedBand: offset = 2; break;
- case GCI_GreenBand: offset = 1; break;
- case GCI_BlueBand: offset = 0; break;
- case GCI_AlphaBand: offset = 3; break;
- default: offset = -1;
- }
+ int pbandColour = pBand->GetColorInterpretation();
+ unsigned int offset;
- if(offset >= 0 && offset <= 3)
+ for (offset = 0;
+ offset < sizeof(testPix) && *(((quint8 *)&testPix) + offset) != pbandColour;
+ offset++);
+
+ if(offset < sizeof(testPix))
{
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- offset = 3 - offset;
-#endif
quint8 * pTar = img.bits() + offset;
quint8 * pSrc = buffer.data();
const int size = buffer.size();
@@ -341,7 +336,7 @@ void CMapGeoTiff::draw()
for(int i = 0; i < size; ++i)
{
*pTar = *pSrc;
- pTar += 4;
+ pTar += sizeof(testPix);
pSrc += 1;
}
}
pgpHalr1nUPch.pgp
Description: PGP signature
------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________ Qlandkartegt-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users
