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