2007-03-22 10:30:00 -07:00
|
|
|
/* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-11-14 09:59:00 -08:00
|
|
|
#ifndef nsICODecoder_h
|
|
|
|
#define nsICODecoder_h
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2010-08-22 19:30:46 -07:00
|
|
|
#include "Decoder.h"
|
2014-11-26 13:22:10 -08:00
|
|
|
#include "imgFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBMPDecoder.h"
|
2011-08-25 13:09:01 -07:00
|
|
|
#include "nsPNGDecoder.h"
|
2011-08-25 13:09:05 -07:00
|
|
|
#include "ICOFileHeaders.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-22 19:30:46 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
class nsICODecoder : public Decoder
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-01-15 15:11:35 -08:00
|
|
|
explicit nsICODecoder(RasterImage* aImage);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsICODecoder();
|
|
|
|
|
2011-09-22 06:43:13 -07:00
|
|
|
// Obtains the width of the icon directory entry
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t GetRealWidth() const
|
2011-09-22 06:43:13 -07:00
|
|
|
{
|
2014-11-14 09:59:00 -08:00
|
|
|
return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth;
|
2011-09-22 06:43:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the height of the icon directory entry
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t GetRealHeight() const
|
2011-09-22 06:43:13 -07:00
|
|
|
{
|
2014-11-14 09:59:00 -08:00
|
|
|
return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight;
|
2011-09-22 06:43:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) MOZ_OVERRIDE;
|
2015-01-02 16:16:57 -08:00
|
|
|
virtual void FinishInternal() MOZ_OVERRIDE;
|
2015-01-18 14:02:14 -08:00
|
|
|
virtual nsresult AllocateFrame(const nsIntSize& aTargetSize
|
|
|
|
/* = nsIntSize() */) MOZ_OVERRIDE;
|
2015-01-11 11:43:32 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool NeedsNewFrame() const MOZ_OVERRIDE;
|
2015-01-08 00:04:31 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2012-05-08 05:38:43 -07:00
|
|
|
// Writes to the contained decoder and sets the appropriate errors
|
|
|
|
// Returns true if there are no errors.
|
2015-01-08 00:04:31 -08:00
|
|
|
bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount);
|
2012-05-08 05:38:43 -07:00
|
|
|
|
2011-08-25 13:09:01 -07:00
|
|
|
// Processes a single dir entry of the icon resource
|
2007-03-22 10:30:00 -07:00
|
|
|
void ProcessDirEntry(IconDirEntry& aTarget);
|
2011-08-25 13:09:01 -07:00
|
|
|
// Sets the hotspot property of if we have a cursor
|
|
|
|
void SetHotSpotIfCursor();
|
2011-10-17 07:59:28 -07:00
|
|
|
// Creates a bitmap file header buffer, returns true if successful
|
2012-08-22 08:56:38 -07:00
|
|
|
bool FillBitmapFileHeaderBuffer(int8_t *bfh);
|
2011-11-04 06:56:17 -07: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 08:56:38 -07:00
|
|
|
bool FixBitmapHeight(int8_t *bih);
|
2011-11-04 06:56:17 -07:00
|
|
|
// Fixes the ICO width to match that of the BIH.
|
|
|
|
// Returns false if invalid information is contained within.
|
2012-08-22 08:56:38 -07:00
|
|
|
bool FixBitmapWidth(int8_t *bih);
|
2011-08-29 22:12:59 -07:00
|
|
|
// Extract bitmap info header size count from BMP information header
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ExtractBIHSizeFromBitmap(int8_t *bih);
|
2011-08-25 13:09:01 -07:00
|
|
|
// Extract bit count from BMP information header
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ExtractBPPFromBitmap(int8_t *bih);
|
2011-08-25 13:09:01 -07:00
|
|
|
// Calculates the row size in bytes for the AND mask table
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t CalcAlphaRowSize();
|
2011-08-25 13:09:01 -07:00
|
|
|
// Obtains the number of colors from the BPP, mBPP must be filled in
|
2012-08-22 08:56:38 -07: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
|
2014-11-14 09:59:00 -08:00
|
|
|
uint8_t* mRow; // Holds one raw line of the image
|
2012-08-22 08:56:38 -07:00
|
|
|
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
|
2014-11-14 09:59:00 -08:00
|
|
|
int32_t mOldLine; // Previous index of the line
|
2014-09-09 19:47:02 -07:00
|
|
|
nsRefPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
|
2015-01-11 11:43:32 -08:00
|
|
|
RawAccessFrameRef mRefForContainedDecoder; // Avoid locking off-main-thread
|
2011-08-25 13:09:01 -07:00
|
|
|
|
|
|
|
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
|
2014-11-14 09:59:00 -08:00
|
|
|
char mSignature[PNGSIGNATURESIZE];
|
2011-08-25 13:09:01 -07:00
|
|
|
// 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-28 23:19:26 -07:00
|
|
|
bool mIsCursor;
|
2011-08-25 13:09:01 -07:00
|
|
|
// Stores whether or not the contained resource is a PNG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsPNG;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-22 19:30:46 -07:00
|
|
|
} // namespace mozilla
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-14 09:59:00 -08:00
|
|
|
#endif // nsICODecoder_h
|