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: epgm.cxx,v $
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/svapp.hxx>
35 #include <vcl/graph.hxx>
36 #include <vcl/bmpacc.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svtools/solar.hrc>
39 #include <svtools/fltcall.hxx>
40 #include <svtools/FilterConfigItem.hxx>
41 #include "strings.hrc"
42 #include "dlgepgm.hrc"
43 #include "dlgepgm.hxx"
45 //============================ PGMWriter ==================================
51 SvStream
* mpOStm
; // Die auszugebende PGM-Datei
52 USHORT mpOStmOldModus
;
56 BitmapReadAccess
* mpAcc
;
57 ULONG mnWidth
, mnHeight
; // Bildausmass in Pixeln
59 BOOL
ImplWriteHeader();
61 void ImplWriteNumber( sal_Int32
);
63 com::sun::star::uno::Reference
< com::sun::star::task::XStatusIndicator
> xStatusIndicator
;
69 BOOL
WritePGM( const Graphic
& rGraphic
, SvStream
& rPGM
, FilterConfigItem
* pFilterConfigItem
);
72 //=================== Methoden von PGMWriter ==============================
74 PGMWriter::PGMWriter() :
80 // ------------------------------------------------------------------------
82 PGMWriter::~PGMWriter()
86 // ------------------------------------------------------------------------
88 BOOL
PGMWriter::WritePGM( const Graphic
& rGraphic
, SvStream
& rPGM
, FilterConfigItem
* pFilterConfigItem
)
93 if ( pFilterConfigItem
)
95 mnMode
= pFilterConfigItem
->ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FileFormat" ) ), 0 );
97 xStatusIndicator
= pFilterConfigItem
->GetStatusIndicator();
98 if ( xStatusIndicator
.is() )
101 xStatusIndicator
->start( aMsg
, 100 );
105 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
106 Bitmap aBmp
= aBmpEx
.GetBitmap();
107 aBmp
.Convert( BMP_CONVERSION_8BIT_GREYS
);
109 mpOStmOldModus
= mpOStm
->GetNumberFormatInt();
110 mpOStm
->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN
);
112 mpAcc
= aBmp
.AcquireReadAccess();
115 if ( ImplWriteHeader() )
119 aBmp
.ReleaseAccess( mpAcc
);
124 mpOStm
->SetNumberFormatInt( mpOStmOldModus
);
126 if ( xStatusIndicator
.is() )
127 xStatusIndicator
->end();
132 // ------------------------------------------------------------------------
134 BOOL
PGMWriter::ImplWriteHeader()
136 mnWidth
= mpAcc
->Width();
137 mnHeight
= mpAcc
->Height();
138 if ( mnWidth
&& mnHeight
)
145 ImplWriteNumber( mnWidth
);
147 ImplWriteNumber( mnHeight
);
149 ImplWriteNumber( 255 ); // max. gray value
158 // ------------------------------------------------------------------------
160 void PGMWriter::ImplWriteBody()
164 for ( ULONG y
= 0; y
< mnHeight
; y
++ )
166 for ( ULONG x
= 0; x
< mnWidth
; x
++ )
168 *mpOStm
<< (BYTE
)( mpAcc
->GetPixel( y
, x
) );
174 for ( ULONG y
= 0; y
< mnHeight
; y
++ )
177 for ( ULONG x
= 0; x
< mnWidth
; x
++ )
185 nDat
= (BYTE
)mpAcc
->GetPixel( y
, x
);
189 *mpOStm
<< (BYTE
)( nNumb
+ '0' );
190 nDat
-= ( nNumb
* 100 );
192 *mpOStm
<< (BYTE
)( nNumb
+ '0' );
193 nDat
-= ( nNumb
* 10 );
194 *mpOStm
<< (BYTE
)( nDat
+ '0' );
202 *mpOStm
<< (BYTE
)( nNumb
+ '0' );
203 nDat
-= ( nNumb
* 10 );
204 *mpOStm
<< (BYTE
)( nDat
+ '0' );
209 *mpOStm
<< (BYTE
)( nDat
+ '0' );
213 *mpOStm
<< (BYTE
)' ';
220 // ------------------------------------------------------------------------
221 // eine Dezimalzahl im ASCII format wird in den Stream geschrieben
223 void PGMWriter::ImplWriteNumber( sal_Int32 nNumber
)
225 const ByteString
aNum( ByteString::CreateFromInt32( nNumber
) );
227 for( sal_Int16 n
= 0UL, nLen
= aNum
.Len(); n
< nLen
; n
++ )
228 *mpOStm
<< aNum
.GetChar( n
);
232 // ------------------------------------------------------------------------
234 // ---------------------
235 // - exported function -
236 // ---------------------
238 extern "C" BOOL __LOADONCALLAPI
GraphicExport( SvStream
& rStream
, Graphic
& rGraphic
, FilterConfigItem
* pFilterConfigItem
, BOOL
)
240 PGMWriter aPGMWriter
;
242 return aPGMWriter
.WritePGM( rGraphic
, rStream
, pFilterConfigItem
);
245 // ------------------------------------------------------------------------
247 extern "C" BOOL __LOADONCALLAPI
DoExportDialog( FltCallDialogParameter
& rPara
)
253 ByteString
aResMgrName( "epg" );
256 pResMgr
= ResMgr::CreateResMgr( aResMgrName
.GetBuffer(), Application::GetSettings().GetUILocale() );
260 rPara
.pResMgr
= pResMgr
;
261 bRet
= ( DlgExportEPGM( rPara
).Execute() == RET_OK
);
271 // ------------------------------------------------------------------------
281 static HINSTANCE hDLLInst
= 0;
283 extern "C" int CALLBACK
LibMain( HINSTANCE hDLL
, WORD
, WORD nHeap
, LPSTR
)
293 // ------------------------------------------------------------------------
295 extern "C" int CALLBACK
WEP( int )