xref: /trunk/main/svx/source/dialog/grfflt.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <tools/shl.hxx>
27 #include <vcl/msgbox.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/viewsh.hxx>
30 #ifndef _SFXOBJSH_HXX
31 #include <sfx2/objsh.hxx>
32 #endif
33 #include <sfx2/request.hxx>
34 
35 #include <svx/dialmgr.hxx>
36 #include <svx/grfflt.hxx>
37 //#include "grfflt.hrc"
38 #include <svx/dialogs.hrc>
39 #include <svx/svxdlg.hxx> //CHINA001
40 
41 // --------------------
42 // - SvxGraphicFilter -
43 // --------------------
44 
ExecuteGrfFilterSlot(SfxRequest & rReq,GraphicObject & rFilterObject)45 sal_uIntPtr SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest& rReq, GraphicObject& rFilterObject )
46 {
47 	const Graphic&	rGraphic = rFilterObject.GetGraphic();
48 	sal_uIntPtr			nRet = SVX_GRAPHICFILTER_UNSUPPORTED_GRAPHICTYPE;
49 
50 	if( rGraphic.GetType() == GRAPHIC_BITMAP )
51 	{
52 		SfxViewFrame*	pViewFrame = SfxViewFrame::Current();
53 		SfxObjectShell*	pShell = pViewFrame ? pViewFrame->GetObjectShell() : NULL;
54 		Window*			pWindow = ( pViewFrame && pViewFrame->GetViewShell() ) ? pViewFrame->GetViewShell()->GetWindow() : NULL;
55 		Graphic			aGraphic;
56 
57 		switch( rReq.GetSlot() )
58 		{
59 			case( SID_GRFFILTER_INVERT ):
60 			{
61 				if( pShell )
62 					pShell->SetWaitCursor( sal_True );
63 
64 				if( rGraphic.IsAnimated() )
65 				{
66 					Animation aAnimation( rGraphic.GetAnimation() );
67 
68 					if( aAnimation.Invert() )
69 						aGraphic = aAnimation;
70 				}
71 				else
72 				{
73 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
74 
75 					if( aBmpEx.Invert() )
76 						aGraphic = aBmpEx;
77 				}
78 
79 				if( pShell )
80 					pShell->SetWaitCursor( sal_False );
81 			}
82 			break;
83 
84 			case( SID_GRFFILTER_SMOOTH ):
85 			{
86 				if( pShell )
87 					pShell->SetWaitCursor( sal_True );
88 
89 				if( rGraphic.IsAnimated() )
90 				{
91 					Animation aAnimation( rGraphic.GetAnimation() );
92 
93 					if( aAnimation.Filter( BMP_FILTER_SMOOTH ) )
94 						aGraphic = aAnimation;
95 				}
96 				else
97 				{
98 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
99 
100 					if( aBmpEx.Filter( BMP_FILTER_SMOOTH ) )
101 						aGraphic = aBmpEx;
102 				}
103 
104 				if( pShell )
105 					pShell->SetWaitCursor( sal_False );
106 			}
107 			break;
108 
109 			case( SID_GRFFILTER_SHARPEN ):
110 			{
111 				if( pShell )
112 					pShell->SetWaitCursor( sal_True );
113 
114 				if( rGraphic.IsAnimated() )
115 				{
116 					Animation aAnimation( rGraphic.GetAnimation() );
117 
118 					if( aAnimation.Filter( BMP_FILTER_SHARPEN ) )
119 						aGraphic = aAnimation;
120 				}
121 				else
122 				{
123 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
124 
125 					if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) )
126 						aGraphic = aBmpEx;
127 				}
128 
129 				if( pShell )
130 					pShell->SetWaitCursor( sal_False );
131 			}
132 			break;
133 
134 			case( SID_GRFFILTER_REMOVENOISE ):
135 			{
136 				if( pShell )
137 					pShell->SetWaitCursor( sal_True );
138 
139 				if( rGraphic.IsAnimated() )
140 				{
141 					Animation aAnimation( rGraphic.GetAnimation() );
142 
143 					if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) )
144 						aGraphic = aAnimation;
145 				}
146 				else
147 				{
148 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
149 
150 					if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) )
151 						aGraphic = aBmpEx;
152 				}
153 
154 				if( pShell )
155 					pShell->SetWaitCursor( sal_False );
156 			}
157 			break;
158 
159 			case( SID_GRFFILTER_SOBEL ):
160 			{
161 				if( pShell )
162 					pShell->SetWaitCursor( sal_True );
163 
164 				if( rGraphic.IsAnimated() )
165 				{
166 					Animation aAnimation( rGraphic.GetAnimation() );
167 
168 					if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) )
169 						aGraphic = aAnimation;
170 				}
171 				else
172 				{
173 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
174 
175 					if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) )
176 						aGraphic = aBmpEx;
177 				}
178 
179 				if( pShell )
180 					pShell->SetWaitCursor( sal_False );
181 			}
182 			break;
183 
184 			case( SID_GRFFILTER_MOSAIC ):
185 			{
186 				//CHINA001 GraphicFilterMosaic aDlg( pWindow, rGraphic, 4, 4, sal_False );
187 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
188 				if(pFact)
189 				{
190 					AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterMosaic( pWindow, rGraphic, 4, 4, sal_False, RID_SVX_GRFFILTER_DLG_MOSAIC);
191 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
192 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
193 						aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); //CHINA001 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
194 					delete aDlg; //add by CHINA001
195 				}
196 			}
197 			break;
198 
199 			case( SID_GRFFILTER_EMBOSS	):
200 			{
201 				//CHINA001 GraphicFilterEmboss aDlg( pWindow, rGraphic, RP_MM );
202 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
203 				if(pFact)
204 				{
205 					AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterEmboss( pWindow, rGraphic, RP_MM, RID_SVX_GRFFILTER_DLG_EMBOSS );
206 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
207 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
208 						aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); //CHINA001 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
209 					delete aDlg; //add by CHINA001
210 				}
211 			}
212 			break;
213 
214 			case( SID_GRFFILTER_POSTER	):
215 			{
216 				//CHINA001 GraphicFilterPoster aDlg( pWindow, rGraphic, 16 );
217 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
218 				if(pFact)
219 				{
220 					AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterPosterSepia( pWindow, rGraphic, 16, RID_SVX_GRFFILTER_DLG_POSTER );
221 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
222 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
223 						aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); //CHINA001 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
224 					delete aDlg; //add by CHINA001
225 				}
226 			}
227 			break;
228 
229 			case( SID_GRFFILTER_POPART	):
230 			{
231 				if( pShell )
232 					pShell->SetWaitCursor( sal_True );
233 
234 				if( rGraphic.IsAnimated() )
235 				{
236 					Animation aAnimation( rGraphic.GetAnimation() );
237 
238 					if( aAnimation.Filter( BMP_FILTER_POPART ) )
239 						aGraphic = aAnimation;
240 				}
241 				else
242 				{
243 					BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
244 
245 					if( aBmpEx.Filter( BMP_FILTER_POPART ) )
246 						aGraphic = aBmpEx;
247 				}
248 
249 				if( pShell )
250 					pShell->SetWaitCursor( sal_False );
251 			}
252 			break;
253 
254 			case( SID_GRFFILTER_SEPIA ):
255 			{
256 				//CHINA001 GraphicFilterSepia aDlg( pWindow, rGraphic, 10 );
257 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
258 				if(pFact)
259 				{
260 					AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterPosterSepia( pWindow, rGraphic, 10, RID_SVX_GRFFILTER_DLG_SEPIA );
261 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
262 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
263 						aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); //CHINA001 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
264 					delete aDlg; //add by CHINA001
265 				}
266 			}
267 			break;
268 
269 			case( SID_GRFFILTER_SOLARIZE ):
270 			{
271 				//CHINA001 GraphicFilterSolarize aDlg( pWindow, rGraphic, 128, sal_False );
272 				SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
273 				if(pFact)
274 				{
275 					AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterSolarize( pWindow, rGraphic, 128, sal_False, RID_SVX_GRFFILTER_DLG_SOLARIZE );
276 					DBG_ASSERT(aDlg, "Dialogdiet fail!");//CHINA001
277 					if( aDlg->Execute() == RET_OK ) //CHINA001 if( aDlg.Execute() == RET_OK )
278 						aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); //CHINA001 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
279 					delete aDlg; //add by CHINA001
280 				}
281 			}
282 			break;
283 
284             case SID_GRFFILTER :
285             {
286                 // do nothing; no error
287                 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
288                 break;
289             }
290 
291 			default:
292 			{
293 				DBG_ERROR( "SvxGraphicFilter: selected filter slot not yet implemented" );
294 				nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT;
295 			}
296 			break;
297 		}
298 
299 		if( aGraphic.GetType() != GRAPHIC_NONE )
300 		{
301 			rFilterObject.SetGraphic( aGraphic );
302 			nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
303 		}
304 	}
305 
306 	return nRet;
307 }
308 
309 // -----------------------------------------------------------------------------
310 
DisableGraphicFilterSlots(SfxItemSet & rSet)311 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet )
312 {
313 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER ) )
314 		rSet.DisableItem( SID_GRFFILTER );
315 
316 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
317 		rSet.DisableItem( SID_GRFFILTER_INVERT );
318 
319 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
320 		rSet.DisableItem( SID_GRFFILTER_SMOOTH );
321 
322 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
323 		rSet.DisableItem( SID_GRFFILTER_SHARPEN );
324 
325 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
326 		rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
327 
328 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
329 		rSet.DisableItem( SID_GRFFILTER_SOBEL );
330 
331 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
332 		rSet.DisableItem( SID_GRFFILTER_MOSAIC );
333 
334 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
335 		rSet.DisableItem( SID_GRFFILTER_EMBOSS );
336 
337 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
338 		rSet.DisableItem( SID_GRFFILTER_POSTER );
339 
340 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
341 		rSet.DisableItem( SID_GRFFILTER_POPART );
342 
343 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
344 		rSet.DisableItem( SID_GRFFILTER_SEPIA );
345 
346 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
347 		rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
348 };
349 /* CHINA001 move to cuigrfflt.cxx
350 // --------------------------------------
351 // - GraphicFilterDialog::PreviewWindow -
352 // --------------------------------------
353 
354 GraphicFilterDialog::PreviewWindow::PreviewWindow( Window* pParent, const ResId& rResId ) :
355 	Control( pParent, rResId )
356 {
357 }
358 
359 // -----------------------------------------------------------------------------
360 
361 GraphicFilterDialog::PreviewWindow::~PreviewWindow()
362 {
363 }
364 
365 // -----------------------------------------------------------------------------
366 
367 void GraphicFilterDialog::PreviewWindow::Paint( const Rectangle& rRect )
368 {
369 	Control::Paint( rRect );
370 
371 	const Size	aGrfSize( LogicToPixel( maGraphic.GetPrefSize(), maGraphic.GetPrefMapMode() ) );
372 	const Size	aOutSize( GetOutputSizePixel() );
373 	const Point aGrfPos( ( aOutSize.Width() - aGrfSize.Width() ) >> 1,
374 						 ( aOutSize.Height() - aGrfSize.Height() ) >> 1 );
375 
376 	if( maGraphic.IsAnimated() )
377 		maGraphic.StartAnimation( this , aGrfPos, aGrfSize );
378 	else
379 		maGraphic.Draw( this, aGrfPos, aGrfSize );
380 }
381 
382 // -----------------------------------------------------------------------------
383 
384 void GraphicFilterDialog::PreviewWindow::SetGraphic( const Graphic& rGraphic )
385 {
386 	maGraphic = rGraphic;
387 
388 	if( maGraphic.IsAnimated() || maGraphic.IsTransparent() )
389 		Invalidate();
390 	else
391 		Paint( Rectangle( Point(), GetOutputSizePixel() ) );
392 }
393 
394 // -----------------------
395 // - GraphicFilterDialog -
396 // -----------------------
397 
398 GraphicFilterDialog::GraphicFilterDialog( Window* pParent, const ResId& rResId, const Graphic& rGraphic ) :
399 	ModalDialog		( pParent, rResId ),
400 	mfScaleX		( 0.0 ),
401 	mfScaleY		( 0.0 ),
402 	maSizePixel		( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) ),
403 	maModifyHdl		( LINK( this, GraphicFilterDialog, ImplModifyHdl ) ),
404 	maPreview		( this, SVX_RES( CTL_PREVIEW ) ),
405 	maFlParameter	( this, SVX_RES( FL_PARAMETER ) ),
406 	maBtnOK			( this, SVX_RES( BTN_OK ) ),
407 	maBtnCancel		( this, SVX_RES( BTN_CANCEL ) ),
408 	maBtnHelp		( this, SVX_RES( BTN_HELP ) )
409 {
410 	const Size	aPreviewSize( maPreview.GetOutputSizePixel() );
411 	Size		aGrfSize( maSizePixel );
412 
413 	if( rGraphic.GetType() == GRAPHIC_BITMAP &&
414 		aPreviewSize.Width() && aPreviewSize.Height() &&
415 		aGrfSize.Width() && aGrfSize.Height() )
416 	{
417 		const double fGrfWH = (double) aGrfSize.Width() / aGrfSize.Height();
418 		const double fPreWH = (double) aPreviewSize.Width() / aPreviewSize.Height();
419 
420 		if( fGrfWH < fPreWH )
421 		{
422 			aGrfSize.Width() = (long) ( aPreviewSize.Height() * fGrfWH );
423 			aGrfSize.Height()= aPreviewSize.Height();
424 		}
425 		else
426 		{
427 			aGrfSize.Width() = aPreviewSize.Width();
428 			aGrfSize.Height()= (long) ( aPreviewSize.Width() / fGrfWH);
429 		}
430 
431 		mfScaleX = (double) aGrfSize.Width() / maSizePixel.Width();
432 		mfScaleY = (double) aGrfSize.Height() / maSizePixel.Height();
433 
434 		if( !rGraphic.IsAnimated() )
435 		{
436 			BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
437 
438 			if( aBmpEx.Scale( aGrfSize, BMP_SCALE_INTERPOLATE ) )
439 				maGraphic = aBmpEx;
440 		}
441 	}
442 
443 	maTimer.SetTimeoutHdl( LINK( this, GraphicFilterDialog, ImplPreviewTimeoutHdl ) );
444 	maTimer.SetTimeout( 100 );
445 	ImplModifyHdl( NULL );
446 }
447 
448 // -----------------------------------------------------------------------------
449 
450 GraphicFilterDialog::~GraphicFilterDialog()
451 {
452 }
453 
454 // -----------------------------------------------------------------------------
455 
456 IMPL_LINK( GraphicFilterDialog, ImplPreviewTimeoutHdl, Timer*, pTimer )
457 {
458 	maTimer.Stop();
459 	maPreview.SetGraphic( GetFilteredGraphic( maGraphic, mfScaleX, mfScaleY ) );
460 
461 	return 0;
462 }
463 
464 // -----------------------------------------------------------------------------
465 
466 IMPL_LINK( GraphicFilterDialog, ImplModifyHdl, void*, p )
467 {
468 	if( maGraphic.GetType() == GRAPHIC_BITMAP )
469 	{
470 		maTimer.Stop();
471 		maTimer.Start();
472 	}
473 
474 	return 0;
475 }
476 
477 // ----------------
478 // - FilterMosaic -
479 // ----------------
480 
481 GraphicFilterMosaic::GraphicFilterMosaic( Window* pParent, const Graphic& rGraphic,
482 										  sal_uInt16 nTileWidth, sal_uInt16 nTileHeight, sal_Bool bEnhanceEdges ) :
483 	GraphicFilterDialog( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_MOSAIC ), rGraphic ),
484 	maFtWidth	( this, SVX_RES( DLG_FILTERMOSAIC_FT_WIDTH ) ),
485 	maMtrWidth	( this, SVX_RES( DLG_FILTERMOSAIC_MTR_WIDTH ) ),
486 	maFtHeight	( this, SVX_RES( DLG_FILTERMOSAIC_FT_HEIGHT ) ),
487 	maMtrHeight ( this, SVX_RES( DLG_FILTERMOSAIC_MTR_HEIGHT ) ),
488 	maCbxEdges	( this, SVX_RES( DLG_FILTERMOSAIC_CBX_EDGES ) )
489 {
490 	FreeResource();
491 
492 	maMtrWidth.SetValue( nTileWidth );
493 	maMtrWidth.SetLast( GetGraphicSizePixel().Width() );
494 	maMtrWidth.SetModifyHdl( GetModifyHdl() );
495 
496 	maMtrHeight.SetValue( nTileHeight );
497 	maMtrHeight.SetLast( GetGraphicSizePixel().Height() );
498 	maMtrHeight.SetModifyHdl( GetModifyHdl() );
499 
500 	maCbxEdges.Check( bEnhanceEdges );
501 	maCbxEdges.SetToggleHdl( GetModifyHdl() );
502 
503 	maMtrWidth.GrabFocus();
504 }
505 
506 // -----------------------------------------------------------------------------
507 
508 GraphicFilterMosaic::~GraphicFilterMosaic()
509 {
510 }
511 
512 // -----------------------------------------------------------------------------
513 
514 Graphic	GraphicFilterMosaic::GetFilteredGraphic( const Graphic& rGraphic,
515 												 double fScaleX, double fScaleY )
516 {
517 	Graphic			aRet;
518 	const Size		aSize( Max( FRound( GetTileWidth() * fScaleX ), 1L ),
519 						   Max( FRound( GetTileHeight() * fScaleY ), 1L ) );
520 	BmpFilterParam	aParam( aSize );
521 
522 	if( rGraphic.IsAnimated() )
523 	{
524 		Animation aAnim( rGraphic.GetAnimation() );
525 
526 		if( aAnim.Filter( BMP_FILTER_MOSAIC, &aParam ) )
527 		{
528 			if( IsEnhanceEdges() )
529 				aAnim.Filter( BMP_FILTER_SHARPEN );
530 
531 			aRet = aAnim;
532 		}
533 	}
534 	else
535 	{
536 		BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
537 
538 		if( aBmpEx.Filter( BMP_FILTER_MOSAIC, &aParam ) )
539 		{
540 			if( IsEnhanceEdges() )
541 				aBmpEx.Filter( BMP_FILTER_SHARPEN );
542 
543 			aRet = aBmpEx;
544 		}
545 	}
546 
547 	return aRet;
548 }
549 
550 // ------------------
551 // - GraphicFilterSolarize -
552 // ------------------
553 
554 GraphicFilterSolarize::GraphicFilterSolarize( Window* pParent, const Graphic& rGraphic,
555 											  sal_uInt8 cGreyThreshold, sal_Bool bInvert ) :
556 	GraphicFilterDialog	( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_SOLARIZE ), rGraphic ),
557 	maFtThreshold	( this, SVX_RES( DLG_FILTERSOLARIZE_FT_THRESHOLD ) ),
558 	maMtrThreshold	( this, SVX_RES( DLG_FILTERSOLARIZE_MTR_THRESHOLD ) ),
559 	maCbxInvert		( this, SVX_RES( DLG_FILTERSOLARIZE_CBX_INVERT ) )
560 {
561 	FreeResource();
562 
563 	maMtrThreshold.SetValue( FRound( cGreyThreshold / 2.55 ) );
564 	maMtrThreshold.SetModifyHdl( GetModifyHdl() );
565 
566 	maCbxInvert.Check( bInvert );
567 	maCbxInvert.SetToggleHdl( GetModifyHdl() );
568 
569 	maMtrThreshold.GrabFocus();
570 }
571 
572 // -----------------------------------------------------------------------------
573 
574 GraphicFilterSolarize::~GraphicFilterSolarize()
575 {
576 }
577 
578 // -----------------------------------------------------------------------------
579 
580 Graphic	GraphicFilterSolarize::GetFilteredGraphic( const Graphic& rGraphic,
581 												   double fScaleX, double fScaleY )
582 {
583 	Graphic			aRet;
584 	BmpFilterParam	aParam( GetGreyThreshold() );
585 
586 	if( rGraphic.IsAnimated() )
587 	{
588 		Animation aAnim( rGraphic.GetAnimation() );
589 
590 		if( aAnim.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
591 		{
592 			if( IsInvert() )
593 				aAnim.Invert();
594 
595 			aRet = aAnim;
596 		}
597 	}
598 	else
599 	{
600 		BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
601 
602 		if( aBmpEx.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
603 		{
604 			if( IsInvert() )
605 				aBmpEx.Invert();
606 
607 			aRet = aBmpEx;
608 		}
609 	}
610 
611 	return aRet;
612 }
613 
614 // ----------------------
615 // - GraphicFilterSepia -
616 // ----------------------
617 
618 GraphicFilterSepia::GraphicFilterSepia( Window* pParent, const Graphic& rGraphic,
619 										sal_uInt16 nSepiaPercent ) :
620 	GraphicFilterDialog	( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_SEPIA ), rGraphic ),
621 	maFtSepia		( this, SVX_RES( DLG_FILTERSEPIA_FT_SEPIA ) ),
622 	maMtrSepia		( this, SVX_RES( DLG_FILTERSEPIA_MTR_SEPIA ) )
623 {
624 	FreeResource();
625 
626 	maMtrSepia.SetValue( nSepiaPercent );
627 	maMtrSepia.SetModifyHdl( GetModifyHdl() );
628 
629 	maMtrSepia.GrabFocus();
630 }
631 
632 // -----------------------------------------------------------------------------
633 
634 GraphicFilterSepia::~GraphicFilterSepia()
635 {
636 }
637 
638 // -----------------------------------------------------------------------------
639 
640 Graphic	GraphicFilterSepia::GetFilteredGraphic( const Graphic& rGraphic,
641 												double fScaleX, double fScaleY )
642 {
643 	Graphic			aRet;
644 	BmpFilterParam	aParam( GetSepiaPercent() );
645 
646 	if( rGraphic.IsAnimated() )
647 	{
648 		Animation aAnim( rGraphic.GetAnimation() );
649 
650 		if( aAnim.Filter( BMP_FILTER_SEPIA, &aParam ) )
651 			aRet = aAnim;
652 	}
653 	else
654 	{
655 		BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
656 
657 		if( aBmpEx.Filter( BMP_FILTER_SEPIA, &aParam ) )
658 			aRet = aBmpEx;
659 	}
660 
661 	return aRet;
662 }
663 
664 // -----------------------
665 // - GraphicFilterPoster -
666 // -----------------------
667 
668 GraphicFilterPoster::GraphicFilterPoster( Window* pParent, const Graphic& rGraphic,
669 										  sal_uInt16 nPosterCount ) :
670 	GraphicFilterDialog	( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_POSTER ), rGraphic ),
671 	maFtPoster		( this, SVX_RES( DLG_FILTERPOSTER_FT_POSTER ) ),
672 	maNumPoster		( this, SVX_RES( DLG_FILTERPOSTER_NUM_POSTER ) )
673 {
674 	FreeResource();
675 
676 	maNumPoster.SetFirst( 2 );
677 	maNumPoster.SetLast( rGraphic.GetBitmapEx().GetBitCount() );
678 	maNumPoster.SetValue( nPosterCount );
679 	maNumPoster.SetModifyHdl( GetModifyHdl() );
680 	maNumPoster.GrabFocus();
681 }
682 
683 // -----------------------------------------------------------------------------
684 
685 GraphicFilterPoster::~GraphicFilterPoster()
686 {
687 }
688 
689 // -----------------------------------------------------------------------------
690 
691 Graphic	GraphicFilterPoster::GetFilteredGraphic( const Graphic& rGraphic,
692 												 double fScaleX, double fScaleY )
693 {
694 	Graphic			aRet;
695 	const sal_uInt16	nPosterCount = GetPosterColorCount();
696 
697 	if( rGraphic.IsAnimated() )
698 	{
699 		Animation aAnim( rGraphic.GetAnimation() );
700 
701 		if( aAnim.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
702 			aRet = aAnim;
703 	}
704 	else
705 	{
706 		BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
707 
708 		if( aBmpEx.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
709 			aRet = aBmpEx;
710 	}
711 
712 	return aRet;
713 }
714 
715 // -----------------------
716 // - GraphicFilterEmboss -
717 // -----------------------
718 
719 void GraphicFilterEmboss::EmbossControl::MouseButtonDown( const MouseEvent& rEvt )
720 {
721 	const RECT_POINT eOldRP = GetActualRP();
722 
723 	SvxRectCtl::MouseButtonDown( rEvt );
724 
725 	if( GetActualRP() != eOldRP )
726 		maModifyHdl.Call( this );
727 }
728 
729 // -----------------------------------------------------------------------------
730 
731 GraphicFilterEmboss::GraphicFilterEmboss( Window* pParent, const Graphic& rGraphic,
732 										  RECT_POINT eLightSource ) :
733 	GraphicFilterDialog	( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_EMBOSS ), rGraphic ),
734 	maFtLight		( this, SVX_RES( DLG_FILTEREMBOSS_FT_LIGHT ) ),
735 	maCtlLight		( this, SVX_RES( DLG_FILTEREMBOSS_CTL_LIGHT ), eLightSource )
736 {
737 	FreeResource();
738 
739 	maCtlLight.SetModifyHdl( GetModifyHdl() );
740 	maCtlLight.GrabFocus();
741 }
742 
743 // -----------------------------------------------------------------------------
744 
745 GraphicFilterEmboss::~GraphicFilterEmboss()
746 {
747 }
748 
749 // -----------------------------------------------------------------------------
750 
751 Graphic	GraphicFilterEmboss::GetFilteredGraphic( const Graphic& rGraphic,
752 												 double fScaleX, double fScaleY )
753 {
754 	Graphic	aRet;
755 	sal_uInt16	nAzim, nElev;
756 
757 	switch( maCtlLight.GetActualRP() )
758 	{
759 		case( RP_LT ): nAzim = 4500,	nElev = 4500; break;
760 		case( RP_MT ): nAzim = 9000,	nElev = 4500; break;
761 		case( RP_RT ): nAzim = 13500,	nElev = 4500; break;
762 		case( RP_LM ): nAzim = 0,		nElev = 4500; break;
763 		case( RP_MM ): nAzim = 0,		nElev = 9000; break;
764 		case( RP_RM ): nAzim = 18000,	nElev = 4500; break;
765 		case( RP_LB ): nAzim = 31500,	nElev = 4500; break;
766 		case( RP_MB ): nAzim = 27000,	nElev = 4500; break;
767 		case( RP_RB ): nAzim = 22500,	nElev = 4500; break;
768 	}
769 
770 	BmpFilterParam aParam( nAzim, nElev );
771 
772 	if( rGraphic.IsAnimated() )
773 	{
774 		Animation aAnim( rGraphic.GetAnimation() );
775 
776 		if( aAnim.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
777 			aRet = aAnim;
778 	}
779 	else
780 	{
781 		BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
782 
783 		if( aBmpEx.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
784 			aRet = aBmpEx;
785 	}
786 
787 	return aRet;
788 }
789 */
790