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