LCOV - code coverage report
Current view: top level - gfx/2d - FilterProcessingScalar.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 110 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #define FILTER_PROCESSING_SCALAR
       7             : 
       8             : #include "FilterProcessingSIMD-inl.h"
       9             : #include "Logging.h"
      10             : 
      11             : namespace mozilla {
      12             : namespace gfx {
      13             : 
      14             : void
      15           0 : FilterProcessing::ExtractAlpha_Scalar(const IntSize& size, uint8_t* sourceData, int32_t sourceStride, uint8_t* alphaData, int32_t alphaStride)
      16             : {
      17           0 :   for (int32_t y = 0; y < size.height; y++) {
      18           0 :     for (int32_t x = 0; x < size.width; x++) {
      19           0 :       int32_t sourceIndex = y * sourceStride + 4 * x;
      20           0 :       int32_t targetIndex = y * alphaStride + x;
      21           0 :       alphaData[targetIndex] = sourceData[sourceIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A];
      22             :     }
      23             :   }
      24           0 : }
      25             : 
      26             : already_AddRefed<DataSourceSurface>
      27           0 : FilterProcessing::ConvertToB8G8R8A8_Scalar(SourceSurface* aSurface)
      28             : {
      29           0 :   return ConvertToB8G8R8A8_SIMD<simd::Scalaru8x16_t>(aSurface);
      30             : }
      31             : 
      32             : template<MorphologyOperator Operator>
      33             : static void
      34           0 : ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
      35             :                                  uint8_t* aDestData, int32_t aDestStride,
      36             :                                  const IntRect& aDestRect, int32_t aRadius)
      37             : {
      38             :   static_assert(Operator == MORPHOLOGY_OPERATOR_ERODE ||
      39             :                 Operator == MORPHOLOGY_OPERATOR_DILATE,
      40             :                 "unexpected morphology operator");
      41             : 
      42           0 :   for (int32_t y = aDestRect.y; y < aDestRect.YMost(); y++) {
      43           0 :     int32_t startX = aDestRect.x - aRadius;
      44           0 :     int32_t endX = aDestRect.x + aRadius;
      45           0 :     for (int32_t x = aDestRect.x; x < aDestRect.XMost(); x++, startX++, endX++) {
      46           0 :       int32_t sourceIndex = y * aSourceStride + 4 * startX;
      47             :       uint8_t u[4];
      48           0 :       for (size_t i = 0; i < 4; i++) {
      49           0 :         u[i] = aSourceData[sourceIndex + i];
      50             :       }
      51           0 :       sourceIndex += 4;
      52           0 :       for (int32_t ix = startX + 1; ix <= endX; ix++, sourceIndex += 4) {
      53           0 :         for (size_t i = 0; i < 4; i++) {
      54             :           if (Operator == MORPHOLOGY_OPERATOR_ERODE) {
      55           0 :             u[i] = umin(u[i], aSourceData[sourceIndex + i]);
      56             :           } else {
      57           0 :             u[i] = umax(u[i], aSourceData[sourceIndex + i]);
      58             :           }
      59             :         }
      60             :       }
      61             : 
      62           0 :       int32_t destIndex = y * aDestStride + 4 * x;
      63           0 :       for (size_t i = 0; i < 4; i++) {
      64           0 :         aDestData[destIndex+i] = u[i];
      65             :       }
      66             :     }
      67             :   }
      68           0 : }
      69             : 
      70             : void
      71           0 : FilterProcessing::ApplyMorphologyHorizontal_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
      72             :                                                    uint8_t* aDestData, int32_t aDestStride,
      73             :                                                    const IntRect& aDestRect, int32_t aRadius,
      74             :                                                    MorphologyOperator aOp)
      75             : {
      76           0 :   if (aOp == MORPHOLOGY_OPERATOR_ERODE) {
      77             :     gfx::ApplyMorphologyHorizontal_Scalar<MORPHOLOGY_OPERATOR_ERODE>(
      78           0 :       aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius);
      79             :   } else {
      80             :     gfx::ApplyMorphologyHorizontal_Scalar<MORPHOLOGY_OPERATOR_DILATE>(
      81           0 :       aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius);
      82             :   }
      83           0 : }
      84             : 
      85             : template<MorphologyOperator Operator>
      86           0 : static void ApplyMorphologyVertical_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
      87             :                                            uint8_t* aDestData, int32_t aDestStride,
      88             :                                            const IntRect& aDestRect, int32_t aRadius)
      89             : {
      90             :   static_assert(Operator == MORPHOLOGY_OPERATOR_ERODE ||
      91             :                 Operator == MORPHOLOGY_OPERATOR_DILATE,
      92             :                 "unexpected morphology operator");
      93             : 
      94           0 :   int32_t startY = aDestRect.y - aRadius;
      95           0 :   int32_t endY = aDestRect.y + aRadius;
      96           0 :   for (int32_t y = aDestRect.y; y < aDestRect.YMost(); y++, startY++, endY++) {
      97           0 :     for (int32_t x = aDestRect.x; x < aDestRect.XMost(); x++) {
      98           0 :       int32_t sourceIndex = startY * aSourceStride + 4 * x;
      99             :       uint8_t u[4];
     100           0 :       for (size_t i = 0; i < 4; i++) {
     101           0 :         u[i] = aSourceData[sourceIndex + i];
     102             :       }
     103           0 :       sourceIndex += aSourceStride;
     104           0 :       for (int32_t iy = startY + 1; iy <= endY; iy++, sourceIndex += aSourceStride) {
     105           0 :         for (size_t i = 0; i < 4; i++) {
     106             :           if (Operator == MORPHOLOGY_OPERATOR_ERODE) {
     107           0 :             u[i] = umin(u[i], aSourceData[sourceIndex + i]);
     108             :           } else {
     109           0 :             u[i] = umax(u[i], aSourceData[sourceIndex + i]);
     110             :           }
     111             :         }
     112             :       }
     113             : 
     114           0 :       int32_t destIndex = y * aDestStride + 4 * x;
     115           0 :       for (size_t i = 0; i < 4; i++) {
     116           0 :         aDestData[destIndex+i] = u[i];
     117             :       }
     118             :     }
     119             :   }
     120           0 : }
     121             : 
     122             : void
     123           0 : FilterProcessing::ApplyMorphologyVertical_Scalar(uint8_t* aSourceData, int32_t aSourceStride,
     124             :                                                    uint8_t* aDestData, int32_t aDestStride,
     125             :                                                    const IntRect& aDestRect, int32_t aRadius,
     126             :                                                    MorphologyOperator aOp)
     127             : {
     128           0 :   if (aOp == MORPHOLOGY_OPERATOR_ERODE) {
     129             :     gfx::ApplyMorphologyVertical_Scalar<MORPHOLOGY_OPERATOR_ERODE>(
     130           0 :       aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius);
     131             :   } else {
     132             :     gfx::ApplyMorphologyVertical_Scalar<MORPHOLOGY_OPERATOR_DILATE>(
     133           0 :       aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius);
     134             :   }
     135           0 : }
     136             : 
     137             : already_AddRefed<DataSourceSurface>
     138           0 : FilterProcessing::ApplyColorMatrix_Scalar(DataSourceSurface* aInput, const Matrix5x4 &aMatrix)
     139             : {
     140           0 :   return ApplyColorMatrix_SIMD<simd::Scalari32x4_t,simd::Scalari16x8_t,simd::Scalaru8x16_t>(aInput, aMatrix);
     141             : }
     142             : 
     143             : void
     144           0 : FilterProcessing::ApplyComposition_Scalar(DataSourceSurface* aSource, DataSourceSurface* aDest,
     145             :                                           CompositeOperator aOperator)
     146             : {
     147           0 :   return ApplyComposition_SIMD<simd::Scalari32x4_t,simd::Scalaru16x8_t,simd::Scalaru8x16_t>(aSource, aDest, aOperator);
     148             : }
     149             : 
     150             : void
     151           0 : FilterProcessing::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)
     152             : {
     153           0 :   for (int32_t y = 0; y < size.height; y++) {
     154           0 :     for (int32_t x = 0; x < size.width; x++) {
     155           0 :       int32_t sourceIndex = y * sourceStride + 4 * x;
     156           0 :       int32_t targetIndex = y * channelStride + x;
     157           0 :       channel0Data[targetIndex] = sourceData[sourceIndex];
     158           0 :       channel1Data[targetIndex] = sourceData[sourceIndex+1];
     159           0 :       channel2Data[targetIndex] = sourceData[sourceIndex+2];
     160           0 :       channel3Data[targetIndex] = sourceData[sourceIndex+3];
     161             :     }
     162             :   }
     163           0 : }
     164             : 
     165             : void
     166           0 : FilterProcessing::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)
     167             : {
     168           0 :   for (int32_t y = 0; y < size.height; y++) {
     169           0 :     for (int32_t x = 0; x < size.width; x++) {
     170           0 :       int32_t resultIndex = y * resultStride + 4 * x;
     171           0 :       int32_t channelIndex = y * channelStride + x;
     172           0 :       resultData[resultIndex] = channel0Data[channelIndex];
     173           0 :       resultData[resultIndex+1] = channel1Data[channelIndex];
     174           0 :       resultData[resultIndex+2] = channel2Data[channelIndex];
     175           0 :       resultData[resultIndex+3] = channel3Data[channelIndex];
     176             :     }
     177             :   }
     178           0 : }
     179             : 
     180             : void
     181           0 : FilterProcessing::DoPremultiplicationCalculation_Scalar(const IntSize& aSize,
     182             :                                      uint8_t* aTargetData, int32_t aTargetStride,
     183             :                                      uint8_t* aSourceData, int32_t aSourceStride)
     184             : {
     185           0 :   for (int32_t y = 0; y < aSize.height; y++) {
     186           0 :     for (int32_t x = 0; x < aSize.width; x++) {
     187           0 :       int32_t inputIndex = y * aSourceStride + 4 * x;
     188           0 :       int32_t targetIndex = y * aTargetStride + 4 * x;
     189           0 :       uint8_t alpha = aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A];
     190           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_R] =
     191           0 :         FastDivideBy255<uint8_t>(aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_R] * alpha);
     192           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_G] =
     193           0 :         FastDivideBy255<uint8_t>(aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_G] * alpha);
     194           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_B] =
     195           0 :         FastDivideBy255<uint8_t>(aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_B] * alpha);
     196           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A] = alpha;
     197             :     }
     198             :   }
     199           0 : }
     200             : 
     201             : void
     202           0 : FilterProcessing::DoUnpremultiplicationCalculation_Scalar(
     203             :                                  const IntSize& aSize,
     204             :                                  uint8_t* aTargetData, int32_t aTargetStride,
     205             :                                  uint8_t* aSourceData, int32_t aSourceStride)
     206             : {
     207           0 :   for (int32_t y = 0; y < aSize.height; y++) {
     208           0 :     for (int32_t x = 0; x < aSize.width; x++) {
     209           0 :       int32_t inputIndex = y * aSourceStride + 4 * x;
     210           0 :       int32_t targetIndex = y * aTargetStride + 4 * x;
     211           0 :       uint8_t alpha = aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A];
     212           0 :       uint16_t alphaFactor = sAlphaFactors[alpha];
     213             :       // inputColor * alphaFactor + 128 is guaranteed to fit into uint16_t
     214             :       // because the input is premultiplied and thus inputColor <= inputAlpha.
     215             :       // The maximum value this can attain is 65520 (which is less than 65535)
     216             :       // for color == alpha == 244:
     217             :       // 244 * sAlphaFactors[244] + 128 == 244 * 268 + 128 == 65520
     218           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_R] =
     219           0 :         (aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_R] * alphaFactor + 128) >> 8;
     220           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_G] =
     221           0 :         (aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_G] * alphaFactor + 128) >> 8;
     222           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_B] =
     223           0 :         (aSourceData[inputIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_B] * alphaFactor + 128) >> 8;
     224           0 :       aTargetData[targetIndex + B8G8R8A8_COMPONENT_BYTEOFFSET_A] = alpha;
     225             :     }
     226             :   }
     227           0 : }
     228             : 
     229             : already_AddRefed<DataSourceSurface>
     230           0 : FilterProcessing::RenderTurbulence_Scalar(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency,
     231             :                                           int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect)
     232             : {
     233             :    return RenderTurbulence_SIMD<simd::Scalarf32x4_t,simd::Scalari32x4_t,simd::Scalaru8x16_t>(
     234           0 :      aSize, aOffset, aBaseFrequency, aSeed, aNumOctaves, aType, aStitch, aTileRect);
     235             : }
     236             : 
     237             : already_AddRefed<DataSourceSurface>
     238           0 : FilterProcessing::ApplyArithmeticCombine_Scalar(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4)
     239             : {
     240           0 :   return ApplyArithmeticCombine_SIMD<simd::Scalari32x4_t,simd::Scalari16x8_t,simd::Scalaru8x16_t>(aInput1, aInput2, aK1, aK2, aK3, aK4);
     241             : }
     242             : 
     243             : } // namespace gfx
     244             : } // namespace mozilla

Generated by: LCOV version 1.13