Backing out Elantech patches (bug 593372) because they broke scroll wheel functionali...
[mozilla-central.git] / modules / libpr0n / decoders / nsJPEGDecoder.h
blob74c83a6b44539d526326cb2301b5becbf3627527
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Stuart Parmenter <pavlov@netscape.com>
25 * Bobby Holley <bobbyholley@gmail.com>
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.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef nsJPEGDecoder_h__
42 #define nsJPEGDecoder_h__
44 #include "RasterImage.h"
45 /* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
46 * But the jpeg decoder has its own definition of INT32. To avoid build issues,
47 * we need to undefine the version from 'windows.h'. */
48 #undef INT32
50 #include "Decoder.h"
52 #include "nsAutoPtr.h"
54 #include "imgIDecoderObserver.h"
55 #include "nsIInputStream.h"
56 #include "nsIPipe.h"
57 #include "qcms.h"
59 extern "C" {
60 #include "jpeglib.h"
63 #include <setjmp.h>
65 namespace mozilla {
66 namespace imagelib {
68 typedef struct {
69 struct jpeg_error_mgr pub; /* "public" fields for IJG library*/
70 jmp_buf setjmp_buffer; /* For handling catastropic errors */
71 } decoder_error_mgr;
73 typedef enum {
74 JPEG_HEADER, /* Reading JFIF headers */
75 JPEG_START_DECOMPRESS,
76 JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */
77 JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */
78 JPEG_DONE,
79 JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */
80 /* non-JPEG trailer */
81 JPEG_ERROR
82 } jstate;
84 class RasterImage;
86 class nsJPEGDecoder : public Decoder
88 public:
89 nsJPEGDecoder();
90 virtual ~nsJPEGDecoder();
92 virtual void InitInternal();
93 virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
94 virtual void FinishInternal();
96 void NotifyDone();
98 protected:
99 void OutputScanlines(PRBool* suspend);
101 public:
102 PRUint8 *mImageData;
104 struct jpeg_decompress_struct mInfo;
105 struct jpeg_source_mgr mSourceMgr;
106 decoder_error_mgr mErr;
107 jstate mState;
109 PRUint32 mBytesToSkip;
111 const JOCTET *mSegment; // The current segment we are decoding from
112 PRUint32 mSegmentLen; // amount of data in mSegment
114 JOCTET *mBackBuffer;
115 PRUint32 mBackBufferLen; // Offset of end of active backtrack data
116 PRUint32 mBackBufferSize; // size in bytes what mBackBuffer was created with
117 PRUint32 mBackBufferUnreadLen; // amount of data currently in mBackBuffer
119 JOCTET *mProfile;
120 PRUint32 mProfileLength;
122 qcms_profile *mInProfile;
123 qcms_transform *mTransform;
125 PRPackedBool mReading;
127 PRUint32 mCMSMode;
130 } // namespace imagelib
131 } // namespace mozilla
133 #endif // nsJPEGDecoder_h__