2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-08-25 20:09:05 +00:00
|
|
|
|
2012-01-02 20:23:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-08-25 20:09:05 +00:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
|
2012-01-02 20:23:41 +00:00
|
|
|
#include "imgIEncoder.h"
|
|
|
|
|
2011-08-25 20:09:05 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "ICOFileHeaders.h"
|
|
|
|
|
|
|
|
class nsBMPEncoder;
|
|
|
|
class nsPNGEncoder;
|
|
|
|
|
|
|
|
#define NS_ICOENCODER_CID \
|
|
|
|
{ /*92AE3AB2-8968-41B1-8709-B6123BCEAF21 */ \
|
|
|
|
0x92ae3ab2, \
|
|
|
|
0x8968, \
|
|
|
|
0x41b1, \
|
|
|
|
{0x87, 0x09, 0xb6, 0x12, 0x3b, 0Xce, 0xaf, 0x21} \
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provides ICO encoding functionality. Use InitFromData() to do the
|
|
|
|
// encoding. See that function definition for encoding options.
|
|
|
|
|
2012-01-02 20:23:41 +00:00
|
|
|
class nsICOEncoder MOZ_FINAL : public imgIEncoder
|
2011-08-25 20:09:05 +00:00
|
|
|
{
|
|
|
|
typedef mozilla::ReentrantMonitor ReentrantMonitor;
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_IMGIENCODER
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAM
|
|
|
|
|
|
|
|
nsICOEncoder();
|
|
|
|
~nsICOEncoder();
|
2011-09-22 13:43:13 +00:00
|
|
|
|
|
|
|
// Obtains the width of the icon directory entry
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetRealWidth() const
|
2011-09-22 13:43:13 +00:00
|
|
|
{
|
|
|
|
return mICODirEntry.mWidth == 0 ? 256 : mICODirEntry.mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the height of the icon directory entry
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetRealHeight() const
|
2011-09-22 13:43:13 +00:00
|
|
|
{
|
|
|
|
return mICODirEntry.mHeight == 0 ? 256 : mICODirEntry.mHeight;
|
|
|
|
}
|
2011-08-25 20:09:05 +00:00
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult ParseOptions(const nsAString& aOptions, uint32_t* bpp,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *usePNG);
|
2011-08-25 20:09:05 +00:00
|
|
|
void NotifyListener();
|
|
|
|
|
|
|
|
// Initializes the icon file header mICOFileHeader
|
|
|
|
void InitFileHeader();
|
|
|
|
// Initializes the icon directory info header mICODirEntry
|
2012-08-22 15:56:38 +00:00
|
|
|
void InitInfoHeader(uint32_t aBPP, uint8_t aWidth, uint8_t aHeight);
|
2011-08-25 20:09:05 +00:00
|
|
|
// Encodes the icon file header mICOFileHeader
|
|
|
|
void EncodeFileHeader();
|
|
|
|
// Encodes the icon directory info header mICODirEntry
|
|
|
|
void EncodeInfoHeader();
|
|
|
|
// Obtains the current offset filled up to for the image buffer
|
2012-08-22 15:56:38 +00:00
|
|
|
inline int32_t GetCurrentImageBufferOffset()
|
2011-08-25 20:09:05 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart);
|
2011-08-25 20:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Holds either a PNG or a BMP depending on the encoding options specified
|
|
|
|
// or if no encoding options specified will use the default (PNG)
|
|
|
|
nsCOMPtr<imgIEncoder> mContainedEncoder;
|
|
|
|
|
2011-09-22 13:43:13 +00:00
|
|
|
// These headers will always contain endian independent stuff.
|
|
|
|
// Don't trust the width and height of mICODirEntry directly,
|
|
|
|
// instead use the accessors GetRealWidth() and GetRealHeight().
|
2012-01-06 16:02:27 +00:00
|
|
|
mozilla::image::IconFileHeader mICOFileHeader;
|
|
|
|
mozilla::image::IconDirEntry mICODirEntry;
|
2011-08-25 20:09:05 +00:00
|
|
|
|
|
|
|
// Keeps track of the start of the image buffer
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t* mImageBufferStart;
|
2011-08-25 20:09:05 +00:00
|
|
|
// Keeps track of the current position in the image buffer
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t* mImageBufferCurr;
|
2011-08-25 20:09:05 +00:00
|
|
|
// Keeps track of the image buffer size
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mImageBufferSize;
|
2011-08-25 20:09:05 +00:00
|
|
|
// Keeps track of the number of bytes in the image buffer which are read
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mImageBufferReadPoint;
|
2011-10-17 14:59:28 +00:00
|
|
|
// Stores true if the image is done being encoded
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mFinished;
|
2011-10-17 14:59:28 +00:00
|
|
|
// Stores true if the contained image is a PNG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mUsePNG;
|
2011-08-25 20:09:05 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
|
|
|
nsCOMPtr<nsIEventTarget> mCallbackTarget;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mNotifyThreshold;
|
2011-08-25 20:09:05 +00:00
|
|
|
};
|