]> git.sesse.net Git - kdenlive/blob - src/stopmotion/capturehandler.cpp
Small improvements to stop motion widget
[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 {
29 }
30
31 CaptureHandler::~CaptureHandler()
32 {
33     stopCapture();
34 }
35
36 void CaptureHandler::stopCapture()
37 {
38 }
39
40 //static
41 void CaptureHandler::yuv2rgb(unsigned char *yuv_buffer, unsigned char *rgb_buffer, int width, int height)
42 {
43     int len;
44     int r, g, b;
45     int Y, U, V, Y2;
46     int rgb_ptr, y_ptr, t;
47
48     len = width * height / 2;
49
50     rgb_ptr = 0;
51     y_ptr = 0;
52
53     for (t = 0; t < len; t++) { /* process 2 pixels at a time */
54         /* Compute parts of the UV components */
55
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];
60         y_ptr += 4;
61
62
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);*/
66
67
68         r = ((298 * (Y - 16)               + 409 * (V - 128) + 128) >> 8);
69
70         g = ((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
71
72         b = ((298 * (Y - 16) + 516 * (U - 128)               + 128) >> 8);
73
74         if (r > 255) r = 255;
75         if (g > 255) g = 255;
76         if (b > 255) b = 255;
77
78         if (r < 0) r = 0;
79         if (g < 0) g = 0;
80         if (b < 0) b = 0;
81
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;
86
87         rgb_ptr += 4;
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);*/
91
92
93         r = ((298 * (Y2 - 16)               + 409 * (V - 128) + 128) >> 8);
94
95         g = ((298 * (Y2 - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
96
97         b = ((298 * (Y2 - 16) + 516 * (U - 128)               + 128) >> 8);
98
99         if (r > 255) r = 255;
100         if (g > 255) g = 255;
101         if (b > 255) b = 255;
102
103         if (r < 0) r = 0;
104         if (g < 0) g = 0;
105         if (b < 0) b = 0;
106
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;
111         rgb_ptr += 4;
112     }
113 }
114
115
116