1 /***************************************************************************
2 * Copyright (C) 2010 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "capturehandler.h"
23 #include "kdenlivesettings.h"
25 CaptureHandler::CaptureHandler(QVBoxLayout *lay, QWidget *parent):
31 CaptureHandler::~CaptureHandler()
36 void CaptureHandler::stopCapture()
41 void CaptureHandler::uyvy2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
46 int rgb_ptr, y_ptr, t;
48 len = width * height / 2;
53 for (t = 0; t < len; t++) { /* process 2 pixels at a time */
54 /* Compute parts of the UV components */
56 U = yuv_buffer[y_ptr];
57 Y = yuv_buffer[y_ptr+1];
58 V = yuv_buffer[y_ptr+2];
59 Y2 = yuv_buffer[y_ptr+3];
63 /*r = 1.164*(Y-16) + 1.596*(V-128);
64 g = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128);
65 b = 1.164*(Y-16) + 2.018*(U-128);*/
68 r = ((298 * (Y - 16) + 409 * (V - 128) + 128) >> 8);
70 g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
72 b = ((298 * (Y - 16) + 516 * (U - 128) + 128) >> 8);
82 rgb_buffer[rgb_ptr] = b;
83 rgb_buffer[rgb_ptr+1] = g;
84 rgb_buffer[rgb_ptr+2] = r;
85 rgb_buffer[rgb_ptr+3] = 255;
88 /*r = 1.164*(Y2-16) + 1.596*(V-128);
89 g = 1.164*(Y2-16) - 0.813*(V-128) - 0.391*(U-128);
90 b = 1.164*(Y2-16) + 2.018*(U-128);*/
93 r = ((298 * (Y2 - 16) + 409 * (V - 128) + 128) >> 8);
95 g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
97 b = ((298 * (Y2 - 16) + 516 * (U - 128) + 128) >> 8);
100 if (g > 255) g = 255;
101 if (b > 255) b = 255;
107 rgb_buffer[rgb_ptr] = b;
108 rgb_buffer[rgb_ptr+1] = g;
109 rgb_buffer[rgb_ptr+2] = r;
110 rgb_buffer[rgb_ptr+3] = 255;
115 void CaptureHandler::yuyv2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
120 int rgb_ptr, y_ptr, t;
122 len = width * height / 2;
127 for (t = 0; t < len; t++) { /* process 2 pixels at a time */
128 /* Compute parts of the UV components */
130 Y = yuv_buffer[y_ptr];
131 U = yuv_buffer[y_ptr+1];
132 Y2 = yuv_buffer[y_ptr+2];
133 V = yuv_buffer[y_ptr+3];
137 /*r = 1.164*(Y-16) + 1.596*(V-128);
138 g = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128);
139 b = 1.164*(Y-16) + 2.018*(U-128);*/
142 r = ((298 * (Y - 16) + 409 * (V - 128) + 128) >> 8);
144 g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
146 b = ((298 * (Y - 16) + 516 * (U - 128) + 128) >> 8);
148 if (r > 255) r = 255;
149 if (g > 255) g = 255;
150 if (b > 255) b = 255;
156 rgb_buffer[rgb_ptr] = b;
157 rgb_buffer[rgb_ptr+1] = g;
158 rgb_buffer[rgb_ptr+2] = r;
159 rgb_buffer[rgb_ptr+3] = 255;
162 /*r = 1.164*(Y2-16) + 1.596*(V-128);
163 g = 1.164*(Y2-16) - 0.813*(V-128) - 0.391*(U-128);
164 b = 1.164*(Y2-16) + 2.018*(U-128);*/
167 r = ((298 * (Y2 - 16) + 409 * (V - 128) + 128) >> 8);
169 g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
171 b = ((298 * (Y2 - 16) + 516 * (U - 128) + 128) >> 8);
173 if (r > 255) r = 255;
174 if (g > 255) g = 255;
175 if (b > 255) b = 255;
181 rgb_buffer[rgb_ptr] = b;
182 rgb_buffer[rgb_ptr+1] = g;
183 rgb_buffer[rgb_ptr+2] = r;
184 rgb_buffer[rgb_ptr+3] = 255;