dibtools.cxx (2f62c77d) dibtools.cxx (3aedac3e)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 376 unchanged lines hidden (view full) ---

385 }
386 }
387 }
388 while ( !bEndDecoding && ( nY >= 0L ) );
389}
390
391bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& rAcc, BitmapWriteAccess* pAccAlpha, bool bTopDown, bool& rAlphaUsed)
392{
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 376 unchanged lines hidden (view full) ---

385 }
386 }
387 }
388 while ( !bEndDecoding && ( nY >= 0L ) );
389}
390
391bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& rAcc, BitmapWriteAccess* pAccAlpha, bool bTopDown, bool& rAlphaUsed)
392{
393 const sal_uLong nAlignedWidth = AlignedWidth4Bytes(rHeader.nWidth * rHeader.nBitCount);
393 const sal_Int64 nBitsPerLine (static_cast<sal_Int64>(rHeader.nWidth) * static_cast<sal_Int64>(rHeader.nBitCount));
394 if (nBitsPerLine > SAL_MAX_UINT32)
395 return false;
396
397 const sal_uLong nAlignedWidth = AlignedWidth4Bytes(static_cast<sal_uLong>(nBitsPerLine));
394 sal_uInt32 nRMask(( rHeader.nBitCount == 16 ) ? 0x00007c00UL : 0x00ff0000UL);
395 sal_uInt32 nGMask(( rHeader.nBitCount == 16 ) ? 0x000003e0UL : 0x0000ff00UL);
396 sal_uInt32 nBMask(( rHeader.nBitCount == 16 ) ? 0x0000001fUL : 0x000000ffUL);
397 bool bNative(false);
398 bool bTCMask(!pAccAlpha && ((16 == rHeader.nBitCount) || (32 == rHeader.nBitCount)));
399 bool bRLE((RLE_8 == rHeader.nCompression && 8 == rHeader.nBitCount) || (RLE_4 == rHeader.nCompression && 4 == rHeader.nBitCount));
400
401 // Is native format?

--- 209 unchanged lines hidden (view full) ---

611{
612 DIBV5Header aHeader;
613 const sal_uLong nStmPos = rIStm.Tell();
614 bool bRet(false);
615 bool bTopDown(false);
616
617 if(ImplReadDIBInfoHeader(rIStm, aHeader, bTopDown) && aHeader.nWidth && aHeader.nHeight && aHeader.nBitCount)
618 {
398 sal_uInt32 nRMask(( rHeader.nBitCount == 16 ) ? 0x00007c00UL : 0x00ff0000UL);
399 sal_uInt32 nGMask(( rHeader.nBitCount == 16 ) ? 0x000003e0UL : 0x0000ff00UL);
400 sal_uInt32 nBMask(( rHeader.nBitCount == 16 ) ? 0x0000001fUL : 0x000000ffUL);
401 bool bNative(false);
402 bool bTCMask(!pAccAlpha && ((16 == rHeader.nBitCount) || (32 == rHeader.nBitCount)));
403 bool bRLE((RLE_8 == rHeader.nCompression && 8 == rHeader.nBitCount) || (RLE_4 == rHeader.nCompression && 4 == rHeader.nBitCount));
404
405 // Is native format?

--- 209 unchanged lines hidden (view full) ---

615{
616 DIBV5Header aHeader;
617 const sal_uLong nStmPos = rIStm.Tell();
618 bool bRet(false);
619 bool bTopDown(false);
620
621 if(ImplReadDIBInfoHeader(rIStm, aHeader, bTopDown) && aHeader.nWidth && aHeader.nHeight && aHeader.nBitCount)
622 {
623 if (aHeader.nSize > nOffset)
624 {
625 // Header size claims to extend into the image data.
626 // Looks like an error.
627 return false;
628 }
629
619 const sal_uInt16 nBitCount(discretizeBitcount(aHeader.nBitCount));
620 const Size aSizePixel(aHeader.nWidth, aHeader.nHeight);
621 BitmapPalette aDummyPal;
622 Bitmap aNewBmp(aSizePixel, nBitCount, &aDummyPal);
623 Bitmap aNewBmpAlpha;
624 BitmapWriteAccess* pAcc = aNewBmp.AcquireWriteAccess();
625 BitmapWriteAccess* pAccAlpha = 0;
626 bool bAlphaPossible(pBmpAlpha && aHeader.nBitCount == 32);

--- 136 unchanged lines hidden (view full) ---

763}
764
765bool ImplReadDIBFileHeader( SvStream& rIStm, sal_uLong& rOffset )
766{
767 sal_uInt32 nTmp32;
768 sal_uInt16 nTmp16 = 0;
769 bool bRet = false;
770
630 const sal_uInt16 nBitCount(discretizeBitcount(aHeader.nBitCount));
631 const Size aSizePixel(aHeader.nWidth, aHeader.nHeight);
632 BitmapPalette aDummyPal;
633 Bitmap aNewBmp(aSizePixel, nBitCount, &aDummyPal);
634 Bitmap aNewBmpAlpha;
635 BitmapWriteAccess* pAcc = aNewBmp.AcquireWriteAccess();
636 BitmapWriteAccess* pAccAlpha = 0;
637 bool bAlphaPossible(pBmpAlpha && aHeader.nBitCount == 32);

--- 136 unchanged lines hidden (view full) ---

774}
775
776bool ImplReadDIBFileHeader( SvStream& rIStm, sal_uLong& rOffset )
777{
778 sal_uInt32 nTmp32;
779 sal_uInt16 nTmp16 = 0;
780 bool bRet = false;
781
782 const sal_Int64 nStreamLength (rIStm.Seek(STREAM_SEEK_TO_END));
783 rIStm.Seek(STREAM_SEEK_TO_BEGIN);
784
771 rIStm >> nTmp16;
772
773 if ( ( 0x4D42 == nTmp16 ) || ( 0x4142 == nTmp16 ) )
774 {
775 if ( 0x4142 == nTmp16 )
776 {
777 rIStm.SeekRel( 12L );
778 rIStm >> nTmp16;

--- 4 unchanged lines hidden (view full) ---

783 }
784 else // 0x4D42 == nTmp16, 'MB' from BITMAPFILEHEADER
785 {
786 rIStm.SeekRel( 8L ); // we are on bfSize member of BITMAPFILEHEADER, forward to bfOffBits
787 rIStm >> nTmp32; // read bfOffBits
788 rOffset = nTmp32 - 14UL; // adapt offset by sizeof(BITMAPFILEHEADER)
789 bRet = ( rIStm.GetError() == 0UL );
790 }
785 rIStm >> nTmp16;
786
787 if ( ( 0x4D42 == nTmp16 ) || ( 0x4142 == nTmp16 ) )
788 {
789 if ( 0x4142 == nTmp16 )
790 {
791 rIStm.SeekRel( 12L );
792 rIStm >> nTmp16;

--- 4 unchanged lines hidden (view full) ---

797 }
798 else // 0x4D42 == nTmp16, 'MB' from BITMAPFILEHEADER
799 {
800 rIStm.SeekRel( 8L ); // we are on bfSize member of BITMAPFILEHEADER, forward to bfOffBits
801 rIStm >> nTmp32; // read bfOffBits
802 rOffset = nTmp32 - 14UL; // adapt offset by sizeof(BITMAPFILEHEADER)
803 bRet = ( rIStm.GetError() == 0UL );
804 }
805
806 if (rOffset >= nStreamLength)
807 {
808 // Offset claims that image starts past the end of the
809 // stream. Unlikely.
810 rIStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
811 bRet = false;
812 }
791 }
792 else
793 rIStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
794
795 return bRet;
796}
797
798bool ImplWriteDIBPalette( SvStream& rOStm, BitmapReadAccess& rAcc )

--- 783 unchanged lines hidden ---
813 }
814 else
815 rIStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
816
817 return bRet;
818}
819
820bool ImplWriteDIBPalette( SvStream& rOStm, BitmapReadAccess& rAcc )

--- 783 unchanged lines hidden ---