2001-11-03 10:10:51 +03:00
|
|
|
/* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-11-03 10:10:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef _nsICODecoder_h
|
|
|
|
#define _nsICODecoder_h
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2001-11-03 10:10:51 +03:00
|
|
|
#include "nsBMPDecoder.h"
|
2011-08-26 00:09:01 +04:00
|
|
|
#include "nsPNGDecoder.h"
|
2011-08-26 00:09:05 +04:00
|
|
|
#include "ICOFileHeaders.h"
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class nsICODecoder : public Decoder
|
2001-11-03 10:10:51 +03:00
|
|
|
{
|
|
|
|
public:
|
2002-05-15 00:32:13 +04:00
|
|
|
|
2013-01-19 01:47:18 +04:00
|
|
|
nsICODecoder(RasterImage &aImage);
|
2001-11-03 10:10:51 +03:00
|
|
|
virtual ~nsICODecoder();
|
|
|
|
|
2011-09-22 17:43:13 +04:00
|
|
|
// Obtains the width of the icon directory entry
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetRealWidth() const
|
2011-09-22 17:43:13 +04:00
|
|
|
{
|
|
|
|
return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the height of the icon directory entry
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetRealHeight() const
|
2011-09-22 17:43:13 +04:00
|
|
|
{
|
|
|
|
return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight;
|
|
|
|
}
|
|
|
|
|
2013-12-18 02:04:24 +04:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
|
2010-09-12 19:22:30 +04:00
|
|
|
virtual void FinishInternal();
|
2013-02-27 23:23:08 +04:00
|
|
|
virtual bool NeedsNewFrame() const;
|
|
|
|
virtual nsresult AllocateFrame();
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2001-11-03 10:10:51 +03:00
|
|
|
private:
|
2012-05-08 16:38:43 +04:00
|
|
|
// Writes to the contained decoder and sets the appropriate errors
|
|
|
|
// Returns true if there are no errors.
|
2013-12-18 02:04:24 +04:00
|
|
|
bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
|
2012-05-08 16:38:43 +04:00
|
|
|
|
2011-08-26 00:09:01 +04:00
|
|
|
// Processes a single dir entry of the icon resource
|
2002-05-15 00:32:13 +04:00
|
|
|
void ProcessDirEntry(IconDirEntry& aTarget);
|
2011-08-26 00:09:01 +04:00
|
|
|
// Sets the hotspot property of if we have a cursor
|
|
|
|
void SetHotSpotIfCursor();
|
2011-10-17 18:59:28 +04:00
|
|
|
// Creates a bitmap file header buffer, returns true if successful
|
2012-08-22 19:56:38 +04:00
|
|
|
bool FillBitmapFileHeaderBuffer(int8_t *bfh);
|
2011-11-04 17:56:17 +04:00
|
|
|
// Fixes the ICO height to match that of the BIH.
|
|
|
|
// and also fixes the BIH height to be /2 of what it was.
|
|
|
|
// See definition for explanation.
|
|
|
|
// Returns false if invalid information is contained within.
|
2012-08-22 19:56:38 +04:00
|
|
|
bool FixBitmapHeight(int8_t *bih);
|
2011-11-04 17:56:17 +04:00
|
|
|
// Fixes the ICO width to match that of the BIH.
|
|
|
|
// Returns false if invalid information is contained within.
|
2012-08-22 19:56:38 +04:00
|
|
|
bool FixBitmapWidth(int8_t *bih);
|
2011-08-30 09:12:59 +04:00
|
|
|
// Extract bitmap info header size count from BMP information header
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t ExtractBIHSizeFromBitmap(int8_t *bih);
|
2011-08-26 00:09:01 +04:00
|
|
|
// Extract bit count from BMP information header
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t ExtractBPPFromBitmap(int8_t *bih);
|
2011-08-26 00:09:01 +04:00
|
|
|
// Calculates the row size in bytes for the AND mask table
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t CalcAlphaRowSize();
|
2011-08-26 00:09:01 +04:00
|
|
|
// Obtains the number of colors from the BPP, mBPP must be filled in
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t GetNumColors();
|
|
|
|
|
|
|
|
uint16_t mBPP; // Stores the images BPP
|
|
|
|
uint32_t mPos; // Keeps track of the position we have decoded up until
|
|
|
|
uint16_t mNumIcons; // Stores the number of icons in the ICO file
|
|
|
|
uint16_t mCurrIcon; // Stores the current dir entry index we are processing
|
|
|
|
uint32_t mImageOffset; // Stores the offset of the image data we want
|
|
|
|
uint8_t *mRow; // Holds one raw line of the image
|
|
|
|
int32_t mCurLine; // Line index of the image that's currently being decoded
|
|
|
|
uint32_t mRowBytes; // How many bytes of the row were already received
|
|
|
|
int32_t mOldLine; // Previous index of the line
|
2011-08-26 00:09:01 +04:00
|
|
|
nsAutoPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
|
|
|
|
|
|
|
|
char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer
|
|
|
|
IconDirEntry mDirEntry; // Holds a decoded dir entry
|
|
|
|
// Holds the potential bytes that can be a PNG signature
|
|
|
|
char mSignature[PNGSIGNATURESIZE];
|
|
|
|
// Holds the potential bytes for a bitmap information header
|
|
|
|
char mBIHraw[40];
|
|
|
|
// Stores whether or not the icon file we are processing has type 1 (icon)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsCursor;
|
2011-08-26 00:09:01 +04:00
|
|
|
// Stores whether or not the contained resource is a PNG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsPNG;
|
2001-11-03 10:10:51 +03:00
|
|
|
};
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-23 06:30:46 +04:00
|
|
|
} // namespace mozilla
|
2001-11-03 10:10:51 +03:00
|
|
|
|
|
|
|
#endif
|