~ubuntu-branches/ubuntu/utopic/libopenraw/utopic

« back to all changes in this revision

Viewing changes to lib/ljpegdecompressor.h

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-04-03 22:41:08 UTC
  • mto: (7.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20090403224108-f90nhq50nv5ze5ce
Tags: upstream-0.0.6
ImportĀ upstreamĀ versionĀ 0.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (C) 2007 Hubert Figuiere
5
5
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2.1 of the License, or (at your option) any later version.
 
6
 * This library is free software: you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public License
 
8
 * as published by the Free Software Foundation, either version 3 of
 
9
 * the License, or (at your option) any later version.
10
10
 *
11
11
 * This library is distributed in the hope that it will be useful,
12
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 * Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
17
 * License along with this library.  If not, see
 
18
 * <http://www.gnu.org/licenses/>.
19
19
 */
20
20
 
21
21
#ifndef __OPENRAW_LJPEGDECOMPRESSOR_H__
32
32
 
33
33
namespace OpenRaw {
34
34
 
35
 
        class RawData;
 
35
class RawData;
36
36
                
37
 
        namespace Internals {
38
 
                struct HuffmanTable;
39
 
                struct DecompressInfo;
40
 
                typedef int16_t ComponentType;
41
 
                typedef ComponentType *MCU;
42
 
 
43
 
 
44
 
                class LJpegDecompressor
45
 
                        : public Decompressor
46
 
                {
47
 
                public:
48
 
                        LJpegDecompressor(IO::Stream *,
49
 
                                                                                                RawContainer *);
50
 
                        virtual ~LJpegDecompressor();
51
 
                        
52
 
                        /** decompress the bitmapdata and return a new bitmap
53
 
                         * @param in a preallocated BitmapData instance
54
 
                         * or NULL if decompress has to allocate it.
55
 
                         * @return the new bitmap decompressed. NULL is failure.
56
 
                         * Caller owns it.
57
 
                         * @todo use a shared_ptr here, or something
58
 
                         */
59
 
                        virtual RawData *decompress(RawData *in = NULL);
60
 
                        void setSlices(const std::vector<uint16_t> & slices, 
61
 
                                                                                 std::vector<uint16_t>::size_type idx = 0);
62
 
                        bool isSliced() const
63
 
                                { 
64
 
                                        return m_slices.size() > 1; 
65
 
                                }
66
 
                private:
67
 
                        
68
 
                        /** read the bits
69
 
                         * @param s the stream to read from
70
 
                         * @param bitCount the number of bit
71
 
                         * @return the value
72
 
                         */
73
 
                        int32_t readBits(IO::Stream * s, uint16_t bitCount);
74
 
                        int32_t show_bits8(IO::Stream * s);
75
 
                        void flush_bits(uint16_t nbits);
76
 
                        int32_t get_bits(uint16_t nbits);
77
 
                        int32_t get_bit();
 
37
namespace Internals {
 
38
struct HuffmanTable;
 
39
struct DecompressInfo;
 
40
typedef int16_t ComponentType;
 
41
typedef ComponentType *MCU;
 
42
 
 
43
 
 
44
class LJpegDecompressor
 
45
    : public Decompressor
 
46
{
 
47
public:
 
48
    LJpegDecompressor(IO::Stream *,
 
49
                      RawContainer *);
 
50
    virtual ~LJpegDecompressor();
 
51
                        
 
52
    /** decompress the bitmapdata and return a new bitmap
 
53
     * @param in a preallocated BitmapData instance
 
54
     * or NULL if decompress has to allocate it.
 
55
     * @return the new bitmap decompressed. NULL is failure.
 
56
     * Caller owns it.
 
57
     * @todo use a shared_ptr here, or something
 
58
     */
 
59
    virtual RawData *decompress(RawData *in = NULL);
 
60
    /** Set the "slices"
 
61
     * @param slices the vector containing the Canon-style slices.
 
62
     *
 
63
     * the format of the slices vector is as follow
 
64
     * N col1 col2
 
65
     * N is the number of repeat for col1. The total 
 
66
     * number of slices is always N+1
 
67
     * This is for Canon CR2.
 
68
     */
 
69
    void setSlices(const std::vector<uint16_t> & slices);
 
70
    bool isSliced() const
 
71
        { 
 
72
            return m_slices.size() > 1; 
 
73
        }
 
74
private:
 
75
                        
 
76
    /** read the bits
 
77
     * @param s the stream to read from
 
78
     * @param bitCount the number of bit
 
79
     * @return the value
 
80
     */
 
81
    int32_t readBits(IO::Stream * s, uint16_t bitCount);
 
82
    int32_t show_bits8(IO::Stream * s);
 
83
    void flush_bits(uint16_t nbits);
 
84
    int32_t get_bits(uint16_t nbits);
 
85
    int32_t get_bit();
78
86
                        
79
87
/** 
80
88
 * Enumerate all the JPEG marker codes
81
89
 */
82
 
                        typedef enum {
83
 
                                M_SOF0 = 0xc0,
84
 
                                M_SOF1 = 0xc1,
85
 
                                M_SOF2 = 0xc2,
86
 
                                M_SOF3 = 0xc3,
 
90
    typedef enum {
 
91
        M_SOF0 = 0xc0,
 
92
        M_SOF1 = 0xc1,
 
93
        M_SOF2 = 0xc2,
 
94
        M_SOF3 = 0xc3,
87
95
                                
88
 
                                M_SOF5 = 0xc5,
89
 
                                M_SOF6 = 0xc6,
90
 
                                M_SOF7 = 0xc7,
91
 
 
92
 
                                M_JPG = 0xc8,
93
 
                                M_SOF9 = 0xc9,
94
 
                                M_SOF10 = 0xca,
95
 
                                M_SOF11 = 0xcb,
96
 
 
97
 
                                M_SOF13 = 0xcd,
98
 
                                M_SOF14 = 0xce,
99
 
                                M_SOF15 = 0xcf,
100
 
 
101
 
                                M_DHT = 0xc4,
102
 
 
103
 
                                M_DAC = 0xcc,
104
 
 
105
 
                                M_RST0 = 0xd0,
106
 
                                M_RST1 = 0xd1,
107
 
                                M_RST2 = 0xd2,
108
 
                                M_RST3 = 0xd3,
109
 
                                M_RST4 = 0xd4,
110
 
                                M_RST5 = 0xd5,
111
 
                                M_RST6 = 0xd6,
112
 
                                M_RST7 = 0xd7,
113
 
 
114
 
                                M_SOI = 0xd8,
115
 
                                M_EOI = 0xd9,
116
 
                                M_SOS = 0xda,
117
 
                                M_DQT = 0xdb,
118
 
                                M_DNL = 0xdc,
119
 
                                M_DRI = 0xdd,
120
 
                                M_DHP = 0xde,
121
 
                                M_EXP = 0xdf,
122
 
 
123
 
                                M_APP0 = 0xe0,
124
 
                                M_APP15 = 0xef,
125
 
 
126
 
                                M_JPG0 = 0xf0,
127
 
                                M_JPG13 = 0xfd,
128
 
                                M_COM = 0xfe,
129
 
 
130
 
                                M_TEM = 0x01,
131
 
 
132
 
                                M_ERROR = 0x100
133
 
                        } JpegMarker;
134
 
 
135
 
                        void DecoderStructInit (DecompressInfo *dcPtr) throw(DecodingException);
136
 
                        void HuffDecoderInit (DecompressInfo *dcPtr) throw(DecodingException);
137
 
                        void ProcessRestart (DecompressInfo *dcPtr) throw(DecodingException);
138
 
                        void DecodeFirstRow(DecompressInfo *dcPtr,
139
 
                                                                                                        MCU *curRowBuf);
140
 
                        void DecodeImage(DecompressInfo *dcPtr);
141
 
                        int32_t QuickPredict(int32_t col, int16_t curComp,
142
 
                                                                                                         MCU *curRowBuf, MCU *prevRowBuf,
143
 
                                                                                                         int32_t psv);
144
 
                        void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
145
 
                        void GetDht (DecompressInfo *dcPtr) throw(DecodingException);
146
 
                        void GetDri (DecompressInfo *dcPtr) throw(DecodingException);
147
 
                        void GetSof (DecompressInfo *dcPtr) throw(DecodingException);
148
 
                        void GetSos (DecompressInfo *dcPtr) throw(DecodingException);
149
 
                        JpegMarker ProcessTables (DecompressInfo *dcPtr);
150
 
                        void ReadFileHeader (DecompressInfo *dcPtr) throw(DecodingException);
151
 
                        int32_t ReadScanHeader (DecompressInfo *dcPtr);
152
 
                        int32_t HuffDecode(HuffmanTable *htbl);
153
 
 
154
 
                        std::vector<uint16_t> m_slices;
155
 
 
156
 
                        MCU *m_mcuROW1, *m_mcuROW2;
157
 
                        char *m_buf1,*m_buf2;
158
 
 
159
 
                        /** fill the bit buffer */
160
 
                        void fillBitBuffer (IO::Stream * s, uint16_t nbits);
161
 
                        uint16_t m_bitsLeft;
162
 
                        uint32_t m_getBuffer;
163
 
                        RawData *m_output;
164
 
 
165
 
                        /** private copy constructor to make sure it is not called */
166
 
                        LJpegDecompressor(const LJpegDecompressor& f);
167
 
                        /** private = operator to make sure it is never called */
168
 
                        LJpegDecompressor & operator=(const LJpegDecompressor&);
169
 
                };
170
 
 
171
 
        }
 
96
        M_SOF5 = 0xc5,
 
97
        M_SOF6 = 0xc6,
 
98
        M_SOF7 = 0xc7,
 
99
 
 
100
        M_JPG = 0xc8,
 
101
        M_SOF9 = 0xc9,
 
102
        M_SOF10 = 0xca,
 
103
        M_SOF11 = 0xcb,
 
104
 
 
105
        M_SOF13 = 0xcd,
 
106
        M_SOF14 = 0xce,
 
107
        M_SOF15 = 0xcf,
 
108
 
 
109
        M_DHT = 0xc4,
 
110
 
 
111
        M_DAC = 0xcc,
 
112
 
 
113
        M_RST0 = 0xd0,
 
114
        M_RST1 = 0xd1,
 
115
        M_RST2 = 0xd2,
 
116
        M_RST3 = 0xd3,
 
117
        M_RST4 = 0xd4,
 
118
        M_RST5 = 0xd5,
 
119
        M_RST6 = 0xd6,
 
120
        M_RST7 = 0xd7,
 
121
 
 
122
        M_SOI = 0xd8,
 
123
        M_EOI = 0xd9,
 
124
        M_SOS = 0xda,
 
125
        M_DQT = 0xdb,
 
126
        M_DNL = 0xdc,
 
127
        M_DRI = 0xdd,
 
128
        M_DHP = 0xde,
 
129
        M_EXP = 0xdf,
 
130
 
 
131
        M_APP0 = 0xe0,
 
132
        M_APP15 = 0xef,
 
133
 
 
134
        M_JPG0 = 0xf0,
 
135
        M_JPG13 = 0xfd,
 
136
        M_COM = 0xfe,
 
137
 
 
138
        M_TEM = 0x01,
 
139
 
 
140
        M_ERROR = 0x100
 
141
    } JpegMarker;
 
142
 
 
143
    void DecoderStructInit (DecompressInfo *dcPtr) throw(DecodingException);
 
144
    void HuffDecoderInit (DecompressInfo *dcPtr) throw(DecodingException);
 
145
    void ProcessRestart (DecompressInfo *dcPtr) throw(DecodingException);
 
146
    void DecodeFirstRow(DecompressInfo *dcPtr,
 
147
                        MCU *curRowBuf);
 
148
    void DecodeImage(DecompressInfo *dcPtr);
 
149
    int32_t QuickPredict(int32_t col, int16_t curComp,
 
150
                         MCU *curRowBuf, MCU *prevRowBuf,
 
151
                         int32_t psv);
 
152
    void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
 
153
    void GetDht (DecompressInfo *dcPtr) throw(DecodingException);
 
154
    void GetDri (DecompressInfo *dcPtr) throw(DecodingException);
 
155
    void GetSof (DecompressInfo *dcPtr) throw(DecodingException);
 
156
    void GetSos (DecompressInfo *dcPtr) throw(DecodingException);
 
157
    JpegMarker ProcessTables (DecompressInfo *dcPtr);
 
158
    void ReadFileHeader (DecompressInfo *dcPtr) throw(DecodingException);
 
159
    int32_t ReadScanHeader (DecompressInfo *dcPtr);
 
160
    int32_t HuffDecode(HuffmanTable *htbl);
 
161
 
 
162
    std::vector<uint16_t> m_slices;
 
163
 
 
164
    MCU *m_mcuROW1, *m_mcuROW2;
 
165
    char *m_buf1,*m_buf2;
 
166
 
 
167
    /** fill the bit buffer */
 
168
    void fillBitBuffer (IO::Stream * s, uint16_t nbits);
 
169
    uint16_t m_bitsLeft;
 
170
    uint32_t m_getBuffer;
 
171
    RawData *m_output;
 
172
 
 
173
    /** private copy constructor to make sure it is not called */
 
174
    LJpegDecompressor(const LJpegDecompressor& f);
 
175
    /** private = operator to make sure it is never called */
 
176
    LJpegDecompressor & operator=(const LJpegDecompressor&);
 
177
};
 
178
 
 
179
}
172
180
}
173
181
 
174
182
 
175
183
 
176
184
#endif
 
185
/*
 
186
  Local Variables:
 
187
  mode:c++
 
188
  c-file-style:"stroustrup"
 
189
  c-file-offsets:((innamespace . 0))
 
190
  indent-tabs-mode:nil
 
191
  fill-column:80
 
192
  End:
 
193
*/