Back to index

lightning-sunbird  0.9+nobinonly
nsJPEGDecoder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Stuart Parmenter <pavlov@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsJPEGDecoder_h__
00041 #define nsJPEGDecoder_h__
00042 
00043 #include "imgIDecoder.h"
00044 
00045 #include "nsCOMPtr.h"
00046 
00047 #include "imgIContainer.h"
00048 #include "gfxIImageFrame.h"
00049 #include "imgIDecoderObserver.h"
00050 #include "imgILoad.h"
00051 #include "nsIInputStream.h"
00052 #include "nsIPipe.h"
00053 
00054 extern "C" {
00055 #include "jpeglib.h"
00056 }
00057 
00058 #include <setjmp.h>
00059 
00060 #define NS_JPEGDECODER_CID \
00061 { /* 5871a422-1dd2-11b2-ab3f-e2e56be5da9c */         \
00062      0x5871a422,                                     \
00063      0x1dd2,                                         \
00064      0x11b2,                                         \
00065     {0xab, 0x3f, 0xe2, 0xe5, 0x6b, 0xe5, 0xda, 0x9c} \
00066 }
00067 
00068 typedef struct {
00069     struct jpeg_error_mgr pub;  /* "public" fields for IJG library*/
00070     jmp_buf setjmp_buffer;      /* For handling catastropic errors */
00071 } decoder_error_mgr;
00072 
00073 
00074 typedef enum {
00075     JPEG_HEADER,                          /* Reading JFIF headers */
00076     JPEG_START_DECOMPRESS,
00077     JPEG_DECOMPRESS_PROGRESSIVE,          /* Output progressive pixels */
00078     JPEG_DECOMPRESS_SEQUENTIAL,           /* Output sequential pixels */
00079     JPEG_DONE,
00080     JPEG_SINK_NON_JPEG_TRAILER,          /* Some image files have a */
00081                                          /* non-JPEG trailer */
00082     JPEG_ERROR    
00083 } jstate;
00084 
00085 class nsJPEGDecoder : public imgIDecoder
00086 {
00087 public:
00088   NS_DECL_ISUPPORTS
00089   NS_DECL_IMGIDECODER
00090 
00091   nsJPEGDecoder();
00092   virtual ~nsJPEGDecoder();
00093 
00094   PRBool FillInput(j_decompress_ptr jd);
00095 
00096   PRUint32 mBytesToSkip;
00097 
00098 protected:
00099   int OutputScanlines();
00100 
00101 public:
00102   nsCOMPtr<imgIContainer> mImage;
00103   nsCOMPtr<imgILoad> mImageLoad;
00104   nsCOMPtr<gfxIImageFrame> mFrame;
00105 
00106   nsCOMPtr<imgIDecoderObserver> mObserver;
00107 
00108   struct jpeg_decompress_struct mInfo;
00109   decoder_error_mgr mErr;
00110   jstate mState;
00111 
00112   JSAMPARRAY mSamples;
00113   PRUint8*   mRGBRow;
00114 
00115   PRInt32 mCompletedPasses;
00116   PRInt32 mPasses;
00117 
00118   int mFillState;
00119 
00120   JOCTET *mBuffer;
00121   PRUint32 mBufferLen;  // amount of data currently in mBuffer
00122   PRUint32 mBufferSize; // size in bytes what mBuffer was created with
00123 
00124   JOCTET *mBackBuffer;
00125   PRUint32 mBackBufferLen; // Offset of end of active backtrack data
00126   PRUint32 mBackBufferSize; // size in bytes what mBackBuffer was created with
00127   PRUint32 mBackBufferUnreadLen; // amount of data currently in mBackBuffer
00128 };
00129 
00130 #endif // nsJPEGDecoder_h__