image/encoders/bmp/nsBMPEncoder.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:7d55537c2490
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include "mozilla/Attributes.h"
6 #include "mozilla/ReentrantMonitor.h"
7
8 #include "imgIEncoder.h"
9 #include "BMPFileHeaders.h"
10
11 #include "nsCOMPtr.h"
12
13 #define NS_BMPENCODER_CID \
14 { /* 13a5320c-4c91-4FA4-bd16-b081a3ba8c0b */ \
15 0x13a5320c, \
16 0x4c91, \
17 0x4fa4, \
18 {0xbd, 0x16, 0xb0, 0x81, 0xa3, 0Xba, 0x8c, 0x0b} \
19 }
20
21 // Provides BMP encoding functionality. Use InitFromData() to do the
22 // encoding. See that function definition for encoding options.
23
24 class nsBMPEncoder MOZ_FINAL : public imgIEncoder
25 {
26 typedef mozilla::ReentrantMonitor ReentrantMonitor;
27 public:
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_IMGIENCODER
30 NS_DECL_NSIINPUTSTREAM
31 NS_DECL_NSIASYNCINPUTSTREAM
32
33 nsBMPEncoder();
34 ~nsBMPEncoder();
35
36 protected:
37 enum Version {
38 VERSION_3 = 3,
39 VERSION_5 = 5
40 };
41
42 // See InitData in the cpp for valid parse options
43 nsresult ParseOptions(const nsAString& aOptions, Version* version,
44 uint32_t* bpp);
45 // Obtains data with no alpha in machine-independent byte order
46 void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest,
47 uint32_t aPixelWidth);
48 // Thread safe notify listener
49 void NotifyListener();
50
51 // Initializes the bitmap file header member mBMPFileHeader
52 void InitFileHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth,
53 uint32_t aHeight);
54 // Initializes the bitmap info header member mBMPInfoHeader
55 void InitInfoHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth,
56 uint32_t aHeight);
57
58 // Encodes the bitmap file header member mBMPFileHeader
59 void EncodeFileHeader();
60 // Encodes the bitmap info header member mBMPInfoHeader
61 void EncodeInfoHeader();
62 // Encodes a row of image data which does not have alpha data
63 void EncodeImageDataRow24(const uint8_t* aData);
64 // Encodes a row of image data which does have alpha data
65 void EncodeImageDataRow32(const uint8_t* aData);
66 // Obtains the current offset filled up to for the image buffer
67 inline int32_t GetCurrentImageBufferOffset()
68 {
69 return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart);
70 }
71
72 // These headers will always contain endian independent stuff
73 // They store the BMP headers which will be encoded
74 mozilla::image::BMPFILEHEADER mBMPFileHeader;
75 mozilla::image::BITMAPV5HEADER mBMPInfoHeader;
76
77 // Keeps track of the start of the image buffer
78 uint8_t* mImageBufferStart;
79 // Keeps track of the current position in the image buffer
80 uint8_t* mImageBufferCurr;
81 // Keeps track of the image buffer size
82 uint32_t mImageBufferSize;
83 // Keeps track of the number of bytes in the image buffer which are read
84 uint32_t mImageBufferReadPoint;
85 // Stores true if the image is done being encoded
86 bool mFinished;
87
88 nsCOMPtr<nsIInputStreamCallback> mCallback;
89 nsCOMPtr<nsIEventTarget> mCallbackTarget;
90 uint32_t mNotifyThreshold;
91 };

mercurial