File: spca501.c

package info (click to toggle)
v4l-utils 1.32.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,276 kB
  • sloc: ansic: 85,528; cpp: 69,473; perl: 11,915; sh: 1,333; python: 883; php: 119; makefile: 39
file content (251 lines) | stat: -rw-r--r-- 6,974 bytes parent folder | download | duplicates (8)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
#             (C) 2008 Hans de Goede <hdegoede@redhat.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA
 */

#include <string.h>
#include "libv4lconvert-priv.h"

/* YUYV per line */
void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst,
		int width, int height, int yvu)
{
	int i, j;
	unsigned long *lsrc = (unsigned long *)src;

	for (i = 0; i < height; i += 2) {
		/* -128 - 127 --> 0 - 255 and copy first line Y */
		unsigned long *ldst = (unsigned long *)(dst + i * width);

		for (j = 0; j < width; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line U */
		if (yvu)
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		else
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy second line Y */
		ldst = (unsigned long *)(dst + i * width + width);
		for (j = 0; j < width; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line V */
		if (yvu)
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		else
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}
	}
}

/* YYUV per line */
void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst,
		int width, int height, int yvu)
{
	int i, j;
	unsigned long *lsrc = (unsigned long *)src;

	for (i = 0; i < height; i += 2) {
		/* -128 - 127 --> 0 - 255 and copy 2 lines of Y */
		unsigned long *ldst = (unsigned long *)(dst + i * width);

		for (j = 0; j < width*2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line U */
		if (yvu)
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		else
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line V */
		if (yvu)
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		else
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}
	}
}

/* YUVY per line */
void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst,
		int width, int height, int yvu)
{
	int i, j;
	unsigned long *lsrc = (unsigned long *)src;

	for (i = 0; i < height; i += 2) {
		/* -128 - 127 --> 0 - 255 and copy first line Y */
		unsigned long *ldst = (unsigned long *)(dst + i * width);
		for (j = 0; j < width; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line U */
		if (yvu)
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		else
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy 1 line V */
		if (yvu)
			ldst = (unsigned long *)(dst + width * height + i * width / 4);
		else
			ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4);
		for (j = 0; j < width/2; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}

		/* -128 - 127 --> 0 - 255 and copy second line Y */
		ldst = (unsigned long *)(dst + i * width + width);
		for (j = 0; j < width; j += sizeof(long)) {
			*ldst = *lsrc++;
			*ldst++ ^= 0x8080808080808080ULL;
		}
	}
}

/* Note this is not a spca specific format, bit it fits in this file in that
   it is another funny yuv format */
/* one line of Y then 1 line of VYUY */
void v4lconvert_cit_yyvyuy_to_yuv420(const unsigned char *src,
		unsigned char *ydest,
		int width, int height, int yvu)
{
	int x, y;
	unsigned char *udest, *vdest;

	if (yvu) {
		vdest = ydest + width * height;
		udest = vdest + (width * height) / 4;
	} else {
		udest = ydest + width * height;
		vdest = udest + (width * height) / 4;
	}

	for (y = 0; y < height; y += 2) {
		/* copy 1 line of Y */
		memcpy(ydest, src, width);
		src += width;
		ydest += width;

		/* Split one line of VYUY */
		for (x = 0; x < width; x += 2) {
			*vdest++ = *src++;
			*ydest++ = *src++;
			*udest++ = *src++;
			*ydest++ = *src++;
		}
	}
}

/* Note this is not a spca specific format, but it fits in this file in that
   it is another funny yuv format */
/* The konica gspca subdriver using cams send data in blocks of 256 pixels
   in YUV420 format. */
void v4lconvert_konica_yuv420_to_yuv420(const unsigned char *src,
		unsigned char *ydest,
		int width, int height, int yvu)
{
	int i, no_blocks;
	unsigned char *udest, *vdest;

	if (yvu) {
		vdest = ydest + width * height;
		udest = vdest + (width * height) / 4;
	} else {
		udest = ydest + width * height;
		vdest = udest + (width * height) / 4;
	}

	no_blocks = width * height / 256;
	for (i = 0; i < no_blocks; i++) {
		/* copy 256 Y pixels */
		memcpy(ydest, src, 256);
		src += 256;
		ydest += 256;

		/* copy 64 U pixels */
		memcpy(udest, src, 64);
		src += 64;
		udest += 64;

		/* copy 64 V pixels */
		memcpy(vdest, src, 64);
		src += 64;
		vdest += 64;
	}
}

/* And another not a spca specific format, but fitting in this file in that
   it is another funny yuv format */
/* Two lines of Y then 1 line of UV */
void v4lconvert_m420_to_yuv420(const unsigned char *src,
		unsigned char *ydest,
		int width, int height, int yvu)
{
	int x, y;
	unsigned char *udest, *vdest;

	if (yvu) {
		vdest = ydest + width * height;
		udest = vdest + (width * height) / 4;
	} else {
		udest = ydest + width * height;
		vdest = udest + (width * height) / 4;
	}

	for (y = 0; y < height; y += 2) {
		/* copy 2 lines of Y */
		memcpy(ydest, src, 2 * width);
		src += 2 * width;
		ydest += 2 * width;

		/* Split one line of UV */
		for (x = 0; x < width; x += 2) {
			*udest++ = *src++;
			*vdest++ = *src++;
		}
	}
}