summaryrefslogtreecommitdiff
path: root/examples/jpeg/jpeg_internal.h
blob: a5e8ff25cb39691e2902ad2acbaa974308384f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

#ifndef _JPEG_INTERNAL_H_
#define _JPEG_INTERNAL_H_

#include "jpeg.h"
#include "jpeg_huffman.h"
#include "jpeg_bits.h"
#include "jpeg_debug.h"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif


#define JPEG_MAX_COMPONENTS 256

typedef struct _JpegScan JpegScan;
typedef struct _JpegQuantTable JpegQuantTable;

#define JPEG_ENTROPY_SEGMENT 0x0001
#define JPEG_LENGTH 0x0002

struct _JpegQuantTable {
  int pq;
  int16_t quantizer[64];
};

struct _JpegDecoder {
	int width;
	int height;
	int depth;
	int n_components;
	JpegBits bits;
        int error;
        char *error_message;

        int sof_type;

	int width_blocks;
	int height_blocks;

	int restart_interval;

	unsigned char *data;
	unsigned int data_len;

	struct{
		int id;
		int h_sample;
		int v_sample;
		int quant_table;

		int h_subsample;
		int v_subsample;
		unsigned char *image;
		int rowstride;
	} components[JPEG_MAX_COMPONENTS];

        JpegQuantTable quant_tables[4];
	HuffmanTable dc_huff_table[4];
	HuffmanTable ac_huff_table[4];

	int scan_list_length;
	struct{
		int component_index;
		int dc_table;
		int ac_table;
		int quant_table;
		int x;
		int y;
		int offset;
	}scan_list[10];
	int scan_h_subsample;
	int scan_v_subsample;

	/* scan state */
	int x,y;
	int dc[4];
};

struct _JpegScan {
	int length;
	
	int n_components;
	struct {
		int index;
		int dc_table;
		int ac_table;
	}block_list[10];
};


/* jpeg.c */

int jpeg_decoder_sof_baseline_dct(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_define_quant_table(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_define_huffman_table(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_sos(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_soi(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_eoi(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_application0(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_application_misc(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_comment(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_restart_interval(JpegDecoder *dec, JpegBits *bits);
int jpeg_decoder_restart(JpegDecoder *dec, JpegBits *bits);
void jpeg_decoder_decode_entropy_segment(JpegDecoder *dec);


#endif