Use number of components from ICC profile and alternate color space
[pdfium.git] / core / src / fxcodec / codec / codec_int.h
index 571af61..78672e6 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include <limits.h>\r
-class CCodec_BasicModule : public ICodec_BasicModule\r
-{\r
-public:\r
-    virtual FX_BOOL    RunLengthEncode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,\r
-                                    FX_DWORD& dest_size);\r
-    virtual FX_BOOL    A85Encode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,\r
-                              FX_DWORD& dest_size);\r
-    virtual ICodec_ScanlineDecoder*    CreateRunLengthDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,\r
-            int nComps, int bpc);\r
-};\r
-struct CCodec_ImageDataCache {\r
-    int                        m_Width, m_Height;\r
-    int                        m_nCachedLines;\r
-    FX_BYTE            m_Data;\r
-};\r
-class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder\r
-{\r
-public:\r
-\r
-    CCodec_ScanlineDecoder();\r
-\r
-    virtual ~CCodec_ScanlineDecoder();\r
-\r
-    virtual FX_DWORD   GetSrcOffset()\r
-    {\r
-        return -1;\r
-    }\r
-\r
-    virtual void               DownScale(int dest_width, int dest_height);\r
-\r
-    FX_LPBYTE                  GetScanline(int line);\r
-\r
-    FX_BOOL                            SkipToScanline(int line, IFX_Pause* pPause);\r
-\r
-    int                                        GetWidth()\r
-    {\r
-        return m_OutputWidth;\r
-    }\r
-\r
-    int                                        GetHeight()\r
-    {\r
-        return m_OutputHeight;\r
-    }\r
-\r
-    int                                        CountComps()\r
-    {\r
-        return m_nComps;\r
-    }\r
-\r
-    int                                        GetBPC()\r
-    {\r
-        return m_bpc;\r
-    }\r
-\r
-    FX_BOOL                            IsColorTransformed()\r
-    {\r
-        return m_bColorTransformed;\r
-    }\r
-\r
-    void                               ClearImageData()\r
-    {\r
-        if (m_pDataCache) {\r
-            FX_Free(m_pDataCache);\r
-        }\r
-        m_pDataCache = NULL;\r
-    }\r
-protected:\r
-\r
-    int                                        m_OrigWidth;\r
-\r
-    int                                        m_OrigHeight;\r
-\r
-    int                                        m_DownScale;\r
-\r
-    int                                        m_OutputWidth;\r
-\r
-    int                                        m_OutputHeight;\r
-\r
-    int                                        m_nComps;\r
-\r
-    int                                        m_bpc;\r
-\r
-    int                                        m_Pitch;\r
-\r
-    FX_BOOL                            m_bColorTransformed;\r
-\r
-    FX_LPBYTE                  ReadNextLine();\r
-\r
-    virtual FX_BOOL            v_Rewind() = 0;\r
-\r
-    virtual FX_LPBYTE  v_GetNextLine() = 0;\r
-\r
-    virtual void               v_DownScale(int dest_width, int dest_height) = 0;\r
-\r
-    int                                        m_NextLine;\r
-\r
-    FX_LPBYTE                  m_pLastScanline;\r
-\r
-    CCodec_ImageDataCache*     m_pDataCache;\r
-};\r
-class CCodec_FaxModule : public ICodec_FaxModule\r
-{\r
-public:\r
-    virtual ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,\r
-            int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, int Columns, int Rows);\r
-    FX_BOOL            Encode(FX_LPCBYTE src_buf, int width, int height, int pitch, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-};\r
-class CCodec_FlateModule : public ICodec_FlateModule\r
-{\r
-public:\r
-    virtual ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,\r
-            int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, int Columns);\r
-    virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_buf, FX_DWORD src_size, FX_BOOL bEarlyChange,\r
-                                      int predictor, int Colors, int BitsPerComponent, int Columns,\r
-                                      FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-    virtual FX_BOOL Encode(const FX_BYTE* src_buf, FX_DWORD src_size,\r
-                           int predictor, int Colors, int BitsPerComponent, int Columns,\r
-                           FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-    virtual FX_BOOL            Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-};\r
-class CCodec_JpegModule : public ICodec_JpegModule\r
-{\r
-public:\r
-    CCodec_JpegModule() : m_pExtProvider(NULL) {}\r
-    void SetPovider(IFX_JpegProvider* pJP)\r
-    {\r
-        m_pExtProvider = pJP;\r
-    }\r
-    ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                                          int width, int height, int nComps, FX_BOOL ColorTransform);\r
-    FX_BOOL            LoadInfo(FX_LPCBYTE src_buf, FX_DWORD src_size, int& width, int& height,\r
-                         int& num_components, int& bits_per_components, FX_BOOL& color_transform,\r
-                         FX_LPBYTE* icc_buf_ptr, FX_DWORD* icc_length);\r
-    FX_BOOL            Encode(const CFX_DIBSource* pSource, FX_LPBYTE& dest_buf, FX_STRSIZE& dest_size, int quality, FX_LPCBYTE icc_buf, FX_DWORD icc_length);\r
-    virtual void*              Start();\r
-    virtual void               Finish(void* pContext);\r
-    virtual void               Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size);\r
-    virtual int                        ReadHeader(void* pContext, int* width, int* height, int* nComps);\r
-    virtual FX_BOOL            StartScanline(void* pContext, int down_scale);\r
-    virtual FX_BOOL            ReadScanline(void* pContext, FX_LPBYTE dest_buf);\r
-    virtual FX_DWORD   GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_ptr);\r
-protected:\r
-    IFX_JpegProvider* m_pExtProvider;\r
-};\r
-class CCodec_IccModule : public ICodec_IccModule\r
-{\r
-public:\r
-    virtual IccCS                      GetProfileCS(FX_LPCBYTE pProfileData, unsigned int dwProfileSize);\r
-    virtual IccCS                      GetProfileCS(IFX_FileRead* pFile);\r
-    virtual FX_LPVOID          CreateTransform(ICodec_IccModule::IccParam* pInputParam,\r
-                                            ICodec_IccModule::IccParam* pOutputParam,\r
-                                            ICodec_IccModule::IccParam* pProofParam = NULL,\r
-                                            FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL,\r
-                                            FX_DWORD dwFlag = Icc_FLAGS_DEFAULT,\r
-                                            FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC,\r
-                                            FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING\r
-                                      );\r
-    virtual FX_LPVOID          CreateTransform_sRGB(FX_LPCBYTE pProfileData, unsigned int dwProfileSize, int nComponents, int intent = 0,\r
-            FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT);\r
-    virtual FX_LPVOID          CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, unsigned int dwSrcProfileSize, int nSrcComponents,\r
-            FX_LPCBYTE pDstProfileData, unsigned int dwDstProfileSize, int intent = 0,\r
-            FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,\r
-            FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT\r
-                                           );\r
-    virtual void                       DestroyTransform(FX_LPVOID pTransform);\r
-    virtual void                       Translate(FX_LPVOID pTransform, FX_FLOAT* pSrcValues, FX_FLOAT* pDestValues);\r
-    virtual void                       TranslateScanline(FX_LPVOID pTransform, FX_LPBYTE pDest, FX_LPCBYTE pSrc, int pixels);\r
-    virtual ~CCodec_IccModule();\r
-protected:\r
-    CFX_MapByteStringToPtr             m_MapTranform;\r
-    CFX_MapByteStringToPtr             m_MapProfile;\r
-    typedef enum {\r
-        Icc_CLASS_INPUT = 0,\r
-        Icc_CLASS_OUTPUT,\r
-        Icc_CLASS_PROOF,\r
-        Icc_CLASS_MAX\r
-    } Icc_CLASS;\r
-    FX_LPVOID          CreateProfile(ICodec_IccModule::IccParam* pIccParam, Icc_CLASS ic, CFX_BinaryBuf* pTransformKey);\r
-};\r
-class CCodec_JpxModule : public ICodec_JpxModule\r
-{\r
-public:\r
-    CCodec_JpxModule();\r
-    void*              CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_BOOL useColorSpace = FALSE);\r
-    void               GetImageInfo(FX_LPVOID ctx, FX_DWORD& width, FX_DWORD& height,\r
-                             FX_DWORD& codestream_nComps, FX_DWORD& output_nComps);\r
-    FX_BOOL            Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets);\r
-    void               DestroyDecoder(void* ctx);\r
-};\r
-#include "../jbig2/JBig2_Context.h"\r
-class CPDF_Jbig2Interface : public CFX_Object, public CJBig2_Module\r
-{\r
-public:\r
-    virtual void *JBig2_Malloc(FX_DWORD dwSize)\r
-    {\r
-        return FX_Alloc(FX_BYTE, dwSize);\r
-    }\r
-    virtual void *JBig2_Malloc2(FX_DWORD num, FX_DWORD dwSize)\r
-    {\r
-        if (dwSize && num >= UINT_MAX / dwSize) {\r
-            return NULL;\r
-        }\r
-        return FX_Alloc(FX_BYTE, num * dwSize);\r
-    }\r
-    virtual void *JBig2_Malloc3(FX_DWORD num, FX_DWORD dwSize, FX_DWORD dwSize2)\r
-    {\r
-        if (dwSize2 && dwSize >= UINT_MAX / dwSize2) {\r
-            return NULL;\r
-        }\r
-        FX_DWORD size = dwSize2 * dwSize;\r
-        if (size && num >= UINT_MAX / size) {\r
-            return NULL;\r
-        }\r
-        return FX_Alloc(FX_BYTE, num * size);\r
-    }\r
-    virtual void *JBig2_Realloc(FX_LPVOID pMem, FX_DWORD dwSize)\r
-    {\r
-        return FX_Realloc(FX_BYTE, pMem, dwSize);\r
-    }\r
-    virtual void JBig2_Free(FX_LPVOID pMem)\r
-    {\r
-        FX_Free(pMem);\r
-    }\r
-};\r
-class CCodec_Jbig2Context : public CFX_Object\r
-{\r
-public:\r
-    CCodec_Jbig2Context();\r
-    ~CCodec_Jbig2Context() {};\r
-    IFX_FileRead* m_file_ptr;\r
-    FX_DWORD m_width;\r
-    FX_DWORD m_height;\r
-    FX_LPBYTE m_src_buf;\r
-    FX_DWORD m_src_size;\r
-    FX_LPCBYTE m_global_data;\r
-    FX_DWORD m_global_size;\r
-    FX_LPBYTE m_dest_buf;\r
-    FX_DWORD m_dest_pitch;\r
-    FX_BOOL    m_bFileReader;\r
-    IFX_Pause* m_pPause;\r
-    CJBig2_Context* m_pContext;\r
-    CJBig2_Image* m_dest_image;\r
-};\r
-class CCodec_Jbig2Module : public ICodec_Jbig2Module\r
-{\r
-public:\r
-    CCodec_Jbig2Module() {};\r
-    ~CCodec_Jbig2Module();\r
-    FX_BOOL            Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                       FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch);\r
-    FX_BOOL            Decode(IFX_FileRead* file_ptr,\r
-                       FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, FX_LPBYTE& dest_buf);\r
-    void*                              CreateJbig2Context();\r
-    FXCODEC_STATUS             StartDecode(void* pJbig2Context, FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                                    FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch, IFX_Pause* pPause);\r
-\r
-    FXCODEC_STATUS             StartDecode(void* pJbig2Context, IFX_FileRead* file_ptr,\r
-                                    FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, FX_LPBYTE& dest_buf, IFX_Pause* pPause);\r
-    FXCODEC_STATUS             ContinueDecode(void* pJbig2Context, IFX_Pause* pPause);\r
-    void                               DestroyJbig2Context(void* pJbig2Context);\r
-    CPDF_Jbig2Interface        m_Module;\r
-private:\r
-};\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include <limits.h>
+class CCodec_BasicModule : public ICodec_BasicModule
+{
+public:
+    virtual FX_BOOL    RunLengthEncode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,
+                                    FX_DWORD& dest_size);
+    virtual FX_BOOL    A85Encode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf,
+                              FX_DWORD& dest_size);
+    virtual ICodec_ScanlineDecoder*    CreateRunLengthDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,
+            int nComps, int bpc);
+};
+struct CCodec_ImageDataCache {
+    int                        m_Width, m_Height;
+    int                        m_nCachedLines;
+    FX_BYTE            m_Data;
+};
+class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder
+{
+public:
+
+    CCodec_ScanlineDecoder();
+
+    virtual ~CCodec_ScanlineDecoder();
+
+    virtual FX_DWORD   GetSrcOffset()
+    {
+        return -1;
+    }
+
+    virtual void               DownScale(int dest_width, int dest_height);
+
+    FX_LPBYTE                  GetScanline(int line);
+
+    FX_BOOL                            SkipToScanline(int line, IFX_Pause* pPause);
+
+    int                                        GetWidth()
+    {
+        return m_OutputWidth;
+    }
+
+    int                                        GetHeight()
+    {
+        return m_OutputHeight;
+    }
+
+    int                                        CountComps()
+    {
+        return m_nComps;
+    }
+
+    int                                        GetBPC()
+    {
+        return m_bpc;
+    }
+
+    FX_BOOL                            IsColorTransformed()
+    {
+        return m_bColorTransformed;
+    }
+
+    void                               ClearImageData()
+    {
+        if (m_pDataCache) {
+            FX_Free(m_pDataCache);
+        }
+        m_pDataCache = NULL;
+    }
+protected:
+
+    int                                        m_OrigWidth;
+
+    int                                        m_OrigHeight;
+
+    int                                        m_DownScale;
+
+    int                                        m_OutputWidth;
+
+    int                                        m_OutputHeight;
+
+    int                                        m_nComps;
+
+    int                                        m_bpc;
+
+    int                                        m_Pitch;
+
+    FX_BOOL                            m_bColorTransformed;
+
+    FX_LPBYTE                  ReadNextLine();
+
+    virtual FX_BOOL            v_Rewind() = 0;
+
+    virtual FX_LPBYTE  v_GetNextLine() = 0;
+
+    virtual void               v_DownScale(int dest_width, int dest_height) = 0;
+
+    int                                        m_NextLine;
+
+    FX_LPBYTE                  m_pLastScanline;
+
+    CCodec_ImageDataCache*     m_pDataCache;
+};
+class CCodec_FaxModule : public ICodec_FaxModule
+{
+public:
+    virtual ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,
+            int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, int Columns, int Rows);
+    FX_BOOL            Encode(FX_LPCBYTE src_buf, int width, int height, int pitch, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);
+};
+class CCodec_FlateModule : public ICodec_FlateModule
+{
+public:
+    virtual ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,
+            int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, int Columns);
+    virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_buf, FX_DWORD src_size, FX_BOOL bEarlyChange,
+                                      int predictor, int Colors, int BitsPerComponent, int Columns,
+                                      FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);
+    virtual FX_BOOL Encode(const FX_BYTE* src_buf, FX_DWORD src_size,
+                           int predictor, int Colors, int BitsPerComponent, int Columns,
+                           FX_LPBYTE& dest_buf, FX_DWORD& dest_size);
+    virtual FX_BOOL            Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);
+};
+class CCodec_JpegModule : public ICodec_JpegModule
+{
+public:
+    CCodec_JpegModule() : m_pExtProvider(NULL) {}
+    void SetPovider(IFX_JpegProvider* pJP)
+    {
+        m_pExtProvider = pJP;
+    }
+    ICodec_ScanlineDecoder*    CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size,
+                                          int width, int height, int nComps, FX_BOOL ColorTransform);
+    FX_BOOL            LoadInfo(FX_LPCBYTE src_buf, FX_DWORD src_size, int& width, int& height,
+                         int& num_components, int& bits_per_components, FX_BOOL& color_transform,
+                         FX_LPBYTE* icc_buf_ptr, FX_DWORD* icc_length);
+    FX_BOOL            Encode(const CFX_DIBSource* pSource, FX_LPBYTE& dest_buf, FX_STRSIZE& dest_size, int quality, FX_LPCBYTE icc_buf, FX_DWORD icc_length);
+    virtual void*              Start();
+    virtual void               Finish(void* pContext);
+    virtual void               Input(void* pContext, FX_LPCBYTE src_buf, FX_DWORD src_size);
+    virtual int                        ReadHeader(void* pContext, int* width, int* height, int* nComps);
+    virtual FX_BOOL            StartScanline(void* pContext, int down_scale);
+    virtual FX_BOOL            ReadScanline(void* pContext, FX_LPBYTE dest_buf);
+    virtual FX_DWORD   GetAvailInput(void* pContext, FX_LPBYTE* avail_buf_ptr);
+protected:
+    IFX_JpegProvider* m_pExtProvider;
+};
+class CCodec_IccModule : public ICodec_IccModule
+{
+public:
+    virtual IccCS                      GetProfileCS(FX_LPCBYTE pProfileData, unsigned int dwProfileSize);
+    virtual IccCS                      GetProfileCS(IFX_FileRead* pFile);
+    virtual FX_LPVOID          CreateTransform(ICodec_IccModule::IccParam* pInputParam,
+                                            ICodec_IccModule::IccParam* pOutputParam,
+                                            ICodec_IccModule::IccParam* pProofParam = NULL,
+                                            FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL,
+                                            FX_DWORD dwFlag = Icc_FLAGS_DEFAULT,
+                                            FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC,
+                                            FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING
+                                      );
+    virtual FX_LPVOID          CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize, FX_INT32& nComponents, FX_INT32 intent = 0,
+            FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT);
+    virtual FX_LPVOID          CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWORD dwSrcProfileSize, FX_INT32& nSrcComponents,
+            FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent = 0,
+            FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
+            FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT
+                                           );
+    virtual void                       DestroyTransform(FX_LPVOID pTransform);
+    virtual void                       Translate(FX_LPVOID pTransform, FX_FLOAT* pSrcValues, FX_FLOAT* pDestValues);
+    virtual void                       TranslateScanline(FX_LPVOID pTransform, FX_LPBYTE pDest, FX_LPCBYTE pSrc, int pixels);
+    virtual void                        SetComponents(FX_DWORD nComponents) {m_nComponents = nComponents;}
+    virtual ~CCodec_IccModule();
+protected:
+    CFX_MapByteStringToPtr             m_MapTranform;
+    CFX_MapByteStringToPtr             m_MapProfile;
+    FX_DWORD                            m_nComponents;
+    typedef enum {
+        Icc_CLASS_INPUT = 0,
+        Icc_CLASS_OUTPUT,
+        Icc_CLASS_PROOF,
+        Icc_CLASS_MAX
+    } Icc_CLASS;
+    FX_LPVOID          CreateProfile(ICodec_IccModule::IccParam* pIccParam, Icc_CLASS ic, CFX_BinaryBuf* pTransformKey);
+};
+class CCodec_JpxModule : public ICodec_JpxModule
+{
+public:
+    CCodec_JpxModule();
+    void*              CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_BOOL useColorSpace = FALSE);
+    void               GetImageInfo(FX_LPVOID ctx, FX_DWORD& width, FX_DWORD& height,
+                             FX_DWORD& codestream_nComps, FX_DWORD& output_nComps);
+    FX_BOOL            Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_BOOL bTranslateColor, FX_LPBYTE offsets);
+    void               DestroyDecoder(void* ctx);
+};
+#include "../jbig2/JBig2_Context.h"
+class CPDF_Jbig2Interface : public CFX_Object, public CJBig2_Module
+{
+public:
+    virtual void *JBig2_Malloc(FX_DWORD dwSize)
+    {
+        return FX_Alloc(FX_BYTE, dwSize);
+    }
+    virtual void *JBig2_Malloc2(FX_DWORD num, FX_DWORD dwSize)
+    {
+        if (dwSize && num >= UINT_MAX / dwSize) {
+            return NULL;
+        }
+        return FX_Alloc(FX_BYTE, num * dwSize);
+    }
+    virtual void *JBig2_Malloc3(FX_DWORD num, FX_DWORD dwSize, FX_DWORD dwSize2)
+    {
+        if (dwSize2 && dwSize >= UINT_MAX / dwSize2) {
+            return NULL;
+        }
+        FX_DWORD size = dwSize2 * dwSize;
+        if (size && num >= UINT_MAX / size) {
+            return NULL;
+        }
+        return FX_Alloc(FX_BYTE, num * size);
+    }
+    virtual void *JBig2_Realloc(FX_LPVOID pMem, FX_DWORD dwSize)
+    {
+        return FX_Realloc(FX_BYTE, pMem, dwSize);
+    }
+    virtual void JBig2_Free(FX_LPVOID pMem)
+    {
+        FX_Free(pMem);
+    }
+};
+class CCodec_Jbig2Context : public CFX_Object
+{
+public:
+    CCodec_Jbig2Context();
+    ~CCodec_Jbig2Context() {};
+    IFX_FileRead* m_file_ptr;
+    FX_DWORD m_width;
+    FX_DWORD m_height;
+    FX_LPBYTE m_src_buf;
+    FX_DWORD m_src_size;
+    FX_LPCBYTE m_global_data;
+    FX_DWORD m_global_size;
+    FX_LPBYTE m_dest_buf;
+    FX_DWORD m_dest_pitch;
+    FX_BOOL    m_bFileReader;
+    IFX_Pause* m_pPause;
+    CJBig2_Context* m_pContext;
+    CJBig2_Image* m_dest_image;
+};
+class CCodec_Jbig2Module : public ICodec_Jbig2Module
+{
+public:
+    CCodec_Jbig2Module() {};
+    ~CCodec_Jbig2Module();
+    FX_BOOL            Decode(FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,
+                       FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch);
+    FX_BOOL            Decode(IFX_FileRead* file_ptr,
+                       FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, FX_LPBYTE& dest_buf);
+    void*                              CreateJbig2Context();
+    FXCODEC_STATUS             StartDecode(void* pJbig2Context, FX_DWORD width, FX_DWORD height, FX_LPCBYTE src_buf, FX_DWORD src_size,
+                                    FX_LPCBYTE global_data, FX_DWORD global_size, FX_LPBYTE dest_buf, FX_DWORD dest_pitch, IFX_Pause* pPause);
+
+    FXCODEC_STATUS             StartDecode(void* pJbig2Context, IFX_FileRead* file_ptr,
+                                    FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, FX_LPBYTE& dest_buf, IFX_Pause* pPause);
+    FXCODEC_STATUS             ContinueDecode(void* pJbig2Context, IFX_Pause* pPause);
+    void                               DestroyJbig2Context(void* pJbig2Context);
+    CPDF_Jbig2Interface        m_Module;
+private:
+};