1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_svx.hxx"
32 #include <tools/stream.hxx>
33 #include <tools/zcodec.hxx>
40 GalleryCodec::GalleryCodec( SvStream
& rIOStm
) :
45 // -----------------------------------------------------------------------------
47 GalleryCodec::~GalleryCodec()
51 // -----------------------------------------------------------------------------
53 sal_Bool
GalleryCodec::IsCoded( SvStream
& rStm
, sal_uInt32
& rVersion
)
55 const sal_uIntPtr nPos
= rStm
.Tell();
57 sal_uInt8 cByte1
, cByte2
, cByte3
, cByte4
, cByte5
, cByte6
;
59 rStm
>> cByte1
>> cByte2
>> cByte3
>> cByte4
>> cByte5
>> cByte6
;
61 if ( cByte1
== 'S' && cByte2
== 'V' && cByte3
== 'R' && cByte4
== 'L' && cByte5
== 'E' && ( cByte6
== '1' || cByte6
== '2' ) )
63 rVersion
= ( ( cByte6
== '1' ) ? 1 : 2 );
77 // -----------------------------------------------------------------------------
79 void GalleryCodec::Write( SvStream
& rStmToWrite
)
81 sal_uInt32 nPos
, nCompSize
;
83 rStmToWrite
.Seek( STREAM_SEEK_TO_END
);
84 const sal_uInt32 nSize
= rStmToWrite
.Tell();
85 rStmToWrite
.Seek( 0UL );
87 rStm
<< 'S' << 'V' << 'R' << 'L' << 'E' << '2';
94 aCodec
.BeginCompression();
95 aCodec
.Compress( rStmToWrite
, rStm
);
96 aCodec
.EndCompression();
98 nCompSize
= rStm
.Tell() - nPos
- 4UL;
101 rStm
.Seek( STREAM_SEEK_TO_END
);
104 // -----------------------------------------------------------------------------
106 void GalleryCodec::Read( SvStream
& rStmToRead
)
108 sal_uInt32 nVersion
= 0;
110 if( IsCoded( rStm
, nVersion
) )
112 sal_uInt32 nCompressedSize
, nUnCompressedSize
;
115 rStm
>> nUnCompressedSize
>> nCompressedSize
;
120 sal_uInt8
* pCompressedBuffer
= new sal_uInt8
[ nCompressedSize
]; rStm
.Read( pCompressedBuffer
, nCompressedSize
);
121 sal_uInt8
* pInBuf
= pCompressedBuffer
;
122 sal_uInt8
* pOutBuf
= new sal_uInt8
[ nUnCompressedSize
];
123 sal_uInt8
* pTmpBuf
= pOutBuf
;
124 sal_uInt8
* pLast
= pOutBuf
+ nUnCompressedSize
- 1;
125 sal_uIntPtr nIndex
= 0UL, nCountByte
, nRunByte
;
126 sal_Bool bEndDecoding
= sal_False
;
130 nCountByte
= *pInBuf
++;
134 nRunByte
= *pInBuf
++;
139 memcpy( &pTmpBuf
[ nIndex
], pInBuf
, nRunByte
);
143 // WORD-Alignment beachten
147 else if ( nRunByte
== 1 ) // Ende des Bildes
148 bEndDecoding
= sal_True
;
152 const sal_uInt8 cVal
= *pInBuf
++;
154 memset( &pTmpBuf
[ nIndex
], cVal
, nCountByte
);
155 nIndex
+= nCountByte
;
158 while ( !bEndDecoding
&& ( pTmpBuf
<= pLast
) );
160 rStmToRead
.Write( pOutBuf
, nUnCompressedSize
);
163 delete[] pCompressedBuffer
;
165 else if( 2 == nVersion
)
169 aCodec
.BeginCompression();
170 aCodec
.Decompress( rStm
, rStmToRead
);
171 aCodec
.EndCompression();
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */