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