Fix returning too early (before cleanup) in RFAC, which led to not cancelling
[kugel-rb/myfork.git] / apps / recorder / jpeg_common.h
blob061cfc8e64c09cb49e997674c42ca6cae83a8403
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * JPEG image viewer
11 * Common structs and defines for plugin and core JPEG decoders
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_COMMON_H
29 #define _JPEG_COMMON_H
31 #include "bmp.h"
33 #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
34 #define JPEG_READ_BUF_SIZE 16
35 struct derived_tbl
37 /* Basic tables: (element [0] of each array is unused) */
38 long mincode[17]; /* smallest code of length k */
39 long maxcode[18]; /* largest code of length k (-1 if none) */
40 /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
41 int valptr[17]; /* huffval[] index of 1st symbol of length k */
43 /* Back link to public Huffman table (needed only in slow_DECODE) */
44 int* pub;
46 /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
47 the input data stream. If the next Huffman code is no more
48 than HUFF_LOOKAHEAD bits long, we can obtain its length and
49 the corresponding symbol directly from these tables. */
50 int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
51 unsigned char look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
54 #define QUANT_TABLE_LENGTH 64
57 * Conversion of full 0-255 range YCrCb to RGB:
58 * |R| |1.000000 -0.000001 1.402000| |Y'|
59 * |G| = |1.000000 -0.334136 -0.714136| |Pb|
60 * |B| |1.000000 1.772000 0.000000| |Pr|
61 * Scaled (yields s15-bit output):
62 * |R| |128 0 179| |Y |
63 * |G| = |128 -43 -91| |Cb - 128|
64 * |B| |128 227 0| |Cr - 128|
66 #define YFAC 128
67 #define RVFAC 179
68 #define GUFAC (-43)
69 #define GVFAC (-91)
70 #define BUFAC 227
71 #define COMPONENT_SHIFT 15
73 struct uint8_yuv {
74 uint8_t y;
75 uint8_t u;
76 uint8_t v;
79 union uint8_rgbyuv {
80 struct uint8_yuv yuv;
81 struct uint8_rgb rgb;
84 static inline int clamp_component(int x)
86 if ((unsigned)x > 255)
87 x = x < 0 ? 0 : 255;
88 return x;
90 #include <debug.h>
91 static inline void yuv_to_rgb(int y, int u, int v, unsigned *r, unsigned *g, unsigned *b)
93 int rv, guv, bu;
94 y = y * YFAC + (YFAC >> 1);
95 u = u - 128;
96 v = v - 128;
97 rv = RVFAC * v;
98 guv = GUFAC * u + GVFAC * v;
99 bu = BUFAC * u;
100 *r = clamp_component((y + rv) / YFAC);
101 *g = clamp_component((y + guv) / YFAC);
102 *b = clamp_component((y + bu) / YFAC);
105 /* for type of Huffman table */
106 #define DC_LEN 28
107 #define AC_LEN 178
109 struct huffman_table
110 { /* length and code according to JFIF format */
111 int huffmancodes_dc[DC_LEN];
112 int huffmancodes_ac[AC_LEN];
115 struct frame_component
117 int ID;
118 int horizontal_sampling;
119 int vertical_sampling;
120 int quanttable_select;
123 struct scan_component
125 int ID;
126 int DC_select;
127 int AC_select;
130 struct bitstream
132 unsigned long get_buffer; /* current bit-extraction buffer */
133 int bits_left; /* # of unused bits in it */
134 unsigned char* next_input_byte;
135 unsigned char* input_end; /* upper limit +1 */
138 /* possible return flags for process_markers() */
139 #define HUFFTAB 0x0001 /* with huffman table */
140 #define QUANTTAB 0x0002 /* with quantization table */
141 #define APP0_JFIF 0x0004 /* with APP0 segment following JFIF standard */
142 #define FILL_FF 0x0008 /* with 0xFF padding bytes at begin/end */
143 #define SOF0 0x0010 /* with SOF0-Segment */
144 #define DHT 0x0020 /* with Definition of huffman tables */
145 #define SOS 0x0040 /* with Start-of-Scan segment */
146 #define DQT 0x0080 /* with definition of quantization table */
148 #endif /* _JPEG_COMMON_H */