1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: eras.cxx,v $
10 * $Revision: 1.11.38.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
34 #include <vcl/graph.hxx>
35 #include <vcl/bmpacc.hxx>
36 #include <svtools/fltcall.hxx>
37 #include <svtools/FilterConfigItem.hxx>
39 //============================ RASWriter ==================================
46 USHORT mpOStmOldModus
;
49 BitmapReadAccess
* mpAcc
;
51 ULONG mnWidth
, mnHeight
;
52 USHORT mnColors
, mnDepth
;
57 com::sun::star::uno::Reference
< com::sun::star::task::XStatusIndicator
> xStatusIndicator
;
59 void ImplCallback( ULONG nCurrentYPos
);
60 BOOL
ImplWriteHeader();
61 void ImplWritePalette();
63 void ImplPutByte( BYTE
); // RLE decoding
69 BOOL
WriteRAS( const Graphic
& rGraphic
, SvStream
& rRAS
, FilterConfigItem
* pFilterConfigItem
);
72 //=================== Methoden von RASWriter ==============================
74 RASWriter::RASWriter() :
77 mnRepCount ( 0xffffffff )
81 // ------------------------------------------------------------------------
83 RASWriter::~RASWriter()
87 // ------------------------------------------------------------------------
89 void RASWriter::ImplCallback( ULONG nYPos
)
91 if ( xStatusIndicator
.is() )
92 xStatusIndicator
->setValue( (USHORT
)( ( 100 * nYPos
) / mnHeight
) );
95 // ------------------------------------------------------------------------
97 BOOL
RASWriter::WriteRAS( const Graphic
& rGraphic
, SvStream
& rRAS
, FilterConfigItem
* pFilterConfigItem
)
103 if ( pFilterConfigItem
)
105 xStatusIndicator
= pFilterConfigItem
->GetStatusIndicator();
106 if ( xStatusIndicator
.is() )
109 xStatusIndicator
->start( aMsg
, 100 );
113 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
114 aBmp
= aBmpEx
.GetBitmap();
116 if ( aBmp
.GetBitCount() == 4 )
117 aBmp
.Convert( BMP_CONVERSION_8BIT_COLORS
);
119 mnDepth
= aBmp
.GetBitCount();
121 // export code below only handles three discrete cases
122 mnDepth
= mnDepth
<= 1 ? 1 : mnDepth
<= 8 ? 8 : 24;
124 mpAcc
= aBmp
.AcquireReadAccess();
127 mpOStmOldModus
= mpOStm
->GetNumberFormatInt();
128 mpOStm
->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN
);
130 if ( ImplWriteHeader() )
136 aBmp
.ReleaseAccess( mpAcc
);
141 mpOStm
->SetNumberFormatInt( mpOStmOldModus
);
143 if ( xStatusIndicator
.is() )
144 xStatusIndicator
->end();
149 // ------------------------------------------------------------------------
151 BOOL
RASWriter::ImplWriteHeader()
153 mnWidth
= mpAcc
->Width();
154 mnHeight
= mpAcc
->Height();
157 mnColors
= mpAcc
->GetPaletteEntryCount();
161 if ( mbStatus
&& mnWidth
&& mnHeight
&& mnDepth
)
163 *mpOStm
<< (UINT32
)0x59a66a95 << (UINT32
)mnWidth
<< (UINT32
)mnHeight
165 << (UINT32
)(( ( ( ( mnWidth
* mnDepth
) + 15 ) >> 4 ) << 1 ) * mnHeight
)
169 *mpOStm
<< (UINT32
)0 << (UINT32
)0;
173 *mpOStm
<< (UINT32
)1 << (UINT32
)( mnColors
* 3 );
176 else mbStatus
= FALSE
;
181 // ------------------------------------------------------------------------
183 void RASWriter::ImplWritePalette()
187 for ( i
= 0; i
< mnColors
; *mpOStm
<< mpAcc
->GetPaletteColor( i
++ ).GetRed() ) ;
188 for ( i
= 0; i
< mnColors
; *mpOStm
<< mpAcc
->GetPaletteColor( i
++ ).GetGreen() ) ;
189 for ( i
= 0; i
< mnColors
; *mpOStm
<< mpAcc
->GetPaletteColor( i
++ ).GetBlue() ) ;
192 // ------------------------------------------------------------------------
194 void RASWriter::ImplWriteBody()
200 for ( y
= 0; y
< mnHeight
; y
++ )
202 ImplCallback( y
); // processing output
203 for ( x
= 0; x
< mnWidth
; x
++ )
205 BitmapColor
aColor( mpAcc
->GetPixel( y
, x
) );
206 ImplPutByte( aColor
.GetBlue() ); // Format ist BGR
207 ImplPutByte( aColor
.GetGreen() );
208 ImplPutByte( aColor
.GetRed() );
210 if ( x
& 1 ) ImplPutByte( 0 ); // WORD ALIGNMENT ???
213 else if ( mnDepth
== 8 )
215 for ( y
= 0; y
< mnHeight
; y
++ )
217 ImplCallback( y
); // processing output
218 for ( x
= 0; x
< mnWidth
; x
++ )
220 ImplPutByte ( mpAcc
->GetPixel( y
, x
) );
222 if ( x
& 1 ) ImplPutByte( 0 ); // WORD ALIGNMENT ???
225 else if ( mnDepth
== 1 )
229 for ( y
= 0; y
< mnHeight
; y
++ )
231 ImplCallback( y
); // processing output
232 for ( x
= 0; x
< mnWidth
; x
++ )
234 nDat
= ( ( nDat
<< 1 ) | ( mpAcc
->GetPixel ( y
, x
) & 1 ) );
235 if ( ( x
& 7 ) == 7 )
239 ImplPutByte( sal::static_int_cast
< BYTE
>(nDat
<< ( ( ( x
& 7 ) ^ 7 ) + 1)) );// write remaining bits
240 if (!( ( x
- 1 ) & 0x8 ) )
241 ImplPutByte( 0 ); // WORD ALIGNMENT ???
244 ImplPutByte( mnRepVal
+ 1 ); // end of RLE decoding
247 // ------------------------------------------------------------------------
249 void RASWriter::ImplPutByte( BYTE nPutThis
)
251 if ( mnRepCount
== 0xffffffff )
258 if ( ( nPutThis
== mnRepVal
) && ( mnRepCount
!= 0xff ) )
262 if ( mnRepCount
== 0 )
264 *mpOStm
<< (BYTE
)mnRepVal
;
265 if ( mnRepVal
== 0x80 )
270 *mpOStm
<< (BYTE
)0x80;
271 *mpOStm
<< (BYTE
)mnRepCount
;
272 *mpOStm
<< (BYTE
)mnRepVal
;
280 // ------------------------------------------------------------------------
282 // ---------------------
283 // - exported function -
284 // ---------------------
286 extern "C" BOOL __LOADONCALLAPI
GraphicExport( SvStream
& rStream
, Graphic
& rGraphic
, FilterConfigItem
* pFilterConfigItem
, BOOL
)
288 RASWriter aRASWriter
;
290 return aRASWriter
.WriteRAS( rGraphic
, rStream
, pFilterConfigItem
);
301 static HINSTANCE hDLLInst
= 0;
303 extern "C" int CALLBACK
LibMain( HINSTANCE hDLL
, WORD
, WORD nHeap
, LPSTR
)
313 // ------------------------------------------------------------------------
315 extern "C" int CALLBACK
WEP( int )