]> git.sesse.net Git - kdenlive/blob - src/stopmotion/capturehandler.cpp
f1778ddfc486990d7c594f6f4fff2c8a695bfb94
[kdenlive] / src / stopmotion / capturehandler.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <KLocale>
21
22 #include "capturehandler.h"
23 #include "kdenlivesettings.h"
24
25 CaptureHandler::CaptureHandler(QVBoxLayout *lay, QWidget *parent):
26     m_layout(lay),
27     m_parent(parent),
28     m_analyseFrame(KdenliveSettings::analyse_stopmotion())
29 {
30 }
31
32 CaptureHandler::~CaptureHandler()
33 {
34     stopCapture();
35 }
36
37 void CaptureHandler::setAnalyse(bool isOn)
38 {
39     m_analyseFrame = isOn;
40 }
41
42 void CaptureHandler::stopCapture()
43 {
44 }
45
46 //static
47 void CaptureHandler::uyvy2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
48 {
49     int len;
50     int r, g, b;
51     int Y, U, V, Y2;
52     int rgb_ptr, y_ptr, t;
53
54     len = width * height / 2;
55
56     rgb_ptr = 0;
57     y_ptr = 0;
58
59     for (t = 0; t < len; t++) { /* process 2 pixels at a time */
60         /* Compute parts of the UV components */
61
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];
66         y_ptr += 4;
67
68
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);*/
72
73
74         r = ((298 * (Y - 16)               + 409 * (V - 128) + 128) >> 8);
75
76         g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
77
78         b = ((298 * (Y - 16) + 516 * (U - 128)               + 128) >> 8);
79
80         if (r > 255) r = 255;
81         if (g > 255) g = 255;
82         if (b > 255) b = 255;
83
84         if (r < 0) r = 0;
85         if (g < 0) g = 0;
86         if (b < 0) b = 0;
87
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;
92
93         rgb_ptr += 4;
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);*/
97
98
99         r = ((298 * (Y2 - 16)               + 409 * (V - 128) + 128) >> 8);
100
101         g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
102
103         b = ((298 * (Y2 - 16) + 516 * (U - 128)               + 128) >> 8);
104
105         if (r > 255) r = 255;
106         if (g > 255) g = 255;
107         if (b > 255) b = 255;
108
109         if (r < 0) r = 0;
110         if (g < 0) g = 0;
111         if (b < 0) b = 0;
112
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;
117         rgb_ptr += 4;
118     }
119 }
120
121 void CaptureHandler::yuyv2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
122 {
123     int len;
124     int r, g, b;
125     int Y, U, V, Y2;
126     int rgb_ptr, y_ptr, t;
127
128     len = width * height / 2;
129
130     rgb_ptr = 0;
131     y_ptr = 0;
132
133     for (t = 0; t < len; t++) { /* process 2 pixels at a time */
134         /* Compute parts of the UV components */
135
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];
140         y_ptr += 4;
141
142
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);*/
146
147
148         r = ((298 * (Y - 16)               + 409 * (V - 128) + 128) >> 8);
149
150         g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
151
152         b = ((298 * (Y - 16) + 516 * (U - 128)               + 128) >> 8);
153
154         if (r > 255) r = 255;
155         if (g > 255) g = 255;
156         if (b > 255) b = 255;
157
158         if (r < 0) r = 0;
159         if (g < 0) g = 0;
160         if (b < 0) b = 0;
161
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;
166
167         rgb_ptr += 4;
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);*/
171
172
173         r = ((298 * (Y2 - 16)               + 409 * (V - 128) + 128) >> 8);
174
175         g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
176
177         b = ((298 * (Y2 - 16) + 516 * (U - 128)               + 128) >> 8);
178
179         if (r > 255) r = 255;
180         if (g > 255) g = 255;
181         if (b > 255) b = 255;
182
183         if (r < 0) r = 0;
184         if (g < 0) g = 0;
185         if (b < 0) b = 0;
186
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;
191         rgb_ptr += 4;
192     }
193 }
194
195
196
197 #include "capturehandler.moc"