- temp = (aWord & rmask) >> rshift << (8-rbits);
- ptr[poffset] = temp;
- temp = (aWord & gmask) >> gshift << (8-gbits);
- ptr[poffset + 1] = temp;
- temp = (aWord & bmask) >> bshift << (8-bbits);
- ptr[poffset + 2] = temp;
- column++;
- }
- else
- {
- unsigned char temp;
- stream.Read(&aDword, 4);
- aDword = wxINT32_SWAP_ON_BE(aDword);
- linepos += 4;
- temp = (aDword & rmask) >> rshift;
- ptr[poffset] = temp;
- temp = (aDword & gmask) >> gshift;
- ptr[poffset + 1] = temp;
- temp = (aDword & bmask) >> bshift;
- ptr[poffset + 2] = temp;
- column++;
- }
- }
- while ( (linepos < linesize) && (comp != 1) && (comp != 2) )
- {
- stream.Read(&aByte, 1);
- linepos += 1;
- if ( stream.LastError() != wxStream_NOERROR )
- break;
- }
- }
- if (cmap)
- delete[] cmap;
-
- image->SetMask(FALSE);
-
- return ( stream.LastError() == wxSTREAM_NO_ERROR || stream.LastError() == wxSTREAM_EOF );
+ temp = (unsigned char)(((aWord & rmask) >> rshift) << (8-rbits));
+ ptr[poffset] = temp;
+ temp = (unsigned char)(((aWord & gmask) >> gshift) << (8-gbits));
+ ptr[poffset + 1] = temp;
+ temp = (unsigned char)(((aWord & bmask) >> bshift) << (8-bbits));
+ ptr[poffset + 2] = temp;
+ column++;
+ }
+ else
+ {
+ unsigned char temp;
+ if ( !stream.ReadAll(&aDword, 4) )
+ return false;
+
+ aDword = wxINT32_SWAP_ON_BE(aDword);
+ linepos += 4;
+ temp = (unsigned char)((aDword & rmask) >> rshift);
+ ptr[poffset] = temp;
+ temp = (unsigned char)((aDword & gmask) >> gshift);
+ ptr[poffset + 1] = temp;
+ temp = (unsigned char)((aDword & bmask) >> bshift);
+ ptr[poffset + 2] = temp;
+ if ( alpha )
+ {
+ temp = (unsigned char)((aDword & amask) >> ashift);
+ alpha[line * width + column] = temp;
+
+ if ( temp != wxALPHA_TRANSPARENT )
+ hasValidAlpha = true;
+ }
+ column++;
+ }
+ }
+ while ( (linepos < linesize) && (comp != 1) && (comp != 2) )
+ {
+ ++linepos;
+ if ( !stream.ReadAll(&aByte, 1) )
+ break;
+ }
+ }
+
+ image->SetMask(false);
+
+ // check if we had any valid alpha values in this bitmap
+ if ( alpha && !hasValidAlpha )
+ {
+ // we didn't, so finally discard the alpha channel completely
+ image->ClearAlpha();
+ }
+
+ const wxStreamError err = stream.GetLastError();
+ return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;