gfx/2d/ImageScaling.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/ImageScaling.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     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_IMAGESCALING_H
    1.10 +#define _MOZILLA_GFX_IMAGESCALING_H
    1.11 +
    1.12 +#include "Types.h"
    1.13 +
    1.14 +#include <vector>
    1.15 +#include "Point.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace gfx {
    1.19 +
    1.20 +class ImageHalfScaler
    1.21 +{
    1.22 +public:
    1.23 +  ImageHalfScaler(uint8_t *aData, int32_t aStride, const IntSize &aSize)
    1.24 +    : mOrigData(aData), mOrigStride(aStride), mOrigSize(aSize)
    1.25 +    , mDataStorage(nullptr)
    1.26 +  {
    1.27 +  }
    1.28 +
    1.29 +  ~ImageHalfScaler()
    1.30 +  {
    1.31 +    delete [] mDataStorage;
    1.32 +  }
    1.33 +
    1.34 +  void ScaleForSize(const IntSize &aSize);
    1.35 +
    1.36 +  uint8_t *GetScaledData() const { return mData; }
    1.37 +  IntSize GetSize() const { return mSize; }
    1.38 +  uint32_t GetStride() const { return mStride; }
    1.39 +
    1.40 +private:
    1.41 +  void HalfImage2D(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.42 +                   uint8_t *aDest, uint32_t aDestStride);
    1.43 +  void HalfImageVertical(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.44 +                         uint8_t *aDest, uint32_t aDestStride);
    1.45 +  void HalfImageHorizontal(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.46 +                           uint8_t *aDest, uint32_t aDestStride);
    1.47 +
    1.48 +  // This is our SSE2 scaling function. Our destination must always be 16-byte
    1.49 +  // aligned and use a 16-byte aligned stride.
    1.50 +  void HalfImage2D_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.51 +                        uint8_t *aDest, uint32_t aDestStride);
    1.52 +  void HalfImageVertical_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.53 +                              uint8_t *aDest, uint32_t aDestStride);
    1.54 +  void HalfImageHorizontal_SSE2(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.55 +                                uint8_t *aDest, uint32_t aDestStride);
    1.56 +
    1.57 +  void HalfImage2D_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.58 +                     uint8_t *aDest, uint32_t aDestStride);
    1.59 +  void HalfImageVertical_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.60 +                           uint8_t *aDest, uint32_t aDestStride);
    1.61 +  void HalfImageHorizontal_C(uint8_t *aSource, int32_t aSourceStride, const IntSize &aSourceSize,
    1.62 +                             uint8_t *aDest, uint32_t aDestStride);
    1.63 +
    1.64 +  uint8_t *mOrigData;
    1.65 +  int32_t mOrigStride;
    1.66 +  IntSize mOrigSize;
    1.67 +
    1.68 +  uint8_t *mDataStorage;
    1.69 +  // Guaranteed 16-byte aligned
    1.70 +  uint8_t *mData;
    1.71 +  IntSize mSize;
    1.72 +  // Guaranteed 16-byte aligned
    1.73 +  uint32_t mStride;
    1.74 +};
    1.75 +
    1.76 +}
    1.77 +}
    1.78 +
    1.79 +#endif

mercurial