- }
- else if ( bpp == 24 )
- {
- stream.Read(bbuf, 3);
- linepos += 3;
- ptr[poffset ] = (unsigned char)bbuf[2];
- ptr[poffset + 1] = (unsigned char)bbuf[1];
- ptr[poffset + 2] = (unsigned char)bbuf[0];
- column++;
- }
- else if ( bpp == 16 )
- {
- unsigned char temp;
- stream.Read(&aWord, 2);
- aWord = wxUINT16_SWAP_ON_BE(aWord);
- linepos += 2;
- temp = (aWord & rmask) >> rshift;
- ptr[poffset] = temp;
- temp = (aWord & gmask) >> gshift;
- ptr[poffset + 1] = temp;
- temp = (aWord & bmask) >> bshift;
- 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.IsOk();
+ }
+ else if ( bpp == 24 )
+ {
+ stream.Read(bbuf, 3);
+ linepos += 3;
+ ptr[poffset ] = (unsigned char)bbuf[2];
+ ptr[poffset + 1] = (unsigned char)bbuf[1];
+ ptr[poffset + 2] = (unsigned char)bbuf[0];
+ column++;
+ }
+ else if ( bpp == 16 )
+ {
+ unsigned char temp;
+ stream.Read(&aWord, 2);
+ aWord = wxUINT16_SWAP_ON_BE(aWord);
+ linepos += 2;
+ /* Use the masks and calculated amount of shift
+ to retrieve the color data out of the word. Then
+ shift it left by (8 - number of bits) such that
+ the image has the proper dynamic range */
+ 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;
+ stream.Read(&aDword, 4);
+ 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;
+ }
+ column++;
+ }
+ }
+ while ( (linepos < linesize) && (comp != 1) && (comp != 2) )
+ {
+ stream.Read(&aByte, 1);
+ linepos += 1;
+ if ( !stream )
+ break;
+ }
+ }
+
+ image->SetMask(false);
+
+ const wxStreamError err = stream.GetLastError();
+ return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;