Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc

Issue 6883202: audiovideo_V4L2: Added more pixel formats. (Closed) Base URL: http://git.chromium.org/git/autotest.git@master
Patch Set: Fixed some indentation inconsistencies. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <assert.h> 5 #include <assert.h>
6 #include <getopt.h> 6 #include <getopt.h>
7 #include <signal.h> 7 #include <signal.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 #include <iostream> 10 #include <iostream>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 XFreeGC(xdisplay_, gc); 115 XFreeGC(xdisplay_, gc);
116 } 116 }
117 117
118 inline int32_t clip(int32_t value, int32_t min, int32_t max) { 118 inline int32_t clip(int32_t value, int32_t min, int32_t max) {
119 return (value > max ? max : value < min ? min : value); 119 return (value > max ? max : value < min ? min : value);
120 } 120 }
121 121
122 void ConvertYUVToRGB32(uint8_t* in, uint8_t* out, int32_t ifmt, 122 void ConvertYUVToRGB32(uint8_t* in, uint8_t* out, int32_t ifmt,
123 int32_t width, int32_t height, 123 int32_t width, int32_t height,
124 int32_t istride, int32_t ostride) { 124 int32_t istride, int32_t ostride) {
125 if (ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) { 125 if ((ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) ||
126 (ifmt == v4l2_fourcc('Y', 'V', 'Y', 'U')) ||
127 (ifmt == v4l2_fourcc('U', 'Y', 'V', 'Y')) ||
128 (ifmt == v4l2_fourcc('V', 'Y', 'U', 'Y'))) {
126 for (int32_t i = 0; i < height; ++i) { 129 for (int32_t i = 0; i < height; ++i) {
127 for (int32_t j = 0; j < width * 2; j += 4) { 130 for (int32_t j = 0; j < width * 2; j += 4) {
128 int32_t y0 = in[j]; 131 int32_t y0;
129 int32_t y1 = in[j + 2]; 132 int32_t y1;
130 int32_t u = in[j + 1] - 128; 133 int32_t u;
131 int32_t v = in[j + 3] - 128; 134 int32_t v;
132 135
133 int32_t r = (298 * y0 + 409 * v + 128) >> 8; 136 if (ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) {
134 int32_t g = (298 * y0 - 100 * u - 208 * v + 128) >> 8; 137 y0 = in[j];
135 int32_t b = (298 * y0 + 516 * u + 128) >> 8; 138 y1 = in[j + 2];
136 out[j * 2 + 0] = clip(b, 0, 255); 139 u = in[j + 1] - 128;
137 out[j * 2 + 1] = clip(g, 0, 255); 140 v = in[j + 3] - 128;
138 out[j * 2 + 2] = clip(r, 0, 255); 141 } else if (ifmt == v4l2_fourcc('Y', 'V', 'Y', 'U')) {
139 out[j * 2 + 3] = 255; 142 y0 = in[j];
140 r = (298 * y1 + 409 * v + 128) >> 8; 143 y1 = in[j + 2];
141 g = (298 * y1 - 100 * u - 208 * v + 128) >> 8; 144 u = in[j + 3] - 128;
142 b = (298 * y1 + 516 * u + 128) >> 8; 145 v = in[j + 1] - 128;
143 out[j * 2 + 4] = clip(b, 0, 255); 146 } else if (ifmt == v4l2_fourcc('U', 'Y', 'V', 'Y')) {
144 out[j * 2 + 5] = clip(g, 0, 255); 147 y0 = in[j + 1];
145 out[j * 2 + 6] = clip(r, 0, 255); 148 y1 = in[j + 3];
146 out[j * 2 + 7] = 255; 149 u = in[j] - 128;
150 v = in[j + 2] - 128;
151 } else if (ifmt == v4l2_fourcc('V', 'Y', 'U', 'Y')) {
152 y0 = in[j + 1];
153 y1 = in[j + 3];
154 u = in[j + 2] - 128;
155 v = in[j] - 128;
156 } else {
157 CHECK(0);
158 }
jiesun 2011/04/28 17:28:27 I actually prefer to do the branching outside the
159
160 int32_t r = (298 * y0 + 409 * v + 128) >> 8;
161 int32_t g = (298 * y0 - 100 * u - 208 * v + 128) >> 8;
162 int32_t b = (298 * y0 + 516 * u + 128) >> 8;
163
164 out[j * 2 + 0] = clip(b, 0, 255);
165 out[j * 2 + 1] = clip(g, 0, 255);
166 out[j * 2 + 2] = clip(r, 0, 255);
167 out[j * 2 + 3] = 255;
168
169 r = (298 * y1 + 409 * v + 128) >> 8;
170 g = (298 * y1 - 100 * u - 208 * v + 128) >> 8;
171 b = (298 * y1 + 516 * u + 128) >> 8;
172
173 out[j * 2 + 4] = clip(b, 0, 255);
174 out[j * 2 + 5] = clip(g, 0, 255);
175 out[j * 2 + 6] = clip(r, 0, 255);
176 out[j * 2 + 7] = 255;
147 } 177 }
148 in += istride; 178 in += istride;
149 out += ostride; 179 out += ostride;
150 } 180 }
181 } else if (ifmt == v4l2_fourcc('Y', 'U', '1', '2')) {
jiesun 2011/04/28 17:32:31 || ifmt == v4l2_fourcc('Y', 'V', '1', '2') since i
182 // Can't use pixels_per_line for this. While pixels per line is 12,
183 // the rest of this part of code is using line stride as the
184 // y-plane's line stride, which should just be the width of the image.
185 istride = width;
186
187 uint8_t* y_plane = in;
188 uint8_t* u_plane = in + height * istride;
189 // assumption. stride for uv is half of the y stride.
190 uint8_t* v_plane = u_plane + height * istride / 4;
jiesun 2011/04/28 17:32:31 if (ifmt == v4l2_fourcc('Y', 'V', '1', '2')) swap
191 for (int32_t i = 0; i < height; ++i) {
192 for (int32_t j = 0; j < width; ++j) {
193 int32_t y = y_plane[j];
194 int32_t u = u_plane[j>>1];
jiesun 2011/04/28 17:28:27 apparently that I had forgetten to -128 here and t
195 int32_t v = v_plane[j>>1];
jiesun 2011/04/28 17:28:27 please also add space around binary operator >>.
196
197 int32_t r = (298 * y + 409 * v + 128) >> 8;
198 int32_t g = (298 * y - 100 * u - 208 * v + 128) >> 8;
199 int32_t b = (298 * y + 516 * u + 128) >> 8;
200
201 out[j * 4 + 0] = clip(b, 0, 255);
202 out[j * 4 + 1] = clip(g, 0, 255);
203 out[j * 4 + 2] = clip(r, 0, 255);
204 out[j * 4 + 3] = 255;
205 }
206 y_plane += istride;
207 if (i&1) {
208 u_plane += istride >> 1;
209 v_plane += istride >> 1;
210 }
211 out += ostride;
212 }
151 } else { 213 } else {
152 CHECK(0); 214 CHECK(0);
153 } 215 }
154 } 216 }
155 217
156 private: 218 private:
157 Display* xdisplay_; 219 Display* xdisplay_;
158 Window xwindow_; 220 Window xwindow_;
159 XImage* ximage_; 221 XImage* ximage_;
160 bool xrunning_; 222 bool xrunning_;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 retcode = 6; 370 retcode = 6;
309 371
310 device->CloseDevice(); 372 device->CloseDevice();
311 373
312 if (device) 374 if (device)
313 delete device; 375 delete device;
314 376
315 return retcode; 377 return retcode;
316 } 378 }
317 379
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698