1 /*
2  Source File : InputDCTDecodeStream.h
3 
4 
5  Copyright 2012 Gal Kahana PDFWriter
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 
20  */
21 #pragma once
22 
23 #ifndef PDFHUMMUS_NO_DCT
24 
25 #include "EStatusCode.h"
26 #include "IByteReader.h"
27 #include "jpeglib.h"
28 
29 class InputDCTDecodeStream : public IByteReader
30 {
31 public:
32     InputDCTDecodeStream();
33     virtual ~InputDCTDecodeStream();
34 
35 	// Note that assigning passes ownership on the stream, use Assign(NULL) to remove ownership
36     InputDCTDecodeStream(IByteReader* inSourceReader);
37 
38  	// Assigning passes ownership of the input stream to the decoder stream.
39 	// if you don't care for that, then after finishing with the decode, Assign(NULL).
40     void Assign(IByteReader* inSourceReader);
41 
42 	// IByteReader implementation. note that "inBufferSize" determines how many
43 	// bytes will be placed in the Buffer...not how many are actually read from the underlying
44 	// encoded stream. got it?!
45 	virtual IOBasicTypes::LongBufferSizeType Read(IOBasicTypes::Byte* inBuffer,IOBasicTypes::LongBufferSizeType inBufferSize);
46 
47 	virtual bool NotEnded();
48 
49 private:
50     jpeg_decompress_struct mJPGState;
51     jpeg_error_mgr mJPGError;
52 
53     IByteReader* mStream;
54     JSAMPARRAY mSamplesBuffer;
55     bool mIsDecoding;
56     IOBasicTypes::LongBufferSizeType mIndexInRow;
57     IOBasicTypes::LongBufferSizeType mCurrentSampleRow;
58     IOBasicTypes::LongBufferSizeType mTotalSampleRows;
59     bool mIsHeaderRead;
60 
61     void InitializeDecodingState();
62     PDFHummus::EStatusCode StartRead();
63     void FinalizeDecoding();
64     IOBasicTypes::Byte* CopySamplesArrayToBuffer(IOBasicTypes::Byte* inBuffer, IOBasicTypes::LongBufferSizeType inBufferSize);
65 
66 };
67 
68 #endif