0005-YUV-RGB-convertor-in-NEON.patch 24.4 KB
Newer Older
1
From a29f0c4a1777d8bdd6cf4fc6649938aedd807404 Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?S=C3=A9bastien=20Toque?= <xilasz@gmail.com>
3
Date: Tue, 4 Oct 2011 22:38:36 +0200
4
Subject: [PATCH 5/7] YUV->RGB convertor in NEON
5 6

---
7 8
 modules/arm_neon/Modules.am    |   10 ++
 modules/arm_neon/chroma_neon.h |   12 +++
Sébastien Toque's avatar
Sébastien Toque committed
9
 modules/arm_neon/i420_rgb.S    |  209 ++++++++++++++++++++++++++++++++++++++++
10
 modules/arm_neon/nv12_rgb.S    |  206 +++++++++++++++++++++++++++++++++++++++
Sébastien Toque's avatar
Sébastien Toque committed
11
 modules/arm_neon/nv21_rgb.S    |  206 +++++++++++++++++++++++++++++++++++++++
12 13
 modules/arm_neon/yuv_rgb.c     |  179 ++++++++++++++++++++++++++++++++++
 6 files changed, 822 insertions(+), 0 deletions(-)
14
 create mode 100644 modules/arm_neon/i420_rgb.S
15
 create mode 100644 modules/arm_neon/nv12_rgb.S
Sébastien Toque's avatar
Sébastien Toque committed
16
 create mode 100644 modules/arm_neon/nv21_rgb.S
17
 create mode 100644 modules/arm_neon/yuv_rgb.c
18 19

diff --git a/modules/arm_neon/Modules.am b/modules/arm_neon/Modules.am
20
index 83576eb..9dfd4ab 100644
21 22
--- a/modules/arm_neon/Modules.am
+++ b/modules/arm_neon/Modules.am
23
@@ -18,7 +18,17 @@ libchroma_yuv_neon_plugin_la_CFLAGS = $(AM_CFLAGS)
24 25 26
 libchroma_yuv_neon_plugin_la_LIBADD = $(AM_LIBADD)
 libchroma_yuv_neon_plugin_la_DEPENDENCIES =
 
27
+libyuv_rgb_neon_plugin_la_SOURCES = \
28
+	i420_rgb.S \
Sébastien Toque's avatar
Sébastien Toque committed
29
+	nv21_rgb.S \
30
+	nv12_rgb.S \
31 32 33 34
+	yuv_rgb.c
+libyuv_rgb_neon_plugin_la_CFLAGS = $(AM_CFLAGS)
+libyuv_rgb_neon_plugin_la_LIBADD = $(AM_LIBADD)
+libyuv_rgb_neon_plugin_la_DEPENDENCIES =
35 36 37 38
+
 libvlc_LTLIBRARIES += \
 	libaudio_format_neon_plugin.la \
 	libchroma_yuv_neon_plugin.la \
39
+	libyuv_rgb_neon_plugin.la \
40
 	$(NULL)
