summaryrefslogtreecommitdiff
path: root/apps/recorder/jpeg_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/jpeg_common.h')
-rw-r--r--apps/recorder/jpeg_common.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/apps/recorder/jpeg_common.h b/apps/recorder/jpeg_common.h
index 44bf81e435..061cfc8e64 100644
--- a/apps/recorder/jpeg_common.h
+++ b/apps/recorder/jpeg_common.h
@@ -28,6 +28,8 @@
28#ifndef _JPEG_COMMON_H 28#ifndef _JPEG_COMMON_H
29#define _JPEG_COMMON_H 29#define _JPEG_COMMON_H
30 30
31#include "bmp.h"
32
31#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ 33#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
32#define JPEG_READ_BUF_SIZE 16 34#define JPEG_READ_BUF_SIZE 16
33struct derived_tbl 35struct derived_tbl
@@ -51,6 +53,55 @@ struct derived_tbl
51 53
52#define QUANT_TABLE_LENGTH 64 54#define QUANT_TABLE_LENGTH 64
53 55
56/*
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|
65 */
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
72
73struct uint8_yuv {
74 uint8_t y;
75 uint8_t u;
76 uint8_t v;
77};
78
79union uint8_rgbyuv {
80 struct uint8_yuv yuv;
81 struct uint8_rgb rgb;
82};
83
84static inline int clamp_component(int x)
85{
86 if ((unsigned)x > 255)
87 x = x < 0 ? 0 : 255;
88 return x;
89}
90#include <debug.h>
91static inline void yuv_to_rgb(int y, int u, int v, unsigned *r, unsigned *g, unsigned *b)
92{
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);
103}
104
54/* for type of Huffman table */ 105/* for type of Huffman table */
55#define DC_LEN 28 106#define DC_LEN 28
56#define AC_LEN 178 107#define AC_LEN 178