1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/encoders/bmp/nsBMPEncoder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "mozilla/Attributes.h" 1.9 +#include "mozilla/ReentrantMonitor.h" 1.10 + 1.11 +#include "imgIEncoder.h" 1.12 +#include "BMPFileHeaders.h" 1.13 + 1.14 +#include "nsCOMPtr.h" 1.15 + 1.16 +#define NS_BMPENCODER_CID \ 1.17 +{ /* 13a5320c-4c91-4FA4-bd16-b081a3ba8c0b */ \ 1.18 + 0x13a5320c, \ 1.19 + 0x4c91, \ 1.20 + 0x4fa4, \ 1.21 + {0xbd, 0x16, 0xb0, 0x81, 0xa3, 0Xba, 0x8c, 0x0b} \ 1.22 +} 1.23 + 1.24 +// Provides BMP encoding functionality. Use InitFromData() to do the 1.25 +// encoding. See that function definition for encoding options. 1.26 + 1.27 +class nsBMPEncoder MOZ_FINAL : public imgIEncoder 1.28 +{ 1.29 + typedef mozilla::ReentrantMonitor ReentrantMonitor; 1.30 +public: 1.31 + NS_DECL_THREADSAFE_ISUPPORTS 1.32 + NS_DECL_IMGIENCODER 1.33 + NS_DECL_NSIINPUTSTREAM 1.34 + NS_DECL_NSIASYNCINPUTSTREAM 1.35 + 1.36 + nsBMPEncoder(); 1.37 + ~nsBMPEncoder(); 1.38 + 1.39 +protected: 1.40 + enum Version { 1.41 + VERSION_3 = 3, 1.42 + VERSION_5 = 5 1.43 + }; 1.44 + 1.45 + // See InitData in the cpp for valid parse options 1.46 + nsresult ParseOptions(const nsAString& aOptions, Version* version, 1.47 + uint32_t* bpp); 1.48 + // Obtains data with no alpha in machine-independent byte order 1.49 + void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest, 1.50 + uint32_t aPixelWidth); 1.51 + // Thread safe notify listener 1.52 + void NotifyListener(); 1.53 + 1.54 + // Initializes the bitmap file header member mBMPFileHeader 1.55 + void InitFileHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth, 1.56 + uint32_t aHeight); 1.57 + // Initializes the bitmap info header member mBMPInfoHeader 1.58 + void InitInfoHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth, 1.59 + uint32_t aHeight); 1.60 + 1.61 + // Encodes the bitmap file header member mBMPFileHeader 1.62 + void EncodeFileHeader(); 1.63 + // Encodes the bitmap info header member mBMPInfoHeader 1.64 + void EncodeInfoHeader(); 1.65 + // Encodes a row of image data which does not have alpha data 1.66 + void EncodeImageDataRow24(const uint8_t* aData); 1.67 + // Encodes a row of image data which does have alpha data 1.68 + void EncodeImageDataRow32(const uint8_t* aData); 1.69 + // Obtains the current offset filled up to for the image buffer 1.70 + inline int32_t GetCurrentImageBufferOffset() 1.71 + { 1.72 + return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart); 1.73 + } 1.74 + 1.75 + // These headers will always contain endian independent stuff 1.76 + // They store the BMP headers which will be encoded 1.77 + mozilla::image::BMPFILEHEADER mBMPFileHeader; 1.78 + mozilla::image::BITMAPV5HEADER mBMPInfoHeader; 1.79 + 1.80 + // Keeps track of the start of the image buffer 1.81 + uint8_t* mImageBufferStart; 1.82 + // Keeps track of the current position in the image buffer 1.83 + uint8_t* mImageBufferCurr; 1.84 + // Keeps track of the image buffer size 1.85 + uint32_t mImageBufferSize; 1.86 + // Keeps track of the number of bytes in the image buffer which are read 1.87 + uint32_t mImageBufferReadPoint; 1.88 + // Stores true if the image is done being encoded 1.89 + bool mFinished; 1.90 + 1.91 + nsCOMPtr<nsIInputStreamCallback> mCallback; 1.92 + nsCOMPtr<nsIEventTarget> mCallbackTarget; 1.93 + uint32_t mNotifyThreshold; 1.94 +};