Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/encoders/ico/nsICOEncoder.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef mozilla_image_encoders_ico_nsICOEncoder_h
6
#define mozilla_image_encoders_ico_nsICOEncoder_h
7
8
#include "mozilla/Attributes.h"
9
#include "mozilla/ReentrantMonitor.h"
10
11
#include "imgIEncoder.h"
12
13
#include "nsCOMPtr.h"
14
#include "ICOFileHeaders.h"
15
16
#define NS_ICOENCODER_CID \
17
{ /*92AE3AB2-8968-41B1-8709-B6123BCEAF21 */          \
18
     0x92ae3ab2,                                     \
19
     0x8968,                                         \
20
     0x41b1,                                         \
21
    {0x87, 0x09, 0xb6, 0x12, 0x3b, 0Xce, 0xaf, 0x21} \
22
}
23
24
// Provides ICO encoding functionality. Use InitFromData() to do the
25
// encoding. See that function definition for encoding options.
26
27
class nsICOEncoder final : public imgIEncoder
28
{
29
  typedef mozilla::ReentrantMonitor ReentrantMonitor;
30
public:
31
  NS_DECL_THREADSAFE_ISUPPORTS
32
  NS_DECL_IMGIENCODER
33
  NS_DECL_NSIINPUTSTREAM
34
  NS_DECL_NSIASYNCINPUTSTREAM
35
36
  nsICOEncoder();
37
38
  // Obtains the width of the icon directory entry
39
  uint32_t GetRealWidth() const
40
0
  {
41
0
    return mICODirEntry.mWidth == 0 ? 256 : mICODirEntry.mWidth;
42
0
  }
43
44
  // Obtains the height of the icon directory entry
45
  uint32_t GetRealHeight() const
46
0
  {
47
0
    return mICODirEntry.mHeight == 0 ? 256 : mICODirEntry.mHeight;
48
0
  }
49
50
protected:
51
  ~nsICOEncoder();
52
53
  nsresult ParseOptions(const nsAString& aOptions, uint16_t& aBppOut,
54
                        bool& aUsePNGOut);
55
  void NotifyListener();
56
57
  // Initializes the icon file header mICOFileHeader
58
  void InitFileHeader();
59
  // Initializes the icon directory info header mICODirEntry
60
  void InitInfoHeader(uint16_t aBPP, uint8_t aWidth, uint8_t aHeight);
61
  // Encodes the icon file header mICOFileHeader
62
  void EncodeFileHeader();
63
  // Encodes the icon directory info header mICODirEntry
64
  void EncodeInfoHeader();
65
  // Obtains the current offset filled up to for the image buffer
66
  inline int32_t GetCurrentImageBufferOffset()
67
0
  {
68
0
    return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart);
69
0
  }
70
71
  // Holds either a PNG or a BMP depending on the encoding options specified
72
  // or if no encoding options specified will use the default (PNG)
73
  nsCOMPtr<imgIEncoder> mContainedEncoder;
74
75
  // These headers will always contain endian independent stuff.
76
  // Don't trust the width and height of mICODirEntry directly,
77
  // instead use the accessors GetRealWidth() and GetRealHeight().
78
  mozilla::image::IconFileHeader mICOFileHeader;
79
  mozilla::image::IconDirEntry mICODirEntry;
80
81
  // Keeps track of the start of the image buffer
82
  uint8_t* mImageBufferStart;
83
  // Keeps track of the current position in the image buffer
84
  uint8_t* mImageBufferCurr;
85
  // Keeps track of the image buffer size
86
  uint32_t mImageBufferSize;
87
  // Keeps track of the number of bytes in the image buffer which are read
88
  uint32_t mImageBufferReadPoint;
89
  // Stores true if the image is done being encoded
90
  bool mFinished;
91
  // Stores true if the contained image is a PNG
92
  bool mUsePNG;
93
94
  nsCOMPtr<nsIInputStreamCallback> mCallback;
95
  nsCOMPtr<nsIEventTarget> mCallbackTarget;
96
  uint32_t mNotifyThreshold;
97
};
98
99
#endif // mozilla_image_encoders_ico_nsICOEncoder_h