summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-04-02 15:49:32 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-05-06 04:02:05 +0200
commite9c50fbbc3b07ef927d133da9cf2395c55611e0f (patch)
tree7b2dbf92184b5b2707685dc44ee4764d4d58fdad /tools
parente4a7a50d831cb6fca95f2afff2af5298d66b5876 (diff)
tdf#103954: Z compressed graphic formats support for EMF/WMF
- Added .emz and .wmz file opening support - Added a function to check for Z compression that all z comp. formats can use - Added 3 unit tests for emf/emz/wmz files and the example files have been checked with a different tool (File Viewer 4) - emf/emz file detection changed from magic byte checking to extension checking, like wmf/wmz does Change-Id: I3e433fd23d18482648a51cd04b8f467368e97b62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132456 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/zcodec/zcodec.cxx23
1 files changed, 16 insertions, 7 deletions
diff --git a/tools/source/zcodec/zcodec.cxx b/tools/source/zcodec/zcodec.cxx
index 97a03a463021..80daa1507a19 100644
--- a/tools/source/zcodec/zcodec.cxx
+++ b/tools/source/zcodec/zcodec.cxx
@@ -36,7 +36,7 @@
#define GZ_COMMENT 0x10 /* bit 4 set: file comment present */
#define GZ_RESERVED 0xE0 /* bits 5..7: reserved */
-const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */
+constexpr sal_uInt16 GZ_MAGIC_BYTES_LE = 0x8B1F; /* gzip magic bytes, little endian */
ZCodec::ZCodec( size_t nInBufSize, size_t nOutBufSize )
: meState(STATE_INIT)
@@ -58,6 +58,16 @@ ZCodec::~ZCodec()
delete pStream;
}
+bool ZCodec::IsZCompressed( SvStream& rIStm )
+{
+ sal_uInt64 nCurPos = rIStm.Tell();
+ rIStm.Seek( 0 );
+ sal_uInt16 nFirstTwoBytes = 0;
+ rIStm.ReadUInt16( nFirstTwoBytes );
+ rIStm.Seek( nCurPos );
+ return nFirstTwoBytes == GZ_MAGIC_BYTES_LE;
+}
+
void ZCodec::BeginCompression( int nCompressLevel, bool gzLib )
{
assert(meState == STATE_INIT);
@@ -272,12 +282,11 @@ void ZCodec::InitDecompress(SvStream & inStream)
if ( mbStatus && mbGzLib )
{
sal_uInt8 j, nMethod, nFlags;
- for (int i : gz_magic) // gz - magic number
- {
- inStream.ReadUChar( j );
- if ( j != i )
- mbStatus = false;
- }
+ sal_uInt16 nFirstTwoBytes;
+ inStream.Seek( 0 );
+ inStream.ReadUInt16( nFirstTwoBytes );
+ if ( nFirstTwoBytes != GZ_MAGIC_BYTES_LE )
+ mbStatus = false;
inStream.ReadUChar( nMethod );
inStream.ReadUChar( nFlags );
if ( nMethod != Z_DEFLATED )