Instrument Neutral Distributed Interface INDI 2.2.5
ccvt_c2.c
Go to the documentation of this file.
1/* CCVT_C2: Convert an image from yuv colourspace to rgb
2 Copyright (C) 2001 Tony Hague <[email protected]>
3
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 For questions, remarks, patches, etc. for this program, the author can be
20 reached at [email protected].
21*/
22
23#include "ccvt.h"
24#include "ccvt_types.h"
25
26/* by suitable definition of PIXTYPE, can do yuv to rgb or bgr, with or
27without word alignment */
28
29/* This doesn't exactly earn a prize in a programming beauty contest. */
30
31#define WHOLE_FUNC2RGB(type) \
32 const unsigned char *y1, *y2, *u, *v; \
33 PIXTYPE_##type *l1, *l2; \
34 int r, g, b, cr, cg, cb, yp, j, i; \
35 \
36 if ((width & 1) || (height & 1)) \
37 return; \
38 \
39 l1 = (PIXTYPE_##type *)dst; \
40 l2 = l1 + width; \
41 y1 = (unsigned char *)src; \
42 y2 = y1 + width; \
43 u = (unsigned char *)src + width * height; \
44 v = u + (width * height) / 4; \
45 j = height / 2; \
46 while (j--) \
47 { \
48 i = width / 2; \
49 while (i--) \
50 { \
51 /* Since U & V are valid for 4 pixels, repeat code 4 \
52 times for different Y */ \
53 cb = ((*u - 128) * 454) >> 8; \
54 cr = ((*v - 128) * 359) >> 8; \
55 cg = ((*v - 128) * 183 + (*u - 128) * 88) >> 8; \
56 \
57 yp = *(y1++); \
58 r = yp + cr; \
59 b = yp + cb; \
60 g = yp - cg; \
61 SAT(r); \
62 SAT(g); \
63 SAT(b); \
64 l1->b = b; \
65 l1->g = g; \
66 l1->r = r; \
67 l1++; \
68 \
69 yp = *(y1++); \
70 r = yp + cr; \
71 b = yp + cb; \
72 g = yp - cg; \
73 SAT(r); \
74 SAT(g); \
75 SAT(b); \
76 l1->b = b; \
77 l1->g = g; \
78 l1->r = r; \
79 l1++; \
80 \
81 yp = *(y2++); \
82 r = yp + cr; \
83 b = yp + cb; \
84 g = yp - cg; \
85 SAT(r); \
86 SAT(g); \
87 SAT(b); \
88 l2->b = b; \
89 l2->g = g; \
90 l2->r = r; \
91 l2++; \
92 \
93 yp = *(y2++); \
94 r = yp + cr; \
95 b = yp + cb; \
96 g = yp - cg; \
97 SAT(r); \
98 SAT(g); \
99 SAT(b); \
100 l2->b = b; \
101 l2->g = g; \
102 l2->r = r; \
103 l2++; \
104 \
105 u++; \
106 v++; \
107 } \
108 y1 = y2; \
109 y2 += width; \
110 l1 = l2; \
111 l2 += width; \
112 }
114void ccvt_420p_bgr32(int width, int height, const void *src, void *dst)
115{
116 WHOLE_FUNC2RGB(bgr32)
117}
119void ccvt_420p_bgr24(int width, int height, const void *src, void *dst)
120{
121 WHOLE_FUNC2RGB(bgr24)
122}
124void ccvt_420p_rgb32(int width, int height, const void *src, void *dst)
125{
126 WHOLE_FUNC2RGB(rgb32)
127}
129void ccvt_420p_rgb24(int width, int height, const void *src, void *dst)
130{
131 WHOLE_FUNC2RGB(rgb24)
132}
void ccvt_420p_rgb24(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:128
void ccvt_420p_rgb32(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:123
#define WHOLE_FUNC2RGB(type)
Definition ccvt_c2.c:31
void ccvt_420p_bgr32(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:113
void ccvt_420p_bgr24(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:118