transformer.cxx (5900e8ec) transformer.cxx (87bc88d3)
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

--- 48 unchanged lines hidden (view full) ---

57// ------------------------------------------------------------------------------
58
59GraphicTransformer::~GraphicTransformer()
60{
61}
62
63// ------------------------------------------------------------------------------
64
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

--- 48 unchanged lines hidden (view full) ---

57// ------------------------------------------------------------------------------
58
59GraphicTransformer::~GraphicTransformer()
60{
61}
62
63// ------------------------------------------------------------------------------
64
65void setAlpha( Bitmap& rBitmap, AlphaMask& rAlpha, sal_Int32 nColorFrom, sal_Int8 nAlphaTo )
65void setAlpha( Bitmap& rBitmap, AlphaMask& rAlpha, sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
66{
67 BitmapWriteAccess* pWriteAccess = rAlpha.AcquireWriteAccess();
68 BitmapReadAccess* pReadAccess = rBitmap.AcquireReadAccess();
66{
67 BitmapWriteAccess* pWriteAccess = rAlpha.AcquireWriteAccess();
68 BitmapReadAccess* pReadAccess = rBitmap.AcquireReadAccess();
69 BitmapColor aColorFrom( static_cast< sal_uInt8 >( nColorFrom >> 16 ),
70 static_cast< sal_uInt8 >( nColorFrom >> 8 ),
71 static_cast< sal_uInt8 >( nColorFrom ) );
72 if ( pReadAccess && pWriteAccess )
73 {
74 for ( sal_Int32 nY = 0; nY < pReadAccess->Height(); nY++ )
75 {
76 for ( sal_Int32 nX = 0; nX < pReadAccess->Width(); nX++ )
77 {
69 if ( pReadAccess && pWriteAccess )
70 {
71 for ( sal_Int32 nY = 0; nY < pReadAccess->Height(); nY++ )
72 {
73 for ( sal_Int32 nX = 0; nX < pReadAccess->Width(); nX++ )
74 {
78 BitmapColor aColor( pReadAccess->GetPixel( nY, nX ) );
79 if ( aColor == aColorFrom )
80 pWriteAccess->SetPixel( nY, nX, nAlphaTo );
75 const sal_uInt8 cIndex = pReadAccess->GetPixelIndex( nY, nX );
76 if ( cIndex == cIndexFrom )
77 pWriteAccess->SetPixelIndex( nY, nX, nAlphaTo );
81 }
82 }
83 }
84 rBitmap.ReleaseAccess( pReadAccess );
85 rAlpha.ReleaseAccess( pWriteAccess );
86}
87
88// XGraphicTransformer
89uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
90 const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo )
91 throw ( lang::IllegalArgumentException, uno::RuntimeException)
92{
93 const uno::Reference< uno::XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
94 ::Graphic aGraphic( *::unographic::Graphic::getImplementation( xIFace ) );
95
96 BitmapColor aColorFrom( static_cast< sal_uInt8 >( nColorFrom ), static_cast< sal_uInt8 >( nColorFrom >> 8 ), static_cast< sal_uInt8 >( nColorFrom >> 16 ) );
97 BitmapColor aColorTo( static_cast< sal_uInt8 >( nColorTo ), static_cast< sal_uInt8 >( nColorTo >> 8 ), static_cast< sal_uInt8 >( nColorTo >> 16 ) );
78 }
79 }
80 }
81 rBitmap.ReleaseAccess( pReadAccess );
82 rAlpha.ReleaseAccess( pWriteAccess );
83}
84
85// XGraphicTransformer
86uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
87 const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo )
88 throw ( lang::IllegalArgumentException, uno::RuntimeException)
89{
90 const uno::Reference< uno::XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
91 ::Graphic aGraphic( *::unographic::Graphic::getImplementation( xIFace ) );
92
93 BitmapColor aColorFrom( static_cast< sal_uInt8 >( nColorFrom ), static_cast< sal_uInt8 >( nColorFrom >> 8 ), static_cast< sal_uInt8 >( nColorFrom >> 16 ) );
94 BitmapColor aColorTo( static_cast< sal_uInt8 >( nColorTo ), static_cast< sal_uInt8 >( nColorTo >> 8 ), static_cast< sal_uInt8 >( nColorTo >> 16 ) );
95 const sal_uInt8 cIndexFrom = aColorFrom.GetBlueOrIndex();
98
99 if ( aGraphic.GetType() == GRAPHIC_BITMAP )
100 {
101 BitmapEx aBitmapEx( aGraphic.GetBitmapEx() );
102 Bitmap aBitmap( aBitmapEx.GetBitmap() );
103
104 if ( aBitmapEx.IsAlpha() )
105 {
106 AlphaMask aAlphaMask( aBitmapEx.GetAlpha() );
96
97 if ( aGraphic.GetType() == GRAPHIC_BITMAP )
98 {
99 BitmapEx aBitmapEx( aGraphic.GetBitmapEx() );
100 Bitmap aBitmap( aBitmapEx.GetBitmap() );
101
102 if ( aBitmapEx.IsAlpha() )
103 {
104 AlphaMask aAlphaMask( aBitmapEx.GetAlpha() );
107 setAlpha( aBitmap, aAlphaMask, aColorFrom, nAlphaTo );
105 setAlpha( aBitmap, aAlphaMask, cIndexFrom, nAlphaTo );
108 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
109 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
110 }
111 else if ( aBitmapEx.IsTransparent() )
112 {
113 if ( ( nAlphaTo == 0 ) || ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) ) )
114 {
115 Bitmap aMask( aBitmapEx.GetMask() );
116 Bitmap aMask2( aBitmap.CreateMask( aColorFrom, nTolerance ) );
117 aMask.CombineSimple( aMask2, BMP_COMBINE_OR );
118 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
119 aGraphic = ::Graphic( BitmapEx( aBitmap, aMask ) );
120 }
121 else
122 {
123 AlphaMask aAlphaMask( aBitmapEx.GetMask() );
106 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
107 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
108 }
109 else if ( aBitmapEx.IsTransparent() )
110 {
111 if ( ( nAlphaTo == 0 ) || ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) ) )
112 {
113 Bitmap aMask( aBitmapEx.GetMask() );
114 Bitmap aMask2( aBitmap.CreateMask( aColorFrom, nTolerance ) );
115 aMask.CombineSimple( aMask2, BMP_COMBINE_OR );
116 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
117 aGraphic = ::Graphic( BitmapEx( aBitmap, aMask ) );
118 }
119 else
120 {
121 AlphaMask aAlphaMask( aBitmapEx.GetMask() );
124 setAlpha( aBitmap, aAlphaMask, aColorFrom, nAlphaTo );
122 setAlpha( aBitmap, aAlphaMask, cIndexFrom, nAlphaTo );
125 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
126 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
127 }
128 }
129 else
130 {
131 if ( ( nAlphaTo == 0 ) || ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) ) )
132 {
133 Bitmap aMask( aBitmap.CreateMask( aColorFrom, nTolerance ) );
134 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
135 aGraphic = ::Graphic( BitmapEx( aBitmap, aMask ) );
136 }
137 else
138 {
139 AlphaMask aAlphaMask( aBitmapEx.GetSizePixel() );
123 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
124 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
125 }
126 }
127 else
128 {
129 if ( ( nAlphaTo == 0 ) || ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) ) )
130 {
131 Bitmap aMask( aBitmap.CreateMask( aColorFrom, nTolerance ) );
132 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
133 aGraphic = ::Graphic( BitmapEx( aBitmap, aMask ) );
134 }
135 else
136 {
137 AlphaMask aAlphaMask( aBitmapEx.GetSizePixel() );
140 setAlpha( aBitmap, aAlphaMask, aColorFrom, nAlphaTo );
138 setAlpha( aBitmap, aAlphaMask, cIndexFrom, nAlphaTo );
141 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
142 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
143 }
144 }
145 }
146 ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic();
147 pUnoGraphic->init( aGraphic );
148 uno::Reference< graphic::XGraphic > xRet( pUnoGraphic );
149 return xRet;
150}
151
152}
139 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
140 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
141 }
142 }
143 }
144 ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic();
145 pUnoGraphic->init( aGraphic );
146 uno::Reference< graphic::XGraphic > xRet( pUnoGraphic );
147 return xRet;
148}
149
150}