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
PreviewWindow(Window * pParent,const ResId & rResId)317 GraphicFilterDialog::PreviewWindow::PreviewWindow( Window* pParent, const ResId& rResId ) :
318 Control( pParent, rResId )
319 {
320 }
321
322 // -----------------------------------------------------------------------------
323
~PreviewWindow()324 GraphicFilterDialog::PreviewWindow::~PreviewWindow()
325 {
326 }
327
328 // -----------------------------------------------------------------------------
329
Paint(const Rectangle & rRect)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
SetGraphic(const Graphic & rGraphic)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
GraphicFilterDialog(Window * pParent,const ResId & rResId,const Graphic & rGraphic)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
~GraphicFilterDialog()413 GraphicFilterDialog::~GraphicFilterDialog()
414 {
415 }
416
417 // -----------------------------------------------------------------------------
418
IMPL_LINK(GraphicFilterDialog,ImplPreviewTimeoutHdl,Timer *,EMPTYARG)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
IMPL_LINK(GraphicFilterDialog,ImplModifyHdl,void *,EMPTYARG)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
GraphicFilterMosaic(Window * pParent,const Graphic & rGraphic,sal_uInt16 nTileWidth,sal_uInt16 nTileHeight,sal_Bool bEnhanceEdges)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
~GraphicFilterMosaic()477 GraphicFilterMosaic::~GraphicFilterMosaic()
478 {
479 }
480
481 // -----------------------------------------------------------------------------
482
GetFilteredGraphic(const Graphic & rGraphic,double fScaleX,double fScaleY)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
GraphicFilterSolarize(Window * pParent,const Graphic & rGraphic,sal_uInt8 cGreyThreshold,sal_Bool bInvert)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
539 // -----------------------------------------------------------------------------
540
~GraphicFilterSolarize()541 GraphicFilterSolarize::~GraphicFilterSolarize()
542 {
543 }
544
545 // -----------------------------------------------------------------------------
546
GetFilteredGraphic(const Graphic & rGraphic,double,double)547 Graphic GraphicFilterSolarize::GetFilteredGraphic( const Graphic& rGraphic,
548 double /*fScaleX*/, double /*fScaleY*/ )
549 {
550 Graphic aRet;
551 BmpFilterParam aParam( GetGreyThreshold() );
552
553 if( rGraphic.IsAnimated() )
554 {
555 Animation aAnim( rGraphic.GetAnimation() );
556
557 if( aAnim.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
558 {
559 if( IsInvert() )
560 aAnim.Invert();
561
562 aRet = aAnim;
563 }
564 }
565 else
566 {
567 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
568
569 if( aBmpEx.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
570 {
571 if( IsInvert() )
572 aBmpEx.Invert();
573
574 aRet = aBmpEx;
575 }
576 }
577
578 return aRet;
579 }
580
581 // ----------------------
582 // - GraphicFilterSepia -
583 // ----------------------
584
GraphicFilterSepia(Window * pParent,const Graphic & rGraphic,sal_uInt16 nSepiaPercent)585 GraphicFilterSepia::GraphicFilterSepia( Window* pParent, const Graphic& rGraphic,
586 sal_uInt16 nSepiaPercent ) :
587 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_SEPIA ), rGraphic ),
588 maFtSepia ( this, CUI_RES( DLG_FILTERSEPIA_FT_SEPIA ) ),
589 maMtrSepia ( this, CUI_RES( DLG_FILTERSEPIA_MTR_SEPIA ) )
590 {
591 FreeResource();
592
593 maMtrSepia.SetValue( nSepiaPercent );
594 maMtrSepia.SetModifyHdl( GetModifyHdl() );
595 }
596
597 // -----------------------------------------------------------------------------
598
~GraphicFilterSepia()599 GraphicFilterSepia::~GraphicFilterSepia()
600 {
601 }
602
603 // -----------------------------------------------------------------------------
604
GetFilteredGraphic(const Graphic & rGraphic,double,double)605 Graphic GraphicFilterSepia::GetFilteredGraphic( const Graphic& rGraphic,
606 double /*fScaleX*/, double /*fScaleY*/ )
607 {
608 Graphic aRet;
609 BmpFilterParam aParam( GetSepiaPercent() );
610
611 if( rGraphic.IsAnimated() )
612 {
613 Animation aAnim( rGraphic.GetAnimation() );
614
615 if( aAnim.Filter( BMP_FILTER_SEPIA, &aParam ) )
616 aRet = aAnim;
617 }
618 else
619 {
620 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
621
622 if( aBmpEx.Filter( BMP_FILTER_SEPIA, &aParam ) )
623 aRet = aBmpEx;
624 }
625
626 return aRet;
627 }
628
629 // -----------------------
630 // - GraphicFilterPoster -
631 // -----------------------
632
GraphicFilterPoster(Window * pParent,const Graphic & rGraphic,sal_uInt16 nPosterCount)633 GraphicFilterPoster::GraphicFilterPoster( Window* pParent, const Graphic& rGraphic,
634 sal_uInt16 nPosterCount ) :
635 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_POSTER ), rGraphic ),
636 maFtPoster ( this, CUI_RES( DLG_FILTERPOSTER_FT_POSTER ) ),
637 maNumPoster ( this, CUI_RES( DLG_FILTERPOSTER_NUM_POSTER ) )
638 {
639 FreeResource();
640
641 maNumPoster.SetFirst( 2 );
642 maNumPoster.SetLast( rGraphic.GetBitmapEx().GetBitCount() );
643 maNumPoster.SetValue( nPosterCount );
644 maNumPoster.SetModifyHdl( GetModifyHdl() );
645 }
646
647 // -----------------------------------------------------------------------------
648
~GraphicFilterPoster()649 GraphicFilterPoster::~GraphicFilterPoster()
650 {
651 }
652
653 // -----------------------------------------------------------------------------
654
GetFilteredGraphic(const Graphic & rGraphic,double,double)655 Graphic GraphicFilterPoster::GetFilteredGraphic( const Graphic& rGraphic,
656 double /*fScaleX*/, double /*fScaleY*/ )
657 {
658 Graphic aRet;
659 const sal_uInt16 nPosterCount = GetPosterColorCount();
660
661 if( rGraphic.IsAnimated() )
662 {
663 Animation aAnim( rGraphic.GetAnimation() );
664
665 if( aAnim.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
666 aRet = aAnim;
667 }
668 else
669 {
670 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
671
672 if( aBmpEx.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
673 aRet = aBmpEx;
674 }
675
676 return aRet;
677 }
678
679 // -----------------------
680 // - GraphicFilterEmboss -
681 // -----------------------
682
MouseButtonDown(const MouseEvent & rEvt)683 void GraphicFilterEmboss::EmbossControl::MouseButtonDown( const MouseEvent& rEvt )
684 {
685 const RECT_POINT eOldRP = GetActualRP();
686
687 SvxRectCtl::MouseButtonDown( rEvt );
688
689 if( GetActualRP() != eOldRP )
690 maModifyHdl.Call( this );
691 }
692
693 // -----------------------------------------------------------------------------
694
GraphicFilterEmboss(Window * pParent,const Graphic & rGraphic,RECT_POINT eLightSource)695 GraphicFilterEmboss::GraphicFilterEmboss( Window* pParent, const Graphic& rGraphic,
696 RECT_POINT eLightSource ) :
697 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_EMBOSS ), rGraphic ),
698 maFtLight ( this, CUI_RES( DLG_FILTEREMBOSS_FT_LIGHT ) ),
699 maCtlLight ( this, CUI_RES( DLG_FILTEREMBOSS_CTL_LIGHT ), eLightSource )
700 {
701 FreeResource();
702
703 maCtlLight.SetModifyHdl( GetModifyHdl() );
704 maCtlLight.GrabFocus();
705 }
706
707 // -----------------------------------------------------------------------------
708
~GraphicFilterEmboss()709 GraphicFilterEmboss::~GraphicFilterEmboss()
710 {
711 }
712
713 // -----------------------------------------------------------------------------
714
GetFilteredGraphic(const Graphic & rGraphic,double,double)715 Graphic GraphicFilterEmboss::GetFilteredGraphic( const Graphic& rGraphic,
716 double /*fScaleX*/, double /*fScaleY*/ )
717 {
718 Graphic aRet;
719 sal_uInt16 nAzim, nElev;
720
721 switch( maCtlLight.GetActualRP() )
722 {
723 default: DBG_ERROR("svx::GraphicFilterEmboss::GetFilteredGraphic(), unknown Reference Point!" );
724 case( RP_LT ): nAzim = 4500, nElev = 4500; break;
725 case( RP_MT ): nAzim = 9000, nElev = 4500; break;
726 case( RP_RT ): nAzim = 13500, nElev = 4500; break;
727 case( RP_LM ): nAzim = 0, nElev = 4500; break;
728 case( RP_MM ): nAzim = 0, nElev = 9000; break;
729 case( RP_RM ): nAzim = 18000, nElev = 4500; break;
730 case( RP_LB ): nAzim = 31500, nElev = 4500; break;
731 case( RP_MB ): nAzim = 27000, nElev = 4500; break;
732 case( RP_RB ): nAzim = 22500, nElev = 4500; break;
733 }
734
735 BmpFilterParam aParam( nAzim, nElev );
736
737 if( rGraphic.IsAnimated() )
738 {
739 Animation aAnim( rGraphic.GetAnimation() );
740
741 if( aAnim.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
742 aRet = aAnim;
743 }
744 else
745 {
746 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
747
748 if( aBmpEx.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
749 aRet = aBmpEx;
750 }
751
752 return aRet;
753 }
754