diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-07-27 11:47:43 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-07-27 12:27:24 +0100 |
commit | 2346f0d15822f9226cbb7e3cf2d63824bc26d817 (patch) | |
tree | 1b13b273b40e1174e62ccf693c679df85c4a8202 /svtools | |
parent | add some more tiff tests (diff) | |
download | core-2346f0d15822f9226cbb7e3cf2d63824bc26d817.tar.gz core-2346f0d15822f9226cbb7e3cf2d63824bc26d817.zip |
merge the two pict/pct detectors which disagree together
Change-Id: I63fc63884e3377f2707d99e7e85ab6761d37cd0a
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/filter/filter.cxx | 83 | ||||
-rw-r--r-- | svtools/source/filter/filter2.cxx | 23 | ||||
-rw-r--r-- | svtools/source/misc/imagemgr.cxx | 1 |
3 files changed, 50 insertions, 57 deletions
diff --git a/svtools/source/filter/filter.cxx b/svtools/source/filter/filter.cxx index aebb2d5c6d8e..217f9a207c1e 100644 --- a/svtools/source/filter/filter.cxx +++ b/svtools/source/filter/filter.cxx @@ -198,6 +198,44 @@ inline String ImpGetExtension( const String &rPath ) return aExt; } +bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen) +{ + sal_uInt8 sBuf[3]; + // store number format + sal_uInt16 oldNumberFormat = rStream.GetNumberFormatInt(); + sal_uInt32 nOffset; // in ms documents the pict format is used without the first 512 bytes + for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 ) + { + short y1,x1,y2,x2; + sal_Bool bdBoxOk = sal_True; + + rStream.Seek( nStreamPos + nOffset); + // size of the pict in version 1 pict ( 2bytes) : ignored + rStream.SeekRel(2); + // bounding box (bytes 2 -> 9) + rStream.SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); + rStream >> y1 >> x1 >> y2 >> x2; + rStream.SetNumberFormatInt(oldNumberFormat); // reset format + + if (x1 > x2 || y1 > y2 || // bad bdbox + (x1 == x2 && y1 == y2) || // 1 pixel picture + x2-x1 > 2048 || y2-y1 > 2048 ) // picture anormaly big + bdBoxOk = sal_False; + + // read version op + rStream.Read( sBuf,3 ); + // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf + // normal version 2 - page A23 and A24 + if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02) + return true; + // normal version 1 - page A25 + else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk) + return true; + } + return false; +} + + /************************************************************************* |* |* ImpPeekGraphicFormat() @@ -533,49 +571,10 @@ static sal_Bool ImpPeekGraphicFormat( SvStream& rStream, String& rFormatExtensio if( !bTest || ( rFormatExtension.CompareToAscii( "PCT", 3 ) == COMPARE_EQUAL ) ) { bSomethingTested = sal_True; - sal_uInt8 sBuf[3]; - // store number format - sal_uInt16 oldNumberFormat = rStream.GetNumberFormatInt(); - sal_uInt32 nOffset; // in ms documents the pict format is used without the first 512 bytes - for ( nOffset = 0; ( nOffset <= 512 ) && ( ( nStreamPos + nOffset + 14 ) <= nStreamLen ); nOffset += 512 ) + if (isPCT(rStream, nStreamPos, nStreamLen)) { - short y1,x1,y2,x2; - sal_Bool bdBoxOk = sal_True; - - rStream.Seek( nStreamPos + nOffset); - // size of the pict in version 1 pict ( 2bytes) : ignored - rStream.SeekRel(2); - // bounding box (bytes 2 -> 9) - rStream.SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); - rStream >> y1 >> x1 >> y2 >> x2; - rStream.SetNumberFormatInt(oldNumberFormat); // reset format - - if (x1 > x2 || y1 > y2 || // bad bdbox - (x1 == x2 && y1 == y2) || // 1 pixel picture - x2-x1 > 2048 || y2-y1 > 2048 ) // picture anormaly big - bdBoxOk = sal_False; - - // read version op - rStream.Read( sBuf,3 ); - // see http://developer.apple.com/legacy/mac/library/documentation/mac/pdf/Imaging_With_QuickDraw/Appendix_A.pdf - // normal version 2 - page A23 and A24 - if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x02) - { - rFormatExtension = rtl::OUString("PCT"); - return sal_True; - } - // normal version 1 - page A25 - else if (sBuf[ 0 ] == 0x11 && sBuf[ 1 ] == 0x01 && bdBoxOk) { - rFormatExtension = rtl::OUString("PCT"); - return sal_True; - } - // previous code kept in order to do not break any compatibility - // probably eroneous - else if ( sBuf[ 0 ] == 0x00 && sBuf[ 1 ] == 0x11 && sBuf[ 2 ] == 0x01 && bdBoxOk) - { - rFormatExtension = rtl::OUString("PCT"); - return sal_True; - } + rFormatExtension = rtl::OUString("PCT"); + return sal_True; } } diff --git a/svtools/source/filter/filter2.cxx b/svtools/source/filter/filter2.cxx index d229dcb62a6d..54649b25c836 100644 --- a/svtools/source/filter/filter2.cxx +++ b/svtools/source/filter/filter2.cxx @@ -1104,6 +1104,8 @@ sal_Bool GraphicDescriptor::ImpDetectMET( SvStream&, sal_Bool ) |* \************************************************************************/ +extern bool isPCT(SvStream& rStream, sal_uLong nStreamPos, sal_uLong nStreamLen); + sal_Bool GraphicDescriptor::ImpDetectPCT( SvStream& rStm, sal_Bool ) { sal_Bool bRet = aPathExt.CompareToAscii( "pct", 3 ) == COMPARE_EQUAL; @@ -1111,23 +1113,14 @@ sal_Bool GraphicDescriptor::ImpDetectPCT( SvStream& rStm, sal_Bool ) nFormat = GFF_PCT; else { - sal_Int32 nStmPos = rStm.Tell(); - - sal_uInt8 sBuf[4]; - - rStm.SeekRel( 522 ); - rStm.Read( sBuf, 3 ); - - if( !rStm.GetError() ) + sal_Size nStreamPos = rStm.Tell(); + sal_Size nStreamLen = rStm.remainingSize(); + if (isPCT(rStm, nStreamPos, nStreamLen)) { - if ( ( sBuf[0] == 0x00 ) && ( sBuf[1] == 0x11 ) && - ( ( sBuf[2] == 0x01 ) || ( sBuf[2] == 0x02 ) ) ) - { - bRet = sal_True; - nFormat = GFF_PCT; - } + bRet = sal_True; + nFormat = GFF_PCT; } - rStm.Seek( nStmPos ); + rStm.Seek(nStreamPos); } return bRet; diff --git a/svtools/source/misc/imagemgr.cxx b/svtools/source/misc/imagemgr.cxx index 044275eca64a..3a0943f726a9 100644 --- a/svtools/source/misc/imagemgr.cxx +++ b/svtools/source/misc/imagemgr.cxx @@ -121,6 +121,7 @@ static SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] = { "pas", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, { "pcd", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD }, { "pct", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT }, + { "pict", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT }, { "pcx", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX }, { "pl", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, { "png", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PNG }, |