|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "common.h" |
|
20 |
|
21 #ifndef NULL |
|
22 #define NULL (void*)0 |
|
23 #endif |
|
24 |
|
25 int32 IPEmz_sYUV420toY2VY1U(tBaseVideoFrame* yuv420Frame, tBaseVideoFrame* yuv422Frame, int16 stride); |
|
26 int32 IPEmz_sYUV420toUY1VY2(tBaseVideoFrame* yuv420Frame, tBaseVideoFrame* yuv422Frame, int16 stride); |
|
27 |
|
28 /* |
|
29 ******************************************************************************* |
|
30 Name : IPEmz_gYUV420toY2VY1U |
|
31 Description : This fuction converts image from yuv420 to YUYV interleaved format |
|
32 Parameter : yuv420Frame :contains the decoded image of jpeg stream in yuv420 format |
|
33 yuyvFrame:this is user passed buffer to store the output in YUYV |
|
34 interleaved format |
|
35 Return Value : int32 |
|
36 ******************************************************************************* |
|
37 */ |
|
38 |
|
39 int32 IPEmz_sYUV420toY2VY1U(tBaseVideoFrame* yuv420Frame, tBaseVideoFrame* yuv422Frame, int16 stride) |
|
40 { |
|
41 int32 lLumWidth, lLumHeight; |
|
42 uint8 *lLumPtr1; |
|
43 uint8 *lCrPtr; |
|
44 uint8 *lCbPtr; |
|
45 int32 lY1, lCr, lCb,lTemp; |
|
46 int32 i,j; |
|
47 uint32 *lOutyuvBufferPtr; |
|
48 uint8 *pOutputLinePtr; |
|
49 |
|
50 lLumWidth = yuv420Frame->width; |
|
51 lLumHeight = yuv420Frame->height; |
|
52 |
|
53 if (stride < lLumWidth<<1) |
|
54 return E_ERROR_ARGUMENT; |
|
55 |
|
56 lLumPtr1 = yuv420Frame->lum+lLumWidth*(lLumHeight-1); |
|
57 lCbPtr = yuv420Frame->cb+(lLumWidth>>1)*((lLumHeight>>1)-1); |
|
58 lCrPtr = yuv420Frame->cr+(lLumWidth>>1)*((lLumHeight>>1)-1); |
|
59 |
|
60 lOutyuvBufferPtr = (uint32*) (yuv422Frame->lum+((lLumHeight-1)*(stride))); |
|
61 pOutputLinePtr= (uint8*)lOutyuvBufferPtr; |
|
62 |
|
63 for(i = 0; i < lLumHeight ; i ++) |
|
64 { |
|
65 j=(lLumWidth >> 1) + 1; |
|
66 while(--j) |
|
67 { |
|
68 lY1 = *lLumPtr1++; //Y1 |
|
69 lCr = *lCrPtr++; |
|
70 lTemp = *lLumPtr1++; //Y2 |
|
71 lCb = *lCbPtr++; |
|
72 |
|
73 lTemp |= (lY1 << 16); |
|
74 lCr |= (lCb<<16); //Cb and Cr are common |
|
75 *lOutyuvBufferPtr++ = (uint32)(lTemp|(lCr<<8)); |
|
76 } |
|
77 |
|
78 if(i&1) |
|
79 { |
|
80 lCbPtr -= lLumWidth; |
|
81 lCrPtr -= lLumWidth; |
|
82 } |
|
83 else |
|
84 { |
|
85 lCbPtr -= lLumWidth/2; |
|
86 lCrPtr -= lLumWidth/2; |
|
87 } |
|
88 |
|
89 lLumPtr1 -= lLumWidth*2; |
|
90 pOutputLinePtr -= stride; |
|
91 lOutyuvBufferPtr = (uint32*) pOutputLinePtr; |
|
92 } |
|
93 |
|
94 return E_SUCCESS; |
|
95 } |
|
96 |
|
97 /* |
|
98 ******************************************************************************* |
|
99 Name : IPEmz_gYUV420toUY1VY2 |
|
100 Description : This fuction converts image from yuv420 to YUYV interleaved format |
|
101 Parameter : yuv420Frame :contains the decoded image of jpeg stream in yuv420 format |
|
102 yuyvFrame:this is user passed buffer to store the output in YUYV |
|
103 interleaved format |
|
104 Return Value : int32 |
|
105 ******************************************************************************* |
|
106 */ |
|
107 #if (defined ARM_V5) || (defined ARM_V5E) || (defined __WINSCW__) |
|
108 int32 IPEmz_sYUV420toUY1VY2(tBaseVideoFrame* yuv420Frame, tBaseVideoFrame* yuv422Frame, int16 stride) |
|
109 { |
|
110 int32 lLumWidth, lLumHeight; |
|
111 uint8 *lLumPtr; |
|
112 uint8 *lCrPtr; |
|
113 uint8 *lCbPtr; |
|
114 int32 lY1, lCr, lCb,lTemp; |
|
115 int32 i,j; |
|
116 uint32 *lOutyuvBufferPtr; |
|
117 uint8 *pOutputLinePtr; |
|
118 |
|
119 lLumWidth = yuv420Frame->width; |
|
120 lLumHeight = yuv420Frame->height; |
|
121 |
|
122 if (stride < lLumWidth<<1) |
|
123 return E_ERROR_ARGUMENT; |
|
124 |
|
125 lLumPtr = yuv420Frame->lum+lLumWidth*(lLumHeight-1); |
|
126 lCbPtr = yuv420Frame->cb+(lLumWidth>>1)*((lLumHeight>>1)-1); |
|
127 lCrPtr = yuv420Frame->cr+(lLumWidth>>1)*((lLumHeight>>1)-1); |
|
128 |
|
129 lOutyuvBufferPtr = (uint32*) (yuv422Frame->lum+((lLumHeight-1)*(stride))); |
|
130 pOutputLinePtr= (uint8*)lOutyuvBufferPtr; |
|
131 |
|
132 for(i = 0; i < lLumHeight ; i ++) |
|
133 { |
|
134 j=(lLumWidth >> 1) + 1; |
|
135 |
|
136 while (--j) |
|
137 { |
|
138 lCr = *lCrPtr++; |
|
139 lTemp = *lLumPtr++; //Y1 |
|
140 lCb = *lCbPtr++; |
|
141 lY1 = *lLumPtr++; //Y2 |
|
142 |
|
143 lCb |= (lCr << 16); |
|
144 lTemp |= (lY1 << 16); |
|
145 *lOutyuvBufferPtr++ = (uint32)((lTemp << 8)|(lCb)); |
|
146 } |
|
147 |
|
148 if(i&1) |
|
149 { |
|
150 lCbPtr -= lLumWidth; |
|
151 lCrPtr -= lLumWidth; |
|
152 } |
|
153 else |
|
154 { |
|
155 lCbPtr -= lLumWidth >> 1; |
|
156 lCrPtr -= lLumWidth >> 1; |
|
157 } |
|
158 |
|
159 lLumPtr -= (lLumWidth << 1); |
|
160 pOutputLinePtr -= stride; |
|
161 lOutyuvBufferPtr = (uint32*) pOutputLinePtr; |
|
162 } |
|
163 return E_SUCCESS; |
|
164 } |
|
165 |
|
166 #else |
|
167 __asm int32 IPEmz_sYUV420toUY1VY2(tBaseVideoFrame* yuv420Frame, tBaseVideoFrame* yuv422Frame, int16 stride) |
|
168 { |
|
169 STMFD r13!,{r4-r11,lr} |
|
170 LDR r12,[r1,#0] |
|
171 LDRH r1,[r0,#0xc] |
|
172 LDR r6,[r0,#4] |
|
173 LDR r5,[r0,#8] |
|
174 LDRH r4,[r0,#0xe] |
|
175 LSR r3,r1,#1 |
|
176 LDR lr,[r0,#0] |
|
177 |
|
178 CMP r2,r3,LSL #2 |
|
179 MOVLT r0,#-16 |
|
180 STMLTFD r13!,{r4-r11,pc} |
|
181 ADD r0,r2,r2,LSR #31 |
|
182 ASR r0,r0,#1 |
|
183 SUB r2,r4,#1 |
|
184 LSL r11,r0,#2 |
|
185 MUL r0,r3,r2 |
|
186 ADD r1,r4,r4,LSR #31 |
|
187 LSL r0,r0,#1 |
|
188 ADD r0,r0,r0,LSR #31 |
|
189 BIC r0,r0,#1 |
|
190 ADD lr,r0,lr |
|
191 MVN r0,#0 |
|
192 ADD r0,r0,r1,ASR #1 |
|
193 MLA r1,r3,r0,r6 |
|
194 MLA r0,r3,r0,r5 |
|
195 ADD r5,r11,r11,LSR #31 |
|
196 ASR r5,r5,#1 |
|
197 MUL r2,r5,r2 |
|
198 ASR r5,r2,#31 |
|
199 ADD r2,r2,r5,LSR #30 |
|
200 BIC r2,r2,#3 |
|
201 ADD r12,r2,r12 |
|
202 MOV r2,#0xff00 |
|
203 ORR r10,r2,r2,LSL #16 |
|
204 MOV r5,r3 |
|
205 outer_loop |
|
206 LDRH r2,[lr],#2 |
|
207 LDRB r6,[r1],#1 |
|
208 LDRB r7,[r0],#1 |
|
209 inner_loop |
|
210 SUBS r5,r5,#1 |
|
211 PKHBT r9,r2,r2,LSL #8 |
|
212 PKHBT r8,r6,r7,LSL #16 |
|
213 AND r9,r10,r9,LSL #8 |
|
214 LDRBNE r7,[r0],#1 |
|
215 LDRBNE r6,[r1],#1 |
|
216 LDRHNE r2,[lr],#2 |
|
217 ORR r8,r9,r8 |
|
218 STR r8,[r12],#4 |
|
219 BNE inner_loop |
|
220 ANDS r2,r4,#1 |
|
221 SUBEQ r1,r1,r3 |
|
222 SUBEQ r0,r0,r3 |
|
223 SUBNE r0,r0,r3,LSL #1 |
|
224 SUBNE r1,r1,r3,LSL #1 |
|
225 SUBS r4,r4,#1 |
|
226 SUB lr,lr,r3,LSL #2 |
|
227 SUB r12,r12,r11,ASR #1 |
|
228 SUB r12,r12,r3,LSL #2 |
|
229 MOV r5,r3 |
|
230 BNE outer_loop |
|
231 MOV r0,#1 |
|
232 LDMFD r13!, {r4-r11,pc} |
|
233 |
|
234 } |
|
235 #endif |
|
236 |
|
237 /* |
|
238 ****************************************************************************** |
|
239 Name : gColorSpaceConvertYUV |
|
240 Description : Converts YUV Data to YUV 422 Interleaved format. |
|
241 Parameter : yuv420Frame - Source structure |
|
242 yuv422Frame - Pointer to yuv 422 Interleaved data. |
|
243 outClrFmt - input color format. |
|
244 Return Value : int32 |
|
245 ****************************************************************************** |
|
246 */ |
|
247 |
|
248 int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame, |
|
249 uint8 outClrFmt, int stride) |
|
250 { |
|
251 if( (NULL == yuv420Frame) || (NULL == yuv422Frame) || (NULL == yuv420Frame->lum) || |
|
252 (NULL == yuv420Frame->cb) || (NULL == yuv420Frame->cr)) |
|
253 { |
|
254 return E_OUT_OF_MEMORY; |
|
255 } |
|
256 |
|
257 switch(outClrFmt) |
|
258 { |
|
259 case(YUV422INT_LE): |
|
260 return IPEmz_sYUV420toY2VY1U(yuv420Frame, yuv422Frame, stride); |
|
261 |
|
262 case(YUV422INT_BE): |
|
263 return IPEmz_sYUV420toUY1VY2(yuv420Frame, yuv422Frame, stride); |
|
264 |
|
265 default: |
|
266 return E_ERROR_ARGUMENT; |
|
267 } |
|
268 } |
|
269 |