41
diff --git a/modules/arm_neon/chroma_neon.h b/modules/arm_neon/chroma_neon.h
42
index 204c5f1..3e867e3 100644
43 44
--- a/modules/arm_neon/chroma_neon.h
+++ b/modules/arm_neon/chroma_neon.h
45
@@ -64,3 +64,15 @@ void yuyv_i422_neon (struct yuv_planes *const out,
46 47 48 49
 /* UYVY to I422 conversion. */
 void uyvy_i422_neon (struct yuv_planes *const out,
                      const struct yuv_pack *const in, int width, int height);
+
50
+/* I420 to RGBA conversion. */
51 52
+void i420_rgb_neon (struct yuv_pack *const out,
+                    const struct yuv_planes *const in, int width, int height);
53 54 55 56
+
+/* NV21 to RGBA conversion. */
+void nv21_rgb_neon (struct yuv_pack *const out,
+                    const struct yuv_planes *const in, int width, int height);
57 58 59 60
+
+/* NV12 to RGBA conversion. */
+void nv12_rgb_neon (struct yuv_pack *const out,
+                    const struct yuv_planes *const in, int width, int height);
61 62
diff --git a/modules/arm_neon/i420_rgb.S b/modules/arm_neon/i420_rgb.S
new file mode 100644
Sébastien Toque's avatar
Sébastien Toque committed
63
index 0000000..cc0caf3
64 65
--- /dev/null
+++ b/modules/arm_neon/i420_rgb.S
Sébastien Toque's avatar
Sébastien Toque committed
66
@@ -0,0 +1,209 @@
67 68 69 70
+ @*****************************************************************************
+ @ i420_rgb.S : ARM NEONv1 I420 to RGB chroma conversion
+ @*****************************************************************************
+ @ Copyright (C) 2011 Sébastien Toque
71
+ @                    Rémi Denis-Courmont
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
+ @
+ @ This program is free software; you can redistribute it and/or modify
+ @ it under the terms of the GNU General Public License as published by
+ @ the Free Software Foundation; either version 2 of the License, or
+ @ (at your option) any later version.
+ @
+ @ This program is distributed in the hope that it will be useful,
+ @ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ @ GNU General Public License for more details.
+ @
+ @ You should have received a copy of the GNU General Public License
+ @ along with this program; if not, write to the Free Software Foundation,
+ @ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ @****************************************************************************/
+
+	.fpu neon
+	.text
+
+/* ARM */
+#define O1	r0
+#define O2	r1
+#define WIDTH	r2
+#define HEIGHT	r3
+#define Y1	r4
+#define Y2	r5
+#define U	r6
+#define V	r7
+#define YPITCH	r8
+#define OPAD	r10
+#define YPAD	r11
+#define COUNT	ip
+#define OPITCH	lr
+
+/* NEON */
+#define coefY	D0
+#define coefRV	D1
+#define coefGU	D2
+#define coefGV	D3
+#define coefBU	D4
+#define Rc	Q3
+#define Gc	Q4
+#define Bc	Q5
+
+#define u	D24
+#define v	D25
+#define y1	D28
+#define y2	D29
+
+#define chro_r	Q6
+#define chro_g	Q7
+#define chro_b	Q8
+#define red		Q9
+#define green	Q10
+#define blue	Q11
+#define lumi	Q15
+
+#define red1	D24
+#define green1	D25
+#define blue1	D26
+#define alpha1	D27
+#define red2	D28
+#define green2	D29
+#define blue2	D30
+#define alpha2	D31
+
+coefficients:
+    .short  -15872
+    .short    4992
+    .short  -18432
+
+	.align
+	.global i420_rgb_neon
+	.type	i420_rgb_neon, %function
+i420_rgb_neon:
+	push		{r4-r8,r10-r11,lr}
+	vpush		{q4-q7}
149
+
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
+	/* load arguments */
+	ldmia		r0,	{O1, OPITCH}
+	ldmia		r1,	{Y1, U, V, YPITCH}
+
+	/* round the width to be a multiple of 16 */
+	ands		OPAD, WIDTH, #15
+	sub			WIDTH, WIDTH, OPAD
+	addne		WIDTH, WIDTH, #16
+
+	/* init constants (scale value by 64) */
+	vmov.u8		coefY, #74
+	vmov.u8		coefRV, #115
+	vmov.u8		coefGU, #14
+	vmov.u8		coefGV, #34
+	vmov.u8		coefBU, #135
+	adr			OPAD, coefficients
+	vld1.s16	{d6[], d7[]}, [OPAD]!
+	vld1.s16	{d8[], d9[]}, [OPAD]!
+	vld1.s16	{d10[], d11[]}, [OPAD]!
169 170
+	vmov.u8		alpha1, #255
+
171 172 173 174 175
+	/* init padding */
+	cmp			HEIGHT,	#0
+	sub			OPAD,	OPITCH,	WIDTH, lsl #2
+	sub			YPAD,	YPITCH,	WIDTH
+
Sébastien Toque's avatar
Sébastien Toque committed
176
+loop_row:
177 178 179 180 181 182 183
+	movgts	COUNT,	WIDTH
+	add		O2,	O1,	OPITCH
+	add		Y2,	Y1,	YPITCH
+	/* exit if all rows have been processed */
+	vpople	{q4-q7}
+	pople	{r4-r8,r10-r11,pc}
+
Sébastien Toque's avatar
Sébastien Toque committed
184
+loop_col:
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
+
+	/* Common U & V */
+
+	vld1.u8	{u}, [U,:64]!
+	vld1.u8	{v}, [V,:64]!
+
+	vmull.u8	chro_r, v, coefRV
+	vmull.u8	chro_g, u, coefGU
+	vmlal.u8	chro_g, v, coefGV
+	vmull.u8	chro_b, u, coefBU
+
+	vadd.s16	chro_r, Rc, chro_r
+	vsub.s16	chro_g, Gc, chro_g
+	vadd.s16	chro_b, Bc, chro_b
+
+	PLD	[U]
+	PLD	[V]
+
+	/* Y Top Row */
+	vld2.u8	{y1,y2}, [Y1,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y1]
+
226
+	vmov.u8	alpha2, #255
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O1,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O1,:128]!
+
+	/* Y Bottom Row */
+	vld2.u8	{y1,y2}, [Y2,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y2]
+
257
+	vmov.u8	alpha2, #255
258 259 260 261 262 263 264 265 266
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O2,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O2,:128]!
+
+	/* next columns (x16) */
+	subs	COUNT,	COUNT,	#16
Sébastien Toque's avatar
Sébastien Toque committed
267
+	bgt		loop_col
268 269 270 271 272 273 274
+
+	/* next rows (x2) */
+	subs	HEIGHT,	#2
+	add		O1,	O2,	OPAD
+	add		Y1,	Y2,	YPAD
+	add		U,	U,	YPAD,	lsr #1
+	add		V,	V,	YPAD,	lsr #1
Sébastien Toque's avatar
Sébastien Toque committed
275
+	b		loop_row
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
diff --git a/modules/arm_neon/nv12_rgb.S b/modules/arm_neon/nv12_rgb.S
new file mode 100644
index 0000000..f4bb510
--- /dev/null
+++ b/modules/arm_neon/nv12_rgb.S
@@ -0,0 +1,206 @@
+ @*****************************************************************************
+ @ nv12_rgb.S : ARM NEONv1 NV12 to RGB chroma conversion
+ @*****************************************************************************
+ @ Copyright (C) 2011 Sébastien Toque
+ @                    Rémi Denis-Courmont
+ @
+ @ This program is free software; you can redistribute it and/or modify
+ @ it under the terms of the GNU General Public License as published by
+ @ the Free Software Foundation; either version 2 of the License, or
+ @ (at your option) any later version.
+ @
+ @ This program is distributed in the hope that it will be useful,
+ @ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ @ GNU General Public License for more details.
+ @
+ @ You should have received a copy of the GNU General Public License
+ @ along with this program; if not, write to the Free Software Foundation,
+ @ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ @****************************************************************************/
+
+	.fpu neon
+	.text
+
+/* ARM */
+#define O1	r0
+#define O2	r1
+#define WIDTH	r2
+#define HEIGHT	r3
+#define Y1	r4
+#define Y2	r5
+#define U	r6
+#define V	r7
+#define YPITCH	r8
+#define OPAD	r10
+#define YPAD	r11
+#define COUNT	ip
+#define OPITCH	lr
+
+/* NEON */
+#define coefY	D0
+#define coefRV	D1
+#define coefGU	D2
+#define coefGV	D3
+#define coefBU	D4
+#define Rc	Q3
+#define Gc	Q4
+#define Bc	Q5
+
+#define u	D24
+#define v	D25
+#define y1	D28
+#define y2	D29
+
+#define chro_r	Q6
+#define chro_g	Q7
+#define chro_b	Q8
+#define red		Q9
+#define green	Q10
+#define blue	Q11
+#define lumi	Q15
+
+#define red1	D24
+#define green1	D25
+#define blue1	D26
+#define alpha1	D27
+#define red2	D28
+#define green2	D29
+#define blue2	D30
+#define alpha2	D31
+
+coefficients:
+    .short  -15872
+    .short    4992
+    .short  -18432
+
+	.align
+	.global nv12_rgb_neon
+	.type	nv12_rgb_neon, %function
+nv12_rgb_neon:
+	push		{r4-r8,r10-r11,lr}
+	vpush		{q4-q7}
+
+	/* load arguments */
+	ldmia		r0,	{O1, OPITCH}
+	ldmia		r1,	{Y1, U, V, YPITCH}
+
+	/* round the width to be a multiple of 16 */
+	ands		OPAD, WIDTH, #15
+	sub			WIDTH, WIDTH, OPAD
+	addne		WIDTH, WIDTH, #16
+
+	/* init constants (scale value by 64) */
+	vmov.u8		coefY, #74
+	vmov.u8		coefRV, #115
+	vmov.u8		coefGU, #14
+	vmov.u8		coefGV, #34
+	vmov.u8		coefBU, #135
+	adr			OPAD, coefficients
+	vld1.s16	{d6[], d7[]}, [OPAD]!
+	vld1.s16	{d8[], d9[]}, [OPAD]!
+	vld1.s16	{d10[], d11[]}, [OPAD]!
+	vmov.u8		alpha1, #255
+
+	/* init padding */
+	cmp			HEIGHT,	#0
+	sub			OPAD,	OPITCH,	WIDTH, lsl #2
+	sub			YPAD,	YPITCH,	WIDTH
+
+loop_row:
+	movgts	COUNT,	WIDTH
+	add		O2,	O1,	OPITCH
+	add		Y2,	Y1,	YPITCH
+	/* exit if all rows have been processed */
+	vpople	{q4-q7}
+	pople	{r4-r8,r10-r11,pc}
+
+loop_col:
+
+	/* Common U & V */
+
+	vld2.u8	{u,v}, [U,:128]!
+
+	vmull.u8	chro_r, v, coefRV
+	vmull.u8	chro_g, u, coefGU
+	vmlal.u8	chro_g, v, coefGV
+	vmull.u8	chro_b, u, coefBU
+
+	vadd.s16	chro_r, Rc, chro_r
+	vsub.s16	chro_g, Gc, chro_g
+	vadd.s16	chro_b, Bc, chro_b
+
+	PLD	[U]
+
+	/* Y Top Row */
+	vld2.u8	{y1,y2}, [Y1,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y1]
+
+	vmov.u8	alpha2, #255
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O1,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O1,:128]!
+
+	/* Y Bottom Row */
+	vld2.u8	{y1,y2}, [Y2,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y2]
+
+	vmov.u8	alpha2, #255
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O2,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O2,:128]!
+
+	/* next columns (x16) */
+	subs	COUNT,	COUNT,	#16
+	bgt		loop_col
+
+	/* next rows (x2) */
+	subs	HEIGHT,	#2
+	add		O1,	O2,	OPAD
+	add		Y1,	Y2,	YPAD
+	add		U,	U,	YPAD
+	b		loop_row
Sébastien Toque's avatar
Sébastien Toque committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
diff --git a/modules/arm_neon/nv21_rgb.S b/modules/arm_neon/nv21_rgb.S
new file mode 100644
index 0000000..82a7099
--- /dev/null
+++ b/modules/arm_neon/nv21_rgb.S
@@ -0,0 +1,206 @@
+ @*****************************************************************************
+ @ nv21_rgb.S : ARM NEONv1 NV21 to RGB chroma conversion
+ @*****************************************************************************
+ @ Copyright (C) 2011 Sébastien Toque
+ @                    Rémi Denis-Courmont
+ @
+ @ This program is free software; you can redistribute it and/or modify
+ @ it under the terms of the GNU General Public License as published by
+ @ the Free Software Foundation; either version 2 of the License, or
+ @ (at your option) any later version.
+ @
+ @ This program is distributed in the hope that it will be useful,
+ @ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ @ GNU General Public License for more details.
+ @
+ @ You should have received a copy of the GNU General Public License
+ @ along with this program; if not, write to the Free Software Foundation,
+ @ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ @****************************************************************************/
+
+	.fpu neon
+	.text
+
+/* ARM */
+#define O1	r0
+#define O2	r1
+#define WIDTH	r2
+#define HEIGHT	r3
+#define Y1	r4
+#define Y2	r5
+#define U	r6
+#define V	r7
+#define YPITCH	r8
+#define OPAD	r10
+#define YPAD	r11
+#define COUNT	ip
+#define OPITCH	lr
+
+/* NEON */
+#define coefY	D0
+#define coefRV	D1
+#define coefGU	D2
+#define coefGV	D3
+#define coefBU	D4
+#define Rc	Q3
+#define Gc	Q4
+#define Bc	Q5
+
+#define u	D24
+#define v	D25
+#define y1	D28
+#define y2	D29
+
+#define chro_r	Q6
+#define chro_g	Q7
+#define chro_b	Q8
+#define red		Q9
+#define green	Q10
+#define blue	Q11
+#define lumi	Q15
555
+
Sébastien Toque's avatar
Sébastien Toque committed
556 557 558 559 560 561 562 563
+#define red1	D24
+#define green1	D25
+#define blue1	D26
+#define alpha1	D27
+#define red2	D28
+#define green2	D29
+#define blue2	D30
+#define alpha2	D31
564
+
Sébastien Toque's avatar
Sébastien Toque committed
565 566 567 568 569 570
+coefficients:
+    .short  -15872
+    .short    4992
+    .short  -18432
+
+	.align
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
+	.global nv21_rgb_neon
+	.type	nv21_rgb_neon, %function
+nv21_rgb_neon:
+	push		{r4-r8,r10-r11,lr}
+	vpush		{q4-q7}
+
+	/* load arguments */
+	ldmia		r0,	{O1, OPITCH}
+	ldmia		r1,	{Y1, U, V, YPITCH}
+
+	/* round the width to be a multiple of 16 */
+	ands		OPAD, WIDTH, #15
+	sub			WIDTH, WIDTH, OPAD
+	addne		WIDTH, WIDTH, #16
+
+	/* init constants (scale value by 64) */
+	vmov.u8		coefY, #74
+	vmov.u8		coefRV, #115
+	vmov.u8		coefGU, #14
+	vmov.u8		coefGV, #34
+	vmov.u8		coefBU, #135
+	adr			OPAD, coefficients
+	vld1.s16	{d6[], d7[]}, [OPAD]!
+	vld1.s16	{d8[], d9[]}, [OPAD]!
+	vld1.s16	{d10[], d11[]}, [OPAD]!
+	vmov.u8		alpha1, #255
+
+	/* init padding */
+	cmp			HEIGHT,	#0
+	sub			OPAD,	OPITCH,	WIDTH, lsl #2
+	sub			YPAD,	YPITCH,	WIDTH
+
Sébastien Toque's avatar
Sébastien Toque committed
603
+loop_row:
604 605 606 607 608 609 610
+	movgts	COUNT,	WIDTH
+	add		O2,	O1,	OPITCH
+	add		Y2,	Y1,	YPITCH
+	/* exit if all rows have been processed */
+	vpople	{q4-q7}
+	pople	{r4-r8,r10-r11,pc}
+
Sébastien Toque's avatar
Sébastien Toque committed
611
+loop_col:
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
+
+	/* Common U & V */
+
+	vld2.u8	{u,v}, [U,:128]!
+
+	vmull.u8	chro_r, u, coefRV
+	vmull.u8	chro_g, v, coefGU
+	vmlal.u8	chro_g, u, coefGV
+	vmull.u8	chro_b, v, coefBU
+
+	vadd.s16	chro_r, Rc, chro_r
+	vsub.s16	chro_g, Gc, chro_g
+	vadd.s16	chro_b, Bc, chro_b
+
+	PLD	[U]
+
+	/* Y Top Row */
+	vld2.u8	{y1,y2}, [Y1,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y1]
+
+	vmov.u8	alpha2, #255
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O1,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O1,:128]!
+
+	/* Y Bottom Row */
+	vld2.u8	{y1,y2}, [Y2,:128]!
+
+	/* y1 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y1, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red1, red, #6
+	vqrshrun.s16	green1, green, #6
+	vqrshrun.s16	blue1, blue, #6
+
+	/* y2 : chrominance + luminance, then clamp (divide by 64) */
+	vmull.u8	lumi, y2, coefY
+	vqadd.s16	red, lumi, chro_r
+	vqadd.s16	green, lumi, chro_g
+	vqadd.s16	blue, lumi, chro_b
+	vqrshrun.s16	red2, red, #6
+	vqrshrun.s16	green2, green, #6
+	vqrshrun.s16	blue2, blue, #6
+
+	PLD	[Y2]
+
+	vmov.u8	alpha2, #255
+	vzip.u8	red1, red2
+	vzip.u8	green1, green2
+	vzip.u8	blue1, blue2
+
+	vst4.u8		{red1,green1,blue1,alpha1}, [O2,:128]!
+	vst4.u8		{red2,green2,blue2,alpha2}, [O2,:128]!
+
+	/* next columns (x16) */
+	subs	COUNT,	COUNT,	#16
Sébastien Toque's avatar
Sébastien Toque committed
692
+	bgt		loop_col
693 694 695 696 697 698
+
+	/* next rows (x2) */
+	subs	HEIGHT,	#2
+	add		O1,	O2,	OPAD
+	add		Y1,	Y2,	YPAD
+	add		U,	U,	YPAD
Sébastien Toque's avatar
Sébastien Toque committed
699
+	b		loop_row
700
diff --git a/modules/arm_neon/yuv_rgb.c b/modules/arm_neon/yuv_rgb.c
701
new file mode 100644
702
index 0000000..ede49c9
703
--- /dev/null
704
+++ b/modules/arm_neon/yuv_rgb.c
705
@@ -0,0 +1,179 @@
706
+/*****************************************************************************
707
+ * yuv_rgb.c : ARM NEONv1 YUV to RGB32 chroma conversion for VLC
708 709
+ *****************************************************************************
+ * Copyright (C) 2011 Sébastien Toque
710
+ *                    Rémi Denis-Courmont
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_filter.h>
+#include <vlc_cpu.h>
735
+#include "chroma_neon.h"
736 737 738 739
+
+static int Open (vlc_object_t *);
+
+vlc_module_begin ()
740
+    set_description (N_("ARM NEON video chroma YUV->RGBA"))
741 742 743 744
+    set_capability ("video filter2", 250)
+    set_callbacks (Open, NULL)
+vlc_module_end ()
+
745
+/*
746 747 748 749 750 751
+static int CoefY[256];
+static int CoefRV[256];
+static int CoefGU[256];
+static int CoefGV[256];
+static int CoefBU[256];
+
752
+// C reference version of the converter
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
+static void I420_RGBA_C (filter_t *filter, picture_t *src, picture_t *dst)
+{
+    const uint8_t *const out = dst->p->p_pixels;
+    const size_t width = src->p[Y_PLANE].i_visible_pitch;
+    const size_t height = src->p[Y_PLANE].i_visible_lines;
+
+    const int ypitch = src->p[Y_PLANE].i_pitch;
+    const int uvpitch = src->p[U_PLANE].i_pitch;
+    const int dpitch = dst->p->i_pitch / dst->p->i_pixel_pitch;
+
+    for (size_t j = 0; j <  height; ++j)
+    {
+        const int y = j * ypitch;
+        const int u = (j>>1) * uvpitch;
+        const int d = j * dpitch;
+
+        for (size_t i = 0; i < width; ++i)
+        {
+            uint8_t Y = src->Y_PIXELS[y + i];
+            uint8_t U = src->U_PIXELS[u + (i>>1)];
+            uint8_t V = src->V_PIXELS[u + (i>>1)];
+
+            //coef = float * Precision + .5 (Precision=32768)
+            int R = CoefY[Y] + CoefRV[V];
+            int G = CoefY[Y] + CoefGU[U] + CoefGV[V];
+            int B = CoefY[Y] + CoefBU[U];
+
+            //rgb = (rgb+Precision/2) / Precision (Precision=32768)
+            R = R >> 15;
+            G = G >> 15;
+            B = B >> 15;
+
+            if (unlikely(R < 0)) R = 0;
+            if (unlikely(G < 0)) G = 0;
+            if (unlikely(B < 0)) B = 0;
+            if (unlikely(R > 255)) R = 255;
+            if (unlikely(G > 255)) G = 255;
+            if (unlikely(B > 255)) B = 255;
+
792
+            ((uint32_t*)out)[d + i] = R | (G<<8) | (B<<16) | (0xff<<24);
793 794
+        }
+    }
795
+}*/
796 797 798 799 800 801 802
+
+static void I420_RGBA (filter_t *filter, picture_t *src, picture_t *dst)
+{
+    struct yuv_pack out = { dst->p->p_pixels, dst->p->i_pitch };
+    struct yuv_planes in = { src->Y_PIXELS, src->U_PIXELS, src->V_PIXELS, src->Y_PITCH };
+    i420_rgb_neon (&out, &in, filter->fmt_in.video.i_width, filter->fmt_in.video.i_height);
+}
803 804 805 806 807 808
+static void YV12_RGBA (filter_t *filter, picture_t *src, picture_t *dst)
+{
+    struct yuv_pack out = { dst->p->p_pixels, dst->p->i_pitch };
+    struct yuv_planes in = { src->Y_PIXELS, src->V_PIXELS, src->U_PIXELS, src->Y_PITCH };
+    i420_rgb_neon (&out, &in, filter->fmt_in.video.i_width, filter->fmt_in.video.i_height);
+}
809
+
810 811 812 813 814 815 816
+static void NV21_RGBA (filter_t *filter, picture_t *src, picture_t *dst)
+{
+    struct yuv_pack out = { dst->p->p_pixels, dst->p->i_pitch };
+    struct yuv_planes in = { src->Y_PIXELS, src->U_PIXELS, src->V_PIXELS, src->Y_PITCH };
+    nv21_rgb_neon (&out, &in, filter->fmt_in.video.i_width, filter->fmt_in.video.i_height);
+}
+
817 818 819 820 821 822 823
+static void NV12_RGBA (filter_t *filter, picture_t *src, picture_t *dst)
+{
+    struct yuv_pack out = { dst->p->p_pixels, dst->p->i_pitch };
+    struct yuv_planes in = { src->Y_PIXELS, src->U_PIXELS, src->V_PIXELS, src->Y_PITCH };
+    nv12_rgb_neon (&out, &in, filter->fmt_in.video.i_width, filter->fmt_in.video.i_height);
+}
+
824
+VIDEO_FILTER_WRAPPER (I420_RGBA)
825
+VIDEO_FILTER_WRAPPER (YV12_RGBA)
826
+VIDEO_FILTER_WRAPPER (NV21_RGBA)
827
+VIDEO_FILTER_WRAPPER (NV12_RGBA)
828 829 830 831 832 833 834 835 836 837
+
+static int Open (vlc_object_t *obj)
+{
+    filter_t *filter = (filter_t *)obj;
+
+    if (((filter->fmt_in.video.i_width | filter->fmt_in.video.i_height) & 1)
+     || (filter->fmt_in.video.i_width != filter->fmt_out.video.i_width)
+     || (filter->fmt_in.video.i_height != filter->fmt_out.video.i_height))
+        return VLC_EGENERIC;
+
838
+    switch (filter->fmt_out.video.i_chroma)
839
+    {
840 841
+        case VLC_CODEC_RGB32:
+            switch (filter->fmt_in.video.i_chroma)
842
+            {
843
+                case VLC_CODEC_I420:
844 845
+                    filter->pf_video_filter = I420_RGBA_Filter;
+                    break;
846 847 848
+                case VLC_CODEC_YV12:
+                    filter->pf_video_filter = YV12_RGBA_Filter;
+                    break;
849 850 851
+                case VLC_CODEC_NV21:
+                    filter->pf_video_filter = NV21_RGBA_Filter;
+                    break;
852 853 854
+                case VLC_CODEC_NV12:
+                    filter->pf_video_filter = NV12_RGBA_Filter;
+                    break;
855 856 857 858 859 860 861 862 863
+                default:
+                    return VLC_EGENERIC;
+            }
+            break;
+
+        default:
+            return VLC_EGENERIC;
+    }
+
864 865
+    //precompute some values for the C version
+    /*const int coefY  = (int)(1.164 * 32768 + 0.5);
866 867 868 869 870 871 872 873 874 875 876
+    const int coefRV = (int)(1.793 * 32768 + 0.5);
+    const int coefGU = (int)(0.213 * 32768 + 0.5);
+    const int coefGV = (int)(0.533 * 32768 + 0.5);
+    const int coefBU = (int)(2.113 * 32768 + 0.5);
+    for (int i=0; i<256; ++i)
+    {
+        CoefY[i] = coefY * (i-16) + 16384;
+        CoefRV[i] = coefRV*(i-128);
+        CoefGU[i] = -coefGU*(i-128);
+        CoefGV[i] = -coefGV*(i-128);
+        CoefBU[i] = coefBU*(i-128);
877
+    }*/
878 879 880 881 882 883 884 885
+
+    msg_Dbg(filter, "%4.4s(%dx%d) to %4.4s(%dx%d)",
+            (char*)&filter->fmt_in.video.i_chroma, filter->fmt_in.video.i_width, filter->fmt_in.video.i_height,
+            (char*)&filter->fmt_out.video.i_chroma, filter->fmt_out.video.i_width, filter->fmt_out.video.i_height);
+
+    return VLC_SUCCESS;
+}
-- 
886
1.7.5.4
887