blob: c9ee2f6813cd1782dcc1a2e9200c588475973c38 [file] [log] [blame]
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001/*
2 * Copyright (C) 2011 NXP Software
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "VideoEditorTools.h"
19#include "PreviewRenderer.h"
20/*+ Handle the image files here */
21#include <utils/Log.h>
22/*- Handle the image files here */
23
24const M4VIFI_UInt8 M4VIFI_ClipTable[1256]
25= {
260x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
410x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
440x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
450x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
460x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
480x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
500x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
510x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
520x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
530x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
540x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
550x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
560x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
580x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
590x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
630x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
640x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
660x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
670x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
680x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
690x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
700x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
710x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
720x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
730x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
740x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
750x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
760x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
770x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
780x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
790x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
800x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
810x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
820x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
830x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
840x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
850x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
860x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
870x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
880x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
890x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
900x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
910x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
920x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
930x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
940x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
950x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
960x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
970x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
980x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
990x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,
1000x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,
1010x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
1020x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73,
1030x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,
1040x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
1050x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,
1060x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,
1070x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
1080x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3,
1090xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab,
1100xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
1110xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb,
1120xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3,
1130xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
1140xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,
1150xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb,
1160xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
1170xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
1180xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
1190xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
1200xfc, 0xfd, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
1210xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1220xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1230xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1240xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1250xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1260xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1270xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1280xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1290xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1300xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1310xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1320xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1330xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1340xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1350xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1360xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1370xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1380xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1390xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1400xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1410xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1420xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1430xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1440xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1450xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1460xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1470xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1480xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1490xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1500xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1510xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1520xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1530xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1540xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1550xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1560xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1570xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1580xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1590xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1600xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1610xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1620xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1630xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1640xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1650xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1660xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1670xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1680xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1690xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1700xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1710xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1720xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1730xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1740xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1750xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1760xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1770xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1780xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1790xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1800xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1810xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1820xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
183};
184
185/* Division table for ( 65535/x ); x = 0 to 512 */
186const M4VIFI_UInt16 M4VIFI_DivTable[512]
187= {
1880, 65535, 32768, 21845, 16384, 13107, 10922, 9362,
1898192, 7281, 6553, 5957, 5461, 5041, 4681, 4369,
1904096, 3855, 3640, 3449, 3276, 3120, 2978, 2849,
1912730, 2621, 2520, 2427, 2340, 2259, 2184, 2114,
1922048, 1985, 1927, 1872, 1820, 1771, 1724, 1680,
1931638, 1598, 1560, 1524, 1489, 1456, 1424, 1394,
1941365, 1337, 1310, 1285, 1260, 1236, 1213, 1191,
1951170, 1149, 1129, 1110, 1092, 1074, 1057, 1040,
1961024, 1008, 992, 978, 963, 949, 936, 923,
197910, 897, 885, 873, 862, 851, 840, 829,
198819, 809, 799, 789, 780, 771, 762, 753,
199744, 736, 728, 720, 712, 704, 697, 689,
200682, 675, 668, 661, 655, 648, 642, 636,
201630, 624, 618, 612, 606, 601, 595, 590,
202585, 579, 574, 569, 564, 560, 555, 550,
203546, 541, 537, 532, 528, 524, 520, 516,
204512, 508, 504, 500, 496, 492, 489, 485,
205481, 478, 474, 471, 468, 464, 461, 458,
206455, 451, 448, 445, 442, 439, 436, 434,
207431, 428, 425, 422, 420, 417, 414, 412,
208409, 407, 404, 402, 399, 397, 394, 392,
209390, 387, 385, 383, 381, 378, 376, 374,
210372, 370, 368, 366, 364, 362, 360, 358,
211356, 354, 352, 350, 348, 346, 344, 343,
212341, 339, 337, 336, 334, 332, 330, 329,
213327, 326, 324, 322, 321, 319, 318, 316,
214315, 313, 312, 310, 309, 307, 306, 304,
215303, 302, 300, 299, 297, 296, 295, 293,
216292, 291, 289, 288, 287, 286, 284, 283,
217282, 281, 280, 278, 277, 276, 275, 274,
218273, 271, 270, 269, 268, 267, 266, 265,
219264, 263, 262, 261, 260, 259, 258, 257,
220256, 255, 254, 253, 252, 251, 250, 249,
221248, 247, 246, 245, 244, 243, 242, 241,
222240, 240, 239, 238, 237, 236, 235, 234,
223234, 233, 232, 231, 230, 229, 229, 228,
224227, 226, 225, 225, 224, 223, 222, 222,
225221, 220, 219, 219, 218, 217, 217, 216,
226215, 214, 214, 213, 212, 212, 211, 210,
227210, 209, 208, 208, 207, 206, 206, 205,
228204, 204, 203, 202, 202, 201, 201, 200,
229199, 199, 198, 197, 197, 196, 196, 195,
230195, 194, 193, 193, 192, 192, 191, 191,
231190, 189, 189, 188, 188, 187, 187, 186,
232186, 185, 185, 184, 184, 183, 183, 182,
233182, 181, 181, 180, 180, 179, 179, 178,
234178, 177, 177, 176, 176, 175, 175, 174,
235174, 173, 173, 172, 172, 172, 171, 171,
236170, 170, 169, 169, 168, 168, 168, 167,
237167, 166, 166, 165, 165, 165, 164, 164,
238163, 163, 163, 162, 162, 161, 161, 161,
239160, 160, 159, 159, 159, 158, 158, 157,
240157, 157, 156, 156, 156, 155, 155, 154,
241154, 154, 153, 153, 153, 152, 152, 152,
242151, 151, 151, 150, 150, 149, 149, 149,
243148, 148, 148, 147, 147, 147, 146, 146,
244146, 145, 145, 145, 144, 144, 144, 144,
245143, 143, 143, 142, 142, 142, 141, 141,
246141, 140, 140, 140, 140, 139, 139, 139,
247138, 138, 138, 137, 137, 137, 137, 136,
248136, 136, 135, 135, 135, 135, 134, 134,
249134, 134, 133, 133, 133, 132, 132, 132,
250132, 131, 131, 131, 131, 130, 130, 130,
251130, 129, 129, 129, 129, 128, 128, 128
252};
253
254const M4VIFI_Int32 const_storage1[8]
255= {
2560x00002568, 0x00003343,0x00000649,0x00000d0f, 0x0000D86C, 0x0000D83B, 0x00010000, 0x00010000
257};
258
259const M4VIFI_Int32 const_storage[8]
260= {
2610x00002568, 0x00003343, 0x1BF800, 0x00000649, 0x00000d0f, 0x110180, 0x40cf, 0x22BE00
262};
263
264
265const M4VIFI_UInt16 *M4VIFI_DivTable_zero
266 = &M4VIFI_DivTable[0];
267
268const M4VIFI_UInt8 *M4VIFI_ClipTable_zero
269 = &M4VIFI_ClipTable[500];
270
271M4VIFI_UInt8 M4VIFI_YUV420PlanarToYUV420Semiplanar(void *user_data,
272 M4VIFI_ImagePlane *PlaneIn, M4VIFI_ImagePlane *PlaneOut ) {
273
274 M4VIFI_UInt32 i;
275 M4VIFI_UInt8 *p_buf_src, *p_buf_dest, *p_buf_src_u, *p_buf_src_v;
276 M4VIFI_UInt8 return_code = M4VIFI_OK;
277
278 /* the filter is implemented with the assumption that the width is equal to stride */
279 if(PlaneIn[0].u_width != PlaneIn[0].u_stride)
280 return M4VIFI_INVALID_PARAM;
281
282 /* The input Y Plane is the same as the output Y Plane */
283 p_buf_src = &(PlaneIn[0].pac_data[PlaneIn[0].u_topleft]);
284 p_buf_dest = &(PlaneOut[0].pac_data[PlaneOut[0].u_topleft]);
285 M4OSA_memcpy((M4OSA_Int8*)p_buf_dest,(M4OSA_Int8*)p_buf_src ,
286 PlaneOut[0].u_width * PlaneOut[0].u_height);
287
288 /* The U and V components are planar. The need to be made interleaved */
289 p_buf_src_u = &(PlaneIn[1].pac_data[PlaneIn[1].u_topleft]);
290 p_buf_src_v = &(PlaneIn[2].pac_data[PlaneIn[2].u_topleft]);
291 p_buf_dest = &(PlaneOut[1].pac_data[PlaneOut[1].u_topleft]);
292
293 for(i = 0; i < PlaneOut[1].u_width*PlaneOut[1].u_height; i++)
294 {
295 *p_buf_dest++ = *p_buf_src_u++;
296 *p_buf_dest++ = *p_buf_src_v++;
297 }
298 return return_code;
299}
300
301M4VIFI_UInt8 M4VIFI_SemiplanarYUV420toYUV420(void *user_data,
302 M4VIFI_ImagePlane *PlaneIn, M4VIFI_ImagePlane *PlaneOut ) {
303
304 M4VIFI_UInt32 i;
305 M4VIFI_UInt8 *p_buf_src, *p_buf_dest, *p_buf_src_u, *p_buf_src_v;
306 M4VIFI_UInt8 *p_buf_dest_u,*p_buf_dest_v,*p_buf_src_uv;
307 M4VIFI_UInt8 return_code = M4VIFI_OK;
308
309 /* the filter is implemented with the assumption that the width is equal to stride */
310 if(PlaneIn[0].u_width != PlaneIn[0].u_stride)
311 return M4VIFI_INVALID_PARAM;
312
313 /* The input Y Plane is the same as the output Y Plane */
314 p_buf_src = &(PlaneIn[0].pac_data[PlaneIn[0].u_topleft]);
315 p_buf_dest = &(PlaneOut[0].pac_data[PlaneOut[0].u_topleft]);
316 M4OSA_memcpy((M4OSA_Int8*)p_buf_dest,(M4OSA_Int8*)p_buf_src ,
317 PlaneOut[0].u_width * PlaneOut[0].u_height);
318
319 /* The U and V components are planar. The need to be made interleaved */
320 p_buf_src_uv = &(PlaneIn[1].pac_data[PlaneIn[1].u_topleft]);
321 p_buf_dest_u = &(PlaneOut[1].pac_data[PlaneOut[1].u_topleft]);
322 p_buf_dest_v = &(PlaneOut[2].pac_data[PlaneOut[2].u_topleft]);
323
324 for(i = 0; i < PlaneOut[1].u_width*PlaneOut[1].u_height; i++)
325 {
326 *p_buf_dest_u++ = *p_buf_src_uv++;
327 *p_buf_dest_v++ = *p_buf_src_uv++;
328 }
329 return return_code;
330}
331
332
333/**
334 ******************************************************************************
335 * prototype M4VSS3GPP_externalVideoEffectColor(M4OSA_Void *pFunctionContext,
336 * M4VIFI_ImagePlane *PlaneIn,
337 * M4VIFI_ImagePlane *PlaneOut,
338 * M4VSS3GPP_ExternalProgress *pProgress,
339 * M4OSA_UInt32 uiEffectKind)
340 *
341 * @brief This function apply a color effect on an input YUV420 planar frame
342 * @note
343 * @param pFunctionContext(IN) Contains which color to apply (not very clean ...)
344 * @param PlaneIn (IN) Input YUV420 planar
345 * @param PlaneOut (IN/OUT) Output YUV420 planar
346 * @param pProgress (IN/OUT) Progress indication (0-100)
347 * @param uiEffectKind (IN) Unused
348 *
349 * @return M4VIFI_OK: No error
350 ******************************************************************************
351*/
352M4OSA_ERR M4VSS3GPP_externalVideoEffectColor(M4OSA_Void *pFunctionContext,
353 M4VIFI_ImagePlane *PlaneIn, M4VIFI_ImagePlane *PlaneOut,
354 M4VSS3GPP_ExternalProgress *pProgress, M4OSA_UInt32 uiEffectKind) {
355
356 M4VIFI_Int32 plane_number;
357 M4VIFI_UInt32 i,j;
358 M4VIFI_UInt8 *p_buf_src, *p_buf_dest;
359 M4xVSS_ColorStruct* ColorContext = (M4xVSS_ColorStruct*)pFunctionContext;
360
361 for (plane_number = 0; plane_number < 3; plane_number++)
362 {
363 p_buf_src =
364 &(PlaneIn[plane_number].pac_data[PlaneIn[plane_number].u_topleft]);
365
366 p_buf_dest =
367 &(PlaneOut[plane_number].pac_data[PlaneOut[plane_number].u_topleft]);
368 for (i = 0; i < PlaneOut[plane_number].u_height; i++)
369 {
370 /**
371 * Chrominance */
372 if(plane_number==1 || plane_number==2)
373 {
374 //switch ((M4OSA_UInt32)pFunctionContext) // commented because a structure for the effects context exist
375 switch (ColorContext->colorEffectType)
376 {
377 case M4xVSS_kVideoEffectType_BlackAndWhite:
378 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
379 PlaneIn[plane_number].u_width, 128);
380 break;
381 case M4xVSS_kVideoEffectType_Pink:
382 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
383 PlaneIn[plane_number].u_width, 255);
384 break;
385 case M4xVSS_kVideoEffectType_Green:
386 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
387 PlaneIn[plane_number].u_width, 0);
388 break;
389 case M4xVSS_kVideoEffectType_Sepia:
390 if(plane_number==1)
391 {
392 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
393 PlaneIn[plane_number].u_width, 117);
394 }
395 else
396 {
397 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
398 PlaneIn[plane_number].u_width, 139);
399 }
400 break;
401 case M4xVSS_kVideoEffectType_Negative:
402 M4OSA_memcpy((M4OSA_MemAddr8)p_buf_dest,
403 (M4OSA_MemAddr8)p_buf_src ,PlaneOut[plane_number].u_width);
404 break;
405
406 case M4xVSS_kVideoEffectType_ColorRGB16:
407 {
408 M4OSA_UInt16 r = 0,g = 0,b = 0,y = 0,u = 0,v = 0;
409
410 /*first get the r, g, b*/
411 b = (ColorContext->rgb16ColorData & 0x001f);
412 g = (ColorContext->rgb16ColorData & 0x07e0)>>5;
413 r = (ColorContext->rgb16ColorData & 0xf800)>>11;
414
415 /*keep y, but replace u and v*/
416 if(plane_number==1)
417 {
418 /*then convert to u*/
419 u = U16(r, g, b);
420 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
421 PlaneIn[plane_number].u_width, (M4OSA_UInt8)u);
422 }
423 if(plane_number==2)
424 {
425 /*then convert to v*/
426 v = V16(r, g, b);
427 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
428 PlaneIn[plane_number].u_width, (M4OSA_UInt8)v);
429 }
430 }
431 break;
432 case M4xVSS_kVideoEffectType_Gradient:
433 {
434 M4OSA_UInt16 r = 0,g = 0,b = 0,y = 0,u = 0,v = 0;
435
436 /*first get the r, g, b*/
437 b = (ColorContext->rgb16ColorData & 0x001f);
438 g = (ColorContext->rgb16ColorData & 0x07e0)>>5;
439 r = (ColorContext->rgb16ColorData & 0xf800)>>11;
440
441 /*for color gradation*/
442 b = (M4OSA_UInt16)( b - ((b*i)/PlaneIn[plane_number].u_height));
443 g = (M4OSA_UInt16)(g - ((g*i)/PlaneIn[plane_number].u_height));
444 r = (M4OSA_UInt16)(r - ((r*i)/PlaneIn[plane_number].u_height));
445
446 /*keep y, but replace u and v*/
447 if(plane_number==1)
448 {
449 /*then convert to u*/
450 u = U16(r, g, b);
451 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
452 PlaneIn[plane_number].u_width, (M4OSA_UInt8)u);
453 }
454 if(plane_number==2)
455 {
456 /*then convert to v*/
457 v = V16(r, g, b);
458 M4OSA_memset((M4OSA_MemAddr8)p_buf_dest,
459 PlaneIn[plane_number].u_width, (M4OSA_UInt8)v);
460 }
461 }
462 break;
463 }
464 }
465 /**
466 * Luminance */
467 else
468 {
469 //switch ((M4OSA_UInt32)pFunctionContext)// commented because a structure for the effects context exist
470 switch (ColorContext->colorEffectType)
471 {
472 case M4xVSS_kVideoEffectType_Negative:
473 for(j=0;j<PlaneOut[plane_number].u_width;j++)
474 {
475 p_buf_dest[j] = 255 - p_buf_src[j];
476 }
477 break;
478 default:
479 M4OSA_memcpy((M4OSA_MemAddr8)p_buf_dest,
480 (M4OSA_MemAddr8)p_buf_src ,PlaneOut[plane_number].u_width);
481 break;
482 }
483 }
484 p_buf_src += PlaneIn[plane_number].u_stride;
485 p_buf_dest += PlaneOut[plane_number].u_stride;
486 }
487 }
488
489 return M4VIFI_OK;
490}
491
492/**
493 ******************************************************************************
494 * prototype M4VSS3GPP_externalVideoEffectFraming(M4OSA_Void *pFunctionContext,
495 * M4VIFI_ImagePlane *PlaneIn,
496 * M4VIFI_ImagePlane *PlaneOut,
497 * M4VSS3GPP_ExternalProgress *pProgress,
498 * M4OSA_UInt32 uiEffectKind)
499 *
500 * @brief This function add a fixed or animated image on an input YUV420 planar frame
501 * @note
502 * @param pFunctionContext(IN) Contains which color to apply (not very clean ...)
503 * @param PlaneIn (IN) Input YUV420 planar
504 * @param PlaneOut (IN/OUT) Output YUV420 planar
505 * @param pProgress (IN/OUT) Progress indication (0-100)
506 * @param uiEffectKind (IN) Unused
507 *
508 * @return M4VIFI_OK: No error
509 ******************************************************************************
510*/
511M4OSA_ERR M4VSS3GPP_externalVideoEffectFraming(
512 M4OSA_Void *userData, M4VIFI_ImagePlane PlaneIn[3],
513 M4VIFI_ImagePlane *PlaneOut, M4VSS3GPP_ExternalProgress *pProgress,
514 M4OSA_UInt32 uiEffectKind ) {
515
516 M4VIFI_UInt32 x,y;
517
518 M4VIFI_UInt8 *p_in_Y = PlaneIn[0].pac_data;
519 M4VIFI_UInt8 *p_in_U = PlaneIn[1].pac_data;
520 M4VIFI_UInt8 *p_in_V = PlaneIn[2].pac_data;
521
522 M4xVSS_FramingStruct* Framing = M4OSA_NULL;
523 M4xVSS_FramingStruct* currentFraming = M4OSA_NULL;
524 M4VIFI_UInt8 *FramingRGB = M4OSA_NULL;
525
526 M4VIFI_UInt8 *p_out0;
527 M4VIFI_UInt8 *p_out1;
528 M4VIFI_UInt8 *p_out2;
529
530 M4VIFI_UInt32 topleft[2];
531
532 M4OSA_UInt8 transparent1 =
533 (M4OSA_UInt8)((TRANSPARENT_COLOR & 0xFF00)>>8);
534 M4OSA_UInt8 transparent2 = (M4OSA_UInt8)TRANSPARENT_COLOR;
535
536#ifndef DECODE_GIF_ON_SAVING
537 Framing = (M4xVSS_FramingStruct *)userData;
538 currentFraming = (M4xVSS_FramingStruct *)Framing->pCurrent;
539 FramingRGB = Framing->FramingRgb->pac_data;
540#endif /*DECODE_GIF_ON_SAVING*/
541
542#ifdef DECODE_GIF_ON_SAVING
543 M4OSA_ERR err;
544 Framing =
545 (M4xVSS_FramingStruct *)((M4xVSS_FramingContext*)userData)->aFramingCtx;
546 if(Framing == M4OSA_NULL)
547 {
548 ((M4xVSS_FramingContext*)userData)->clipTime = pProgress->uiOutputTime;
549 err = M4xVSS_internalDecodeGIF(userData);
550 if(M4NO_ERROR != err)
551 {
552 M4OSA_TRACE1_1("M4VSS3GPP_externalVideoEffectFraming: \
553 Error in M4xVSS_internalDecodeGIF: 0x%x", err);
554 return err;
555 }
556 Framing =
557 (M4xVSS_FramingStruct *)((M4xVSS_FramingContext*)userData)->aFramingCtx;
558 /* Initializes first GIF time */
559 ((M4xVSS_FramingContext*)userData)->current_gif_time =
560 pProgress->uiOutputTime;
561 }
562 currentFraming = (M4xVSS_FramingStruct *)Framing;
563 FramingRGB = Framing->FramingRgb->pac_data;
564#endif /*DECODE_GIF_ON_SAVING*/
565
566 /**
567 * Initialize input / output plane pointers */
568 p_in_Y += PlaneIn[0].u_topleft;
569 p_in_U += PlaneIn[1].u_topleft;
570 p_in_V += PlaneIn[2].u_topleft;
571
572 p_out0 = PlaneOut[0].pac_data;
573 p_out1 = PlaneOut[1].pac_data;
574 p_out2 = PlaneOut[2].pac_data;
575
576 /**
577 * Depending on time, initialize Framing frame to use */
578 if(Framing->previousClipTime == -1)
579 {
580 Framing->previousClipTime = pProgress->uiOutputTime;
581 }
582
583 /**
584 * If the current clip time has reach the duration of one frame of the framing picture
585 * we need to step to next framing picture */
586#ifdef DECODE_GIF_ON_SAVING
587 if(((M4xVSS_FramingContext*)userData)->b_animated == M4OSA_TRUE)
588 {
589 while((((M4xVSS_FramingContext*)userData)->current_gif_time + currentFraming->duration) < pProgress->uiOutputTime)
590 {
591 ((M4xVSS_FramingContext*)userData)->clipTime =
592 pProgress->uiOutputTime;
593
594 err = M4xVSS_internalDecodeGIF(userData);
595 if(M4NO_ERROR != err)
596 {
597 M4OSA_TRACE1_1("M4VSS3GPP_externalVideoEffectFraming: Error in M4xVSS_internalDecodeGIF: 0x%x", err);
598 return err;
599 }
600 if(currentFraming->duration != 0)
601 {
602 ((M4xVSS_FramingContext*)userData)->current_gif_time += currentFraming->duration;
603 }
604 else
605 {
606 ((M4xVSS_FramingContext*)userData)->current_gif_time +=
607 pProgress->uiOutputTime - Framing->previousClipTime;
608 }
609 Framing = (M4xVSS_FramingStruct *)((M4xVSS_FramingContext*)userData)->aFramingCtx;
610 currentFraming = (M4xVSS_FramingStruct *)Framing;
611 FramingRGB = Framing->FramingRgb->pac_data;
612 }
613 }
614#else
615 Framing->pCurrent = currentFraming->pNext;
616 currentFraming = (M4xVSS_FramingStruct*)Framing->pCurrent;
617#endif /*DECODE_GIF_ON_SAVING*/
618
619 Framing->previousClipTime = pProgress->uiOutputTime;
620 FramingRGB = currentFraming->FramingRgb->pac_data;
621 topleft[0] = currentFraming->topleft_x;
622 topleft[1] = currentFraming->topleft_y;
623
624 for( x=0 ;x < PlaneIn[0].u_height ; x++)
625 {
626 for( y=0 ;y < PlaneIn[0].u_width ; y++)
627 {
628 /**
629 * To handle framing with input size != output size
630 * Framing is applyed if coordinates matches between framing/topleft and input plane */
631 if( y < (topleft[0] + currentFraming->FramingYuv[0].u_width) &&
632 y >= topleft[0] &&
633 x < (topleft[1] + currentFraming->FramingYuv[0].u_height) &&
634 x >= topleft[1])
635 {
636
637 /*Alpha blending support*/
638 M4OSA_Float alphaBlending = 1;
639#ifdef DECODE_GIF_ON_SAVING
640 M4xVSS_internalEffectsAlphaBlending* alphaBlendingStruct =
641 (M4xVSS_internalEffectsAlphaBlending*)((M4xVSS_FramingContext*)userData)->alphaBlendingStruct;
642#else
643 M4xVSS_internalEffectsAlphaBlending* alphaBlendingStruct =
644 (M4xVSS_internalEffectsAlphaBlending*)((M4xVSS_FramingStruct*)userData)->alphaBlendingStruct;
645#endif //#ifdef DECODE_GIF_ON_SAVING
646
647 if(alphaBlendingStruct != M4OSA_NULL)
648 {
649 if(pProgress->uiProgress >= 0 && pProgress->uiProgress < (M4OSA_UInt32)(alphaBlendingStruct->m_fadeInTime*10))
650 {
651 alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle - alphaBlendingStruct->m_start)*pProgress->uiProgress/(alphaBlendingStruct->m_fadeInTime*10));
652 alphaBlending += alphaBlendingStruct->m_start;
653 alphaBlending /= 100;
654 }
655 else if(pProgress->uiProgress >= (M4OSA_UInt32)(alphaBlendingStruct->m_fadeInTime*10) && pProgress->uiProgress < 1000 - (M4OSA_UInt32)(alphaBlendingStruct->m_fadeOutTime*10))
656 {
657 alphaBlending = (M4OSA_Float)((M4OSA_Float)alphaBlendingStruct->m_middle/100);
658 }
659 else if(pProgress->uiProgress >= 1000 - (M4OSA_UInt32)(alphaBlendingStruct->m_fadeOutTime*10))
660 {
661 alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle - alphaBlendingStruct->m_end))*(1000 - pProgress->uiProgress)/(alphaBlendingStruct->m_fadeOutTime*10);
662 alphaBlending += alphaBlendingStruct->m_end;
663 alphaBlending /= 100;
664 }
665 }
666
667 /**/
668
669 if((*(FramingRGB)==transparent1) && (*(FramingRGB+1)==transparent2))
670 {
671 *( p_out0+y+x*PlaneOut[0].u_stride)=(*(p_in_Y+y+x*PlaneIn[0].u_stride));
672 *( p_out1+(y>>1)+(x>>1)*PlaneOut[1].u_stride)=(*(p_in_U+(y>>1)+(x>>1)*PlaneIn[1].u_stride));
673 *( p_out2+(y>>1)+(x>>1)*PlaneOut[2].u_stride)=(*(p_in_V+(y>>1)+(x>>1)*PlaneIn[2].u_stride));
674 }
675 else
676 {
677 *( p_out0+y+x*PlaneOut[0].u_stride)=(*(currentFraming->FramingYuv[0].pac_data+(y-topleft[0])+(x-topleft[1])*currentFraming->FramingYuv[0].u_stride))*alphaBlending;
678 *( p_out0+y+x*PlaneOut[0].u_stride)+=(*(p_in_Y+y+x*PlaneIn[0].u_stride))*(1-alphaBlending);
679 *( p_out1+(y>>1)+(x>>1)*PlaneOut[1].u_stride)=(*(currentFraming->FramingYuv[1].pac_data+((y-topleft[0])>>1)+((x-topleft[1])>>1)*currentFraming->FramingYuv[1].u_stride))*alphaBlending;
680 *( p_out1+(y>>1)+(x>>1)*PlaneOut[1].u_stride)+=(*(p_in_U+(y>>1)+(x>>1)*PlaneIn[1].u_stride))*(1-alphaBlending);
681 *( p_out2+(y>>1)+(x>>1)*PlaneOut[2].u_stride)=(*(currentFraming->FramingYuv[2].pac_data+((y-topleft[0])>>1)+((x-topleft[1])>>1)*currentFraming->FramingYuv[2].u_stride))*alphaBlending;
682 *( p_out2+(y>>1)+(x>>1)*PlaneOut[2].u_stride)+=(*(p_in_V+(y>>1)+(x>>1)*PlaneIn[2].u_stride))*(1-alphaBlending);
683 }
684 if( PlaneIn[0].u_width < (topleft[0] + currentFraming->FramingYuv[0].u_width) &&
685 y == PlaneIn[0].u_width-1)
686 {
687 FramingRGB = FramingRGB + 2 * (topleft[0] + currentFraming->FramingYuv[0].u_width - PlaneIn[0].u_width + 1);
688 }
689 else
690 {
691 FramingRGB = FramingRGB + 2;
692 }
693 }
694 /**
695 * Just copy input plane to output plane */
696 else
697 {
698 *( p_out0+y+x*PlaneOut[0].u_stride)=*(p_in_Y+y+x*PlaneIn[0].u_stride);
699 *( p_out1+(y>>1)+(x>>1)*PlaneOut[1].u_stride)=*(p_in_U+(y>>1)+(x>>1)*PlaneIn[1].u_stride);
700 *( p_out2+(y>>1)+(x>>1)*PlaneOut[2].u_stride)=*(p_in_V+(y>>1)+(x>>1)*PlaneIn[2].u_stride);
701 }
702 }
703 }
704
705#ifdef DECODE_GIF_ON_SAVING
706 if(pProgress->bIsLast == M4OSA_TRUE
707 && (M4OSA_Bool)((M4xVSS_FramingContext*)userData)->b_IsFileGif == M4OSA_TRUE)
708 {
709 M4xVSS_internalDecodeGIF_Cleaning((M4xVSS_FramingContext*)userData);
710 }
711#endif /*DECODE_GIF_ON_SAVING*/
712 return M4VIFI_OK;
713}
714
715
716/**
717 ******************************************************************************
718 * prototype M4VSS3GPP_externalVideoEffectFifties(M4OSA_Void *pFunctionContext,
719 * M4VIFI_ImagePlane *PlaneIn,
720 * M4VIFI_ImagePlane *PlaneOut,
721 * M4VSS3GPP_ExternalProgress *pProgress,
722 * M4OSA_UInt32 uiEffectKind)
723 *
724 * @brief This function make a video look as if it was taken in the fifties
725 * @note
726 * @param pUserData (IN) Context
727 * @param pPlaneIn (IN) Input YUV420 planar
728 * @param pPlaneOut (IN/OUT) Output YUV420 planar
729 * @param pProgress (IN/OUT) Progress indication (0-100)
730 * @param uiEffectKind (IN) Unused
731 *
732 * @return M4VIFI_OK: No error
733 * @return M4ERR_PARAMETER: pFiftiesData, pPlaneOut or pProgress are NULL (DEBUG only)
734 ******************************************************************************
735*/
736M4OSA_ERR M4VSS3GPP_externalVideoEffectFifties(
737 M4OSA_Void *pUserData, M4VIFI_ImagePlane *pPlaneIn,
738 M4VIFI_ImagePlane *pPlaneOut, M4VSS3GPP_ExternalProgress *pProgress,
739 M4OSA_UInt32 uiEffectKind )
740{
741 M4VIFI_UInt32 x, y, xShift;
742 M4VIFI_UInt8 *pInY = pPlaneIn[0].pac_data;
743 M4VIFI_UInt8 *pOutY, *pInYbegin;
744 M4VIFI_UInt8 *pInCr,* pOutCr;
745 M4VIFI_Int32 plane_number;
746
747 /* Internal context*/
748 M4xVSS_FiftiesStruct* p_FiftiesData = (M4xVSS_FiftiesStruct *)pUserData;
749
750 /* Initialize input / output plane pointers */
751 pInY += pPlaneIn[0].u_topleft;
752 pOutY = pPlaneOut[0].pac_data;
753 pInYbegin = pInY;
754
755 /* Initialize the random */
756 if(p_FiftiesData->previousClipTime < 0)
757 {
758 M4OSA_randInit();
759 M4OSA_rand((M4OSA_Int32*)&(p_FiftiesData->shiftRandomValue), (pPlaneIn[0].u_height) >> 4);
760 M4OSA_rand((M4OSA_Int32*)&(p_FiftiesData->stripeRandomValue), (pPlaneIn[0].u_width)<< 2);
761 p_FiftiesData->previousClipTime = pProgress->uiOutputTime;
762 }
763
764 /* Choose random values if we have reached the duration of a partial effect */
765 else if( (pProgress->uiOutputTime - p_FiftiesData->previousClipTime) > p_FiftiesData->fiftiesEffectDuration)
766 {
767 M4OSA_rand((M4OSA_Int32*)&(p_FiftiesData->shiftRandomValue), (pPlaneIn[0].u_height) >> 4);
768 M4OSA_rand((M4OSA_Int32*)&(p_FiftiesData->stripeRandomValue), (pPlaneIn[0].u_width)<< 2);
769 p_FiftiesData->previousClipTime = pProgress->uiOutputTime;
770 }
771
772 /* Put in Sepia the chrominance */
773 for (plane_number = 1; plane_number < 3; plane_number++)
774 {
775 pInCr = pPlaneIn[plane_number].pac_data + pPlaneIn[plane_number].u_topleft;
776 pOutCr = pPlaneOut[plane_number].pac_data + pPlaneOut[plane_number].u_topleft;
777
778 for (x = 0; x < pPlaneOut[plane_number].u_height; x++)
779 {
780 if (1 == plane_number)
781 M4OSA_memset((M4OSA_MemAddr8)pOutCr, pPlaneIn[plane_number].u_width, 117); /* U value */
782 else
783 M4OSA_memset((M4OSA_MemAddr8)pOutCr, pPlaneIn[plane_number].u_width, 139); /* V value */
784
785 pInCr += pPlaneIn[plane_number].u_stride;
786 pOutCr += pPlaneOut[plane_number].u_stride;
787 }
788 }
789
790 /* Compute the new pixels values */
791 for( x = 0 ; x < pPlaneIn[0].u_height ; x++)
792 {
793 M4VIFI_UInt8 *p_outYtmp, *p_inYtmp;
794
795 /* Compute the xShift (random value) */
796 if (0 == (p_FiftiesData->shiftRandomValue % 5 ))
797 xShift = (x + p_FiftiesData->shiftRandomValue ) % (pPlaneIn[0].u_height - 1);
798 else
799 xShift = (x + (pPlaneIn[0].u_height - p_FiftiesData->shiftRandomValue) ) % (pPlaneIn[0].u_height - 1);
800
801 /* Initialize the pointers */
802 p_outYtmp = pOutY + 1; /* yShift of 1 pixel */
803 p_inYtmp = pInYbegin + (xShift * pPlaneIn[0].u_stride); /* Apply the xShift */
804
805 for( y = 0 ; y < pPlaneIn[0].u_width ; y++)
806 {
807 /* Set Y value */
808 if (xShift > (pPlaneIn[0].u_height - 4))
809 *p_outYtmp = 40; /* Add some horizontal black lines between the two parts of the image */
810 else if ( y == p_FiftiesData->stripeRandomValue)
811 *p_outYtmp = 90; /* Add a random vertical line for the bulk */
812 else
813 *p_outYtmp = *p_inYtmp;
814
815
816 /* Go to the next pixel */
817 p_outYtmp++;
818 p_inYtmp++;
819
820 /* Restart at the beginning of the line for the last pixel*/
821 if (y == (pPlaneIn[0].u_width - 2))
822 p_outYtmp = pOutY;
823 }
824
825 /* Go to the next line */
826 pOutY += pPlaneOut[0].u_stride;
827 }
828
829 return M4VIFI_OK;
830}
831
832unsigned char M4VFL_modifyLumaWithScale(M4ViComImagePlane *plane_in,
833 M4ViComImagePlane *plane_out,
834 unsigned long lum_factor,
835 void *user_data)
836{
837 unsigned short *p_src, *p_dest, *p_src_line, *p_dest_line;
838 unsigned char *p_csrc, *p_cdest, *p_csrc_line, *p_cdest_line;
839 unsigned long pix_src;
840 unsigned long u_outpx, u_outpx2;
841 unsigned long u_width, u_stride, u_stride_out,u_height, pix;
842 long i, j;
843
844 /* copy or filter chroma */
845 u_width = plane_in[1].u_width;
846 u_height = plane_in[1].u_height;
847 u_stride = plane_in[1].u_stride;
848 u_stride_out = plane_out[1].u_stride;
849 p_cdest_line = (unsigned char *) &plane_out[1].pac_data[plane_out[1].u_topleft];
850 p_csrc_line = (unsigned char *) &plane_in[1].pac_data[plane_in[1].u_topleft];
851
852 if (lum_factor > 256)
853 {
854 p_cdest = (unsigned char *) &plane_out[2].pac_data[plane_out[2].u_topleft];
855 p_csrc = (unsigned char *) &plane_in[2].pac_data[plane_in[2].u_topleft];
856 /* copy chroma */
857 for (j = u_height; j != 0; j--)
858 {
859 for (i = u_width; i != 0; i--)
860 {
861 M4OSA_memcpy((M4OSA_MemAddr8)p_cdest_line, (M4OSA_MemAddr8)p_csrc_line, u_width);
862 M4OSA_memcpy((M4OSA_MemAddr8)p_cdest, (M4OSA_MemAddr8)p_csrc, u_width);
863 }
864 p_cdest_line += u_stride_out;
865 p_cdest += u_stride_out;
866 p_csrc_line += u_stride;
867 p_csrc += u_stride;
868 }
869 }
870 else
871 {
872 /* filter chroma */
873 pix = (1024 - lum_factor) << 7;
874 for (j = u_height; j != 0; j--)
875 {
876 p_cdest = p_cdest_line;
877 p_csrc = p_csrc_line;
878 for (i = u_width; i != 0; i--)
879 {
880 *p_cdest++ = ((pix + (*p_csrc++ & 0xFF) * lum_factor) >> LUM_FACTOR_MAX);
881 }
882 p_cdest_line += u_stride_out;
883 p_csrc_line += u_stride;
884 }
885 p_cdest_line = (unsigned char *) &plane_out[2].pac_data[plane_out[2].u_topleft];
886 p_csrc_line = (unsigned char *) &plane_in[2].pac_data[plane_in[2].u_topleft];
887 for (j = u_height; j != 0; j--)
888 {
889 p_cdest = p_cdest_line;
890 p_csrc = p_csrc_line;
891 for (i = u_width; i != 0; i--)
892 {
893 *p_cdest++ = ((pix + (*p_csrc & 0xFF) * lum_factor) >> LUM_FACTOR_MAX);
894 }
895 p_cdest_line += u_stride_out;
896 p_csrc_line += u_stride;
897 }
898 }
899 /* apply luma factor */
900 u_width = plane_in[0].u_width;
901 u_height = plane_in[0].u_height;
902 u_stride = (plane_in[0].u_stride >> 1);
903 u_stride_out = (plane_out[0].u_stride >> 1);
904 p_dest = (unsigned short *) &plane_out[0].pac_data[plane_out[0].u_topleft];
905 p_src = (unsigned short *) &plane_in[0].pac_data[plane_in[0].u_topleft];
906 p_dest_line = p_dest;
907 p_src_line = p_src;
908
909 for (j = u_height; j != 0; j--)
910 {
911 p_dest = p_dest_line;
912 p_src = p_src_line;
913 for (i = (u_width >> 1); i != 0; i--)
914 {
915 pix_src = (unsigned long) *p_src++;
916 pix = pix_src & 0xFF;
917 u_outpx = ((pix * lum_factor) >> LUM_FACTOR_MAX);
918 pix = ((pix_src & 0xFF00) >> 8);
919 u_outpx2 = (((pix * lum_factor) >> LUM_FACTOR_MAX)<< 8) ;
920 *p_dest++ = (unsigned short) (u_outpx2 | u_outpx);
921 }
922 p_dest_line += u_stride_out;
923 p_src_line += u_stride;
924 }
925
926 return 0;
927}
928
929/**
930 ******************************************************************************
931 * unsigned char M4VFL_applyCurtain(M4ViComImagePlane *plane_in, M4ViComImagePlane *plane_out, M4VFL_CurtainParam *curtain_factor, void *user_data)
932 * @author Beatrice Nezot (PHILIPS Software Vision)
933 * @brief This function applies a black curtain onto a YUV420 image.
934 * @note THis function writes black lines either at the top of the image or at
935 * the bottom of the image. The other lines are copied from the source image.
936 * First the number of black lines is compted and is rounded to an even integer.
937 * @param plane_in: (IN) pointer to the 3 image planes of the source image
938 * @param plane_out: (OUT) pointer to the 3 image planes of the destination image
939 * @param user_data: (IN) pointer to some user_data
940 * @param curtain_factor: (IN) structure with the parameters of the curtain (nb of black lines and if at the top/bottom of the image)
941 * @return 0: there is no error
942 ******************************************************************************
943*/
944unsigned char M4VFL_applyCurtain(M4ViComImagePlane *plane_in, M4ViComImagePlane *plane_out, M4VFL_CurtainParam *curtain_factor, void *user_data)
945{
946 unsigned char *p_src, *p_srcu, *p_srcv,*p_dest, *p_destu, *p_destv;
947 unsigned long u_width, u_widthuv, u_stride_out, u_stride_out_uv,u_stride, u_stride_uv,u_height;
948 long j;
949 unsigned long nb_black_lines;
950
951 u_width = plane_in[0].u_width;
952 u_height = plane_in[0].u_height;
953 u_stride_out = plane_out[0].u_stride ;
954 u_stride_out_uv = plane_out[1].u_stride;
955 p_dest = (unsigned char *) &plane_out[0].pac_data[plane_out[0].u_topleft];
956 p_destu = (unsigned char *) &plane_out[1].pac_data[plane_out[1].u_topleft];
957 p_destv = (unsigned char *) &plane_out[2].pac_data[plane_out[2].u_topleft];
958 u_widthuv = u_width >> 1;
959 u_stride = plane_in[0].u_stride ;
960 u_stride_uv = plane_in[1].u_stride;
961
962 /* nb_black_lines is even */
963 nb_black_lines = (unsigned long) ((curtain_factor->nb_black_lines >> 1) << 1);
964
965 if (curtain_factor->top_is_black)
966 {
967 /* black lines first */
968 /* compute index of of first source pixels (Y, U and V) to copy after the black lines */
969 p_src = (unsigned char *) &plane_in[0].pac_data[plane_in[0].u_topleft + ((nb_black_lines) * plane_in[0].u_stride)];
970 p_srcu = (unsigned char *) &plane_in[1].pac_data[plane_in[1].u_topleft + (((nb_black_lines) * plane_in[1].u_stride) >> 1)];
971 p_srcv = (unsigned char *) &plane_in[2].pac_data[plane_in[2].u_topleft+ (((nb_black_lines) * plane_in[2].u_stride) >> 1)];
972
973 /* write black lines */
974 for (j = (nb_black_lines >> 1); j != 0; j--)
975 {
976 M4OSA_memset((M4OSA_MemAddr8)p_dest, u_width, 0);
977 p_dest += u_stride_out;
978 M4OSA_memset((M4OSA_MemAddr8)p_dest, u_width, 0);
979 p_dest += u_stride_out;
980 M4OSA_memset((M4OSA_MemAddr8)p_destu, u_widthuv, 128);
981 M4OSA_memset((M4OSA_MemAddr8)p_destv, u_widthuv, 128);
982 p_destu += u_stride_out_uv;
983 p_destv += u_stride_out_uv;
984 }
985
986 /* copy from source image */
987 for (j = (u_height - nb_black_lines) >> 1; j != 0; j--)
988 {
989 M4OSA_memcpy((M4OSA_MemAddr8)p_dest, (M4OSA_MemAddr8)p_src, u_width);
990 p_dest += u_stride_out;
991 p_src += u_stride;
992 M4OSA_memcpy((M4OSA_MemAddr8)p_dest, (M4OSA_MemAddr8)p_src, u_width);
993 p_dest += u_stride_out;
994 p_src += u_stride;
995 M4OSA_memcpy((M4OSA_MemAddr8)p_destu, (M4OSA_MemAddr8)p_srcu, u_widthuv);
996 M4OSA_memcpy((M4OSA_MemAddr8)p_destv, (M4OSA_MemAddr8)p_srcv, u_widthuv);
997 p_destu += u_stride_out_uv;
998 p_destv += u_stride_out_uv;
999 p_srcu += u_stride_uv;
1000 p_srcv += u_stride_uv;
1001 }
1002 }
1003 else
1004 {
1005 /* black lines at the bottom of the image */
1006 p_src = (unsigned char *) &plane_in[0].pac_data[plane_in[0].u_topleft];
1007 p_srcu = (unsigned char *) &plane_in[1].pac_data[plane_in[1].u_topleft];
1008 p_srcv = (unsigned char *) &plane_in[2].pac_data[plane_in[2].u_topleft];
1009
1010 /* copy from source image image */
1011 for (j = (nb_black_lines >> 1); j != 0; j--)
1012 {
1013 M4OSA_memcpy((M4OSA_MemAddr8)p_dest, (M4OSA_MemAddr8)p_src, u_width);
1014 p_dest += u_stride_out;
1015 p_src += u_stride;
1016 M4OSA_memcpy((M4OSA_MemAddr8)p_dest, (M4OSA_MemAddr8)p_src, u_width);
1017 p_dest += u_stride_out;
1018 p_src += u_stride;
1019 M4OSA_memcpy((M4OSA_MemAddr8)p_destu, (M4OSA_MemAddr8)p_srcu, u_widthuv);
1020 M4OSA_memcpy((M4OSA_MemAddr8)p_destv, (M4OSA_MemAddr8)p_srcv, u_widthuv);
1021 p_destu += u_stride_out_uv;
1022 p_destv += u_stride_out_uv;
1023 p_srcu += u_stride_uv;
1024 p_srcv += u_stride_uv;
1025 }
1026
1027 /* write black lines*/
1028 /* the pointers to p_dest, p_destu and p_destv are used through the two loops "for" */
1029 for (j = (u_height - nb_black_lines) >> 1; j != 0; j--)
1030 {
1031 M4OSA_memset((M4OSA_MemAddr8)p_dest, u_width, 0);
1032 p_dest += u_stride_out;
1033 M4OSA_memset((M4OSA_MemAddr8)p_dest, u_width, 0);
1034 p_dest += u_stride_out;
1035 M4OSA_memset((M4OSA_MemAddr8)p_destu, u_widthuv, 128);
1036 M4OSA_memset((M4OSA_MemAddr8)p_destv, u_widthuv, 128);
1037 p_destu += u_stride_out_uv;
1038 p_destv += u_stride_out_uv;
1039 }
1040 }
1041
1042 return 0;
1043}
1044
1045
1046/******************************************************************************
1047 * prototype M4OSA_ERR M4xVSS_internalConvertRGBtoYUV(M4xVSS_FramingStruct* framingCtx)
1048 * @brief This function converts an RGB565 plane to YUV420 planar
1049 * @note It is used only for framing effect
1050 * It allocates output YUV planes
1051 * @param framingCtx (IN) The framing struct containing input RGB565 plane
1052 *
1053 * @return M4NO_ERROR: No error
1054 * @return M4ERR_PARAMETER: At least one of the function parameters is null
1055 * @return M4ERR_ALLOC: Allocation error (no more memory)
1056 ******************************************************************************
1057*/
1058M4OSA_ERR M4xVSS_internalConvertRGBtoYUV(M4xVSS_FramingStruct* framingCtx)
1059{
1060 M4OSA_ERR err;
1061
1062 /**
1063 * Allocate output YUV planes */
1064 framingCtx->FramingYuv = (M4VIFI_ImagePlane*)M4OSA_malloc(3*sizeof(M4VIFI_ImagePlane), M4VS, (M4OSA_Char*)"M4xVSS_internalConvertRGBtoYUV: Output plane YUV");
1065 if(framingCtx->FramingYuv == M4OSA_NULL)
1066 {
1067 M4OSA_TRACE1_0("Allocation error in M4xVSS_internalConvertRGBtoYUV");
1068 return M4ERR_ALLOC;
1069 }
1070 framingCtx->FramingYuv[0].u_width = framingCtx->FramingRgb->u_width;
1071 framingCtx->FramingYuv[0].u_height = framingCtx->FramingRgb->u_height;
1072 framingCtx->FramingYuv[0].u_topleft = 0;
1073 framingCtx->FramingYuv[0].u_stride = framingCtx->FramingRgb->u_width;
1074 framingCtx->FramingYuv[0].pac_data = (M4VIFI_UInt8*)M4OSA_malloc((framingCtx->FramingYuv[0].u_width*framingCtx->FramingYuv[0].u_height*3)>>1, M4VS, (M4OSA_Char*)"Alloc for the Convertion output YUV");;
1075 if(framingCtx->FramingYuv[0].pac_data == M4OSA_NULL)
1076 {
1077 M4OSA_TRACE1_0("Allocation error in M4xVSS_internalConvertRGBtoYUV");
1078 return M4ERR_ALLOC;
1079 }
1080 framingCtx->FramingYuv[1].u_width = (framingCtx->FramingRgb->u_width)>>1;
1081 framingCtx->FramingYuv[1].u_height = (framingCtx->FramingRgb->u_height)>>1;
1082 framingCtx->FramingYuv[1].u_topleft = 0;
1083 framingCtx->FramingYuv[1].u_stride = (framingCtx->FramingRgb->u_width)>>1;
1084 framingCtx->FramingYuv[1].pac_data = framingCtx->FramingYuv[0].pac_data + framingCtx->FramingYuv[0].u_width * framingCtx->FramingYuv[0].u_height;
1085 framingCtx->FramingYuv[2].u_width = (framingCtx->FramingRgb->u_width)>>1;
1086 framingCtx->FramingYuv[2].u_height = (framingCtx->FramingRgb->u_height)>>1;
1087 framingCtx->FramingYuv[2].u_topleft = 0;
1088 framingCtx->FramingYuv[2].u_stride = (framingCtx->FramingRgb->u_width)>>1;
1089 framingCtx->FramingYuv[2].pac_data = framingCtx->FramingYuv[1].pac_data + framingCtx->FramingYuv[1].u_width * framingCtx->FramingYuv[1].u_height;
1090
1091 /**
1092 * Convert input RGB 565 to YUV 420 to be able to merge it with output video in framing effect */
1093 err = M4VIFI_xVSS_RGB565toYUV420(M4OSA_NULL, framingCtx->FramingRgb, framingCtx->FramingYuv);
1094 if(err != M4NO_ERROR)
1095 {
1096 M4OSA_TRACE1_1("M4xVSS_internalConvertRGBtoYUV: error when converting from RGB to YUV: 0x%x\n", err);
1097 }
1098
1099 framingCtx->duration = 0;
1100 framingCtx->previousClipTime = -1;
1101 framingCtx->previewOffsetClipTime = -1;
1102
1103 /**
1104 * Only one element in the chained list (no animated image with RGB buffer...) */
1105 framingCtx->pCurrent = framingCtx;
1106 framingCtx->pNext = framingCtx;
1107
1108 return M4NO_ERROR;
1109}
1110
1111/******************************************************************************
1112 * prototype M4OSA_ERR M4xVSS_internalConvertRGB888toYUV(M4xVSS_FramingStruct* framingCtx)
1113 * @brief This function converts an RGB888 plane to YUV420 planar
1114 * @note It is used only for framing effect
1115 * It allocates output YUV planes
1116 * @param framingCtx (IN) The framing struct containing input RGB888 plane
1117 *
1118 * @return M4NO_ERROR: No error
1119 * @return M4ERR_PARAMETER: At least one of the function parameters is null
1120 * @return M4ERR_ALLOC: Allocation error (no more memory)
1121 ******************************************************************************
1122*/
1123M4OSA_ERR M4xVSS_internalConvertRGB888toYUV(M4xVSS_FramingStruct* framingCtx)
1124{
1125 M4OSA_ERR err;
1126
1127 /**
1128 * Allocate output YUV planes */
1129 framingCtx->FramingYuv = (M4VIFI_ImagePlane*)M4OSA_malloc(3*sizeof(M4VIFI_ImagePlane), M4VS, (M4OSA_Char*)"M4xVSS_internalConvertRGBtoYUV: Output plane YUV");
1130 if(framingCtx->FramingYuv == M4OSA_NULL)
1131 {
1132 M4OSA_TRACE1_0("Allocation error in M4xVSS_internalConvertRGBtoYUV");
1133 return M4ERR_ALLOC;
1134 }
1135 framingCtx->FramingYuv[0].u_width = framingCtx->FramingRgb->u_width;
1136 framingCtx->FramingYuv[0].u_height = framingCtx->FramingRgb->u_height;
1137 framingCtx->FramingYuv[0].u_topleft = 0;
1138 framingCtx->FramingYuv[0].u_stride = framingCtx->FramingRgb->u_width;
1139 framingCtx->FramingYuv[0].pac_data = (M4VIFI_UInt8*)M4OSA_malloc((framingCtx->FramingYuv[0].u_width*framingCtx->FramingYuv[0].u_height*3)>>1, M4VS, (M4OSA_Char*)"Alloc for the Convertion output YUV");;
1140 if(framingCtx->FramingYuv[0].pac_data == M4OSA_NULL)
1141 {
1142 M4OSA_TRACE1_0("Allocation error in M4xVSS_internalConvertRGBtoYUV");
1143 return M4ERR_ALLOC;
1144 }
1145 framingCtx->FramingYuv[1].u_width = (framingCtx->FramingRgb->u_width)>>1;
1146 framingCtx->FramingYuv[1].u_height = (framingCtx->FramingRgb->u_height)>>1;
1147 framingCtx->FramingYuv[1].u_topleft = 0;
1148 framingCtx->FramingYuv[1].u_stride = (framingCtx->FramingRgb->u_width)>>1;
1149 framingCtx->FramingYuv[1].pac_data = framingCtx->FramingYuv[0].pac_data + framingCtx->FramingYuv[0].u_width * framingCtx->FramingYuv[0].u_height;
1150 framingCtx->FramingYuv[2].u_width = (framingCtx->FramingRgb->u_width)>>1;
1151 framingCtx->FramingYuv[2].u_height = (framingCtx->FramingRgb->u_height)>>1;
1152 framingCtx->FramingYuv[2].u_topleft = 0;
1153 framingCtx->FramingYuv[2].u_stride = (framingCtx->FramingRgb->u_width)>>1;
1154 framingCtx->FramingYuv[2].pac_data = framingCtx->FramingYuv[1].pac_data + framingCtx->FramingYuv[1].u_width * framingCtx->FramingYuv[1].u_height;
1155
1156 /**
1157 * Convert input RGB888 to YUV 420 to be able to merge it with output video in framing effect */
1158 err = M4VIFI_RGB888toYUV420(M4OSA_NULL, framingCtx->FramingRgb, framingCtx->FramingYuv);
1159 if(err != M4NO_ERROR)
1160 {
1161 M4OSA_TRACE1_1("M4xVSS_internalConvertRGBtoYUV: error when converting from RGB to YUV: 0x%x\n", err);
1162 }
1163
1164 framingCtx->duration = 0;
1165 framingCtx->previousClipTime = -1;
1166 framingCtx->previewOffsetClipTime = -1;
1167
1168 /**
1169 * Only one element in the chained list (no animated image with RGB buffer...) */
1170 framingCtx->pCurrent = framingCtx;
1171 framingCtx->pNext = framingCtx;
1172
1173 return M4NO_ERROR;
1174}
1175
1176/**
1177 ******************************************************************************
1178 * M4VIFI_UInt8 M4VIFI_RGB565toYUV420 (void *pUserData,
1179 * M4VIFI_ImagePlane *pPlaneIn,
1180 * M4VIFI_ImagePlane *pPlaneOut)
1181 * @author Patrice Martinez / Philips Digital Networks - MP4Net
1182 * @brief transform RGB565 image to a YUV420 image.
1183 * @note Convert RGB565 to YUV420,
1184 * Loop on each row ( 2 rows by 2 rows )
1185 * Loop on each column ( 2 col by 2 col )
1186 * Get 4 RGB samples from input data and build 4 output Y samples
1187 * and each single U & V data
1188 * end loop on col
1189 * end loop on row
1190 * @param pUserData: (IN) User Specific Data
1191 * @param pPlaneIn: (IN) Pointer to RGB565 Plane
1192 * @param pPlaneOut: (OUT) Pointer to YUV420 buffer Plane
1193 * @return M4VIFI_OK: there is no error
1194 * @return M4VIFI_ILLEGAL_FRAME_HEIGHT: YUV Plane height is ODD
1195 * @return M4VIFI_ILLEGAL_FRAME_WIDTH: YUV Plane width is ODD
1196 ******************************************************************************
1197*/
1198M4VIFI_UInt8 M4VIFI_xVSS_RGB565toYUV420(void *pUserData, M4VIFI_ImagePlane *pPlaneIn,
1199 M4VIFI_ImagePlane *pPlaneOut)
1200{
1201 M4VIFI_UInt32 u32_width, u32_height;
1202 M4VIFI_UInt32 u32_stride_Y, u32_stride2_Y, u32_stride_U, u32_stride_V;
1203 M4VIFI_UInt32 u32_stride_rgb, u32_stride_2rgb;
1204 M4VIFI_UInt32 u32_col, u32_row;
1205
1206 M4VIFI_Int32 i32_r00, i32_r01, i32_r10, i32_r11;
1207 M4VIFI_Int32 i32_g00, i32_g01, i32_g10, i32_g11;
1208 M4VIFI_Int32 i32_b00, i32_b01, i32_b10, i32_b11;
1209 M4VIFI_Int32 i32_y00, i32_y01, i32_y10, i32_y11;
1210 M4VIFI_Int32 i32_u00, i32_u01, i32_u10, i32_u11;
1211 M4VIFI_Int32 i32_v00, i32_v01, i32_v10, i32_v11;
1212 M4VIFI_UInt8 *pu8_yn, *pu8_ys, *pu8_u, *pu8_v;
1213 M4VIFI_UInt8 *pu8_y_data, *pu8_u_data, *pu8_v_data;
1214 M4VIFI_UInt8 *pu8_rgbn_data, *pu8_rgbn;
1215 M4VIFI_UInt16 u16_pix1, u16_pix2, u16_pix3, u16_pix4;
1216 M4VIFI_UInt8 count_null=0;
1217
1218 /* Check planes height are appropriate */
1219 if( (pPlaneIn->u_height != pPlaneOut[0].u_height) ||
1220 (pPlaneOut[0].u_height != (pPlaneOut[1].u_height<<1)) ||
1221 (pPlaneOut[0].u_height != (pPlaneOut[2].u_height<<1)))
1222 {
1223 return M4VIFI_ILLEGAL_FRAME_HEIGHT;
1224 }
1225
1226 /* Check planes width are appropriate */
1227 if( (pPlaneIn->u_width != pPlaneOut[0].u_width) ||
1228 (pPlaneOut[0].u_width != (pPlaneOut[1].u_width<<1)) ||
1229 (pPlaneOut[0].u_width != (pPlaneOut[2].u_width<<1)))
1230 {
1231 return M4VIFI_ILLEGAL_FRAME_WIDTH;
1232 }
1233
1234 /* Set the pointer to the beginning of the output data buffers */
1235 pu8_y_data = pPlaneOut[0].pac_data + pPlaneOut[0].u_topleft;
1236 pu8_u_data = pPlaneOut[1].pac_data + pPlaneOut[1].u_topleft;
1237 pu8_v_data = pPlaneOut[2].pac_data + pPlaneOut[2].u_topleft;
1238
1239 /* Set the pointer to the beginning of the input data buffers */
1240 pu8_rgbn_data = pPlaneIn->pac_data + pPlaneIn->u_topleft;
1241
1242 /* Get the size of the output image */
1243 u32_width = pPlaneOut[0].u_width;
1244 u32_height = pPlaneOut[0].u_height;
1245
1246 /* Set the size of the memory jumps corresponding to row jump in each output plane */
1247 u32_stride_Y = pPlaneOut[0].u_stride;
1248 u32_stride2_Y = u32_stride_Y << 1;
1249 u32_stride_U = pPlaneOut[1].u_stride;
1250 u32_stride_V = pPlaneOut[2].u_stride;
1251
1252 /* Set the size of the memory jumps corresponding to row jump in input plane */
1253 u32_stride_rgb = pPlaneIn->u_stride;
1254 u32_stride_2rgb = u32_stride_rgb << 1;
1255
1256
1257 /* Loop on each row of the output image, input coordinates are estimated from output ones */
1258 /* Two YUV rows are computed at each pass */
1259 for (u32_row = u32_height ;u32_row != 0; u32_row -=2)
1260 {
1261 /* Current Y plane row pointers */
1262 pu8_yn = pu8_y_data;
1263 /* Next Y plane row pointers */
1264 pu8_ys = pu8_yn + u32_stride_Y;
1265 /* Current U plane row pointer */
1266 pu8_u = pu8_u_data;
1267 /* Current V plane row pointer */
1268 pu8_v = pu8_v_data;
1269
1270 pu8_rgbn = pu8_rgbn_data;
1271
1272 /* Loop on each column of the output image */
1273 for (u32_col = u32_width; u32_col != 0 ; u32_col -=2)
1274 {
1275 /* Get four RGB 565 samples from input data */
1276 u16_pix1 = *( (M4VIFI_UInt16 *) pu8_rgbn);
1277 u16_pix2 = *( (M4VIFI_UInt16 *) (pu8_rgbn + CST_RGB_16_SIZE));
1278 u16_pix3 = *( (M4VIFI_UInt16 *) (pu8_rgbn + u32_stride_rgb));
1279 u16_pix4 = *( (M4VIFI_UInt16 *) (pu8_rgbn + u32_stride_rgb + CST_RGB_16_SIZE));
1280
1281 /* Unpack RGB565 to 8bit R, G, B */
1282#if 0
1283 /* (x,y) */
1284 GET_RGB565(i32_r00,i32_g00,i32_b00,u16_pix1);
1285 /* (x+1,y) */
1286 GET_RGB565(i32_r10,i32_g10,i32_b10,u16_pix2);
1287 /* (x,y+1) */
1288 GET_RGB565(i32_r01,i32_g01,i32_b01,u16_pix3);
1289 /* (x+1,y+1) */
1290 GET_RGB565(i32_r11,i32_g11,i32_b11,u16_pix4);
1291#else
1292 /* (x,y) */
1293 GET_RGB565(i32_b00,i32_g00,i32_r00,u16_pix1);
1294 /* (x+1,y) */
1295 GET_RGB565(i32_b10,i32_g10,i32_r10,u16_pix2);
1296 /* (x,y+1) */
1297 GET_RGB565(i32_b01,i32_g01,i32_r01,u16_pix3);
1298 /* (x+1,y+1) */
1299 GET_RGB565(i32_b11,i32_g11,i32_r11,u16_pix4);
1300#endif
1301#if 1 /* Solution to avoid green effects due to transparency */
1302 /* If RGB is transparent color (0, 63, 0), we transform it to white (31,63,31) */
1303 if(i32_b00 == 0 && i32_g00 == 63 && i32_r00 == 0)
1304 {
1305 i32_b00 = 31;
1306 i32_r00 = 31;
1307 }
1308 if(i32_b10 == 0 && i32_g10 == 63 && i32_r10 == 0)
1309 {
1310 i32_b10 = 31;
1311 i32_r10 = 31;
1312 }
1313 if(i32_b01 == 0 && i32_g01 == 63 && i32_r01 == 0)
1314 {
1315 i32_b01 = 31;
1316 i32_r01 = 31;
1317 }
1318 if(i32_b11 == 0 && i32_g11 == 63 && i32_r11 == 0)
1319 {
1320 i32_b11 = 31;
1321 i32_r11 = 31;
1322 }
1323#endif
1324 /* Convert RGB value to YUV */
1325 i32_u00 = U16(i32_r00, i32_g00, i32_b00);
1326 i32_v00 = V16(i32_r00, i32_g00, i32_b00);
1327 /* luminance value */
1328 i32_y00 = Y16(i32_r00, i32_g00, i32_b00);
1329
1330 i32_u10 = U16(i32_r10, i32_g10, i32_b10);
1331 i32_v10 = V16(i32_r10, i32_g10, i32_b10);
1332 /* luminance value */
1333 i32_y10 = Y16(i32_r10, i32_g10, i32_b10);
1334
1335 i32_u01 = U16(i32_r01, i32_g01, i32_b01);
1336 i32_v01 = V16(i32_r01, i32_g01, i32_b01);
1337 /* luminance value */
1338 i32_y01 = Y16(i32_r01, i32_g01, i32_b01);
1339
1340 i32_u11 = U16(i32_r11, i32_g11, i32_b11);
1341 i32_v11 = V16(i32_r11, i32_g11, i32_b11);
1342 /* luminance value */
1343 i32_y11 = Y16(i32_r11, i32_g11, i32_b11);
1344
1345 /* Store luminance data */
1346 pu8_yn[0] = (M4VIFI_UInt8)i32_y00;
1347 pu8_yn[1] = (M4VIFI_UInt8)i32_y10;
1348 pu8_ys[0] = (M4VIFI_UInt8)i32_y01;
1349 pu8_ys[1] = (M4VIFI_UInt8)i32_y11;
1350#if 0 /* Temporary solution to avoid green effects due to transparency -> To be removed */
1351 count_null = 4;
1352 /* Store chroma data */
1353 if(i32_b00 == 0 && i32_g00 == 63 && i32_r00 == 0)
1354 {
1355 i32_u00 = 0;
1356 i32_v00 = 0;
1357 count_null --;
1358 }
1359 if(i32_b10 == 0 && i32_g10 == 63 && i32_r10 == 0)
1360 {
1361 i32_u10 = 0;
1362 i32_v10 = 0;
1363 count_null --;
1364 }
1365 if(i32_b01 == 0 && i32_g01 == 63 && i32_r01 == 0)
1366 {
1367 i32_u01 = 0;
1368 i32_v01 = 0;
1369 count_null --;
1370 }
1371 if(i32_b11 == 0 && i32_g11 == 63 && i32_r11 == 0)
1372 {
1373 i32_u11 = 0;
1374 i32_v11 = 0;
1375 count_null --;
1376 }
1377
1378 if(count_null == 0)
1379 {
1380#endif
1381 *pu8_u = (M4VIFI_UInt8)((i32_u00 + i32_u01 + i32_u10 + i32_u11 + 2) >> 2);
1382 *pu8_v = (M4VIFI_UInt8)((i32_v00 + i32_v01 + i32_v10 + i32_v11 + 2) >> 2);
1383#if 0 /* Temporary solution to avoid green effects due to transparency -> To be removed */
1384 }
1385 else
1386 {
1387 *pu8_u = (M4VIFI_UInt8)((i32_u00 + i32_u01 + i32_u10 + i32_u11 + 2) / count_null);
1388 *pu8_v = (M4VIFI_UInt8)((i32_v00 + i32_v01 + i32_v10 + i32_v11 + 2) / count_null);
1389 }
1390#endif
1391 /* Prepare for next column */
1392 pu8_rgbn += (CST_RGB_16_SIZE<<1);
1393 /* Update current Y plane line pointer*/
1394 pu8_yn += 2;
1395 /* Update next Y plane line pointer*/
1396 pu8_ys += 2;
1397 /* Update U plane line pointer*/
1398 pu8_u ++;
1399 /* Update V plane line pointer*/
1400 pu8_v ++;
1401 } /* End of horizontal scanning */
1402
1403 /* Prepare pointers for the next row */
1404 pu8_y_data += u32_stride2_Y;
1405 pu8_u_data += u32_stride_U;
1406 pu8_v_data += u32_stride_V;
1407 pu8_rgbn_data += u32_stride_2rgb;
1408
1409
1410 } /* End of vertical scanning */
1411
1412 return M4VIFI_OK;
1413}
1414
1415/***************************************************************************
1416Proto:
1417M4VIFI_UInt8 M4VIFI_RGB888toYUV420(void *pUserData, M4VIFI_ImagePlane *PlaneIn, M4VIFI_ImagePlane PlaneOut[3]);
1418Author: Patrice Martinez / Philips Digital Networks - MP4Net
1419Purpose: filling of the YUV420 plane from a BGR24 plane
1420Abstract: Loop on each row ( 2 rows by 2 rows )
1421 Loop on each column ( 2 col by 2 col )
1422 Get 4 BGR samples from input data and build 4 output Y samples and each single U & V data
1423 end loop on col
1424 end loop on row
1425
1426In: RGB24 plane
1427InOut: none
1428Out: array of 3 M4VIFI_ImagePlane structures
1429Modified: ML: RGB function modified to BGR.
1430***************************************************************************/
1431M4VIFI_UInt8 M4VIFI_RGB888toYUV420(void *pUserData, M4VIFI_ImagePlane *PlaneIn, M4VIFI_ImagePlane PlaneOut[3])
1432{
1433
1434 M4VIFI_UInt32 u32_width, u32_height;
1435 M4VIFI_UInt32 u32_stride_Y, u32_stride2_Y, u32_stride_U, u32_stride_V, u32_stride_rgb, u32_stride_2rgb;
1436 M4VIFI_UInt32 u32_col, u32_row;
1437
1438 M4VIFI_Int32 i32_r00, i32_r01, i32_r10, i32_r11;
1439 M4VIFI_Int32 i32_g00, i32_g01, i32_g10, i32_g11;
1440 M4VIFI_Int32 i32_b00, i32_b01, i32_b10, i32_b11;
1441 M4VIFI_Int32 i32_y00, i32_y01, i32_y10, i32_y11;
1442 M4VIFI_Int32 i32_u00, i32_u01, i32_u10, i32_u11;
1443 M4VIFI_Int32 i32_v00, i32_v01, i32_v10, i32_v11;
1444 M4VIFI_UInt8 *pu8_yn, *pu8_ys, *pu8_u, *pu8_v;
1445 M4VIFI_UInt8 *pu8_y_data, *pu8_u_data, *pu8_v_data;
1446 M4VIFI_UInt8 *pu8_rgbn_data, *pu8_rgbn;
1447
1448 /* check sizes */
1449 if( (PlaneIn->u_height != PlaneOut[0].u_height) ||
1450 (PlaneOut[0].u_height != (PlaneOut[1].u_height<<1)) ||
1451 (PlaneOut[0].u_height != (PlaneOut[2].u_height<<1)))
1452 return M4VIFI_ILLEGAL_FRAME_HEIGHT;
1453
1454 if( (PlaneIn->u_width != PlaneOut[0].u_width) ||
1455 (PlaneOut[0].u_width != (PlaneOut[1].u_width<<1)) ||
1456 (PlaneOut[0].u_width != (PlaneOut[2].u_width<<1)))
1457 return M4VIFI_ILLEGAL_FRAME_WIDTH;
1458
1459
1460 /* set the pointer to the beginning of the output data buffers */
1461 pu8_y_data = PlaneOut[0].pac_data + PlaneOut[0].u_topleft;
1462 pu8_u_data = PlaneOut[1].pac_data + PlaneOut[1].u_topleft;
1463 pu8_v_data = PlaneOut[2].pac_data + PlaneOut[2].u_topleft;
1464
1465 /* idem for input buffer */
1466 pu8_rgbn_data = PlaneIn->pac_data + PlaneIn->u_topleft;
1467
1468 /* get the size of the output image */
1469 u32_width = PlaneOut[0].u_width;
1470 u32_height = PlaneOut[0].u_height;
1471
1472 /* set the size of the memory jumps corresponding to row jump in each output plane */
1473 u32_stride_Y = PlaneOut[0].u_stride;
1474 u32_stride2_Y= u32_stride_Y << 1;
1475 u32_stride_U = PlaneOut[1].u_stride;
1476 u32_stride_V = PlaneOut[2].u_stride;
1477
1478 /* idem for input plane */
1479 u32_stride_rgb = PlaneIn->u_stride;
1480 u32_stride_2rgb = u32_stride_rgb << 1;
1481
1482 /* loop on each row of the output image, input coordinates are estimated from output ones */
1483 /* two YUV rows are computed at each pass */
1484 for (u32_row = u32_height ;u32_row != 0; u32_row -=2)
1485 {
1486 /* update working pointers */
1487 pu8_yn = pu8_y_data;
1488 pu8_ys = pu8_yn + u32_stride_Y;
1489
1490 pu8_u = pu8_u_data;
1491 pu8_v = pu8_v_data;
1492
1493 pu8_rgbn= pu8_rgbn_data;
1494
1495 /* loop on each column of the output image*/
1496 for (u32_col = u32_width; u32_col != 0 ; u32_col -=2)
1497 {
1498 /* get RGB samples of 4 pixels */
1499 GET_RGB24(i32_r00, i32_g00, i32_b00, pu8_rgbn, 0);
1500 GET_RGB24(i32_r10, i32_g10, i32_b10, pu8_rgbn, CST_RGB_24_SIZE);
1501 GET_RGB24(i32_r01, i32_g01, i32_b01, pu8_rgbn, u32_stride_rgb);
1502 GET_RGB24(i32_r11, i32_g11, i32_b11, pu8_rgbn, u32_stride_rgb + CST_RGB_24_SIZE);
1503
1504 i32_u00 = U24(i32_r00, i32_g00, i32_b00);
1505 i32_v00 = V24(i32_r00, i32_g00, i32_b00);
1506 i32_y00 = Y24(i32_r00, i32_g00, i32_b00); /* matrix luminance */
1507 pu8_yn[0]= (M4VIFI_UInt8)i32_y00;
1508
1509 i32_u10 = U24(i32_r10, i32_g10, i32_b10);
1510 i32_v10 = V24(i32_r10, i32_g10, i32_b10);
1511 i32_y10 = Y24(i32_r10, i32_g10, i32_b10);
1512 pu8_yn[1]= (M4VIFI_UInt8)i32_y10;
1513
1514 i32_u01 = U24(i32_r01, i32_g01, i32_b01);
1515 i32_v01 = V24(i32_r01, i32_g01, i32_b01);
1516 i32_y01 = Y24(i32_r01, i32_g01, i32_b01);
1517 pu8_ys[0]= (M4VIFI_UInt8)i32_y01;
1518
1519 i32_u11 = U24(i32_r11, i32_g11, i32_b11);
1520 i32_v11 = V24(i32_r11, i32_g11, i32_b11);
1521 i32_y11 = Y24(i32_r11, i32_g11, i32_b11);
1522 pu8_ys[1] = (M4VIFI_UInt8)i32_y11;
1523
1524 *pu8_u = (M4VIFI_UInt8)((i32_u00 + i32_u01 + i32_u10 + i32_u11 + 2) >> 2);
1525 *pu8_v = (M4VIFI_UInt8)((i32_v00 + i32_v01 + i32_v10 + i32_v11 + 2) >> 2);
1526
1527 pu8_rgbn += (CST_RGB_24_SIZE<<1);
1528 pu8_yn += 2;
1529 pu8_ys += 2;
1530
1531 pu8_u ++;
1532 pu8_v ++;
1533 } /* end of horizontal scanning */
1534
1535 pu8_y_data += u32_stride2_Y;
1536 pu8_u_data += u32_stride_U;
1537 pu8_v_data += u32_stride_V;
1538 pu8_rgbn_data += u32_stride_2rgb;
1539
1540
1541 } /* End of vertical scanning */
1542
1543 return M4VIFI_OK;
1544}
1545
1546/** YUV420 to YUV420 */
1547/**
1548 *******************************************************************************************
1549 * M4VIFI_UInt8 M4VIFI_YUV420toYUV420 (void *pUserData,
1550 * M4VIFI_ImagePlane *pPlaneIn,
1551 * M4VIFI_ImagePlane *pPlaneOut)
1552 * @brief Transform YUV420 image to a YUV420 image.
1553 * @param pUserData: (IN) User Specific Data (Unused - could be NULL)
1554 * @param pPlaneIn: (IN) Pointer to YUV plane buffer
1555 * @param pPlaneOut: (OUT) Pointer to YUV Plane
1556 * @return M4VIFI_OK: there is no error
1557 * @return M4VIFI_ILLEGAL_FRAME_HEIGHT: Error in plane height
1558 * @return M4VIFI_ILLEGAL_FRAME_WIDTH: Error in plane width
1559 *******************************************************************************************
1560 */
1561
1562M4VIFI_UInt8 M4VIFI_YUV420toYUV420(void *user_data, M4VIFI_ImagePlane PlaneIn[3], M4VIFI_ImagePlane *PlaneOut )
1563{
1564 M4VIFI_Int32 plane_number;
1565 M4VIFI_UInt32 i;
1566 M4VIFI_UInt8 *p_buf_src, *p_buf_dest;
1567
1568 for (plane_number = 0; plane_number < 3; plane_number++)
1569 {
1570 p_buf_src = &(PlaneIn[plane_number].pac_data[PlaneIn[plane_number].u_topleft]);
1571 p_buf_dest = &(PlaneOut[plane_number].pac_data[PlaneOut[plane_number].u_topleft]);
1572 for (i = 0; i < PlaneOut[plane_number].u_height; i++)
1573 {
1574 M4OSA_memcpy((M4OSA_MemAddr8)p_buf_dest, (M4OSA_MemAddr8)p_buf_src ,PlaneOut[plane_number].u_width);
1575 p_buf_src += PlaneIn[plane_number].u_stride;
1576 p_buf_dest += PlaneOut[plane_number].u_stride;
1577 }
1578 }
1579 return M4VIFI_OK;
1580}
1581
1582/**
1583 ***********************************************************************************************
1584 * M4VIFI_UInt8 M4VIFI_ResizeBilinearYUV420toYUV420(void *pUserData, M4VIFI_ImagePlane *pPlaneIn,
1585 * M4VIFI_ImagePlane *pPlaneOut)
1586 * @author David Dana (PHILIPS Software)
1587 * @brief Resizes YUV420 Planar plane.
1588 * @note Basic structure of the function
1589 * Loop on each row (step 2)
1590 * Loop on each column (step 2)
1591 * Get four Y samples and 1 U & V sample
1592 * Resize the Y with corresponing U and V samples
1593 * Place the YUV in the ouput plane
1594 * end loop column
1595 * end loop row
1596 * For resizing bilinear interpolation linearly interpolates along
1597 * each row, and then uses that result in a linear interpolation down each column.
1598 * Each estimated pixel in the output image is a weighted
1599 * combination of its four neighbours. The ratio of compression
1600 * or dilatation is estimated using input and output sizes.
1601 * @param pUserData: (IN) User Data
1602 * @param pPlaneIn: (IN) Pointer to YUV420 (Planar) plane buffer
1603 * @param pPlaneOut: (OUT) Pointer to YUV420 (Planar) plane
1604 * @return M4VIFI_OK: there is no error
1605 * @return M4VIFI_ILLEGAL_FRAME_HEIGHT: Error in height
1606 * @return M4VIFI_ILLEGAL_FRAME_WIDTH: Error in width
1607 ***********************************************************************************************
1608*/
1609M4VIFI_UInt8 M4VIFI_ResizeBilinearYUV420toYUV420(void *pUserData,
1610 M4VIFI_ImagePlane *pPlaneIn,
1611 M4VIFI_ImagePlane *pPlaneOut)
1612{
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001613 M4VIFI_UInt8 *pu8_data_in, *pu8_data_out, *pu8dum;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001614 M4VIFI_UInt32 u32_plane;
1615 M4VIFI_UInt32 u32_width_in, u32_width_out, u32_height_in, u32_height_out;
1616 M4VIFI_UInt32 u32_stride_in, u32_stride_out;
1617 M4VIFI_UInt32 u32_x_inc, u32_y_inc;
1618 M4VIFI_UInt32 u32_x_accum, u32_y_accum, u32_x_accum_start;
1619 M4VIFI_UInt32 u32_width, u32_height;
1620 M4VIFI_UInt32 u32_y_frac;
1621 M4VIFI_UInt32 u32_x_frac;
1622 M4VIFI_UInt32 u32_temp_value;
1623 M4VIFI_UInt8 *pu8_src_top;
1624 M4VIFI_UInt8 *pu8_src_bottom;
1625
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001626 M4VIFI_UInt8 u8Wflag = 0;
1627 M4VIFI_UInt8 u8Hflag = 0;
1628 M4VIFI_UInt32 loop = 0;
1629
1630
1631 /*
1632 If input width is equal to output width and input height equal to
1633 output height then M4VIFI_YUV420toYUV420 is called.
1634 */
1635 if ((pPlaneIn[0].u_height == pPlaneOut[0].u_height) &&
1636 (pPlaneIn[0].u_width == pPlaneOut[0].u_width))
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001637 {
1638 return M4VIFI_YUV420toYUV420(pUserData, pPlaneIn, pPlaneOut);
1639 }
1640
1641 /* Check for the YUV width and height are even */
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001642 if ((IS_EVEN(pPlaneIn[0].u_height) == FALSE) ||
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001643 (IS_EVEN(pPlaneOut[0].u_height) == FALSE))
1644 {
1645 return M4VIFI_ILLEGAL_FRAME_HEIGHT;
1646 }
1647
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001648 if ((IS_EVEN(pPlaneIn[0].u_width) == FALSE) ||
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001649 (IS_EVEN(pPlaneOut[0].u_width) == FALSE))
1650 {
1651 return M4VIFI_ILLEGAL_FRAME_WIDTH;
1652 }
1653
1654 /* Loop on planes */
1655 for(u32_plane = 0;u32_plane < PLANES;u32_plane++)
1656 {
1657 /* Set the working pointers at the beginning of the input/output data field */
1658 pu8_data_in = pPlaneIn[u32_plane].pac_data + pPlaneIn[u32_plane].u_topleft;
1659 pu8_data_out = pPlaneOut[u32_plane].pac_data + pPlaneOut[u32_plane].u_topleft;
1660
1661 /* Get the memory jump corresponding to a row jump */
1662 u32_stride_in = pPlaneIn[u32_plane].u_stride;
1663 u32_stride_out = pPlaneOut[u32_plane].u_stride;
1664
1665 /* Set the bounds of the active image */
1666 u32_width_in = pPlaneIn[u32_plane].u_width;
1667 u32_height_in = pPlaneIn[u32_plane].u_height;
1668
1669 u32_width_out = pPlaneOut[u32_plane].u_width;
1670 u32_height_out = pPlaneOut[u32_plane].u_height;
1671
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001672 /*
1673 For the case , width_out = width_in , set the flag to avoid
1674 accessing one column beyond the input width.In this case the last
1675 column is replicated for processing
1676 */
1677 if (u32_width_out == u32_width_in) {
1678 u32_width_out = u32_width_out-1;
1679 u8Wflag = 1;
1680 }
1681
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001682 /* Compute horizontal ratio between src and destination width.*/
1683 if (u32_width_out >= u32_width_in)
1684 {
1685 u32_x_inc = ((u32_width_in-1) * MAX_SHORT) / (u32_width_out-1);
1686 }
1687 else
1688 {
1689 u32_x_inc = (u32_width_in * MAX_SHORT) / (u32_width_out);
1690 }
1691
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001692 /*
1693 For the case , height_out = height_in , set the flag to avoid
1694 accessing one row beyond the input height.In this case the last
1695 row is replicated for processing
1696 */
1697 if (u32_height_out == u32_height_in) {
1698 u32_height_out = u32_height_out-1;
1699 u8Hflag = 1;
1700 }
1701
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001702 /* Compute vertical ratio between src and destination height.*/
1703 if (u32_height_out >= u32_height_in)
1704 {
1705 u32_y_inc = ((u32_height_in - 1) * MAX_SHORT) / (u32_height_out-1);
1706 }
1707 else
1708 {
1709 u32_y_inc = (u32_height_in * MAX_SHORT) / (u32_height_out);
1710 }
1711
1712 /*
1713 Calculate initial accumulator value : u32_y_accum_start.
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001714 u32_y_accum_start is coded on 15 bits, and represents a value
1715 between 0 and 0.5
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001716 */
1717 if (u32_y_inc >= MAX_SHORT)
1718 {
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001719 /*
1720 Keep the fractionnal part, assimung that integer part is coded
1721 on the 16 high bits and the fractional on the 15 low bits
1722 */
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001723 u32_y_accum = u32_y_inc & 0xffff;
1724
1725 if (!u32_y_accum)
1726 {
1727 u32_y_accum = MAX_SHORT;
1728 }
1729
1730 u32_y_accum >>= 1;
1731 }
1732 else
1733 {
1734 u32_y_accum = 0;
1735 }
1736
1737
1738 /*
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001739 Calculate initial accumulator value : u32_x_accum_start.
1740 u32_x_accum_start is coded on 15 bits, and represents a value
1741 between 0 and 0.5
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001742 */
1743 if (u32_x_inc >= MAX_SHORT)
1744 {
1745 u32_x_accum_start = u32_x_inc & 0xffff;
1746
1747 if (!u32_x_accum_start)
1748 {
1749 u32_x_accum_start = MAX_SHORT;
1750 }
1751
1752 u32_x_accum_start >>= 1;
1753 }
1754 else
1755 {
1756 u32_x_accum_start = 0;
1757 }
1758
1759 u32_height = u32_height_out;
1760
1761 /*
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001762 Bilinear interpolation linearly interpolates along each row, and
1763 then uses that result in a linear interpolation donw each column.
1764 Each estimated pixel in the output image is a weighted combination
1765 of its four neighbours according to the formula:
1766 F(p',q')=f(p,q)R(-a)R(b)+f(p,q-1)R(-a)R(b-1)+f(p+1,q)R(1-a)R(b)+
1767 f(p+&,q+1)R(1-a)R(b-1) with R(x) = / x+1 -1 =< x =< 0 \ 1-x
1768 0 =< x =< 1 and a (resp. b)weighting coefficient is the distance
1769 from the nearest neighbor in the p (resp. q) direction
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001770 */
1771
1772 do { /* Scan all the row */
1773
1774 /* Vertical weight factor */
1775 u32_y_frac = (u32_y_accum>>12)&15;
1776
1777 /* Reinit accumulator */
1778 u32_x_accum = u32_x_accum_start;
1779
1780 u32_width = u32_width_out;
1781
1782 do { /* Scan along each row */
1783 pu8_src_top = pu8_data_in + (u32_x_accum >> 16);
1784 pu8_src_bottom = pu8_src_top + u32_stride_in;
1785 u32_x_frac = (u32_x_accum >> 12)&15; /* Horizontal weight factor */
1786
1787 /* Weighted combination */
1788 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[0]*(16-u32_x_frac) +
1789 pu8_src_top[1]*u32_x_frac)*(16-u32_y_frac) +
1790 (pu8_src_bottom[0]*(16-u32_x_frac) +
1791 pu8_src_bottom[1]*u32_x_frac)*u32_y_frac )>>8);
1792
1793 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
1794
1795 /* Update horizontal accumulator */
1796 u32_x_accum += u32_x_inc;
1797 } while(--u32_width);
1798
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001799 /*
1800 This u8Wflag flag gets in to effect if input and output
1801 width is same, and height may be different. So previous
1802 pixel is replicated here
1803 */
1804 if (u8Wflag) {
1805 *pu8_data_out = (M4VIFI_UInt8)u32_temp_value;
1806 }
1807
1808 pu8dum = (pu8_data_out-u32_width_out);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001809 pu8_data_out = pu8_data_out + u32_stride_out - u32_width_out;
1810
1811 /* Update vertical accumulator */
1812 u32_y_accum += u32_y_inc;
1813 if (u32_y_accum>>16) {
1814 pu8_data_in = pu8_data_in + (u32_y_accum >> 16) * u32_stride_in;
1815 u32_y_accum &= 0xffff;
1816 }
1817 } while(--u32_height);
Dheeraj Sharma1ea85832011-02-08 22:36:30 -08001818
1819 /*
1820 This u8Hflag flag gets in to effect if input and output height
1821 is same, and width may be different. So previous pixel row is
1822 replicated here
1823 */
1824 if (u8Hflag) {
1825 for(loop =0; loop < (u32_width_out+u8Wflag); loop++) {
1826 *pu8_data_out++ = (M4VIFI_UInt8)*pu8dum++;
1827 }
1828 }
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08001829 }
1830
1831 return M4VIFI_OK;
1832}
1833
1834M4OSA_ERR applyRenderingMode(M4VIFI_ImagePlane* pPlaneIn, M4VIFI_ImagePlane* pPlaneOut, M4xVSS_MediaRendering mediaRendering)
1835{
1836 M4OSA_ERR err = M4NO_ERROR;
1837
1838 if(mediaRendering == M4xVSS_kResizing)
1839 {
1840 /**
1841 * Call the resize filter. From the intermediate frame to the encoder image plane */
1842 err = M4VIFI_ResizeBilinearYUV420toYUV420(M4OSA_NULL, pPlaneIn, pPlaneOut);
1843 if (M4NO_ERROR != err)
1844 {
1845 M4OSA_TRACE1_1("applyRenderingMode: M4ViFilResizeBilinearYUV420toYUV420 returns 0x%x!", err);
1846 return err;
1847 }
1848 }
1849 else
1850 {
1851 M4AIR_Params Params;
1852 M4OSA_Context m_air_context;
1853 M4VIFI_ImagePlane pImagePlanesTemp[3];
1854 M4VIFI_ImagePlane* pPlaneTemp;
1855 M4OSA_UInt8* pOutPlaneY = pPlaneOut[0].pac_data + pPlaneOut[0].u_topleft;
1856 M4OSA_UInt8* pOutPlaneU = pPlaneOut[1].pac_data + pPlaneOut[1].u_topleft;
1857 M4OSA_UInt8* pOutPlaneV = pPlaneOut[2].pac_data + pPlaneOut[2].u_topleft;
1858 M4OSA_UInt8* pInPlaneY;
1859 M4OSA_UInt8* pInPlaneU;
1860 M4OSA_UInt8* pInPlaneV;
1861 M4OSA_UInt32 i;
1862
1863 /*to keep media aspect ratio*/
1864 /*Initialize AIR Params*/
1865 Params.m_inputCoord.m_x = 0;
1866 Params.m_inputCoord.m_y = 0;
1867 Params.m_inputSize.m_height = pPlaneIn->u_height;
1868 Params.m_inputSize.m_width = pPlaneIn->u_width;
1869 Params.m_outputSize.m_width = pPlaneOut->u_width;
1870 Params.m_outputSize.m_height = pPlaneOut->u_height;
1871 Params.m_bOutputStripe = M4OSA_FALSE;
1872 Params.m_outputOrientation = M4COMMON_kOrientationTopLeft;
1873
1874 /**
1875 Media rendering: Black borders*/
1876 if(mediaRendering == M4xVSS_kBlackBorders)
1877 {
1878 M4OSA_memset((M4OSA_MemAddr8)pPlaneOut[0].pac_data,(pPlaneOut[0].u_height*pPlaneOut[0].u_stride),Y_PLANE_BORDER_VALUE);
1879 M4OSA_memset((M4OSA_MemAddr8)pPlaneOut[1].pac_data,(pPlaneOut[1].u_height*pPlaneOut[1].u_stride),U_PLANE_BORDER_VALUE);
1880 M4OSA_memset((M4OSA_MemAddr8)pPlaneOut[2].pac_data,(pPlaneOut[2].u_height*pPlaneOut[2].u_stride),V_PLANE_BORDER_VALUE);
1881
1882 pImagePlanesTemp[0].u_width = pPlaneOut[0].u_width;
1883 pImagePlanesTemp[0].u_height = pPlaneOut[0].u_height;
1884 pImagePlanesTemp[0].u_stride = pPlaneOut[0].u_width;
1885 pImagePlanesTemp[0].u_topleft = 0;
1886 pImagePlanesTemp[0].pac_data = M4OSA_NULL;
1887
1888 pImagePlanesTemp[1].u_width = pPlaneOut[1].u_width;
1889 pImagePlanesTemp[1].u_height = pPlaneOut[1].u_height;
1890 pImagePlanesTemp[1].u_stride = pPlaneOut[1].u_width;
1891 pImagePlanesTemp[1].u_topleft = 0;
1892 pImagePlanesTemp[1].pac_data = M4OSA_NULL;
1893
1894 pImagePlanesTemp[2].u_width = pPlaneOut[2].u_width;
1895 pImagePlanesTemp[2].u_height = pPlaneOut[2].u_height;
1896 pImagePlanesTemp[2].u_stride = pPlaneOut[2].u_width;
1897 pImagePlanesTemp[2].u_topleft = 0;
1898 pImagePlanesTemp[2].pac_data = M4OSA_NULL;
1899
1900 /* Allocates plan in local image plane structure */
1901 pImagePlanesTemp[0].pac_data = (M4OSA_UInt8*)M4OSA_malloc(pImagePlanesTemp[0].u_width * pImagePlanesTemp[0].u_height, M4VS, (M4OSA_Char*)"applyRenderingMode: temporary plane bufferY") ;
1902 if(pImagePlanesTemp[0].pac_data == M4OSA_NULL)
1903 {
1904 M4OSA_TRACE1_0("Error alloc in applyRenderingMode");
1905 return M4ERR_ALLOC;
1906 }
1907 pImagePlanesTemp[1].pac_data = (M4OSA_UInt8*)M4OSA_malloc(pImagePlanesTemp[1].u_width * pImagePlanesTemp[1].u_height, M4VS, (M4OSA_Char*)"applyRenderingMode: temporary plane bufferU") ;
1908 if(pImagePlanesTemp[1].pac_data == M4OSA_NULL)
1909 {
1910
1911 M4OSA_TRACE1_0("Error alloc in applyRenderingMode");
1912 return M4ERR_ALLOC;
1913 }
1914 pImagePlanesTemp[2].pac_data = (M4OSA_UInt8*)M4OSA_malloc(pImagePlanesTemp[2].u_width * pImagePlanesTemp[2].u_height, M4VS, (M4OSA_Char*)"applyRenderingMode: temporary plane bufferV") ;
1915 if(pImagePlanesTemp[2].pac_data == M4OSA_NULL)
1916 {
1917
1918 M4OSA_TRACE1_0("Error alloc in applyRenderingMode");
1919 return M4ERR_ALLOC;
1920 }
1921
1922 pInPlaneY = pImagePlanesTemp[0].pac_data ;
1923 pInPlaneU = pImagePlanesTemp[1].pac_data ;
1924 pInPlaneV = pImagePlanesTemp[2].pac_data ;
1925
1926 M4OSA_memset((M4OSA_MemAddr8)pImagePlanesTemp[0].pac_data,(pImagePlanesTemp[0].u_height*pImagePlanesTemp[0].u_stride),Y_PLANE_BORDER_VALUE);
1927 M4OSA_memset((M4OSA_MemAddr8)pImagePlanesTemp[1].pac_data,(pImagePlanesTemp[1].u_height*pImagePlanesTemp[1].u_stride),U_PLANE_BORDER_VALUE);
1928 M4OSA_memset((M4OSA_MemAddr8)pImagePlanesTemp[2].pac_data,(pImagePlanesTemp[2].u_height*pImagePlanesTemp[2].u_stride),V_PLANE_BORDER_VALUE);
1929
1930 if((M4OSA_UInt32)((pPlaneIn->u_height * pPlaneOut->u_width) /pPlaneIn->u_width) <= pPlaneOut->u_height)//Params.m_inputSize.m_height < Params.m_inputSize.m_width)
1931 {
1932 /*it is height so black borders will be on the top and on the bottom side*/
1933 Params.m_outputSize.m_width = pPlaneOut->u_width;
1934 Params.m_outputSize.m_height = (M4OSA_UInt32)((pPlaneIn->u_height * pPlaneOut->u_width) /pPlaneIn->u_width);
1935 /*number of lines at the top*/
1936 pImagePlanesTemp[0].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[0].u_height-Params.m_outputSize.m_height)>>1))*pImagePlanesTemp[0].u_stride;
1937 pImagePlanesTemp[0].u_height = Params.m_outputSize.m_height;
1938 pImagePlanesTemp[1].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[1].u_height-(Params.m_outputSize.m_height>>1)))>>1)*pImagePlanesTemp[1].u_stride;
1939 pImagePlanesTemp[1].u_height = Params.m_outputSize.m_height>>1;
1940 pImagePlanesTemp[2].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[2].u_height-(Params.m_outputSize.m_height>>1)))>>1)*pImagePlanesTemp[2].u_stride;
1941 pImagePlanesTemp[2].u_height = Params.m_outputSize.m_height>>1;
1942 }
1943 else
1944 {
1945 /*it is width so black borders will be on the left and right side*/
1946 Params.m_outputSize.m_height = pPlaneOut->u_height;
1947 Params.m_outputSize.m_width = (M4OSA_UInt32)((pPlaneIn->u_width * pPlaneOut->u_height) /pPlaneIn->u_height);
1948
1949 pImagePlanesTemp[0].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[0].u_width-Params.m_outputSize.m_width)>>1));
1950 pImagePlanesTemp[0].u_width = Params.m_outputSize.m_width;
1951 pImagePlanesTemp[1].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[1].u_width-(Params.m_outputSize.m_width>>1)))>>1);
1952 pImagePlanesTemp[1].u_width = Params.m_outputSize.m_width>>1;
1953 pImagePlanesTemp[2].u_topleft = (M4xVSS_ABS((M4OSA_Int32)(pImagePlanesTemp[2].u_width-(Params.m_outputSize.m_width>>1)))>>1);
1954 pImagePlanesTemp[2].u_width = Params.m_outputSize.m_width>>1;
1955 }
1956
1957 /*Width and height have to be even*/
1958 Params.m_outputSize.m_width = (Params.m_outputSize.m_width>>1)<<1;
1959 Params.m_outputSize.m_height = (Params.m_outputSize.m_height>>1)<<1;
1960 Params.m_inputSize.m_width = (Params.m_inputSize.m_width>>1)<<1;
1961 Params.m_inputSize.m_height = (Params.m_inputSize.m_height>>1)<<1;
1962 pImagePlanesTemp[0].u_width = (pImagePlanesTemp[0].u_width>>1)<<1;
1963 pImagePlanesTemp[1].u_width = (pImagePlanesTemp[1].u_width>>1)<<1;
1964 pImagePlanesTemp[2].u_width = (pImagePlanesTemp[2].u_width>>1)<<1;
1965 pImagePlanesTemp[0].u_height = (pImagePlanesTemp[0].u_height>>1)<<1;
1966 pImagePlanesTemp[1].u_height = (pImagePlanesTemp[1].u_height>>1)<<1;
1967 pImagePlanesTemp[2].u_height = (pImagePlanesTemp[2].u_height>>1)<<1;
1968
1969 /*Check that values are coherent*/
1970 if(Params.m_inputSize.m_height == Params.m_outputSize.m_height)
1971 {
1972 Params.m_inputSize.m_width = Params.m_outputSize.m_width;
1973 }
1974 else if(Params.m_inputSize.m_width == Params.m_outputSize.m_width)
1975 {
1976 Params.m_inputSize.m_height = Params.m_outputSize.m_height;
1977 }
1978 pPlaneTemp = pImagePlanesTemp;
1979
1980
1981 }
1982
1983 /**
1984 Media rendering: Cropping*/
1985 if(mediaRendering == M4xVSS_kCropping)
1986 {
1987 Params.m_outputSize.m_height = pPlaneOut->u_height;
1988 Params.m_outputSize.m_width = pPlaneOut->u_width;
1989 if((Params.m_outputSize.m_height * Params.m_inputSize.m_width) /Params.m_outputSize.m_width<Params.m_inputSize.m_height)
1990 {
1991 /*height will be cropped*/
1992 Params.m_inputSize.m_height = (M4OSA_UInt32)((Params.m_outputSize.m_height * Params.m_inputSize.m_width) /Params.m_outputSize.m_width);
1993 Params.m_inputSize.m_height = (Params.m_inputSize.m_height>>1)<<1;
1994 Params.m_inputCoord.m_y = (M4OSA_Int32)((M4OSA_Int32)((pPlaneIn->u_height - Params.m_inputSize.m_height))>>1);
1995 }
1996 else
1997 {
1998 /*width will be cropped*/
1999 Params.m_inputSize.m_width = (M4OSA_UInt32)((Params.m_outputSize.m_width * Params.m_inputSize.m_height) /Params.m_outputSize.m_height);
2000 Params.m_inputSize.m_width = (Params.m_inputSize.m_width>>1)<<1;
2001 Params.m_inputCoord.m_x = (M4OSA_Int32)((M4OSA_Int32)((pPlaneIn->u_width - Params.m_inputSize.m_width))>>1);
2002 }
2003 pPlaneTemp = pPlaneOut;
2004 }
2005
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002006 /**
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002007 * Call AIR functions */
2008 err = M4AIR_create(&m_air_context, M4AIR_kYUV420P);
2009 if(err != M4NO_ERROR)
2010 {
2011
2012 M4OSA_TRACE1_1("applyRenderingMode: Error when initializing AIR: 0x%x", err);
2013 for(i=0; i<3; i++)
2014 {
2015 if(pImagePlanesTemp[i].pac_data != M4OSA_NULL)
2016 {
2017 M4OSA_free((M4OSA_MemAddr32)pImagePlanesTemp[i].pac_data);
2018 pImagePlanesTemp[i].pac_data = M4OSA_NULL;
2019 }
2020 }
2021 return err;
2022 }
2023
2024
2025 err = M4AIR_configure(m_air_context, &Params);
2026 if(err != M4NO_ERROR)
2027 {
2028
2029 M4OSA_TRACE1_1("applyRenderingMode: Error when configuring AIR: 0x%x", err);
2030 M4AIR_cleanUp(m_air_context);
2031 for(i=0; i<3; i++)
2032 {
2033 if(pImagePlanesTemp[i].pac_data != M4OSA_NULL)
2034 {
2035 M4OSA_free((M4OSA_MemAddr32)pImagePlanesTemp[i].pac_data);
2036 pImagePlanesTemp[i].pac_data = M4OSA_NULL;
2037 }
2038 }
2039 return err;
2040 }
2041
2042 err = M4AIR_get(m_air_context, pPlaneIn, pPlaneTemp);
2043 if(err != M4NO_ERROR)
2044 {
2045 M4OSA_TRACE1_1("applyRenderingMode: Error when getting AIR plane: 0x%x", err);
2046 M4AIR_cleanUp(m_air_context);
2047 for(i=0; i<3; i++)
2048 {
2049 if(pImagePlanesTemp[i].pac_data != M4OSA_NULL)
2050 {
2051 M4OSA_free((M4OSA_MemAddr32)pImagePlanesTemp[i].pac_data);
2052 pImagePlanesTemp[i].pac_data = M4OSA_NULL;
2053 }
2054 }
2055 return err;
2056 }
2057
2058 if(mediaRendering == M4xVSS_kBlackBorders)
2059 {
2060 for(i=0; i<pPlaneOut[0].u_height; i++)
2061 {
2062 M4OSA_memcpy((M4OSA_MemAddr8)pOutPlaneY, (M4OSA_MemAddr8)pInPlaneY, pPlaneOut[0].u_width);
2063 pInPlaneY += pPlaneOut[0].u_width;
2064 pOutPlaneY += pPlaneOut[0].u_stride;
2065 }
2066 for(i=0; i<pPlaneOut[1].u_height; i++)
2067 {
2068 M4OSA_memcpy((M4OSA_MemAddr8)pOutPlaneU, (M4OSA_MemAddr8)pInPlaneU, pPlaneOut[1].u_width);
2069 pInPlaneU += pPlaneOut[1].u_width;
2070 pOutPlaneU += pPlaneOut[1].u_stride;
2071 }
2072 for(i=0; i<pPlaneOut[2].u_height; i++)
2073 {
2074 M4OSA_memcpy((M4OSA_MemAddr8)pOutPlaneV, (M4OSA_MemAddr8)pInPlaneV, pPlaneOut[2].u_width);
2075 pInPlaneV += pPlaneOut[2].u_width;
2076 pOutPlaneV += pPlaneOut[2].u_stride;
2077 }
2078
2079 for(i=0; i<3; i++)
2080 {
2081 if(pImagePlanesTemp[i].pac_data != M4OSA_NULL)
2082 {
2083 M4OSA_free((M4OSA_MemAddr32)pImagePlanesTemp[i].pac_data);
2084 pImagePlanesTemp[i].pac_data = M4OSA_NULL;
2085 }
2086 }
2087 }
2088 }
2089
2090 return err;
2091}
2092
2093//TODO: remove this code after link with videoartist lib
2094/* M4AIR code*/
2095#define M4AIR_YUV420_FORMAT_SUPPORTED
2096#define M4AIR_YUV420A_FORMAT_SUPPORTED
2097
2098/************************* COMPILATION CHECKS ***************************/
2099#ifndef M4AIR_YUV420_FORMAT_SUPPORTED
2100#ifndef M4AIR_BGR565_FORMAT_SUPPORTED
2101#ifndef M4AIR_RGB565_FORMAT_SUPPORTED
2102#ifndef M4AIR_BGR888_FORMAT_SUPPORTED
2103#ifndef M4AIR_RGB888_FORMAT_SUPPORTED
2104#ifndef M4AIR_JPG_FORMAT_SUPPORTED
2105
2106#error "Please define at least one input format for the AIR component"
2107
2108#endif
2109#endif
2110#endif
2111#endif
2112#endif
2113#endif
2114
2115/************************ M4AIR INTERNAL TYPES DEFINITIONS ***********************/
2116
2117/**
2118 ******************************************************************************
2119 * enum M4AIR_States
2120 * @brief The following enumeration defines the internal states of the AIR.
2121 ******************************************************************************
2122*/
2123typedef enum
2124{
2125 M4AIR_kCreated, /**< State after M4AIR_create has been called */
2126 M4AIR_kConfigured /**< State after M4AIR_configure has been called */
2127}M4AIR_States;
2128
2129
2130/**
2131 ******************************************************************************
2132 * struct M4AIR_InternalContext
2133 * @brief The following structure is the internal context of the AIR.
2134 ******************************************************************************
2135*/
2136typedef struct
2137{
2138 M4AIR_States m_state; /**< Internal state */
2139 M4AIR_InputFormatType m_inputFormat; /**< Input format like YUV420Planar, RGB565, JPG, etc ... */
2140 M4AIR_Params m_params; /**< Current input Parameter of the processing */
2141 M4OSA_UInt32 u32_x_inc[4]; /**< ratio between input and ouput width for YUV */
2142 M4OSA_UInt32 u32_y_inc[4]; /**< ratio between input and ouput height for YUV */
2143 M4OSA_UInt32 u32_x_accum_start[4]; /**< horizontal initial accumulator value */
2144 M4OSA_UInt32 u32_y_accum_start[4]; /**< Vertical initial accumulator value */
2145 M4OSA_UInt32 u32_x_accum[4]; /**< save of horizontal accumulator value */
2146 M4OSA_UInt32 u32_y_accum[4]; /**< save of vertical accumulator value */
2147 M4OSA_UInt8* pu8_data_in[4]; /**< Save of input plane pointers in case of stripe mode */
2148 M4OSA_UInt32 m_procRows; /**< Number of processed rows, used in stripe mode only */
2149 M4OSA_Bool m_bOnlyCopy; /**< Flag to know if we just perform a copy or a bilinear interpolation */
2150 M4OSA_Bool m_bFlipX; /**< Depend on output orientation, used during processing to revert processing order in X coordinates */
2151 M4OSA_Bool m_bFlipY; /**< Depend on output orientation, used during processing to revert processing order in Y coordinates */
2152 M4OSA_Bool m_bRevertXY; /**< Depend on output orientation, used during processing to revert X and Y processing order (+-90° rotation) */
2153}M4AIR_InternalContext;
2154
2155/********************************* MACROS *******************************/
2156#define M4ERR_CHECK_NULL_RETURN_VALUE(retval, pointer) if ((pointer) == M4OSA_NULL) return ((M4OSA_ERR)(retval));
2157
2158
2159/********************** M4AIR PUBLIC API IMPLEMENTATION ********************/
2160/**
2161 ******************************************************************************
2162 * M4OSA_ERR M4AIR_create(M4OSA_Context* pContext,M4AIR_InputFormatType inputFormat)
2163 * @author Arnaud Collard
2164 * @brief This function initialize an instance of the AIR.
2165 * @param pContext: (IN/OUT) Address of the context to create
2166 * @param inputFormat: (IN) input format type.
2167 * @return M4NO_ERROR: there is no error
2168 * @return M4ERR_PARAMETER: pContext is M4OSA_NULL (debug only). Invalid formatType
2169 * @return M4ERR_ALLOC: No more memory is available
2170 ******************************************************************************
2171*/
2172M4OSA_ERR M4AIR_create(M4OSA_Context* pContext,M4AIR_InputFormatType inputFormat)
2173{
2174 M4OSA_ERR err = M4NO_ERROR ;
2175 M4AIR_InternalContext* pC = M4OSA_NULL ;
2176 /* Check that the address on the context is not NULL */
2177 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext) ;
2178
2179 *pContext = M4OSA_NULL ;
2180
2181 /* Internal Context creation */
2182 pC = (M4AIR_InternalContext*)M4OSA_malloc(sizeof(M4AIR_InternalContext), M4AIR, (M4OSA_Char*)"AIR internal context") ;
2183 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_ALLOC, pC) ;
2184
2185
2186 /* Check if the input format is supported */
2187 switch(inputFormat)
2188 {
2189#ifdef M4AIR_YUV420_FORMAT_SUPPORTED
2190 case M4AIR_kYUV420P:
2191 break ;
2192#endif
2193#ifdef M4AIR_YUV420A_FORMAT_SUPPORTED
2194 case M4AIR_kYUV420AP:
2195 break ;
2196#endif
2197 default:
2198 err = M4ERR_AIR_FORMAT_NOT_SUPPORTED;
2199 goto M4AIR_create_cleanup ;
2200 }
2201
2202 /**< Save input format and update state */
2203 pC->m_inputFormat = inputFormat;
2204 pC->m_state = M4AIR_kCreated;
2205
2206 /* Return the context to the caller */
2207 *pContext = pC ;
2208
2209 return M4NO_ERROR ;
2210
2211M4AIR_create_cleanup:
2212 /* Error management : we destroy the context if needed */
2213 if(M4OSA_NULL != pC)
2214 {
2215 M4OSA_free((M4OSA_MemAddr32)pC) ;
2216 }
2217
2218 *pContext = M4OSA_NULL ;
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08002219
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002220 return err ;
2221}
2222
2223
2224
2225/**
2226 ******************************************************************************
2227 * M4OSA_ERR M4AIR_cleanUp(M4OSA_Context pContext)
2228 * @author Arnaud Collard
2229 * @brief This function destroys an instance of the AIR component
2230 * @param pContext: (IN) Context identifying the instance to destroy
2231 * @return M4NO_ERROR: there is no error
2232 * @return M4ERR_PARAMETER: pContext is M4OSA_NULL (debug only).
2233 * @return M4ERR_STATE: Internal state is incompatible with this function call.
2234******************************************************************************
2235*/
2236M4OSA_ERR M4AIR_cleanUp(M4OSA_Context pContext)
2237{
2238 M4AIR_InternalContext* pC = (M4AIR_InternalContext*)pContext ;
2239
2240 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext) ;
2241
2242 /**< Check state */
2243 if((M4AIR_kCreated != pC->m_state)&&(M4AIR_kConfigured != pC->m_state))
2244 {
2245 return M4ERR_STATE;
2246 }
2247 M4OSA_free((M4OSA_MemAddr32)pC) ;
2248
2249 return M4NO_ERROR ;
2250
2251}
2252
2253
2254/**
2255 ******************************************************************************
2256 * M4OSA_ERR M4AIR_configure(M4OSA_Context pContext, M4AIR_Params* pParams)
2257 * @brief This function will configure the AIR.
2258 * @note It will set the input and output coordinates and sizes,
2259 * and indicates if we will proceed in stripe or not.
2260 * In case a M4AIR_get in stripe mode was on going, it will cancel this previous processing
2261 * and reset the get process.
2262 * @param pContext: (IN) Context identifying the instance
2263 * @param pParams->m_bOutputStripe:(IN) Stripe mode.
2264 * @param pParams->m_inputCoord: (IN) X,Y coordinates of the first valid pixel in input.
2265 * @param pParams->m_inputSize: (IN) input ROI size.
2266 * @param pParams->m_outputSize: (IN) output size.
2267 * @return M4NO_ERROR: there is no error
2268 * @return M4ERR_ALLOC: No more memory space to add a new effect.
2269 * @return M4ERR_PARAMETER: pContext is M4OSA_NULL (debug only).
2270 * @return M4ERR_AIR_FORMAT_NOT_SUPPORTED: the requested input format is not supported.
2271 ******************************************************************************
2272*/
2273M4OSA_ERR M4AIR_configure(M4OSA_Context pContext, M4AIR_Params* pParams)
2274{
2275 M4AIR_InternalContext* pC = (M4AIR_InternalContext*)pContext ;
2276 M4OSA_UInt32 i,u32_width_in, u32_width_out, u32_height_in, u32_height_out;
2277 M4OSA_UInt32 nb_planes;
2278
2279 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext) ;
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08002280
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002281 if(M4AIR_kYUV420AP == pC->m_inputFormat)
2282 {
2283 nb_planes = 4;
2284 }
2285 else
2286 {
2287 nb_planes = 3;
2288 }
2289
2290 /**< Check state */
2291 if((M4AIR_kCreated != pC->m_state)&&(M4AIR_kConfigured != pC->m_state))
2292 {
2293 return M4ERR_STATE;
2294 }
2295
2296 /** Save parameters */
2297 pC->m_params = *pParams;
2298
2299 /* Check for the input&output width and height are even */
2300 if( ((pC->m_params.m_inputSize.m_height)&0x1) ||
2301 ((pC->m_params.m_inputSize.m_height)&0x1))
2302 {
2303 return M4ERR_AIR_ILLEGAL_FRAME_SIZE;
2304 }
2305
2306 if( ((pC->m_params.m_inputSize.m_width)&0x1) ||
2307 ((pC->m_params.m_inputSize.m_width)&0x1))
2308 {
2309 return M4ERR_AIR_ILLEGAL_FRAME_SIZE;
2310 }
2311 if(((pC->m_params.m_inputSize.m_width) == (pC->m_params.m_outputSize.m_width))
2312 &&((pC->m_params.m_inputSize.m_height) == (pC->m_params.m_outputSize.m_height)))
2313 {
2314 /**< No resize in this case, we will just copy input in output */
2315 pC->m_bOnlyCopy = M4OSA_TRUE;
2316 }
2317 else
2318 {
2319 pC->m_bOnlyCopy = M4OSA_FALSE;
2320
2321 /**< Initialize internal variables used for resize filter */
2322 for(i=0;i<nb_planes;i++)
2323 {
2324
2325 u32_width_in = ((i==0)||(i==3))?pC->m_params.m_inputSize.m_width:(pC->m_params.m_inputSize.m_width+1)>>1;
2326 u32_height_in = ((i==0)||(i==3))?pC->m_params.m_inputSize.m_height:(pC->m_params.m_inputSize.m_height+1)>>1;
2327 u32_width_out = ((i==0)||(i==3))?pC->m_params.m_outputSize.m_width:(pC->m_params.m_outputSize.m_width+1)>>1;
2328 u32_height_out = ((i==0)||(i==3))?pC->m_params.m_outputSize.m_height:(pC->m_params.m_outputSize.m_height+1)>>1;
2329
2330 /* Compute horizontal ratio between src and destination width.*/
2331 if (u32_width_out >= u32_width_in)
2332 {
2333 pC->u32_x_inc[i] = ((u32_width_in-1) * 0x10000) / (u32_width_out-1);
2334 }
2335 else
2336 {
2337 pC->u32_x_inc[i] = (u32_width_in * 0x10000) / (u32_width_out);
2338 }
2339
2340 /* Compute vertical ratio between src and destination height.*/
2341 if (u32_height_out >= u32_height_in)
2342 {
2343 pC->u32_y_inc[i] = ((u32_height_in - 1) * 0x10000) / (u32_height_out-1);
2344 }
2345 else
2346 {
2347 pC->u32_y_inc[i] = (u32_height_in * 0x10000) / (u32_height_out);
2348 }
2349
2350 /*
2351 Calculate initial accumulator value : u32_y_accum_start.
2352 u32_y_accum_start is coded on 15 bits, and represents a value between 0 and 0.5
2353 */
2354 if (pC->u32_y_inc[i] >= 0x10000)
2355 {
2356 /*
2357 Keep the fractionnal part, assimung that integer part is coded
2358 on the 16 high bits and the fractionnal on the 15 low bits
2359 */
2360 pC->u32_y_accum_start[i] = pC->u32_y_inc[i] & 0xffff;
2361
2362 if (!pC->u32_y_accum_start[i])
2363 {
2364 pC->u32_y_accum_start[i] = 0x10000;
2365 }
2366
2367 pC->u32_y_accum_start[i] >>= 1;
2368 }
2369 else
2370 {
2371 pC->u32_y_accum_start[i] = 0;
2372 }
2373 /**< Take into account that Y coordinate can be odd
2374 in this case we have to put a 0.5 offset
2375 for U and V plane as there a 2 times sub-sampled vs Y*/
2376 if((pC->m_params.m_inputCoord.m_y&0x1)&&((i==1)||(i==2)))
2377 {
2378 pC->u32_y_accum_start[i] += 0x8000;
2379 }
2380
2381 /*
2382 Calculate initial accumulator value : u32_x_accum_start.
2383 u32_x_accum_start is coded on 15 bits, and represents a value between 0 and 0.5
2384 */
2385
2386 if (pC->u32_x_inc[i] >= 0x10000)
2387 {
2388 pC->u32_x_accum_start[i] = pC->u32_x_inc[i] & 0xffff;
2389
2390 if (!pC->u32_x_accum_start[i])
2391 {
2392 pC->u32_x_accum_start[i] = 0x10000;
2393 }
2394
2395 pC->u32_x_accum_start[i] >>= 1;
2396 }
2397 else
2398 {
2399 pC->u32_x_accum_start[i] = 0;
2400 }
2401 /**< Take into account that X coordinate can be odd
2402 in this case we have to put a 0.5 offset
2403 for U and V plane as there a 2 times sub-sampled vs Y*/
2404 if((pC->m_params.m_inputCoord.m_x&0x1)&&((i==1)||(i==2)))
2405 {
2406 pC->u32_x_accum_start[i] += 0x8000;
2407 }
2408 }
2409 }
2410
2411 /**< Reset variable used for stripe mode */
2412 pC->m_procRows = 0;
2413
2414 /**< Initialize var for X/Y processing order according to orientation */
2415 pC->m_bFlipX = M4OSA_FALSE;
2416 pC->m_bFlipY = M4OSA_FALSE;
2417 pC->m_bRevertXY = M4OSA_FALSE;
2418 switch(pParams->m_outputOrientation)
2419 {
2420 case M4COMMON_kOrientationTopLeft:
2421 break;
2422 case M4COMMON_kOrientationTopRight:
2423 pC->m_bFlipX = M4OSA_TRUE;
2424 break;
2425 case M4COMMON_kOrientationBottomRight:
2426 pC->m_bFlipX = M4OSA_TRUE;
2427 pC->m_bFlipY = M4OSA_TRUE;
2428 break;
2429 case M4COMMON_kOrientationBottomLeft:
2430 pC->m_bFlipY = M4OSA_TRUE;
2431 break;
2432 case M4COMMON_kOrientationLeftTop:
2433 pC->m_bRevertXY = M4OSA_TRUE;
2434 break;
2435 case M4COMMON_kOrientationRightTop:
2436 pC->m_bRevertXY = M4OSA_TRUE;
2437 pC->m_bFlipY = M4OSA_TRUE;
2438 break;
2439 case M4COMMON_kOrientationRightBottom:
2440 pC->m_bRevertXY = M4OSA_TRUE;
2441 pC->m_bFlipX = M4OSA_TRUE;
2442 pC->m_bFlipY = M4OSA_TRUE;
2443 break;
2444 case M4COMMON_kOrientationLeftBottom:
2445 pC->m_bRevertXY = M4OSA_TRUE;
2446 pC->m_bFlipX = M4OSA_TRUE;
2447 break;
2448 default:
2449 return M4ERR_PARAMETER;
2450 }
2451 /**< Update state */
2452 pC->m_state = M4AIR_kConfigured;
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08002453
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002454 return M4NO_ERROR ;
2455}
2456
2457
2458/**
2459 ******************************************************************************
2460 * M4OSA_ERR M4AIR_get(M4OSA_Context pContext, M4VIFI_ImagePlane* pIn, M4VIFI_ImagePlane* pOut)
2461 * @brief This function will provide the requested resized area of interest according to settings
2462 * provided in M4AIR_configure.
2463 * @note In case the input format type is JPEG, input plane(s)
2464 * in pIn is not used. In normal mode, dimension specified in output plane(s) structure must be the
2465 * same than the one specified in M4AIR_configure. In stripe mode, only the width will be the same,
2466 * height will be taken as the stripe height (typically 16).
2467 * In normal mode, this function is call once to get the full output picture. In stripe mode, it is called
2468 * for each stripe till the whole picture has been retrieved,and the position of the output stripe in the output picture
2469 * is internally incremented at each step.
2470 * Any call to M4AIR_configure during stripe process will reset this one to the beginning of the output picture.
2471 * @param pContext: (IN) Context identifying the instance
2472 * @param pIn: (IN) Plane structure containing input Plane(s).
2473 * @param pOut: (IN/OUT) Plane structure containing output Plane(s).
2474 * @return M4NO_ERROR: there is no error
2475 * @return M4ERR_ALLOC: No more memory space to add a new effect.
2476 * @return M4ERR_PARAMETER: pContext is M4OSA_NULL (debug only).
2477 ******************************************************************************
2478*/
2479M4OSA_ERR M4AIR_get(M4OSA_Context pContext, M4VIFI_ImagePlane* pIn, M4VIFI_ImagePlane* pOut)
2480{
2481 M4AIR_InternalContext* pC = (M4AIR_InternalContext*)pContext ;
2482 M4OSA_UInt32 i,j,k,u32_x_frac,u32_y_frac,u32_x_accum,u32_y_accum,u32_shift;
2483 M4OSA_UInt8 *pu8_data_in, *pu8_data_in_org, *pu8_data_in_tmp, *pu8_data_out;
2484 M4OSA_UInt8 *pu8_src_top;
2485 M4OSA_UInt8 *pu8_src_bottom;
2486 M4OSA_UInt32 u32_temp_value;
2487 M4OSA_Int32 i32_tmp_offset;
2488 M4OSA_UInt32 nb_planes;
2489
2490
2491
2492 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext) ;
2493
2494 /**< Check state */
2495 if(M4AIR_kConfigured != pC->m_state)
2496 {
2497 return M4ERR_STATE;
2498 }
2499
2500 if(M4AIR_kYUV420AP == pC->m_inputFormat)
2501 {
2502 nb_planes = 4;
2503 }
2504 else
2505 {
2506 nb_planes = 3;
2507 }
2508
2509 /**< Loop on each Plane */
2510 for(i=0;i<nb_planes;i++)
2511 {
2512
2513 /* Set the working pointers at the beginning of the input/output data field */
2514
2515 u32_shift = ((i==0)||(i==3))?0:1; /**< Depend on Luma or Chroma */
2516
2517 if((M4OSA_FALSE == pC->m_params.m_bOutputStripe)||((M4OSA_TRUE == pC->m_params.m_bOutputStripe)&&(0 == pC->m_procRows)))
2518 {
2519 /**< For input, take care about ROI */
2520 pu8_data_in = pIn[i].pac_data + pIn[i].u_topleft + (pC->m_params.m_inputCoord.m_x>>u32_shift)
2521 + (pC->m_params.m_inputCoord.m_y >> u32_shift) * pIn[i].u_stride;
2522
2523 /** Go at end of line/column in case X/Y scanning is flipped */
2524 if(M4OSA_TRUE == pC->m_bFlipX)
2525 {
2526 pu8_data_in += ((pC->m_params.m_inputSize.m_width)>>u32_shift) -1 ;
2527 }
2528 if(M4OSA_TRUE == pC->m_bFlipY)
2529 {
2530 pu8_data_in += ((pC->m_params.m_inputSize.m_height>>u32_shift) -1) * pIn[i].u_stride;
2531 }
2532
2533 /**< Initialize accumulators in case we are using it (bilinear interpolation) */
2534 if( M4OSA_FALSE == pC->m_bOnlyCopy)
2535 {
2536 pC->u32_x_accum[i] = pC->u32_x_accum_start[i];
2537 pC->u32_y_accum[i] = pC->u32_y_accum_start[i];
2538 }
2539
2540 }
2541 else
2542 {
2543 /**< In case of stripe mode for other than first stripe, we need to recover input pointer from internal context */
2544 pu8_data_in = pC->pu8_data_in[i];
2545 }
2546
2547 /**< In every mode, output data are at the beginning of the output plane */
2548 pu8_data_out = pOut[i].pac_data + pOut[i].u_topleft;
2549
2550 /**< Initialize input offset applied after each pixel */
2551 if(M4OSA_FALSE == pC->m_bFlipY)
2552 {
2553 i32_tmp_offset = pIn[i].u_stride;
2554 }
2555 else
2556 {
2557 i32_tmp_offset = -pIn[i].u_stride;
2558 }
2559
2560 /**< In this case, no bilinear interpolation is needed as input and output dimensions are the same */
2561 if( M4OSA_TRUE == pC->m_bOnlyCopy)
2562 {
2563 /**< No +-90° rotation */
2564 if(M4OSA_FALSE == pC->m_bRevertXY)
2565 {
2566 /**< No flip on X abscissa */
2567 if(M4OSA_FALSE == pC->m_bFlipX)
2568 {
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002569 M4OSA_UInt32 loc_height = pOut[i].u_height;
2570 M4OSA_UInt32 loc_width = pOut[i].u_width;
2571 M4OSA_UInt32 loc_stride = pIn[i].u_stride;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002572 /**< Loop on each row */
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002573 for (j=0; j<loc_height; j++)
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002574 {
2575 /**< Copy one whole line */
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002576 memcpy((M4OSA_MemAddr8)pu8_data_out, (M4OSA_MemAddr8)pu8_data_in, loc_width);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002577
2578 /**< Update pointers */
2579 pu8_data_out += pOut[i].u_stride;
2580 if(M4OSA_FALSE == pC->m_bFlipY)
2581 {
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002582 pu8_data_in += loc_stride;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002583 }
2584 else
2585 {
Dharmaray Kundargi4f155f02011-02-01 19:16:43 -08002586 pu8_data_in -= loc_stride;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08002587 }
2588 }
2589 }
2590 else
2591 {
2592 /**< Loop on each row */
2593 for(j=0;j<pOut[i].u_height;j++)
2594 {
2595 /**< Loop on each pixel of 1 row */
2596 for(k=0;k<pOut[i].u_width;k++)
2597 {
2598 *pu8_data_out++ = *pu8_data_in--;
2599 }
2600
2601 /**< Update pointers */
2602 pu8_data_out += (pOut[i].u_stride - pOut[i].u_width);
2603
2604 pu8_data_in += pOut[i].u_width + i32_tmp_offset;
2605
2606 }
2607 }
2608 }
2609 /**< Here we have a +-90° rotation */
2610 else
2611 {
2612
2613 /**< Loop on each row */
2614 for(j=0;j<pOut[i].u_height;j++)
2615 {
2616 pu8_data_in_tmp = pu8_data_in;
2617
2618 /**< Loop on each pixel of 1 row */
2619 for(k=0;k<pOut[i].u_width;k++)
2620 {
2621 *pu8_data_out++ = *pu8_data_in_tmp;
2622
2623 /**< Update input pointer in order to go to next/past line */
2624 pu8_data_in_tmp += i32_tmp_offset;
2625 }
2626
2627 /**< Update pointers */
2628 pu8_data_out += (pOut[i].u_stride - pOut[i].u_width);
2629 if(M4OSA_FALSE == pC->m_bFlipX)
2630 {
2631 pu8_data_in ++;
2632 }
2633 else
2634 {
2635 pu8_data_in --;
2636 }
2637 }
2638 }
2639 }
2640 /**< Bilinear interpolation */
2641 else
2642 {
2643
2644 if(3 != i) /**< other than alpha plane */
2645 {
2646 /**No +-90° rotation */
2647 if(M4OSA_FALSE == pC->m_bRevertXY)
2648 {
2649
2650 /**< Loop on each row */
2651 for(j=0;j<pOut[i].u_height;j++)
2652 {
2653 /* Vertical weight factor */
2654 u32_y_frac = (pC->u32_y_accum[i]>>12)&15;
2655
2656 /* Reinit horizontal weight factor */
2657 u32_x_accum = pC->u32_x_accum_start[i];
2658
2659
2660
2661 if(M4OSA_TRUE == pC->m_bFlipX)
2662 {
2663
2664 /**< Loop on each output pixel in a row */
2665 for(k=0;k<pOut[i].u_width;k++)
2666 {
2667
2668 u32_x_frac = (u32_x_accum >> 12)&15; /* Fraction of Horizontal weight factor */
2669
2670 pu8_src_top = (pu8_data_in - (u32_x_accum >> 16)) -1 ;
2671
2672 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2673
2674 /* Weighted combination */
2675 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[1]*(16-u32_x_frac) +
2676 pu8_src_top[0]*u32_x_frac)*(16-u32_y_frac) +
2677 (pu8_src_bottom[1]*(16-u32_x_frac) +
2678 pu8_src_bottom[0]*u32_x_frac)*u32_y_frac )>>8);
2679
2680 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2681
2682 /* Update horizontal accumulator */
2683 u32_x_accum += pC->u32_x_inc[i];
2684 }
2685 }
2686
2687 else
2688 {
2689 /**< Loop on each output pixel in a row */
2690 for(k=0;k<pOut[i].u_width;k++)
2691 {
2692 u32_x_frac = (u32_x_accum >> 12)&15; /* Fraction of Horizontal weight factor */
2693
2694 pu8_src_top = pu8_data_in + (u32_x_accum >> 16);
2695
2696 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2697
2698 /* Weighted combination */
2699 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[0]*(16-u32_x_frac) +
2700 pu8_src_top[1]*u32_x_frac)*(16-u32_y_frac) +
2701 (pu8_src_bottom[0]*(16-u32_x_frac) +
2702 pu8_src_bottom[1]*u32_x_frac)*u32_y_frac )>>8);
2703
2704 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2705
2706 /* Update horizontal accumulator */
2707 u32_x_accum += pC->u32_x_inc[i];
2708 }
2709
2710 }
2711
2712 pu8_data_out += pOut[i].u_stride - pOut[i].u_width;
2713
2714 /* Update vertical accumulator */
2715 pC->u32_y_accum[i] += pC->u32_y_inc[i];
2716 if (pC->u32_y_accum[i]>>16)
2717 {
2718 pu8_data_in = pu8_data_in + (pC->u32_y_accum[i] >> 16) * i32_tmp_offset;
2719 pC->u32_y_accum[i] &= 0xffff;
2720 }
2721 }
2722 }
2723 /** +-90° rotation */
2724 else
2725 {
2726 pu8_data_in_org = pu8_data_in;
2727
2728 /**< Loop on each output row */
2729 for(j=0;j<pOut[i].u_height;j++)
2730 {
2731 /* horizontal weight factor */
2732 u32_x_frac = (pC->u32_x_accum[i]>>12)&15;
2733
2734 /* Reinit accumulator */
2735 u32_y_accum = pC->u32_y_accum_start[i];
2736
2737 if(M4OSA_TRUE == pC->m_bFlipX)
2738 {
2739
2740 /**< Loop on each output pixel in a row */
2741 for(k=0;k<pOut[i].u_width;k++)
2742 {
2743
2744 u32_y_frac = (u32_y_accum >> 12)&15; /* Vertical weight factor */
2745
2746
2747 pu8_src_top = (pu8_data_in - (pC->u32_x_accum[i] >> 16)) - 1;
2748
2749 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2750
2751 /* Weighted combination */
2752 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[1]*(16-u32_x_frac) +
2753 pu8_src_top[0]*u32_x_frac)*(16-u32_y_frac) +
2754 (pu8_src_bottom[1]*(16-u32_x_frac) +
2755 pu8_src_bottom[0]*u32_x_frac)*u32_y_frac )>>8);
2756
2757 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2758
2759 /* Update vertical accumulator */
2760 u32_y_accum += pC->u32_y_inc[i];
2761 if (u32_y_accum>>16)
2762 {
2763 pu8_data_in = pu8_data_in + (u32_y_accum >> 16) * i32_tmp_offset;
2764 u32_y_accum &= 0xffff;
2765 }
2766
2767 }
2768 }
2769 else
2770 {
2771 /**< Loop on each output pixel in a row */
2772 for(k=0;k<pOut[i].u_width;k++)
2773 {
2774
2775 u32_y_frac = (u32_y_accum >> 12)&15; /* Vertical weight factor */
2776
2777 pu8_src_top = pu8_data_in + (pC->u32_x_accum[i] >> 16);
2778
2779 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2780
2781 /* Weighted combination */
2782 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[0]*(16-u32_x_frac) +
2783 pu8_src_top[1]*u32_x_frac)*(16-u32_y_frac) +
2784 (pu8_src_bottom[0]*(16-u32_x_frac) +
2785 pu8_src_bottom[1]*u32_x_frac)*u32_y_frac )>>8);
2786
2787 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2788
2789 /* Update vertical accumulator */
2790 u32_y_accum += pC->u32_y_inc[i];
2791 if (u32_y_accum>>16)
2792 {
2793 pu8_data_in = pu8_data_in + (u32_y_accum >> 16) * i32_tmp_offset;
2794 u32_y_accum &= 0xffff;
2795 }
2796 }
2797 }
2798 pu8_data_out += pOut[i].u_stride - pOut[i].u_width;
2799
2800 /* Update horizontal accumulator */
2801 pC->u32_x_accum[i] += pC->u32_x_inc[i];
2802
2803 pu8_data_in = pu8_data_in_org;
2804 }
2805
2806 }
2807 }/** 3 != i */
2808 else
2809 {
2810 /**No +-90° rotation */
2811 if(M4OSA_FALSE == pC->m_bRevertXY)
2812 {
2813
2814 /**< Loop on each row */
2815 for(j=0;j<pOut[i].u_height;j++)
2816 {
2817 /* Vertical weight factor */
2818 u32_y_frac = (pC->u32_y_accum[i]>>12)&15;
2819
2820 /* Reinit horizontal weight factor */
2821 u32_x_accum = pC->u32_x_accum_start[i];
2822
2823
2824
2825 if(M4OSA_TRUE == pC->m_bFlipX)
2826 {
2827
2828 /**< Loop on each output pixel in a row */
2829 for(k=0;k<pOut[i].u_width;k++)
2830 {
2831
2832 u32_x_frac = (u32_x_accum >> 12)&15; /* Fraction of Horizontal weight factor */
2833
2834 pu8_src_top = (pu8_data_in - (u32_x_accum >> 16)) -1 ;
2835
2836 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2837
2838 /* Weighted combination */
2839 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[1]*(16-u32_x_frac) +
2840 pu8_src_top[0]*u32_x_frac)*(16-u32_y_frac) +
2841 (pu8_src_bottom[1]*(16-u32_x_frac) +
2842 pu8_src_bottom[0]*u32_x_frac)*u32_y_frac )>>8);
2843
2844 u32_temp_value= (u32_temp_value >> 7)*0xff;
2845
2846 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2847
2848 /* Update horizontal accumulator */
2849 u32_x_accum += pC->u32_x_inc[i];
2850 }
2851 }
2852
2853 else
2854 {
2855 /**< Loop on each output pixel in a row */
2856 for(k=0;k<pOut[i].u_width;k++)
2857 {
2858 u32_x_frac = (u32_x_accum >> 12)&15; /* Fraction of Horizontal weight factor */
2859
2860 pu8_src_top = pu8_data_in + (u32_x_accum >> 16);
2861
2862 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2863
2864 /* Weighted combination */
2865 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[0]*(16-u32_x_frac) +
2866 pu8_src_top[1]*u32_x_frac)*(16-u32_y_frac) +
2867 (pu8_src_bottom[0]*(16-u32_x_frac) +
2868 pu8_src_bottom[1]*u32_x_frac)*u32_y_frac )>>8);
2869
2870 u32_temp_value= (u32_temp_value >> 7)*0xff;
2871
2872 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2873
2874 /* Update horizontal accumulator */
2875 u32_x_accum += pC->u32_x_inc[i];
2876 }
2877
2878 }
2879
2880 pu8_data_out += pOut[i].u_stride - pOut[i].u_width;
2881
2882 /* Update vertical accumulator */
2883 pC->u32_y_accum[i] += pC->u32_y_inc[i];
2884 if (pC->u32_y_accum[i]>>16)
2885 {
2886 pu8_data_in = pu8_data_in + (pC->u32_y_accum[i] >> 16) * i32_tmp_offset;
2887 pC->u32_y_accum[i] &= 0xffff;
2888 }
2889 }
2890
2891 } /**< M4OSA_FALSE == pC->m_bRevertXY */
2892 /** +-90° rotation */
2893 else
2894 {
2895 pu8_data_in_org = pu8_data_in;
2896
2897 /**< Loop on each output row */
2898 for(j=0;j<pOut[i].u_height;j++)
2899 {
2900 /* horizontal weight factor */
2901 u32_x_frac = (pC->u32_x_accum[i]>>12)&15;
2902
2903 /* Reinit accumulator */
2904 u32_y_accum = pC->u32_y_accum_start[i];
2905
2906 if(M4OSA_TRUE == pC->m_bFlipX)
2907 {
2908
2909 /**< Loop on each output pixel in a row */
2910 for(k=0;k<pOut[i].u_width;k++)
2911 {
2912
2913 u32_y_frac = (u32_y_accum >> 12)&15; /* Vertical weight factor */
2914
2915
2916 pu8_src_top = (pu8_data_in - (pC->u32_x_accum[i] >> 16)) - 1;
2917
2918 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2919
2920 /* Weighted combination */
2921 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[1]*(16-u32_x_frac) +
2922 pu8_src_top[0]*u32_x_frac)*(16-u32_y_frac) +
2923 (pu8_src_bottom[1]*(16-u32_x_frac) +
2924 pu8_src_bottom[0]*u32_x_frac)*u32_y_frac )>>8);
2925
2926 u32_temp_value= (u32_temp_value >> 7)*0xff;
2927
2928 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2929
2930 /* Update vertical accumulator */
2931 u32_y_accum += pC->u32_y_inc[i];
2932 if (u32_y_accum>>16)
2933 {
2934 pu8_data_in = pu8_data_in + (u32_y_accum >> 16) * i32_tmp_offset;
2935 u32_y_accum &= 0xffff;
2936 }
2937
2938 }
2939 }
2940 else
2941 {
2942 /**< Loop on each output pixel in a row */
2943 for(k=0;k<pOut[i].u_width;k++)
2944 {
2945
2946 u32_y_frac = (u32_y_accum >> 12)&15; /* Vertical weight factor */
2947
2948 pu8_src_top = pu8_data_in + (pC->u32_x_accum[i] >> 16);
2949
2950 pu8_src_bottom = pu8_src_top + i32_tmp_offset;
2951
2952 /* Weighted combination */
2953 u32_temp_value = (M4VIFI_UInt8)(((pu8_src_top[0]*(16-u32_x_frac) +
2954 pu8_src_top[1]*u32_x_frac)*(16-u32_y_frac) +
2955 (pu8_src_bottom[0]*(16-u32_x_frac) +
2956 pu8_src_bottom[1]*u32_x_frac)*u32_y_frac )>>8);
2957
2958 u32_temp_value= (u32_temp_value >> 7)*0xff;
2959
2960 *pu8_data_out++ = (M4VIFI_UInt8)u32_temp_value;
2961
2962 /* Update vertical accumulator */
2963 u32_y_accum += pC->u32_y_inc[i];
2964 if (u32_y_accum>>16)
2965 {
2966 pu8_data_in = pu8_data_in + (u32_y_accum >> 16) * i32_tmp_offset;
2967 u32_y_accum &= 0xffff;
2968 }
2969 }
2970 }
2971 pu8_data_out += pOut[i].u_stride - pOut[i].u_width;
2972
2973 /* Update horizontal accumulator */
2974 pC->u32_x_accum[i] += pC->u32_x_inc[i];
2975
2976 pu8_data_in = pu8_data_in_org;
2977
2978 }
2979 } /**< M4OSA_TRUE == pC->m_bRevertXY */
2980 }/** 3 == i */
2981 }
2982 /**< In case of stripe mode, save current input pointer */
2983 if(M4OSA_TRUE == pC->m_params.m_bOutputStripe)
2984 {
2985 pC->pu8_data_in[i] = pu8_data_in;
2986 }
2987 }
2988
2989 /**< Update number of processed rows, reset it if we have finished with the whole processing */
2990 pC->m_procRows += pOut[0].u_height;
2991 if(M4OSA_FALSE == pC->m_bRevertXY)
2992 {
2993 if(pC->m_params.m_outputSize.m_height <= pC->m_procRows) pC->m_procRows = 0;
2994 }
2995 else
2996 {
2997 if(pC->m_params.m_outputSize.m_width <= pC->m_procRows) pC->m_procRows = 0;
2998 }
2999
3000 return M4NO_ERROR ;
3001
3002}
3003/*+ Handle the image files here */
3004
3005/**
3006 ******************************************************************************
3007 * M4OSA_ERR LvGetImageThumbNail(M4OSA_UChar *fileName, M4OSA_Void **pBuffer)
3008 * @brief This function gives YUV420 buffer of a given image file (in argb888 format)
3009 * @Note: The caller of the function is responsible to free the yuv buffer allocated
3010 * @param fileName: (IN) Path to the filename of the image argb data
3011 * @param height: (IN) Height of the image
3012 * @param width: (OUT) pBuffer pointer to the address where the yuv data address needs to be returned.
3013 * @return M4NO_ERROR: there is no error
3014 * @return M4ERR_ALLOC: No more memory space to add a new effect.
3015 * @return M4ERR_FILE_NOT_FOUND: if the file passed does not exists.
3016 ******************************************************************************
3017*/
3018M4OSA_ERR LvGetImageThumbNail(const char *fileName, M4OSA_UInt32 height, M4OSA_UInt32 width, M4OSA_Void **pBuffer) {
3019
3020 M4VIFI_ImagePlane rgbPlane, *yuvPlane;
3021 M4OSA_UInt32 frameSize_argb = (width * height * 4); // argb data
3022 M4OSA_Context lImageFileFp = M4OSA_NULL;
3023 M4OSA_ERR err = M4NO_ERROR;
3024
3025 M4OSA_UInt8 *pTmpData = (M4OSA_UInt8*) M4OSA_malloc(frameSize_argb, M4VS, (M4OSA_Char*)"Image argb data");
3026 if(pTmpData == M4OSA_NULL) {
3027 LOGE("Failed to allocate memory for Image clip");
3028 return M4ERR_ALLOC;
3029 }
3030
3031 /** Read the argb data from the passed file. */
3032 M4OSA_ERR lerr = M4OSA_fileReadOpen(&lImageFileFp, (M4OSA_Void *) fileName, M4OSA_kFileRead);
3033
3034 if((lerr != M4NO_ERROR) || (lImageFileFp == M4OSA_NULL))
3035 {
3036 LOGE("LVPreviewController: Can not open the file ");
3037 M4OSA_free((M4OSA_MemAddr32)pTmpData);
3038 return M4ERR_FILE_NOT_FOUND;
3039 }
3040 lerr = M4OSA_fileReadData(lImageFileFp, (M4OSA_MemAddr8)pTmpData, &frameSize_argb);
3041 if(lerr != M4NO_ERROR)
3042 {
3043 LOGE("LVPreviewController: can not read the data ");
3044 M4OSA_fileReadClose(lImageFileFp);
3045 M4OSA_free((M4OSA_MemAddr32)pTmpData);
3046 return lerr;
3047 }
3048 M4OSA_fileReadClose(lImageFileFp);
3049
3050 M4OSA_UInt32 frameSize = (width * height * 3); //Size of YUV420 data.
3051 rgbPlane.pac_data = (M4VIFI_UInt8*)M4OSA_malloc(frameSize, M4VS, (M4OSA_Char*)"Image clip RGB888 data");
3052 if(rgbPlane.pac_data == M4OSA_NULL)
3053 {
3054 LOGE("Failed to allocate memory for Image clip");
3055 M4OSA_free((M4OSA_MemAddr32)pTmpData);
3056 return M4ERR_ALLOC;
3057 }
3058
3059 /** Remove the alpha channel */
3060 for (int i=0, j = 0; i < frameSize_argb; i++) {
3061 if ((i % 4) == 0) continue;
3062 rgbPlane.pac_data[j] = pTmpData[i];
3063 j++;
3064 }
3065 M4OSA_free((M4OSA_MemAddr32)pTmpData);
3066
3067#ifdef FILE_DUMP
3068 FILE *fp = fopen("/sdcard/Input/test_rgb.raw", "wb");
3069 if(fp == NULL)
3070 LOGE("Errors file can not be created");
3071 else {
3072 fwrite(rgbPlane.pac_data, frameSize, 1, fp);
3073 fclose(fp);
3074 }
3075#endif
3076 rgbPlane.u_height = height;
3077 rgbPlane.u_width = width;
3078 rgbPlane.u_stride = width*3;
3079 rgbPlane.u_topleft = 0;
3080
3081 yuvPlane = (M4VIFI_ImagePlane*)M4OSA_malloc(3*sizeof(M4VIFI_ImagePlane),
3082 M4VS, (M4OSA_Char*)"M4xVSS_internalConvertRGBtoYUV: Output plane YUV");
3083 yuvPlane[0].u_height = height;
3084 yuvPlane[0].u_width = width;
3085 yuvPlane[0].u_stride = width;
3086 yuvPlane[0].u_topleft = 0;
3087 yuvPlane[0].pac_data = (M4VIFI_UInt8*)M4OSA_malloc(yuvPlane[0].u_height * yuvPlane[0].u_width * 1.5, M4VS, (M4OSA_Char*)"imageClip YUV data");
3088
3089 yuvPlane[1].u_height = yuvPlane[0].u_height >>1;
3090 yuvPlane[1].u_width = yuvPlane[0].u_width >> 1;
3091 yuvPlane[1].u_stride = yuvPlane[1].u_width;
3092 yuvPlane[1].u_topleft = 0;
3093 yuvPlane[1].pac_data = (M4VIFI_UInt8*)(yuvPlane[0].pac_data + yuvPlane[0].u_height * yuvPlane[0].u_width);
3094
3095 yuvPlane[2].u_height = yuvPlane[0].u_height >>1;
3096 yuvPlane[2].u_width = yuvPlane[0].u_width >> 1;
3097 yuvPlane[2].u_stride = yuvPlane[2].u_width;
3098 yuvPlane[2].u_topleft = 0;
3099 yuvPlane[2].pac_data = (M4VIFI_UInt8*)(yuvPlane[1].pac_data + yuvPlane[1].u_height * yuvPlane[1].u_width);
3100
3101
3102 err = M4VIFI_RGB888toYUV420(M4OSA_NULL, &rgbPlane, yuvPlane);
3103 //err = M4VIFI_BGR888toYUV420(M4OSA_NULL, &rgbPlane, yuvPlane);
3104 if(err != M4NO_ERROR)
3105 {
3106 LOGE("error when converting from RGB to YUV: 0x%x\n", err);
3107 }
3108 M4OSA_free((M4OSA_MemAddr32)rgbPlane.pac_data);
3109
3110 //LOGE("RGB to YUV done");
3111#ifdef FILE_DUMP
3112 FILE *fp1 = fopen("/sdcard/Input/test_yuv.raw", "wb");
3113 if(fp1 == NULL)
3114 LOGE("Errors file can not be created");
3115 else {
3116 fwrite(yuvPlane[0].pac_data, yuvPlane[0].u_height * yuvPlane[0].u_width * 1.5, 1, fp1);
3117 fclose(fp1);
3118 }
3119#endif
3120 *pBuffer = yuvPlane[0].pac_data;
3121 M4OSA_free((M4OSA_MemAddr32)yuvPlane);
3122 return M4NO_ERROR;
3123
3124}
3125M4OSA_Void prepareYUV420ImagePlane(M4VIFI_ImagePlane *plane,
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003126 M4OSA_UInt32 width, M4OSA_UInt32 height, M4VIFI_UInt8 *buffer,
3127 M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight) {
3128
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003129 //Y plane
3130 plane[0].u_width = width;
3131 plane[0].u_height = height;
Danny Fernandesaa05e8c2011-02-04 16:00:39 -08003132 plane[0].u_stride = reportedWidth;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003133 plane[0].u_topleft = 0;
3134 plane[0].pac_data = buffer;
3135
3136 // U plane
3137 plane[1].u_width = width/2;
3138 plane[1].u_height = height/2;
Danny Fernandesaa05e8c2011-02-04 16:00:39 -08003139 plane[1].u_stride = reportedWidth >> 1;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003140 plane[1].u_topleft = 0;
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003141 plane[1].pac_data = buffer+(reportedWidth*reportedHeight);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003142
3143 // V Plane
3144 plane[2].u_width = width/2;
3145 plane[2].u_height = height/2;
Danny Fernandesaa05e8c2011-02-04 16:00:39 -08003146 plane[2].u_stride = reportedWidth >> 1;
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003147 plane[2].u_topleft = 0;
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003148 plane[2].pac_data = plane[1].pac_data + ((reportedWidth/2)*(reportedHeight/2));
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003149}
3150
3151M4OSA_Void prepareYV12ImagePlane(M4VIFI_ImagePlane *plane,
3152 M4OSA_UInt32 width, M4OSA_UInt32 height, M4OSA_UInt32 stride,
3153 M4VIFI_UInt8 *buffer) {
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003154
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003155 //Y plane
3156 plane[0].u_width = width;
3157 plane[0].u_height = height;
3158 plane[0].u_stride = stride;
3159 plane[0].u_topleft = 0;
3160 plane[0].pac_data = buffer;
3161
3162 // U plane
3163 plane[1].u_width = width/2;
3164 plane[1].u_height = height/2;
3165 plane[1].u_stride = android::PreviewRenderer::ALIGN(plane[0].u_stride/2, 16);
3166 plane[1].u_topleft = 0;
3167 plane[1].pac_data = (buffer
3168 + plane[0].u_height * plane[0].u_stride
3169 + (plane[0].u_height/2) * android::PreviewRenderer::ALIGN((
3170 plane[0].u_stride / 2), 16));
3171
3172 // V Plane
3173 plane[2].u_width = width/2;
3174 plane[2].u_height = height/2;
3175 plane[2].u_stride = android::PreviewRenderer::ALIGN(plane[0].u_stride/2, 16);
3176 plane[2].u_topleft = 0;
3177 plane[2].pac_data = (buffer +
3178 plane[0].u_height * android::PreviewRenderer::ALIGN(plane[0].u_stride, 16));
3179
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003180
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003181}
3182
3183M4OSA_Void swapImagePlanes(
3184 M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
3185 M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2) {
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003186
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003187 planeIn[0].u_height = planeOut[0].u_height;
3188 planeIn[0].u_width = planeOut[0].u_width;
3189 planeIn[0].u_stride = planeOut[0].u_stride;
3190 planeIn[0].u_topleft = planeOut[0].u_topleft;
3191 planeIn[0].pac_data = planeOut[0].pac_data;
3192
3193 /**
3194 * U plane */
3195 planeIn[1].u_width = planeOut[1].u_width;
3196 planeIn[1].u_height = planeOut[1].u_height;
3197 planeIn[1].u_stride = planeOut[1].u_stride;
3198 planeIn[1].u_topleft = planeOut[1].u_topleft;
3199 planeIn[1].pac_data = planeOut[1].pac_data;
3200 /**
3201 * V Plane */
3202 planeIn[2].u_width = planeOut[2].u_width;
3203 planeIn[2].u_height = planeOut[2].u_height;
3204 planeIn[2].u_stride = planeOut[2].u_stride;
3205 planeIn[2].u_topleft = planeOut[2].u_topleft;
3206 planeIn[2].pac_data = planeOut[2].pac_data;
3207
3208 if(planeOut[0].pac_data == (M4VIFI_UInt8*)buffer1)
3209 {
3210 planeOut[0].pac_data = (M4VIFI_UInt8*)buffer2;
3211 planeOut[1].pac_data = (M4VIFI_UInt8*)(buffer2 +
3212 planeOut[0].u_width*planeOut[0].u_height);
3213
3214 planeOut[2].pac_data = (M4VIFI_UInt8*)(buffer2 +
3215 planeOut[0].u_width*planeOut[0].u_height +
3216 planeOut[1].u_width*planeOut[1].u_height);
3217 }
3218 else
3219 {
3220 planeOut[0].pac_data = (M4VIFI_UInt8*)buffer1;
3221 planeOut[1].pac_data = (M4VIFI_UInt8*)(buffer1 +
3222 planeOut[0].u_width*planeOut[0].u_height);
3223
3224 planeOut[2].pac_data = (M4VIFI_UInt8*)(buffer1 +
3225 planeOut[0].u_width*planeOut[0].u_height +
3226 planeOut[1].u_width*planeOut[1].u_height);
3227 }
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003228
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003229}
3230
3231M4OSA_Void computePercentageDone(
3232 M4OSA_UInt32 ctsMs, M4OSA_UInt32 effectStartTimeMs,
3233 M4OSA_UInt32 effectDuration, M4OSA_Double *percentageDone) {
3234
3235 M4OSA_Double videoEffectTime =0;
3236
3237 // Compute how far from the beginning of the effect we are, in clip-base time.
3238 videoEffectTime =
3239 (M4OSA_Int32)(ctsMs+ 0.5) - effectStartTimeMs;
3240
3241 // To calculate %, substract timeIncrement
3242 // because effect should finish on the last frame
3243 // which is from CTS = (eof-timeIncrement) till CTS = eof
3244 *percentageDone =
3245 videoEffectTime / ((M4OSA_Float)effectDuration);
3246
3247 if(*percentageDone < 0.0) *percentageDone = 0.0;
3248 if(*percentageDone > 1.0) *percentageDone = 1.0;
3249
3250}
3251
3252
3253M4OSA_Void computeProgressForVideoEffect(
3254 M4OSA_UInt32 ctsMs, M4OSA_UInt32 effectStartTimeMs,
3255 M4OSA_UInt32 effectDuration, M4VSS3GPP_ExternalProgress* extProgress) {
3256
3257 M4OSA_Double percentageDone =0;
3258
3259 computePercentageDone(ctsMs, effectStartTimeMs, effectDuration, &percentageDone);
3260
3261 extProgress->uiProgress = (M4OSA_UInt32)( percentageDone * 1000 );
3262 extProgress->uiOutputTime = (M4OSA_UInt32)(ctsMs + 0.5);
3263 extProgress->uiClipTime = extProgress->uiOutputTime;
3264 extProgress->bIsLast = M4OSA_FALSE;
3265}
3266
3267M4OSA_ERR prepareFramingStructure(
3268 M4xVSS_FramingStruct* framingCtx,
3269 M4VSS3GPP_EffectSettings* effectsSettings, M4OSA_UInt32 index,
3270 M4VIFI_UInt8* overlayRGB, M4VIFI_UInt8* overlayYUV) {
3271
3272 M4OSA_ERR err = M4NO_ERROR;
3273
3274 // Force input RGB buffer to even size to avoid errors in YUV conversion
3275 framingCtx->FramingRgb = effectsSettings[index].xVSS.pFramingBuffer;
3276 framingCtx->FramingRgb->u_width = framingCtx->FramingRgb->u_width & ~1;
3277 framingCtx->FramingRgb->u_height = framingCtx->FramingRgb->u_height & ~1;
3278 framingCtx->FramingYuv = NULL;
3279
3280 framingCtx->duration = effectsSettings[index].uiDuration;
3281 framingCtx->topleft_x = effectsSettings[index].xVSS.topleft_x;
3282 framingCtx->topleft_y = effectsSettings[index].xVSS.topleft_y;
3283 framingCtx->pCurrent = framingCtx;
3284 framingCtx->pNext = framingCtx;
3285 framingCtx->previousClipTime = -1;
3286
3287 framingCtx->alphaBlendingStruct =
3288 (M4xVSS_internalEffectsAlphaBlending*)M4OSA_malloc(
3289 sizeof(M4xVSS_internalEffectsAlphaBlending), M4VS,
3290 (M4OSA_Char*)"alpha blending struct");
3291
3292 framingCtx->alphaBlendingStruct->m_fadeInTime =
3293 effectsSettings[index].xVSS.uialphaBlendingFadeInTime;
3294
3295 framingCtx->alphaBlendingStruct->m_fadeOutTime =
3296 effectsSettings[index].xVSS.uialphaBlendingFadeOutTime;
3297
3298 framingCtx->alphaBlendingStruct->m_end =
3299 effectsSettings[index].xVSS.uialphaBlendingEnd;
3300
3301 framingCtx->alphaBlendingStruct->m_middle =
3302 effectsSettings[index].xVSS.uialphaBlendingMiddle;
3303
3304 framingCtx->alphaBlendingStruct->m_start =
3305 effectsSettings[index].xVSS.uialphaBlendingStart;
3306
3307 // If new Overlay buffer, convert from RGB to YUV
3308 if((overlayRGB != framingCtx->FramingRgb->pac_data) || (overlayYUV == NULL) ) {
3309
3310 // If YUV buffer exists, delete it
3311 if(overlayYUV != NULL) {
3312 M4OSA_free((M4OSA_MemAddr32)overlayYUV);
3313 overlayYUV = NULL;
3314 }
3315 if(effectsSettings[index].xVSS.rgbType == M4VSS3GPP_kRGB565) {
3316 // Input RGB565 plane is provided,
3317 // let's convert it to YUV420, and update framing structure
3318 err = M4xVSS_internalConvertRGBtoYUV(framingCtx);
3319 }
3320 else if(effectsSettings[index].xVSS.rgbType == M4VSS3GPP_kRGB888) {
3321 // Input RGB888 plane is provided,
3322 // let's convert it to YUV420, and update framing structure
3323 err = M4xVSS_internalConvertRGB888toYUV(framingCtx);
3324 }
3325 else {
3326 err = M4ERR_PARAMETER;
3327 }
3328 overlayYUV = framingCtx->FramingYuv[0].pac_data;
3329 overlayRGB = framingCtx->FramingRgb->pac_data;
3330
3331 }
3332 else {
3333 LOGV(" YUV buffer reuse");
3334 framingCtx->FramingYuv = (M4VIFI_ImagePlane*)M4OSA_malloc(
3335 3*sizeof(M4VIFI_ImagePlane), M4VS, (M4OSA_Char*)"YUV");
3336
3337 if(framingCtx->FramingYuv == M4OSA_NULL) {
3338 return M4ERR_ALLOC;
3339 }
3340
3341 framingCtx->FramingYuv[0].u_width = framingCtx->FramingRgb->u_width;
3342 framingCtx->FramingYuv[0].u_height = framingCtx->FramingRgb->u_height;
3343 framingCtx->FramingYuv[0].u_topleft = 0;
3344 framingCtx->FramingYuv[0].u_stride = framingCtx->FramingRgb->u_width;
3345 framingCtx->FramingYuv[0].pac_data = (M4VIFI_UInt8*)overlayYUV;
3346
3347 framingCtx->FramingYuv[1].u_width = (framingCtx->FramingRgb->u_width)>>1;
3348 framingCtx->FramingYuv[1].u_height = (framingCtx->FramingRgb->u_height)>>1;
3349 framingCtx->FramingYuv[1].u_topleft = 0;
3350 framingCtx->FramingYuv[1].u_stride = (framingCtx->FramingRgb->u_width)>>1;
3351 framingCtx->FramingYuv[1].pac_data = framingCtx->FramingYuv[0].pac_data +
3352 framingCtx->FramingYuv[0].u_width * framingCtx->FramingYuv[0].u_height;
3353
3354 framingCtx->FramingYuv[2].u_width = (framingCtx->FramingRgb->u_width)>>1;
3355 framingCtx->FramingYuv[2].u_height = (framingCtx->FramingRgb->u_height)>>1;
3356 framingCtx->FramingYuv[2].u_topleft = 0;
3357 framingCtx->FramingYuv[2].u_stride = (framingCtx->FramingRgb->u_width)>>1;
3358 framingCtx->FramingYuv[2].pac_data = framingCtx->FramingYuv[1].pac_data +
3359 framingCtx->FramingYuv[1].u_width * framingCtx->FramingYuv[1].u_height;
3360
3361 framingCtx->duration = 0;
3362 framingCtx->previousClipTime = -1;
3363 framingCtx->previewOffsetClipTime = -1;
3364
3365 }
3366 return err;
3367}
3368
3369M4OSA_ERR applyColorEffect(M4xVSS_VideoEffectType colorEffect,
3370 M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
3371 M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2, M4OSA_UInt16 rgbColorData) {
3372
3373 M4xVSS_ColorStruct colorContext;
3374 M4OSA_ERR err = M4NO_ERROR;
3375
3376 colorContext.colorEffectType = colorEffect;
3377 colorContext.rgb16ColorData = rgbColorData;
3378
3379 err = M4VSS3GPP_externalVideoEffectColor(
3380 (M4OSA_Void *)&colorContext, planeIn, planeOut, NULL,
3381 colorEffect);
3382
3383 if(err != M4NO_ERROR) {
3384 LOGV("M4VSS3GPP_externalVideoEffectColor(%d) error %d",
3385 colorEffect, err);
3386
3387 if(NULL != buffer1) {
3388 M4OSA_free((M4OSA_MemAddr32)buffer1);
3389 buffer1 = NULL;
3390 }
3391 if(NULL != buffer2) {
3392 M4OSA_free((M4OSA_MemAddr32)buffer2);
3393 buffer2 = NULL;
3394 }
3395 return err;
3396 }
3397
3398 // The out plane now becomes the in plane for adding other effects
3399 swapImagePlanes(planeIn, planeOut, buffer1, buffer2);
3400
3401 return err;
3402}
3403
3404M4OSA_ERR applyLumaEffect(M4VSS3GPP_VideoEffectType videoEffect,
3405 M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
3406 M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2, M4OSA_Int32 lum_factor) {
3407
3408 M4OSA_ERR err = M4NO_ERROR;
3409
3410 err = M4VFL_modifyLumaWithScale(
3411 (M4ViComImagePlane*)planeIn,(M4ViComImagePlane*)planeOut,
3412 lum_factor, NULL);
3413
3414 if(err != M4NO_ERROR) {
3415 LOGE("M4VFL_modifyLumaWithScale(%d) error %d", videoEffect, err);
3416
3417 if(NULL != buffer1) {
3418 M4OSA_free((M4OSA_MemAddr32)buffer1);
3419 buffer1= NULL;
3420 }
3421 if(NULL != buffer2) {
3422 M4OSA_free((M4OSA_MemAddr32)buffer2);
3423 buffer2= NULL;
3424 }
3425 return err;
3426 }
3427
3428 // The out plane now becomes the in plane for adding other effects
3429 swapImagePlanes(planeIn, planeOut,(M4VIFI_UInt8 *)buffer1,
3430 (M4VIFI_UInt8 *)buffer2);
3431
3432 return err;
3433}
3434
3435M4OSA_ERR applyCurtainEffect(M4VSS3GPP_VideoEffectType videoEffect,
3436 M4VIFI_ImagePlane *planeIn, M4VIFI_ImagePlane *planeOut,
3437 M4VIFI_UInt8 *buffer1, M4VIFI_UInt8 *buffer2,
3438 M4VFL_CurtainParam* curtainParams) {
3439
3440 M4OSA_ERR err = M4NO_ERROR;
3441
3442 // Apply the curtain effect
3443 err = M4VFL_applyCurtain( (M4ViComImagePlane*)planeIn,
3444 (M4ViComImagePlane*)planeOut, curtainParams, NULL);
3445 if(err != M4NO_ERROR) {
3446 LOGE("M4VFL_applyCurtain(%d) error %d", videoEffect, err);
3447
3448 if(NULL != buffer1) {
3449 M4OSA_free((M4OSA_MemAddr32)buffer1);
3450 buffer1= NULL;
3451 }
3452 if(NULL != buffer2) {
3453 M4OSA_free((M4OSA_MemAddr32)buffer2);
3454 buffer2 = NULL;
3455 }
3456 return err;
3457 }
3458
3459 // The out plane now becomes the in plane for adding other effects
3460 swapImagePlanes(planeIn, planeOut,(M4VIFI_UInt8 *)buffer1,
3461 (M4VIFI_UInt8 *)buffer2);
3462
3463 return err;
3464}
3465
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003466M4OSA_ERR applyEffectsAndRenderingMode(vePostProcessParams *params,
3467 M4OSA_UInt32 reportedWidth, M4OSA_UInt32 reportedHeight) {
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003468
3469 M4OSA_ERR err = M4NO_ERROR;
3470 M4VIFI_ImagePlane planeIn[3], planeOut[3];
3471 M4VIFI_UInt8 *finalOutputBuffer = NULL, *tempOutputBuffer= NULL;
3472 M4OSA_Double percentageDone =0;
3473 M4OSA_Int32 lum_factor;
3474 M4VFL_CurtainParam curtainParams;
3475 M4VSS3GPP_ExternalProgress extProgress;
3476 M4xVSS_FiftiesStruct fiftiesCtx;
3477 M4OSA_UInt32 frameSize = 0, i=0;
3478
3479 frameSize = (params->videoWidth*params->videoHeight*3) >> 1;
3480
3481 finalOutputBuffer = (M4VIFI_UInt8*)M4OSA_malloc(frameSize, M4VS,
3482 (M4OSA_Char*)("lvpp finalOutputBuffer"));
3483
3484 if(finalOutputBuffer == NULL) {
3485 LOGE("applyEffectsAndRenderingMode: malloc error");
3486 return M4ERR_ALLOC;
3487 }
3488
3489 // allocate the tempOutputBuffer
3490 tempOutputBuffer = (M4VIFI_UInt8*)M4OSA_malloc(
3491 ((params->videoHeight*params->videoWidth*3)>>1), M4VS, (M4OSA_Char*)("lvpp colorBuffer"));
3492
3493 if(tempOutputBuffer == NULL) {
3494 LOGE("applyEffectsAndRenderingMode: malloc error tempOutputBuffer");
3495 if(NULL != finalOutputBuffer) {
3496 M4OSA_free((M4OSA_MemAddr32)finalOutputBuffer);
3497 finalOutputBuffer = NULL;
3498 }
3499 return M4ERR_ALLOC;
3500 }
3501
3502 // Initialize the In plane
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003503 prepareYUV420ImagePlane(planeIn, params->videoWidth, params->videoHeight,
3504 params->vidBuffer, reportedWidth, reportedHeight);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003505
3506 // Initialize the Out plane
Dharmaray Kundargi35cb2de2011-01-19 19:09:27 -08003507 prepareYUV420ImagePlane(planeOut, params->videoWidth, params->videoHeight,
3508 (M4VIFI_UInt8 *)tempOutputBuffer, params->videoWidth, params->videoHeight);
Dharmaray Kundargi643290d2011-01-16 16:02:42 -08003509
3510 // The planeIn contains the YUV420 input data to postprocessing node
3511 // and planeOut will contain the YUV420 data with effect
3512 // In each successive if condition, apply filter to successive
3513 // output YUV frame so that concurrent effects are both applied
3514
3515 if(params->currentVideoEffect & VIDEO_EFFECT_BLACKANDWHITE) {
3516 err = applyColorEffect(M4xVSS_kVideoEffectType_BlackAndWhite,
3517 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3518 (M4VIFI_UInt8 *)tempOutputBuffer, 0);
3519 if(err != M4NO_ERROR) {
3520 return err;
3521 }
3522 }
3523
3524 if(params->currentVideoEffect & VIDEO_EFFECT_PINK) {
3525 err = applyColorEffect(M4xVSS_kVideoEffectType_Pink,
3526 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3527 (M4VIFI_UInt8 *)tempOutputBuffer, 0);
3528 if(err != M4NO_ERROR) {
3529 return err;
3530 }
3531 }
3532
3533 if(params->currentVideoEffect & VIDEO_EFFECT_GREEN) {
3534 err = applyColorEffect(M4xVSS_kVideoEffectType_Green,
3535 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3536 (M4VIFI_UInt8 *)tempOutputBuffer, 0);
3537 if(err != M4NO_ERROR) {
3538 return err;
3539 }
3540 }
3541
3542 if(params->currentVideoEffect & VIDEO_EFFECT_SEPIA) {
3543 err = applyColorEffect(M4xVSS_kVideoEffectType_Sepia,
3544 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3545 (M4VIFI_UInt8 *)tempOutputBuffer, 0);
3546 if(err != M4NO_ERROR) {
3547 return err;
3548 }
3549 }
3550
3551 if(params->currentVideoEffect & VIDEO_EFFECT_NEGATIVE) {
3552 err = applyColorEffect(M4xVSS_kVideoEffectType_Negative,
3553 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3554 (M4VIFI_UInt8 *)tempOutputBuffer, 0);
3555 if(err != M4NO_ERROR) {
3556 return err;
3557 }
3558 }
3559
3560 if(params->currentVideoEffect & VIDEO_EFFECT_GRADIENT) {
3561 // find the effect in effectSettings array
3562 for(i=0;i<params->numberEffects;i++) {
3563 if(params->effectsSettings[i].VideoEffectType ==
3564 M4xVSS_kVideoEffectType_Gradient)
3565 break;
3566 }
3567 err = applyColorEffect(M4xVSS_kVideoEffectType_Gradient,
3568 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3569 (M4VIFI_UInt8 *)tempOutputBuffer,
3570 params->effectsSettings[i].xVSS.uiRgb16InputColor);
3571 if(err != M4NO_ERROR) {
3572 return err;
3573 }
3574 }
3575
3576 if(params->currentVideoEffect & VIDEO_EFFECT_COLOR_RGB16) {
3577 // Find the effect in effectSettings array
3578 for(i=0;i<params->numberEffects;i++) {
3579 if(params->effectsSettings[i].VideoEffectType ==
3580 M4xVSS_kVideoEffectType_ColorRGB16)
3581 break;
3582 }
3583 err = applyColorEffect(M4xVSS_kVideoEffectType_ColorRGB16,
3584 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3585 (M4VIFI_UInt8 *)tempOutputBuffer,
3586 params->effectsSettings[i].xVSS.uiRgb16InputColor);
3587 if(err != M4NO_ERROR) {
3588 return err;
3589 }
3590 }
3591
3592 if(params->currentVideoEffect & VIDEO_EFFECT_FIFTIES) {
3593 // Find the effect in effectSettings array
3594 for(i=0;i<params->numberEffects;i++) {
3595 if(params->effectsSettings[i].VideoEffectType ==
3596 M4xVSS_kVideoEffectType_Fifties)
3597 break;
3598 }
3599 if(i < params->numberEffects) {
3600 computeProgressForVideoEffect(params->timeMs,
3601 params->effectsSettings[i].uiStartTime,
3602 params->effectsSettings[i].uiDuration, &extProgress);
3603
3604 if(params->isFiftiesEffectStarted) {
3605 fiftiesCtx.previousClipTime = -1;
3606 }
3607 fiftiesCtx.fiftiesEffectDuration =
3608 1000/params->effectsSettings[i].xVSS.uiFiftiesOutFrameRate;
3609
3610 fiftiesCtx.shiftRandomValue = 0;
3611 fiftiesCtx.stripeRandomValue = 0;
3612
3613 err = M4VSS3GPP_externalVideoEffectFifties(
3614 (M4OSA_Void *)&fiftiesCtx, planeIn, planeOut, &extProgress,
3615 M4xVSS_kVideoEffectType_Fifties);
3616
3617 if(err != M4NO_ERROR) {
3618 LOGE("M4VSS3GPP_externalVideoEffectFifties error 0x%x", err);
3619
3620 if(NULL != finalOutputBuffer) {
3621 M4OSA_free((M4OSA_MemAddr32)finalOutputBuffer);
3622 finalOutputBuffer = NULL;
3623 }
3624 if(NULL != tempOutputBuffer) {
3625 M4OSA_free((M4OSA_MemAddr32)tempOutputBuffer);
3626 tempOutputBuffer = NULL;
3627 }
3628 return err;
3629 }
3630
3631 // The out plane now becomes the in plane for adding other effects
3632 swapImagePlanes(planeIn, planeOut,(M4VIFI_UInt8 *)finalOutputBuffer,
3633 (M4VIFI_UInt8 *)tempOutputBuffer);
3634 }
3635 }
3636
3637 if(params->currentVideoEffect & VIDEO_EFFECT_FRAMING) {
3638
3639 M4xVSS_FramingStruct framingCtx;
3640 // Find the effect in effectSettings array
3641 for(i=0;i<params->numberEffects;i++) {
3642 if(params->effectsSettings[i].VideoEffectType ==
3643 M4xVSS_kVideoEffectType_Framing) {
3644 if((params->effectsSettings[i].uiStartTime <= params->timeMs + params->timeOffset) &&
3645 ((params->effectsSettings[i].uiStartTime+
3646 params->effectsSettings[i].uiDuration) >= params->timeMs + params->timeOffset))
3647 {
3648 break;
3649 }
3650 }
3651 }
3652 if(i < params->numberEffects) {
3653 computeProgressForVideoEffect(params->timeMs,
3654 params->effectsSettings[i].uiStartTime,
3655 params->effectsSettings[i].uiDuration, &extProgress);
3656
3657 err = prepareFramingStructure(&framingCtx,
3658 params->effectsSettings, i, params->overlayFrameRGBBuffer,
3659 params->overlayFrameYUVBuffer);
3660
3661 if(err == M4NO_ERROR) {
3662 err = M4VSS3GPP_externalVideoEffectFraming(
3663 (M4OSA_Void *)&framingCtx, planeIn, planeOut, &extProgress,
3664 M4xVSS_kVideoEffectType_Framing);
3665 }
3666
3667 M4OSA_free((M4OSA_MemAddr32)framingCtx.alphaBlendingStruct);
3668
3669 if(framingCtx.FramingYuv != NULL) {
3670 M4OSA_free((M4OSA_MemAddr32)framingCtx.FramingYuv);
3671 framingCtx.FramingYuv = NULL;
3672 }
3673 //If prepareFramingStructure / M4VSS3GPP_externalVideoEffectFraming
3674 // returned error, then return from function
3675 if(err != M4NO_ERROR) {
3676
3677 if(NULL != finalOutputBuffer) {
3678 M4OSA_free((M4OSA_MemAddr32)finalOutputBuffer);
3679 finalOutputBuffer = NULL;
3680 }
3681 if(NULL != tempOutputBuffer) {
3682 M4OSA_free((M4OSA_MemAddr32)tempOutputBuffer);
3683 tempOutputBuffer = NULL;
3684 }
3685 return err;
3686 }
3687
3688 // The out plane now becomes the in plane for adding other effects
3689 swapImagePlanes(planeIn, planeOut,(M4VIFI_UInt8 *)finalOutputBuffer,
3690 (M4VIFI_UInt8 *)tempOutputBuffer);
3691 }
3692 }
3693
3694 if(params->currentVideoEffect & VIDEO_EFFECT_FADEFROMBLACK) {
3695 /* find the effect in effectSettings array*/
3696 for(i=0;i<params->numberEffects;i++) {
3697 if(params->effectsSettings[i].VideoEffectType ==
3698 M4VSS3GPP_kVideoEffectType_FadeFromBlack)
3699 break;
3700 }
3701
3702 if(i < params->numberEffects) {
3703 computePercentageDone(params->timeMs,
3704 params->effectsSettings[i].uiStartTime,
3705 params->effectsSettings[i].uiDuration, &percentageDone);
3706
3707 // Compute where we are in the effect (scale is 0->1024)
3708 lum_factor = (M4OSA_Int32)( percentageDone * 1024 );
3709 // Apply the darkening effect
3710 err = applyLumaEffect(M4VSS3GPP_kVideoEffectType_FadeFromBlack,
3711 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3712 (M4VIFI_UInt8 *)tempOutputBuffer, lum_factor);
3713 if(err != M4NO_ERROR) {
3714 return err;
3715 }
3716 }
3717 }
3718
3719 if(params->currentVideoEffect & VIDEO_EFFECT_FADETOBLACK) {
3720 // Find the effect in effectSettings array
3721 for(i=0;i<params->numberEffects;i++) {
3722 if(params->effectsSettings[i].VideoEffectType ==
3723 M4VSS3GPP_kVideoEffectType_FadeToBlack)
3724 break;
3725 }
3726 if(i < params->numberEffects) {
3727 computePercentageDone(params->timeMs,
3728 params->effectsSettings[i].uiStartTime,
3729 params->effectsSettings[i].uiDuration, &percentageDone);
3730
3731 // Compute where we are in the effect (scale is 0->1024)
3732 lum_factor = (M4OSA_Int32)( (1.0-percentageDone) * 1024 );
3733 // Apply the darkening effect
3734 err = applyLumaEffect(M4VSS3GPP_kVideoEffectType_FadeToBlack,
3735 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3736 (M4VIFI_UInt8 *)tempOutputBuffer, lum_factor);
3737 if(err != M4NO_ERROR) {
3738 return err;
3739 }
3740 }
3741 }
3742
3743 if(params->currentVideoEffect & VIDEO_EFFECT_CURTAINOPEN) {
3744 // Find the effect in effectSettings array
3745 for(i=0;i<params->numberEffects;i++) {
3746 if(params->effectsSettings[i].VideoEffectType ==
3747 M4VSS3GPP_kVideoEffectType_CurtainOpening)
3748 break;
3749 }
3750 if(i < params->numberEffects) {
3751 computePercentageDone(params->timeMs,
3752 params->effectsSettings[i].uiStartTime,
3753 params->effectsSettings[i].uiDuration, &percentageDone);
3754
3755 // Compute where we are in the effect (scale is 0->height).
3756 // It is done with floats because tmp x height
3757 // can be very large (with long clips).
3758 curtainParams.nb_black_lines =
3759 (M4OSA_UInt16)((1.0 - percentageDone) * planeIn[0].u_height );
3760 // The curtain is hanged on the ceiling
3761 curtainParams.top_is_black = 1;
3762
3763 // Apply the curtain effect
3764 err = applyCurtainEffect(M4VSS3GPP_kVideoEffectType_CurtainOpening,
3765 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3766 (M4VIFI_UInt8 *)tempOutputBuffer, &curtainParams);
3767 if(err != M4NO_ERROR) {
3768 return err;
3769 }
3770 }
3771 }
3772
3773 if(params->currentVideoEffect & VIDEO_EFFECT_CURTAINCLOSE) {
3774 // Find the effect in effectSettings array
3775 for(i=0;i<params->numberEffects;i++) {
3776 if(params->effectsSettings[i].VideoEffectType ==
3777 M4VSS3GPP_kVideoEffectType_CurtainClosing)
3778 break;
3779 }
3780 if(i < params->numberEffects) {
3781 computePercentageDone(params->timeMs,
3782 params->effectsSettings[i].uiStartTime,
3783 params->effectsSettings[i].uiDuration, &percentageDone);
3784
3785 // Compute where we are in the effect (scale is 0->height).
3786 // It is done with floats because
3787 // tmp x height can be very large (with long clips).
3788 curtainParams.nb_black_lines =
3789 (M4OSA_UInt16)(percentageDone * planeIn[0].u_height );
3790
3791 // The curtain is hanged on the ceiling
3792 curtainParams.top_is_black = 1;
3793
3794 // Apply the curtain effect
3795 err = applyCurtainEffect(M4VSS3GPP_kVideoEffectType_CurtainClosing,
3796 planeIn, planeOut, (M4VIFI_UInt8 *)finalOutputBuffer,
3797 (M4VIFI_UInt8 *)tempOutputBuffer, &curtainParams);
3798 if(err != M4NO_ERROR) {
3799 return err;
3800 }
3801 }
3802 }
3803
3804 LOGV("doMediaRendering CALL getBuffer()");
3805 // Set the output YUV420 plane to be compatible with YV12 format
3806 // W & H even
3807 // YVU instead of YUV
3808 // align buffers on 32 bits
3809
3810 // Y plane
3811 //in YV12 format, sizes must be even
3812 M4OSA_UInt32 yv12PlaneWidth = ((params->outVideoWidth +1)>>1)<<1;
3813 M4OSA_UInt32 yv12PlaneHeight = ((params->outVideoHeight+1)>>1)<<1;
3814
3815 prepareYV12ImagePlane(planeOut, yv12PlaneWidth, yv12PlaneHeight,
3816 (M4OSA_UInt32)params->outBufferStride, (M4VIFI_UInt8 *)params->pOutBuffer);
3817
3818 err = applyRenderingMode(planeIn, planeOut, params->renderingMode);
3819
3820 if(M4OSA_NULL != finalOutputBuffer) {
3821 M4OSA_free((M4OSA_MemAddr32)finalOutputBuffer);
3822 finalOutputBuffer= M4OSA_NULL;
3823 }
3824 if(M4OSA_NULL != tempOutputBuffer) {
3825 M4OSA_free((M4OSA_MemAddr32)tempOutputBuffer);
3826 tempOutputBuffer = M4OSA_NULL;
3827 }
3828 if(err != M4NO_ERROR) {
3829 LOGV("doVideoPostProcessing: applyRenderingMode returned err=%d",err);
3830 return err;
3831 }
3832 return M4NO_ERROR;
3833}