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):
28 m_analyseFrame(KdenliveSettings::analyse_stopmotion())
32 CaptureHandler::~CaptureHandler()
37 void CaptureHandler::setAnalyse(bool isOn)
39 m_analyseFrame = isOn;
42 void CaptureHandler::stopCapture()
47 void CaptureHandler::uyvy2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
52 int rgb_ptr, y_ptr, t;
54 len = width * height / 2;
59 for (t = 0; t < len; t++) { /* process 2 pixels at a time */
60 /* Compute parts of the UV components */
62 U = yuv_buffer[y_ptr];
63 Y = yuv_buffer[y_ptr+1];
64 V = yuv_buffer[y_ptr+2];
65 Y2 = yuv_buffer[y_ptr+3];
69 /*r = 1.164*(Y-16) + 1.596*(V-128);
70 g = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128);
71 b = 1.164*(Y-16) + 2.018*(U-128);*/
74 r = ((298 * (Y - 16) + 409 * (V - 128) + 128) >> 8);
76 g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
78 b = ((298 * (Y - 16) + 516 * (U - 128) + 128) >> 8);
88 rgb_buffer[rgb_ptr] = b;
89 rgb_buffer[rgb_ptr+1] = g;
90 rgb_buffer[rgb_ptr+2] = r;
91 rgb_buffer[rgb_ptr+3] = 255;
94 /*r = 1.164*(Y2-16) + 1.596*(V-128);
95 g = 1.164*(Y2-16) - 0.813*(V-128) - 0.391*(U-128);
96 b = 1.164*(Y2-16) + 2.018*(U-128);*/
99 r = ((298 * (Y2 - 16) + 409 * (V - 128) + 128) >> 8);
101 g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
103 b = ((298 * (Y2 - 16) + 516 * (U - 128) + 128) >> 8);
105 if (r > 255) r = 255;
106 if (g > 255) g = 255;
107 if (b > 255) b = 255;
113 rgb_buffer[rgb_ptr] = b;
114 rgb_buffer[rgb_ptr+1] = g;
115 rgb_buffer[rgb_ptr+2] = r;
116 rgb_buffer[rgb_ptr+3] = 255;
121 void CaptureHandler::yuyv2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
126 int rgb_ptr, y_ptr, t;
128 len = width * height / 2;
133 for (t = 0; t < len; t++) { /* process 2 pixels at a time */
134 /* Compute parts of the UV components */
136 Y = yuv_buffer[y_ptr];
137 U = yuv_buffer[y_ptr+1];
138 Y2 = yuv_buffer[y_ptr+2];
139 V = yuv_buffer[y_ptr+3];
143 /*r = 1.164*(Y-16) + 1.596*(V-128);
144 g = 1.164*(Y-16) - 0.813*(V-128) - 0.391*(U-128);
145 b = 1.164*(Y-16) + 2.018*(U-128);*/
148 r = ((298 * (Y - 16) + 409 * (V - 128) + 128) >> 8);
150 g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
152 b = ((298 * (Y - 16) + 516 * (U - 128) + 128) >> 8);
154 if (r > 255) r = 255;
155 if (g > 255) g = 255;
156 if (b > 255) b = 255;
162 rgb_buffer[rgb_ptr] = b;
163 rgb_buffer[rgb_ptr+1] = g;
164 rgb_buffer[rgb_ptr+2] = r;
165 rgb_buffer[rgb_ptr+3] = 255;
168 /*r = 1.164*(Y2-16) + 1.596*(V-128);
169 g = 1.164*(Y2-16) - 0.813*(V-128) - 0.391*(U-128);
170 b = 1.164*(Y2-16) + 2.018*(U-128);*/
173 r = ((298 * (Y2 - 16) + 409 * (V - 128) + 128) >> 8);
175 g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
177 b = ((298 * (Y2 - 16) + 516 * (U - 128) + 128) >> 8);
179 if (r > 255) r = 255;
180 if (g > 255) g = 255;
181 if (b > 255) b = 255;
187 rgb_buffer[rgb_ptr] = b;
188 rgb_buffer[rgb_ptr+1] = g;
189 rgb_buffer[rgb_ptr+2] = r;
190 rgb_buffer[rgb_ptr+3] = 255;