LCOV - code coverage report
Current view: directory - image/decoders - nsICODecoder.h (source / functions) Found Hit Coverage
Test: app.info Lines: 4 4 100.0 %
Date: 2012-06-02 Functions: 2 2 100.0 %

       1                 : /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is the Mozilla ICO Decoder.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   David Hyatt <hyatt@netscape.com> (Original Author)
      24                 :  *   Bobby Holley <bobbyholley@gmail.com>
      25                 :  *   Brian R. Bondy <netzen@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : 
      42                 : #ifndef _nsICODecoder_h
      43                 : #define _nsICODecoder_h
      44                 : 
      45                 : #include "nsAutoPtr.h"
      46                 : #include "Decoder.h"
      47                 : #include "imgIDecoderObserver.h"
      48                 : #include "nsBMPDecoder.h"
      49                 : #include "nsPNGDecoder.h"
      50                 : #include "ICOFileHeaders.h"
      51                 : 
      52                 : namespace mozilla {
      53                 : namespace image {
      54                 : 
      55                 : class RasterImage;
      56                 : 
      57                 : class nsICODecoder : public Decoder
      58                 : {
      59                 : public:
      60                 : 
      61                 :   nsICODecoder(RasterImage &aImage, imgIDecoderObserver* aObserver);
      62                 :   virtual ~nsICODecoder();
      63                 : 
      64                 :   // Obtains the width of the icon directory entry
      65             103 :   PRUint32 GetRealWidth() const
      66                 :   {
      67             103 :     return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth; 
      68                 :   }
      69                 : 
      70                 :   // Obtains the height of the icon directory entry
      71               7 :   PRUint32 GetRealHeight() const
      72                 :   {
      73               7 :     return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight; 
      74                 :   }
      75                 : 
      76                 :   virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
      77                 :   virtual void FinishInternal();
      78                 : 
      79                 : private:
      80                 :   // Processes a single dir entry of the icon resource
      81                 :   void ProcessDirEntry(IconDirEntry& aTarget);
      82                 :   // Sets the hotspot property of if we have a cursor
      83                 :   void SetHotSpotIfCursor();
      84                 :   // Creates a bitmap file header buffer, returns true if successful
      85                 :   bool FillBitmapFileHeaderBuffer(PRInt8 *bfh);
      86                 :   // Fixes the ICO height to match that of the BIH.
      87                 :   // and also fixes the BIH height to be /2 of what it was.
      88                 :   // See definition for explanation.
      89                 :   // Returns false if invalid information is contained within.
      90                 :   bool FixBitmapHeight(PRInt8 *bih);
      91                 :   // Fixes the ICO width to match that of the BIH.
      92                 :   // Returns false if invalid information is contained within.
      93                 :   bool FixBitmapWidth(PRInt8 *bih);
      94                 :   // Extract bitmap info header size count from BMP information header
      95                 :   PRInt32 ExtractBIHSizeFromBitmap(PRInt8 *bih);
      96                 :   // Extract bit count from BMP information header
      97                 :   PRInt32 ExtractBPPFromBitmap(PRInt8 *bih);
      98                 :   // Calculates the row size in bytes for the AND mask table
      99                 :   PRUint32 CalcAlphaRowSize();
     100                 :   // Obtains the number of colors from the BPP, mBPP must be filled in
     101                 :   PRUint16 GetNumColors();
     102                 : 
     103                 :   PRUint16 mBPP; // Stores the images BPP
     104                 :   PRUint32 mPos; // Keeps track of the position we have decoded up until
     105                 :   PRUint16 mNumIcons; // Stores the number of icons in the ICO file
     106                 :   PRUint16 mCurrIcon; // Stores the current dir entry index we are processing
     107                 :   PRUint32 mImageOffset; // Stores the offset of the image data we want
     108                 :   PRUint8 *mRow;      // Holds one raw line of the image
     109                 :   PRInt32 mCurLine;   // Line index of the image that's currently being decoded
     110                 :   PRUint32 mRowBytes; // How many bytes of the row were already received
     111                 :   PRInt32 mOldLine;   // Previous index of the line 
     112                 :   nsAutoPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
     113                 : 
     114                 :   char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer
     115                 :   IconDirEntry mDirEntry; // Holds a decoded dir entry
     116                 :   // Holds the potential bytes that can be a PNG signature
     117                 :   char mSignature[PNGSIGNATURESIZE]; 
     118                 :   // Holds the potential bytes for a bitmap information header
     119                 :   char mBIHraw[40];
     120                 :   // Stores whether or not the icon file we are processing has type 1 (icon)
     121                 :   bool mIsCursor;
     122                 :   // Stores whether or not the contained resource is a PNG
     123                 :   bool mIsPNG;
     124                 : };
     125                 : 
     126                 : } // namespace image
     127                 : } // namespace mozilla
     128                 : 
     129                 : #endif

Generated by: LCOV version 1.7