image/decoders/nsICODecoder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/decoders/nsICODecoder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +/* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +#ifndef _nsICODecoder_h
    1.11 +#define _nsICODecoder_h
    1.12 +
    1.13 +#include "nsAutoPtr.h"
    1.14 +#include "Decoder.h"
    1.15 +#include "nsBMPDecoder.h"
    1.16 +#include "nsPNGDecoder.h"
    1.17 +#include "ICOFileHeaders.h"
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace image {
    1.21 +
    1.22 +class RasterImage;
    1.23 +
    1.24 +class nsICODecoder : public Decoder
    1.25 +{
    1.26 +public:
    1.27 +
    1.28 +  nsICODecoder(RasterImage &aImage);
    1.29 +  virtual ~nsICODecoder();
    1.30 +
    1.31 +  // Obtains the width of the icon directory entry
    1.32 +  uint32_t GetRealWidth() const
    1.33 +  {
    1.34 +    return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth; 
    1.35 +  }
    1.36 +
    1.37 +  // Obtains the height of the icon directory entry
    1.38 +  uint32_t GetRealHeight() const
    1.39 +  {
    1.40 +    return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight; 
    1.41 +  }
    1.42 +
    1.43 +  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
    1.44 +  virtual void FinishInternal();
    1.45 +  virtual bool NeedsNewFrame() const;
    1.46 +  virtual nsresult AllocateFrame();
    1.47 +
    1.48 +private:
    1.49 +  // Writes to the contained decoder and sets the appropriate errors
    1.50 +  // Returns true if there are no errors.
    1.51 +  bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
    1.52 +
    1.53 +  // Processes a single dir entry of the icon resource
    1.54 +  void ProcessDirEntry(IconDirEntry& aTarget);
    1.55 +  // Sets the hotspot property of if we have a cursor
    1.56 +  void SetHotSpotIfCursor();
    1.57 +  // Creates a bitmap file header buffer, returns true if successful
    1.58 +  bool FillBitmapFileHeaderBuffer(int8_t *bfh);
    1.59 +  // Fixes the ICO height to match that of the BIH.
    1.60 +  // and also fixes the BIH height to be /2 of what it was.
    1.61 +  // See definition for explanation.
    1.62 +  // Returns false if invalid information is contained within.
    1.63 +  bool FixBitmapHeight(int8_t *bih);
    1.64 +  // Fixes the ICO width to match that of the BIH.
    1.65 +  // Returns false if invalid information is contained within.
    1.66 +  bool FixBitmapWidth(int8_t *bih);
    1.67 +  // Extract bitmap info header size count from BMP information header
    1.68 +  int32_t ExtractBIHSizeFromBitmap(int8_t *bih);
    1.69 +  // Extract bit count from BMP information header
    1.70 +  int32_t ExtractBPPFromBitmap(int8_t *bih);
    1.71 +  // Calculates the row size in bytes for the AND mask table
    1.72 +  uint32_t CalcAlphaRowSize();
    1.73 +  // Obtains the number of colors from the BPP, mBPP must be filled in
    1.74 +  uint16_t GetNumColors();
    1.75 +
    1.76 +  uint16_t mBPP; // Stores the images BPP
    1.77 +  uint32_t mPos; // Keeps track of the position we have decoded up until
    1.78 +  uint16_t mNumIcons; // Stores the number of icons in the ICO file
    1.79 +  uint16_t mCurrIcon; // Stores the current dir entry index we are processing
    1.80 +  uint32_t mImageOffset; // Stores the offset of the image data we want
    1.81 +  uint8_t *mRow;      // Holds one raw line of the image
    1.82 +  int32_t mCurLine;   // Line index of the image that's currently being decoded
    1.83 +  uint32_t mRowBytes; // How many bytes of the row were already received
    1.84 +  int32_t mOldLine;   // Previous index of the line 
    1.85 +  nsAutoPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
    1.86 +
    1.87 +  char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer
    1.88 +  IconDirEntry mDirEntry; // Holds a decoded dir entry
    1.89 +  // Holds the potential bytes that can be a PNG signature
    1.90 +  char mSignature[PNGSIGNATURESIZE]; 
    1.91 +  // Holds the potential bytes for a bitmap information header
    1.92 +  char mBIHraw[40];
    1.93 +  // Stores whether or not the icon file we are processing has type 1 (icon)
    1.94 +  bool mIsCursor;
    1.95 +  // Stores whether or not the contained resource is a PNG
    1.96 +  bool mIsPNG;
    1.97 +};
    1.98 +
    1.99 +} // namespace image
   1.100 +} // namespace mozilla
   1.101 +
   1.102 +#endif

mercurial