|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Implementation of class CYuv2Rgb16. |
|
17 * YUV to EColor64K colorspace converter concrete classes. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 #include "yuv2rgb16.h" |
|
24 |
|
25 // --------------------------------------------------------- |
|
26 // CYuv2Rgb16::CYuv2Rgb16() |
|
27 // Standard C++ constructor. |
|
28 // --------------------------------------------------------- |
|
29 // |
|
30 CYuv2Rgb16::CYuv2Rgb16() |
|
31 { |
|
32 iWidth = iHeight = 0; |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // CYuv2Rgb16::~CYuv2Rgb16() |
|
37 // Destructor |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 CYuv2Rgb16::~CYuv2Rgb16() |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CYuv2Rgb16::ConstructL() |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 void CYuv2Rgb16::ConstructL(TUint aWidth, TUint aHeight, TUint /*aMaxWidth*/, TUint /*aMaxHeight*/) |
|
51 { |
|
52 iWidth = aWidth; |
|
53 iHeight = aHeight; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CYuv2Rgb16::Convert() |
|
58 // Converts a YUV frame to a EColor64K frame |
|
59 // --------------------------------------------------------- |
|
60 // |
|
61 void CYuv2Rgb16::Convert(const TUint8 *aYBuf, const TUint8 *aUBuf, |
|
62 const TUint8 *aVBuf, |
|
63 TUint aBufWidth, TUint aBufHeight, |
|
64 TUint8 *aTarget, TUint aTargetScanlineLength) |
|
65 { |
|
66 |
|
67 |
|
68 TUint cols; |
|
69 TUint rows = iHeight; |
|
70 |
|
71 __ASSERT_ALWAYS((aBufWidth >= iWidth) && (aBufHeight >= iHeight), |
|
72 User::Invariant()); |
|
73 |
|
74 // Convert all rows, two at a time |
|
75 while ( rows ) |
|
76 { |
|
77 // Convert all pixels in this row, two at a time |
|
78 cols = iWidth; |
|
79 |
|
80 TUint8* target1 = aTarget; |
|
81 TUint8* target2 = aTarget + aTargetScanlineLength; |
|
82 const TUint8* YPtr1 = aYBuf; |
|
83 const TUint8* YPtr2 = aYBuf + aBufWidth; |
|
84 const TUint8* UPtr = aUBuf; |
|
85 const TUint8* VPtr = aVBuf; |
|
86 |
|
87 TUint y, u, v; |
|
88 TInt rDiff, gDiff, bDiff; |
|
89 TInt r, g, b; |
|
90 |
|
91 while ( cols ) |
|
92 { |
|
93 y = *(YPtr1)++; |
|
94 u = *(UPtr)++ - 128; |
|
95 v = *(VPtr)++ - 128; |
|
96 |
|
97 rDiff = UvToRDiff(v, u); |
|
98 gDiff = UvToGDiff(v, u); |
|
99 bDiff = UvToBDiff(v, u); |
|
100 |
|
101 // Convert upper left pixel |
|
102 r = (TInt)y + rDiff; |
|
103 r = r<0 ? 0 : r>255 ? 0xF800 : (r<<8)&0xF800; |
|
104 g = (TInt)y - gDiff; |
|
105 g = g<0 ? 0 : g>255 ? 0x07E0 : (g<<3)&0x07E0; |
|
106 b = (TInt)y + bDiff; |
|
107 b = b<0 ? 0 : b>255 ? 0x001F : (b>>3)&0x001F; |
|
108 |
|
109 // Write the pixel in RGB format |
|
110 *(TUint16*)target1 = (TUint16)(r | g | b); |
|
111 target1 += 2; |
|
112 |
|
113 // Convert upper right pixel |
|
114 y = *(YPtr1)++; |
|
115 |
|
116 r = (TInt)y + rDiff; |
|
117 r = r<0 ? 0 : r>255 ? 0xF800 : (r<<8)&0xF800; |
|
118 g = (TInt)y - gDiff; |
|
119 g = g<0 ? 0 : g>255 ? 0x07E0 : (g<<3)&0x07E0; |
|
120 b = (TInt)y + bDiff; |
|
121 b = b<0 ? 0 : b>255 ? 0x001F : (b>>3)&0x001F; |
|
122 |
|
123 *(TUint16*)target1 = (TUint16)(r | g | b); |
|
124 target1 += 2; |
|
125 |
|
126 // Convert lower left pixel |
|
127 y = *(YPtr2)++; |
|
128 |
|
129 r = (TInt)y + rDiff; |
|
130 r = r<0 ? 0 : r>255 ? 0xF800 : (r<<8)&0xF800; |
|
131 g = (TInt)y - gDiff; |
|
132 g = g<0 ? 0 : g>255 ? 0x07E0 : (g<<3)&0x07E0; |
|
133 b = (TInt)y + bDiff; |
|
134 b = b<0 ? 0 : b>255 ? 0x001F : (b>>3)&0x001F; |
|
135 |
|
136 *(TUint16*)target2 = (TUint16)(r | g | b); |
|
137 target2 += 2; |
|
138 |
|
139 // Convert lower right pixel |
|
140 y = *(YPtr2)++; |
|
141 |
|
142 r = (TInt)y + rDiff; |
|
143 r = r<0 ? 0 : r>255 ? 0xF800 : (r<<8)&0xF800; |
|
144 g = (TInt)y - gDiff; |
|
145 g = g<0 ? 0 : g>255 ? 0x07E0 : (g<<3)&0x07E0; |
|
146 b = (TInt)y + bDiff; |
|
147 b = b<0 ? 0 : b>255 ? 0x001F : (b>>3)&0x001F; |
|
148 |
|
149 *(TUint16*)target2 = (TUint16)(r | g | b); |
|
150 target2 += 2; |
|
151 |
|
152 // Next two pixels |
|
153 cols -= 2; |
|
154 } |
|
155 |
|
156 // Next rows |
|
157 rows -= 2; |
|
158 aYBuf += 2*aBufWidth; |
|
159 aUBuf += aBufWidth/2; |
|
160 aVBuf += aBufWidth/2; |
|
161 aTarget += 2*aTargetScanlineLength; |
|
162 } |
|
163 } |