michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "FilterProcessing.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::ExtractAlpha(DataSourceSurface* aSource) michael@0: { michael@0: IntSize size = aSource->GetSize(); michael@0: RefPtr alpha = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); michael@0: uint8_t* sourceData = aSource->GetData(); michael@0: int32_t sourceStride = aSource->Stride(); michael@0: uint8_t* alphaData = alpha->GetData(); michael@0: int32_t alphaStride = alpha->Stride(); michael@0: michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: ExtractAlpha_SSE2(size, sourceData, sourceStride, alphaData, alphaStride); michael@0: #endif michael@0: } else { michael@0: ExtractAlpha_Scalar(size, sourceData, sourceStride, alphaData, alphaStride); michael@0: } michael@0: michael@0: return alpha; michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::ConvertToB8G8R8A8(SourceSurface* aSurface) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: return ConvertToB8G8R8A8_SSE2(aSurface); michael@0: #endif michael@0: } michael@0: return ConvertToB8G8R8A8_Scalar(aSurface); michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::ApplyBlending(DataSourceSurface* aInput1, DataSourceSurface* aInput2, michael@0: BlendMode aBlendMode) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: return ApplyBlending_SSE2(aInput1, aInput2, aBlendMode); michael@0: #endif michael@0: } michael@0: return ApplyBlending_Scalar(aInput1, aInput2, aBlendMode); michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::ApplyMorphologyHorizontal(uint8_t* aSourceData, int32_t aSourceStride, michael@0: uint8_t* aDestData, int32_t aDestStride, michael@0: const IntRect& aDestRect, int32_t aRadius, michael@0: MorphologyOperator aOp) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: ApplyMorphologyHorizontal_SSE2( michael@0: aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); michael@0: #endif michael@0: } else { michael@0: ApplyMorphologyHorizontal_Scalar( michael@0: aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); michael@0: } michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::ApplyMorphologyVertical(uint8_t* aSourceData, int32_t aSourceStride, michael@0: uint8_t* aDestData, int32_t aDestStride, michael@0: const IntRect& aDestRect, int32_t aRadius, michael@0: MorphologyOperator aOp) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: ApplyMorphologyVertical_SSE2( michael@0: aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); michael@0: #endif michael@0: } else { michael@0: ApplyMorphologyVertical_Scalar( michael@0: aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); michael@0: } michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::ApplyColorMatrix(DataSourceSurface* aInput, const Matrix5x4 &aMatrix) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: return ApplyColorMatrix_SSE2(aInput, aMatrix); michael@0: #endif michael@0: } michael@0: return ApplyColorMatrix_Scalar(aInput, aMatrix); michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::ApplyComposition(DataSourceSurface* aSource, DataSourceSurface* aDest, michael@0: CompositeOperator aOperator) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: ApplyComposition_SSE2(aSource, aDest, aOperator); michael@0: #endif michael@0: } else { michael@0: ApplyComposition_Scalar(aSource, aDest, aOperator); michael@0: } michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::SeparateColorChannels(DataSourceSurface* aSource, michael@0: RefPtr& aChannel0, michael@0: RefPtr& aChannel1, michael@0: RefPtr& aChannel2, michael@0: RefPtr& aChannel3) michael@0: { michael@0: IntSize size = aSource->GetSize(); michael@0: aChannel0 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); michael@0: aChannel1 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); michael@0: aChannel2 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); michael@0: aChannel3 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); michael@0: uint8_t* sourceData = aSource->GetData(); michael@0: int32_t sourceStride = aSource->Stride(); michael@0: uint8_t* channel0Data = aChannel0->GetData(); michael@0: uint8_t* channel1Data = aChannel1->GetData(); michael@0: uint8_t* channel2Data = aChannel2->GetData(); michael@0: uint8_t* channel3Data = aChannel3->GetData(); michael@0: int32_t channelStride = aChannel0->Stride(); michael@0: michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: SeparateColorChannels_SSE2(size, sourceData, sourceStride, channel0Data, channel1Data, channel2Data, channel3Data, channelStride); michael@0: #endif michael@0: } else { michael@0: SeparateColorChannels_Scalar(size, sourceData, sourceStride, channel0Data, channel1Data, channel2Data, channel3Data, channelStride); michael@0: } michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::CombineColorChannels(DataSourceSurface* aChannel0, DataSourceSurface* aChannel1, michael@0: DataSourceSurface* aChannel2, DataSourceSurface* aChannel3) michael@0: { michael@0: IntSize size = aChannel0->GetSize(); michael@0: RefPtr result = michael@0: Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8); michael@0: int32_t resultStride = result->Stride(); michael@0: uint8_t* resultData = result->GetData(); michael@0: int32_t channelStride = aChannel0->Stride(); michael@0: uint8_t* channel0Data = aChannel0->GetData(); michael@0: uint8_t* channel1Data = aChannel1->GetData(); michael@0: uint8_t* channel2Data = aChannel2->GetData(); michael@0: uint8_t* channel3Data = aChannel3->GetData(); michael@0: michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: CombineColorChannels_SSE2(size, resultStride, resultData, channelStride, channel0Data, channel1Data, channel2Data, channel3Data); michael@0: #endif michael@0: } else { michael@0: CombineColorChannels_Scalar(size, resultStride, resultData, channelStride, channel0Data, channel1Data, channel2Data, channel3Data); michael@0: } michael@0: michael@0: return result; michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::DoPremultiplicationCalculation(const IntSize& aSize, michael@0: uint8_t* aTargetData, int32_t aTargetStride, michael@0: uint8_t* aSourceData, int32_t aSourceStride) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: DoPremultiplicationCalculation_SSE2( michael@0: aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); michael@0: #endif michael@0: } else { michael@0: DoPremultiplicationCalculation_Scalar( michael@0: aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); michael@0: } michael@0: } michael@0: michael@0: void michael@0: FilterProcessing::DoUnpremultiplicationCalculation(const IntSize& aSize, michael@0: uint8_t* aTargetData, int32_t aTargetStride, michael@0: uint8_t* aSourceData, int32_t aSourceStride) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: DoUnpremultiplicationCalculation_SSE2( michael@0: aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); michael@0: #endif michael@0: } else { michael@0: DoUnpremultiplicationCalculation_Scalar( michael@0: aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); michael@0: } michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::RenderTurbulence(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency, michael@0: int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: return RenderTurbulence_SSE2(aSize, aOffset, aBaseFrequency, aSeed, aNumOctaves, aType, aStitch, aTileRect); michael@0: #endif michael@0: } michael@0: return RenderTurbulence_Scalar(aSize, aOffset, aBaseFrequency, aSeed, aNumOctaves, aType, aStitch, aTileRect); michael@0: } michael@0: michael@0: TemporaryRef michael@0: FilterProcessing::ApplyArithmeticCombine(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4) michael@0: { michael@0: if (Factory::HasSSE2()) { michael@0: #ifdef USE_SSE2 michael@0: return ApplyArithmeticCombine_SSE2(aInput1, aInput2, aK1, aK2, aK3, aK4); michael@0: #endif michael@0: } michael@0: return ApplyArithmeticCombine_Scalar(aInput1, aInput2, aK1, aK2, aK3, aK4); michael@0: } michael@0: michael@0: } // namespace gfx michael@0: } // namespace mozilla