gfx/2d/FilterProcessing.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/FilterProcessing.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef _MOZILLA_GFX_FILTERPROCESSING_H_
    1.10 +#define _MOZILLA_GFX_FILTERPROCESSING_H_
    1.11 +
    1.12 +#include "2D.h"
    1.13 +#include "Filters.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace gfx {
    1.17 +
    1.18 +const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_B = 0;
    1.19 +const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_G = 1;
    1.20 +const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_R = 2;
    1.21 +const ptrdiff_t B8G8R8A8_COMPONENT_BYTEOFFSET_A = 3;
    1.22 +
    1.23 +class FilterProcessing
    1.24 +{
    1.25 +public:
    1.26 +
    1.27 +  // Fast approximate division by 255. It has the property that
    1.28 +  // for all 0 <= v <= 255*255, FastDivideBy255(v) == v/255.
    1.29 +  // But it only uses two adds and two shifts instead of an
    1.30 +  // integer division (which is expensive on many processors).
    1.31 +  template<class B, class A>
    1.32 +  static B FastDivideBy255(A v)
    1.33 +  {
    1.34 +    return ((v << 8) + v + 255) >> 16;
    1.35 +  }
    1.36 +
    1.37 +  static TemporaryRef<DataSourceSurface> ExtractAlpha(DataSourceSurface* aSource);
    1.38 +  static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8(SourceSurface* aSurface);
    1.39 +  static TemporaryRef<DataSourceSurface> ApplyBlending(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
    1.40 +  static void ApplyMorphologyHorizontal(uint8_t* aSourceData, int32_t aSourceStride,
    1.41 +                                          uint8_t* aDestData, int32_t aDestStride,
    1.42 +                                          const IntRect& aDestRect, int32_t aRadius,
    1.43 +                                          MorphologyOperator aOperator);
    1.44 +  static void ApplyMorphologyVertical(uint8_t* aSourceData, int32_t aSourceStride,
    1.45 +                                          uint8_t* aDestData, int32_t aDestStride,
    1.46 +                                          const IntRect& aDestRect, int32_t aRadius,
    1.47 +                                          MorphologyOperator aOperator);
    1.48 +  static TemporaryRef<DataSourceSurface> ApplyColorMatrix(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
    1.49 +  static void ApplyComposition(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
    1.50 +  static void SeparateColorChannels(DataSourceSurface* aSource,
    1.51 +                                    RefPtr<DataSourceSurface>& aChannel0,
    1.52 +                                    RefPtr<DataSourceSurface>& aChannel1,
    1.53 +                                    RefPtr<DataSourceSurface>& aChannel2,
    1.54 +                                    RefPtr<DataSourceSurface>& aChannel3);
    1.55 +  static TemporaryRef<DataSourceSurface>
    1.56 +    CombineColorChannels(DataSourceSurface* aChannel0, DataSourceSurface* aChannel1,
    1.57 +                         DataSourceSurface* aChannel2, DataSourceSurface* aChannel3);
    1.58 +  static void DoPremultiplicationCalculation(const IntSize& aSize,
    1.59 +                                        uint8_t* aTargetData, int32_t aTargetStride,
    1.60 +                                        uint8_t* aSourceData, int32_t aSourceStride);
    1.61 +  static void DoUnpremultiplicationCalculation(const IntSize& aSize,
    1.62 +                                               uint8_t* aTargetData, int32_t aTargetStride,
    1.63 +                                               uint8_t* aSourceData, int32_t aSourceStride);
    1.64 +  static TemporaryRef<DataSourceSurface>
    1.65 +    RenderTurbulence(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
    1.66 +                     int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
    1.67 +  static TemporaryRef<DataSourceSurface>
    1.68 +    ApplyArithmeticCombine(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
    1.69 +
    1.70 +protected:
    1.71 +  static void ExtractAlpha_Scalar(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride);
    1.72 +  static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8_Scalar(SourceSurface* aSurface);
    1.73 +  static TemporaryRef<DataSourceSurface> ApplyBlending_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
    1.74 +  static void ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
    1.75 +                                               uint8_t* aDestData, int32_t aDestStride,
    1.76 +                                               const IntRect& aDestRect, int32_t aRadius,
    1.77 +                                               MorphologyOperator aOperator);
    1.78 +  static void ApplyMorphologyVertical_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
    1.79 +                                               uint8_t* aDestData, int32_t aDestStride,
    1.80 +                                               const IntRect& aDestRect, int32_t aRadius,
    1.81 +                                               MorphologyOperator aOperator);
    1.82 +  static TemporaryRef<DataSourceSurface> ApplyColorMatrix_Scalar(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
    1.83 +  static void ApplyComposition_Scalar(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
    1.84 +
    1.85 +  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);
    1.86 +  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);
    1.87 +  static void DoPremultiplicationCalculation_Scalar(const IntSize& aSize,
    1.88 +                                        uint8_t* aTargetData, int32_t aTargetStride,
    1.89 +                                        uint8_t* aSourceData, int32_t aSourceStride);
    1.90 +  static void DoUnpremultiplicationCalculation_Scalar(const IntSize& aSize,
    1.91 +                                               uint8_t* aTargetData, int32_t aTargetStride,
    1.92 +                                               uint8_t* aSourceData, int32_t aSourceStride);
    1.93 +  static TemporaryRef<DataSourceSurface>
    1.94 +    RenderTurbulence_Scalar(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
    1.95 +                            int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
    1.96 +  static TemporaryRef<DataSourceSurface>
    1.97 +    ApplyArithmeticCombine_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
    1.98 +
    1.99 +#ifdef USE_SSE2
   1.100 +  static void ExtractAlpha_SSE2(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride);
   1.101 +  static TemporaryRef<DataSourceSurface> ConvertToB8G8R8A8_SSE2(SourceSurface* aSurface);
   1.102 +  static TemporaryRef<DataSourceSurface> ApplyBlending_SSE2(DataSourceSurface* aInput1, DataSourceSurface* aInput2, BlendMode aBlendMode);
   1.103 +  static void ApplyMorphologyHorizontal_SSE2(uint8_t* aSourceData, int32_t aSourceStride,
   1.104 +                                             uint8_t* aDestData, int32_t aDestStride,
   1.105 +                                             const IntRect& aDestRect, int32_t aRadius,
   1.106 +                                             MorphologyOperator aOperator);
   1.107 +  static void ApplyMorphologyVertical_SSE2(uint8_t* aSourceData, int32_t aSourceStride,
   1.108 +                                             uint8_t* aDestData, int32_t aDestStride,
   1.109 +                                             const IntRect& aDestRect, int32_t aRadius,
   1.110 +                                             MorphologyOperator aOperator);
   1.111 +  static TemporaryRef<DataSourceSurface> ApplyColorMatrix_SSE2(DataSourceSurface* aInput, const Matrix5x4 &aMatrix);
   1.112 +  static void ApplyComposition_SSE2(DataSourceSurface* aSource, DataSourceSurface* aDest, CompositeOperator aOperator);
   1.113 +  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);
   1.114 +  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);
   1.115 +  static void DoPremultiplicationCalculation_SSE2(const IntSize& aSize,
   1.116 +                                        uint8_t* aTargetData, int32_t aTargetStride,
   1.117 +                                        uint8_t* aSourceData, int32_t aSourceStride);
   1.118 +  static void DoUnpremultiplicationCalculation_SSE2(const IntSize& aSize,
   1.119 +                                               uint8_t* aTargetData, int32_t aTargetStride,
   1.120 +                                               uint8_t* aSourceData, int32_t aSourceStride);
   1.121 +  static TemporaryRef<DataSourceSurface>
   1.122 +    RenderTurbulence_SSE2(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
   1.123 +                          int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect);
   1.124 +  static TemporaryRef<DataSourceSurface>
   1.125 +    ApplyArithmeticCombine_SSE2(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4);
   1.126 +#endif
   1.127 +};
   1.128 +
   1.129 +// Constant-time max and min functions for unsigned arguments
   1.130 +static inline unsigned
   1.131 +umax(unsigned a, unsigned b)
   1.132 +{
   1.133 +  return a - ((a - b) & -(a < b));
   1.134 +}
   1.135 +
   1.136 +static inline unsigned
   1.137 +umin(unsigned a, unsigned b)
   1.138 +{
   1.139 +  return a - ((a - b) & -(a > b));
   1.140 +}
   1.141 +
   1.142 +} // namespace gfx
   1.143 +} // namespace mozilla
   1.144 +
   1.145 +#endif // _MOZILLA_GFX_FILTERPROCESSING_H_

mercurial