ImageScaling.h (3061B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef _MOZILLA_GFX_IMAGESCALING_H 8 #define _MOZILLA_GFX_IMAGESCALING_H 9 10 #include "Types.h" 11 12 #include "Point.h" 13 14 namespace mozilla { 15 namespace gfx { 16 17 class ImageHalfScaler { 18 public: 19 ImageHalfScaler(uint8_t* aData, int32_t aStride, const IntSize& aSize) 20 : mOrigData(aData), 21 mOrigStride(aStride), 22 mOrigSize(aSize), 23 mDataStorage(nullptr), 24 mData(nullptr), 25 mStride(0) {} 26 27 ~ImageHalfScaler() { delete[] mDataStorage; } 28 29 void ScaleForSize(const IntSize& aSize); 30 31 uint8_t* GetScaledData() const { return mData; } 32 IntSize GetSize() const { return mSize; } 33 uint32_t GetStride() const { return mStride; } 34 35 private: 36 void HalfImage2D(uint8_t* aSource, int32_t aSourceStride, 37 const IntSize& aSourceSize, uint8_t* aDest, 38 uint32_t aDestStride); 39 void HalfImageVertical(uint8_t* aSource, int32_t aSourceStride, 40 const IntSize& aSourceSize, uint8_t* aDest, 41 uint32_t aDestStride); 42 void HalfImageHorizontal(uint8_t* aSource, int32_t aSourceStride, 43 const IntSize& aSourceSize, uint8_t* aDest, 44 uint32_t aDestStride); 45 46 // This is our SSE2 scaling function. Our destination must always be 16-byte 47 // aligned and use a 16-byte aligned stride. 48 void HalfImage2D_SSE2(uint8_t* aSource, int32_t aSourceStride, 49 const IntSize& aSourceSize, uint8_t* aDest, 50 uint32_t aDestStride); 51 void HalfImageVertical_SSE2(uint8_t* aSource, int32_t aSourceStride, 52 const IntSize& aSourceSize, uint8_t* aDest, 53 uint32_t aDestStride); 54 void HalfImageHorizontal_SSE2(uint8_t* aSource, int32_t aSourceStride, 55 const IntSize& aSourceSize, uint8_t* aDest, 56 uint32_t aDestStride); 57 58 void HalfImage2D_C(uint8_t* aSource, int32_t aSourceStride, 59 const IntSize& aSourceSize, uint8_t* aDest, 60 uint32_t aDestStride); 61 void HalfImageVertical_C(uint8_t* aSource, int32_t aSourceStride, 62 const IntSize& aSourceSize, uint8_t* aDest, 63 uint32_t aDestStride); 64 void HalfImageHorizontal_C(uint8_t* aSource, int32_t aSourceStride, 65 const IntSize& aSourceSize, uint8_t* aDest, 66 uint32_t aDestStride); 67 68 uint8_t* mOrigData; 69 int32_t mOrigStride; 70 IntSize mOrigSize; 71 72 uint8_t* mDataStorage; 73 // Guaranteed 16-byte aligned 74 uint8_t* mData; 75 IntSize mSize; 76 // Guaranteed 16-byte aligned 77 uint32_t mStride; 78 }; 79 80 } // namespace gfx 81 } // namespace mozilla 82 83 #endif