1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/encoders/ico/nsICOEncoder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 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 + 1.13 +#include "nsAutoPtr.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "ICOFileHeaders.h" 1.16 + 1.17 +class nsBMPEncoder; 1.18 +class nsPNGEncoder; 1.19 + 1.20 +#define NS_ICOENCODER_CID \ 1.21 +{ /*92AE3AB2-8968-41B1-8709-B6123BCEAF21 */ \ 1.22 + 0x92ae3ab2, \ 1.23 + 0x8968, \ 1.24 + 0x41b1, \ 1.25 + {0x87, 0x09, 0xb6, 0x12, 0x3b, 0Xce, 0xaf, 0x21} \ 1.26 +} 1.27 + 1.28 +// Provides ICO encoding functionality. Use InitFromData() to do the 1.29 +// encoding. See that function definition for encoding options. 1.30 + 1.31 +class nsICOEncoder MOZ_FINAL : public imgIEncoder 1.32 +{ 1.33 + typedef mozilla::ReentrantMonitor ReentrantMonitor; 1.34 +public: 1.35 + NS_DECL_THREADSAFE_ISUPPORTS 1.36 + NS_DECL_IMGIENCODER 1.37 + NS_DECL_NSIINPUTSTREAM 1.38 + NS_DECL_NSIASYNCINPUTSTREAM 1.39 + 1.40 + nsICOEncoder(); 1.41 + ~nsICOEncoder(); 1.42 + 1.43 + // Obtains the width of the icon directory entry 1.44 + uint32_t GetRealWidth() const 1.45 + { 1.46 + return mICODirEntry.mWidth == 0 ? 256 : mICODirEntry.mWidth; 1.47 + } 1.48 + 1.49 + // Obtains the height of the icon directory entry 1.50 + uint32_t GetRealHeight() const 1.51 + { 1.52 + return mICODirEntry.mHeight == 0 ? 256 : mICODirEntry.mHeight; 1.53 + } 1.54 + 1.55 +protected: 1.56 + nsresult ParseOptions(const nsAString& aOptions, uint32_t* bpp, 1.57 + bool *usePNG); 1.58 + void NotifyListener(); 1.59 + 1.60 + // Initializes the icon file header mICOFileHeader 1.61 + void InitFileHeader(); 1.62 + // Initializes the icon directory info header mICODirEntry 1.63 + void InitInfoHeader(uint32_t aBPP, uint8_t aWidth, uint8_t aHeight); 1.64 + // Encodes the icon file header mICOFileHeader 1.65 + void EncodeFileHeader(); 1.66 + // Encodes the icon directory info header mICODirEntry 1.67 + void EncodeInfoHeader(); 1.68 + // Obtains the current offset filled up to for the image buffer 1.69 + inline int32_t GetCurrentImageBufferOffset() 1.70 + { 1.71 + return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart); 1.72 + } 1.73 + 1.74 + // Holds either a PNG or a BMP depending on the encoding options specified 1.75 + // or if no encoding options specified will use the default (PNG) 1.76 + nsCOMPtr<imgIEncoder> mContainedEncoder; 1.77 + 1.78 + // These headers will always contain endian independent stuff. 1.79 + // Don't trust the width and height of mICODirEntry directly, 1.80 + // instead use the accessors GetRealWidth() and GetRealHeight(). 1.81 + mozilla::image::IconFileHeader mICOFileHeader; 1.82 + mozilla::image::IconDirEntry mICODirEntry; 1.83 + 1.84 + // Keeps track of the start of the image buffer 1.85 + uint8_t* mImageBufferStart; 1.86 + // Keeps track of the current position in the image buffer 1.87 + uint8_t* mImageBufferCurr; 1.88 + // Keeps track of the image buffer size 1.89 + uint32_t mImageBufferSize; 1.90 + // Keeps track of the number of bytes in the image buffer which are read 1.91 + uint32_t mImageBufferReadPoint; 1.92 + // Stores true if the image is done being encoded 1.93 + bool mFinished; 1.94 + // Stores true if the contained image is a PNG 1.95 + bool mUsePNG; 1.96 + 1.97 + nsCOMPtr<nsIInputStreamCallback> mCallback; 1.98 + nsCOMPtr<nsIEventTarget> mCallbackTarget; 1.99 + uint32_t mNotifyThreshold; 1.100 +};