Accept patch in FS#9637 by Keith Perri, fixing a crash when loading a cfg which speci...
[kugel-rb.git] / apps / plugins / jpeg / jpeg_decoder.h
blobf4dbeaa14736ce9def22cdace29e02326239dd40
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * JPEG image viewer
11 * (This is a real mess if it has to be coded in one single C file)
13 * File scrolling addition (C) 2005 Alexander Spyridakis
14 * Copyright (C) 2004 Jörg Hohensohn aka [IDC]Dragon
15 * Heavily borrowed from the IJG implementation (C) Thomas G. Lane
16 * Small & fast downscaling IDCT (C) 2002 by Guido Vollbeding JPEGclub.org
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
24 * KIND, either express or implied.
26 ****************************************************************************/
28 #ifndef _JPEG_JPEG_DECODER_H
29 #define _JPEG_JPEG_DECODER_H
31 #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
33 struct derived_tbl
35 /* Basic tables: (element [0] of each array is unused) */
36 long mincode[17]; /* smallest code of length k */
37 long maxcode[18]; /* largest code of length k (-1 if none) */
38 /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
39 int valptr[17]; /* huffval[] index of 1st symbol of length k */
41 /* Back link to public Huffman table (needed only in slow_DECODE) */
42 int* pub;
44 /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
45 the input data stream. If the next Huffman code is no more
46 than HUFF_LOOKAHEAD bits long, we can obtain its length and
47 the corresponding symbol directly from these tables. */
48 int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
49 unsigned char look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
52 #define QUANT_TABLE_LENGTH 64
54 /* for type of Huffman table */
55 #define DC_LEN 28
56 #define AC_LEN 178
58 struct huffman_table
59 { /* length and code according to JFIF format */
60 int huffmancodes_dc[DC_LEN];
61 int huffmancodes_ac[AC_LEN];
64 struct frame_component
66 int ID;
67 int horizontal_sampling;
68 int vertical_sampling;
69 int quanttable_select;
72 struct scan_component
74 int ID;
75 int DC_select;
76 int AC_select;
79 struct bitstream
81 unsigned long get_buffer; /* current bit-extraction buffer */
82 int bits_left; /* # of unused bits in it */
83 unsigned char* next_input_byte;
84 unsigned char* input_end; /* upper limit +1 */
87 struct jpeg
89 int x_size, y_size; /* size of image (can be less than block boundary) */
90 int x_phys, y_phys; /* physical size, block aligned */
91 int x_mbl; /* x dimension of MBL */
92 int y_mbl; /* y dimension of MBL */
93 int blocks; /* blocks per MB */
94 int restart_interval; /* number of MCUs between RSTm markers */
95 int store_pos[4]; /* for Y block ordering */
97 unsigned char* p_entropy_data;
98 unsigned char* p_entropy_end;
100 int quanttable[4][QUANT_TABLE_LENGTH]; /* raw quantization tables 0-3 */
101 int qt_idct[2][QUANT_TABLE_LENGTH]; /* quantization tables for IDCT */
103 struct huffman_table hufftable[2]; /* Huffman tables */
104 struct derived_tbl dc_derived_tbls[2]; /* Huffman-LUTs */
105 struct derived_tbl ac_derived_tbls[2];
107 struct frame_component frameheader[3]; /* Component descriptor */
108 struct scan_component scanheader[3]; /* currently not used */
110 int mcu_membership[6]; /* info per block */
111 int tab_membership[6];
112 int subsample_x[3]; /* info per component */
113 int subsample_y[3];
117 /* possible return flags for process_markers() */
118 #define HUFFTAB 0x0001 /* with huffman table */
119 #define QUANTTAB 0x0002 /* with quantization table */
120 #define APP0_JFIF 0x0004 /* with APP0 segment following JFIF standard */
121 #define FILL_FF 0x0008 /* with 0xFF padding bytes at begin/end */
122 #define SOF0 0x0010 /* with SOF0-Segment */
123 #define DHT 0x0020 /* with Definition of huffman tables */
124 #define SOS 0x0040 /* with Start-of-Scan segment */
125 #define DQT 0x0080 /* with definition of quantization table */
127 /* various helper functions */
128 void default_huff_tbl(struct jpeg* p_jpeg);
129 void build_lut(struct jpeg* p_jpeg);
130 int process_markers(unsigned char* p_src, long size, struct jpeg* p_jpeg);
132 /* the main decode function */
133 #ifdef HAVE_LCD_COLOR
134 int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3],
135 int downscale, void (*pf_progress)(int current, int total));
136 #else
137 int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[1], int downscale,
138 void (*pf_progress)(int current, int total));
139 #endif
142 #endif /* _JPEG_JPEG_DECODER_H */