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