gfx/2d/FilterProcessing.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef _MOZILLA_GFX_FILTERPROCESSING_H_
michael@0 7 #define _MOZILLA_GFX_FILTERPROCESSING_H_
michael@0 8
michael@0 9 #include "2D.h"
michael@0 10 #include "Filters.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace gfx {
michael@0 14
michael@0 15 const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_B = 0;
michael@0 16 const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_G = 1;
michael@0 17 const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_R = 2;
michael@0 18 const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_A = 3;
michael@0 19
michael@0 20 class FilterProcessing
michael@0 21 {
michael@0 22 public:
michael@0 23
michael@0 24 // Fast approximate division by 255. It has the property that
michael@0 25 // for all 0 <= v <= 255*255, FastDivideBy255(v) == v/255.
michael@0 26 // But it only uses two adds and two shifts instead of an
michael@0 27 // integer division (which is expensive on many processors).
michael@0 28 template<class B, class A>
michael@0 29 static B FastDivideBy255(A v)
michael@0 30 {
michael@0 31 return ((v << 8) + v + 255) >> 16;
michael@0 32 }
michael@0 33
michael@0 34 static TemporaryRef<DataSourceSurface> ExtractAlpha(DataSourceSurface* aSource);
michael@0 35 static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8(SourceSurface* aSurface);
michael@0 36 static TemporaryRef<DataSourceSurface> ApplyBlending(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
michael@0 37 static void ApplyMorphologyHorizontal(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 38 uint8_t* aDestData, int32_t aDestStride,
michael@0 39 const IntRect& aDestRect, int32_t aRadius,
michael@0 40 MorphologyOperator aOperator);
michael@0 41 static void ApplyMorphologyVertical(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 42 uint8_t* aDestData, int32_t aDestStride,
michael@0 43 const IntRect& aDestRect, int32_t aRadius,
michael@0 44 MorphologyOperator aOperator);
michael@0 45 static TemporaryRef<DataSourceSurface> ApplyColorMatrix(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
michael@0 46 static void ApplyComposition(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
michael@0 47 static void SeparateColorChannels(DataSourceSurface* aSource,
michael@0 48 RefPtr<DataSourceSurface>& aChannel0,
michael@0 49 RefPtr<DataSourceSurface>& aChannel1,
michael@0 50 RefPtr<DataSourceSurface>& aChannel2,
michael@0 51 RefPtr<DataSourceSurface>& aChannel3);
michael@0 52 static TemporaryRef<DataSourceSurface>
michael@0 53 CombineColorChannels(DataSourceSurface* aChannel0, DataSourceSurface* aChannel1,
michael@0 54 DataSourceSurface* aChannel2, DataSourceSurface* aChannel3);
michael@0 55 static void DoPremultiplicationCalculation(const IntSize& aSize,
michael@0 56 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 57 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 58 static void DoUnpremultiplicationCalculation(const IntSize& aSize,
michael@0 59 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 60 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 61 static TemporaryRef<DataSourceSurface>
michael@0 62 RenderTurbulence(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
michael@0 63 int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
michael@0 64 static TemporaryRef<DataSourceSurface>
michael@0 65 ApplyArithmeticCombine(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
michael@0 66
michael@0 67 protected:
michael@0 68 static void ExtractAlpha_Scalar(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride);
michael@0 69 static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8_Scalar(SourceSurface* aSurface);
michael@0 70 static TemporaryRef<DataSourceSurface> ApplyBlending_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
michael@0 71 static void ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 72 uint8_t* aDestData, int32_t aDestStride,
michael@0 73 const IntRect& aDestRect, int32_t aRadius,
michael@0 74 MorphologyOperator aOperator);
michael@0 75 static void ApplyMorphologyVertical_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 76 uint8_t* aDestData, int32_t aDestStride,
michael@0 77 const IntRect& aDestRect, int32_t aRadius,
michael@0 78 MorphologyOperator aOperator);
michael@0 79 static TemporaryRef<DataSourceSurface> ApplyColorMatrix_Scalar(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
michael@0 80 static void ApplyComposition_Scalar(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
michael@0 81
michael@0 82 static void SeparateColorChannels_Scalar(const IntSize &size, uint8_t* sourceData, int32_t sourceStride, uint8_t* channel0Data, uint8_t* channel1Data, uint8_t* channel2Data, uint8_t* channel3Data, int32_t channelStride);
michael@0 83 static void CombineColorChannels_Scalar(const IntSize &size, int32_t resultStride, uint8_t* resultData, int32_t channelStride, uint8_t* channel0Data, uint8_t* channel1Data, uint8_t* channel2Data, uint8_t* channel3Data);
michael@0 84 static void DoPremultiplicationCalculation_Scalar(const IntSize& aSize,
michael@0 85 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 86 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 87 static void DoUnpremultiplicationCalculation_Scalar(const IntSize& aSize,
michael@0 88 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 89 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 90 static TemporaryRef<DataSourceSurface>
michael@0 91 RenderTurbulence_Scalar(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
michael@0 92 int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
michael@0 93 static TemporaryRef<DataSourceSurface>
michael@0 94 ApplyArithmeticCombine_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
michael@0 95
michael@0 96 #ifdef USE_SSE2
michael@0 97 static void ExtractAlpha_SSE2(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride);
michael@0 98 static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8_SSE2(SourceSurface* aSurface);
michael@0 99 static TemporaryRef<DataSourceSurface> ApplyBlending_SSE2(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
michael@0 100 static void ApplyMorphologyHorizontal_SSE2(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 101 uint8_t* aDestData, int32_t aDestStride,
michael@0 102 const IntRect& aDestRect, int32_t aRadius,
michael@0 103 MorphologyOperator aOperator);
michael@0 104 static void ApplyMorphologyVertical_SSE2(uint8_t* aSourceData, int32_t aSourceStride,
michael@0 105 uint8_t* aDestData, int32_t aDestStride,
michael@0 106 const IntRect& aDestRect, int32_t aRadius,
michael@0 107 MorphologyOperator aOperator);
michael@0 108 static TemporaryRef<DataSourceSurface> ApplyColorMatrix_SSE2(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
michael@0 109 static void ApplyComposition_SSE2(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
michael@0 110 static void SeparateColorChannels_SSE2(const IntSize &size, uint8_t* sourceData, int32_t sourceStride, uint8_t* channel0Data, uint8_t* channel1Data, uint8_t* channel2Data, uint8_t* channel3Data, int32_t channelStride);
michael@0 111 static void CombineColorChannels_SSE2(const IntSize &size, int32_t resultStride, uint8_t* resultData, int32_t channelStride, uint8_t* channel0Data, uint8_t* channel1Data, uint8_t* channel2Data, uint8_t* channel3Data);
michael@0 112 static void DoPremultiplicationCalculation_SSE2(const IntSize& aSize,
michael@0 113 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 114 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 115 static void DoUnpremultiplicationCalculation_SSE2(const IntSize& aSize,
michael@0 116 uint8_t* aTargetData, int32_t aTargetStride,
michael@0 117 uint8_t* aSourceData, int32_t aSourceStride);
michael@0 118 static TemporaryRef<DataSourceSurface>
michael@0 119 RenderTurbulence_SSE2(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
michael@0 120 int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
michael@0 121 static TemporaryRef<DataSourceSurface>
michael@0 122 ApplyArithmeticCombine_SSE2(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
michael@0 123 #endif
michael@0 124 };
michael@0 125
michael@0 126 // Constant-time max and min functions for unsigned arguments
michael@0 127 static inline unsigned
michael@0 128 umax(unsigned a, unsigned b)
michael@0 129 {
michael@0 130 return a - ((a - b) & -(a < b));
michael@0 131 }
michael@0 132
michael@0 133 static inline unsigned
michael@0 134 umin(unsigned a, unsigned b)
michael@0 135 {
michael@0 136 return a - ((a - b) & -(a > b));
michael@0 137 }
michael@0 138
michael@0 139 } // namespace gfx
michael@0 140 } // namespace mozilla
michael@0 141
michael@0 142 #endif // _MOZILLA_GFX_FILTERPROCESSING_H_

mercurial