Move the sources to trunk
[opencv] / otherlibs / VlGrFmts / rd_jpeg.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //  
3 //                      INTEL CORPORATION PROPRIETARY INFORMATION              
4 //         This software is supplied under the terms of a license agreement or 
5 //         nondisclosure agreement with Intel Corporation and may not be copied
6 //         or disclosed except in accordance with the terms of that agreement. 
7 //               Copyright (c) 1999 Intel Corporation. All Rights Reserved.    
8 //  
9 //    RCS:
10 //       Source:    rd_jpeg.h$
11 //       $Revision: 1.2 $
12 //      Purpose: 
13 //      Contents:
14 //      Authors: Vadim Pisarevsky
15 //  
16 //M*/
17
18 #pragma once
19
20 #include "grfmt.h"
21 #include "bitstrm.h"
22
23 class rm_jpeg_bit_stream : public rm_bit_stream
24 {
25 public:
26     rm_byte_stream  m_low_strm;
27     
28     rm_jpeg_bit_stream();
29     ~rm_jpeg_bit_stream();
30
31     virtual bool  open( const char* filename );
32     virtual void  close();
33
34     void  flush(); // flushes high-level bit stream
35     void  align_on_byte();
36     int   find_marker();
37
38 protected:
39     virtual void  read_block();
40 };
41
42
43 //////////////////// JPEG reader /////////////////////
44
45 class grfmt_jpeg_reader : public graphics_format_reader
46 {
47 public:
48     
49     grfmt_jpeg_reader();
50     ~grfmt_jpeg_reader();
51
52     int   get_color();
53     bool  read_header();
54     bool  read_data( byte* data, int pitch, int color );
55     void  close();
56
57 protected:
58
59     int   m_offset; // offset of first scan
60     int   m_version; // JFIF version
61     int   m_planes; // 3 (YCrCb) or 1 (Gray)
62     int   m_precision; // 8 or 12-bit per sample
63     int   m_type; // SOF type
64     int   m_MCUs; // MCUs in restart interval
65     int   m_ss, m_se, m_ah, m_al; // progressive JPEG parameters
66     
67     // information about each component
68     struct cmp_info
69     {
70         char h;  // horizontal sampling factor
71         char v;  // vertical   sampling factor
72         char tq; // quantization table index
73         char td, ta; // DC & AC huffman tables
74         int  dc_pred; // DC predictor
75     };
76     
77     cmp_info m_ci[3];
78
79     int     m_tq[4][64];
80     bool    m_is_tq[4];
81     
82     short*  m_td[4];
83     bool    m_is_td[4];
84     
85     short*  m_ta[4];
86     bool    m_is_ta[4];
87     
88     rm_jpeg_bit_stream   m_strm;
89
90 protected:
91
92     bool  load_quant_tables( int length );
93     bool  load_huffman_tables( int length );
94     void  process_scan( int* idx, int ns, byte* data, int pitch, int color );
95     void  reset_decoder();
96     void  get_block( int* block, int c );
97 };