Debian Codegraph @

cvd_src/yuv420.cpp

raw symbols SCIP
1 #include "cvd/colourspace_convert.h"
2
3 namespace CVD
4 {
5 namespace
6 {
7 void yuv420p_to_rgb_c(const unsigned char* y, unsigned char* rgb, unsigned int width, unsigned int height)
8 {
9 const byte* u = y + width * height;
10 const byte* v = u + width * height / 4;
11
12 unsigned int halfwidth = width >> 1;
13 int yy, uu, vv, ug_plus_vg, ub, vr;
14 int r, g, b;
15 unsigned int i, j;
16 for(i = 0; i < height; ++i)
17 {
18 for(j = 0; j < halfwidth; ++j)
19 {
20 yy = y[0] << 8;
21 uu = *u - 128;
22 vv = *v - 128;
23 ug_plus_vg = uu * 88 + vv * 183;
24 ub = uu * 454;
25 vr = vv * 359;
26 r = (yy + vr) >> 8;
27 g = (yy - ug_plus_vg) >> 8;
28 b = (yy + ub) >> 8;
29 rgb[0] = r < 0 ? 0 : (r > 255 ? 255 : (unsigned char)r);
30 rgb[1] = g < 0 ? 0 : (g > 255 ? 255 : (unsigned char)g);
31 rgb[2] = b < 0 ? 0 : (b > 255 ? 255 : (unsigned char)b);
32 yy = y[1] << 8;
33 r = (yy + vr) >> 8;
34 g = (yy - ug_plus_vg) >> 8;
35 b = (yy + ub) >> 8;
36 rgb[3] = r < 0 ? 0 : (r > 255 ? 255 : (unsigned char)r);
37 rgb[4] = g < 0 ? 0 : (g > 255 ? 255 : (unsigned char)g);
38 rgb[5] = b < 0 ? 0 : (b > 255 ? 255 : (unsigned char)b);
39
40 y += 2;
41 rgb += 6;
42 u++;
43 v++;
44 }
45 if((i & 1) == 0)
46 {
47 u -= halfwidth;
48 v -= halfwidth;
49 }
50 }
51 }
52
53 }
54
55 template <>
56 void convert_image(const BasicImage<yuv420p>& from, BasicImage<Rgb<byte>>& to)
57 {
58 if(from.size() != to.size())
59 throw Exceptions::Image::IncompatibleImageSizes(__FUNCTION__);
60
61 const byte* yuv420 = static_cast<const byte*>(from.data());
62 yuv420p_to_rgb_c(yuv420, (byte*)to.data(), from.size().x, from.size().y);
63 }
64
65 template <>
66 void convert_image(const BasicImage<yuv420p>& from, BasicImage<byte>& to)
67 {
68 if(from.size() != to.size())
69 throw Exceptions::Image::IncompatibleImageSizes(__FUNCTION__);
70
71 memcpy(to.data(), from.data(), to.size().area());
72 }
73 }