-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_color_format.c
800 lines (738 loc) · 30.1 KB
/
transform_color_format.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
226
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
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
603
604
605
606
607
608
609
610
611
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
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
792
793
794
795
796
797
798
799
/*
* Cedarx framework.
* Copyright (c) 2008-2015 Allwinner Technology Co. Ltd.
* Copyright (c) 2014 Ning Fang <[email protected]>
*
* This file is part of Cedarx.
*
* Cedarx is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
#include "log.h"
#include "transform_color_format.h"
#include <unistd.h>
#include <stdlib.h>
#include <memory.h>
enum FORMAT_CONVERT_COLORFORMAT
{
CONVERT_COLOR_FORMAT_NONE = 0,
CONVERT_COLOR_FORMAT_YUV420PLANNER,
CONVERT_COLOR_FORMAT_YUV422PLANNER,
CONVERT_COLOR_FORMAT_YUV420MB,
CONVERT_COLOR_FORMAT_YUV422MB,
};
typedef struct ScalerParameter
{
int mode; //0: YV12 1:thumb yuv420p
int format_in;
int format_out;
int width_in;
int height_in;
int width_out;
int height_out;
void *addr_y_in;
void *addr_c_in;
unsigned int addr_y_out;
unsigned int addr_u_out;
unsigned int addr_v_out;
}ScalerParameter;
/*******************************************************************************
Function name: map32x32_to_yuv_Y
Description:
1. we should know : vdecbuf is 32*32 align
2. must match gpuBuf size.
3. we guarantee: vdecbufSize>=gpuBufSize
4. if coded_width is stride, we can support gpu_buf_width 32byte align and 16byte align!
5. A20_GPU:
YV12: y_width_align=16, u_width_align=16, v_width_align=16,
y/u/v_height can be any number(not even).
Parameters:
Return:
Time: 2013/4/15
*******************************************************************************/
static void map32x32_to_yuv_Y(unsigned char* srcY, unsigned char* tarY,unsigned int coded_width,unsigned int coded_height)
{
unsigned int i,j,l,m,n;
unsigned int mb_width,mb_height,twomb_line, twomb_width;
unsigned long offset;
unsigned char *ptr;
unsigned char *dst_asm,*src_asm;
unsigned vdecbuf_width, vdecbuf_height;
int nWidthMatchFlag;
int nLeftValidLine; //in the bottom macroblock(32*32), the valid line is < 32.
ptr = srcY;
mb_width = ((coded_width+31)&~31) >>4;
mb_height = ((coded_height+31)&~31) >>4;
twomb_line = (mb_height+1)>>1;
twomb_width = (mb_width+1)>>1;
if(twomb_line < 1 || twomb_width < 1)
{
loge("fatal error! twomb_line=%d, twomb_width=%d", twomb_line, twomb_width);
}
vdecbuf_width = twomb_width*32;
vdecbuf_height = twomb_line*32;
if(vdecbuf_width > coded_width)
{
nWidthMatchFlag = 0;
if((vdecbuf_width - coded_width) != 16)
{
logw("(f:%s, l:%d) fatal error! vdecbuf_width=%d, gpubuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
}
else
{
//LOGV("(f:%s, l:%d) Be careful! vdecbuf_width=%d, gpubuf_width=%d", __FUNCTION__, __LINE__, vdecbuf_width, coded_width);
}
}
else if(vdecbuf_width == coded_width)
{
nWidthMatchFlag = 1;
}
else
{
logw("(f:%s, l:%d) fatal error! vdecbuf_width=%d <= gpubuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
nWidthMatchFlag = 0;
}
for(i=0;i<twomb_line-1;i++) //twomb line number
{
for(j=0;j<twomb_width-1;j++) //macroblock(32*32) number in one line
{
for(l=0;l<32;l++)
{
//first mb
m=i*32 + l; //line num
n= j*32; //byte num in one line
offset = m*coded_width + n;
//memcpy(tarY+offset,ptr,32);
dst_asm = tarY+offset;
src_asm = ptr;
asm volatile (
"vld1.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0 - d3}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32; //32 byte in one process.
}
}
//process last macroblock of one line, gpu buf must be 16byte align or 32 byte align
{ //last mb of one line
for(l=0;l<32;l++)
{
//first mb
m=i*32 + l; //line num
n= j*32; //byte num in one line
offset = m*coded_width + n;
//memcpy(tarY+offset,ptr,32);
dst_asm = tarY+offset;
src_asm = ptr;
if(nWidthMatchFlag)
{
asm volatile (
"vld1.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0 - d3}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld1.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32; //32 byte in one process.
}
}
}
//last twomb line, we process it alone
nLeftValidLine = coded_height - (twomb_line-1)*32;
if(nLeftValidLine!=32)
{
//LOGV("(f:%s, l:%d)hehehaha,gpuBufHeight[%d] is not 32 align", __FUNCTION__, __LINE__, nLeftValidLine);
}
for(j=0;j<twomb_width-1;j++) //macroblock(32*32) number in one line
{
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*32 + l; //line num
n= j*32; //byte num in one line
offset = m*coded_width + n;
//memcpy(tarY+offset,ptr,32);
dst_asm = tarY+offset;
src_asm = ptr;
asm volatile (
"vld1.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0 - d3}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32; //32 byte in one process.
}
ptr += (32-nLeftValidLine)*32;
}
//process last macroblock of last line, gpu buf must be 16byte align or 32 byte align
{ //last mb of last line
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*32 + l; //line num
n= j*32; //byte num in one line
offset = m*coded_width + n;
//memcpy(tarY+offset,ptr,32);
dst_asm = tarY+offset;
src_asm = ptr;
if(nWidthMatchFlag)
{
asm volatile (
"vld1.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0 - d3}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld1.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst_asm]] \n\t"
: [dst_asm] "+r" (dst_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32; //32 byte in one process.
}
ptr += (32-nLeftValidLine)*32;
}
}
/*******************************************************************************
Function name: map32x32_to_yuv_Y
Description:
1. we should know : vdecbuf_uv is 32*32 align too
2. must match gpuBuf_uv size.
3. gpuBuf_uv size is half of gpuBuf_y size
4. we guarantee: vdecbufSize>=gpuBufSize
5. uv's macroblock is also 16*16. Vdec_macroblock is also twomb(32*32).
6. if coded_width is stride/2, we can support gpu_buf_width 16byte align and 8byte align!
But need outer set right value of coded_width, must meet gpu_uv_buf_width align's request!
Parameters:
1. mode = 0:yv12, 1:thumb yuv420p
2. coded_width and coded_height is uv size, already half of y_size
Return:
Time: 2013/4/15
*******************************************************************************/
//#define USE_VLD2_8 1
static void map32x32_to_yuv_C(int mode, unsigned char* srcC,unsigned char* tarCb,unsigned char* tarCr,unsigned int coded_width,unsigned int coded_height)
{
unsigned int i,j,l,m,n,k;
unsigned int mb_width,mb_height,twomb_line,twomb_width;
unsigned long offset;
unsigned char *ptr;
unsigned char *dst0_asm,*dst1_asm,*src_asm;
unsigned vdecbuf_width, vdecbuf_height; //unit: pixel
int nWidthMatchFlag;
int nLeftValidLine; //in the bottom macroblock(32*32), the valid line is < 32.
unsigned char line[16];
int dst_stride = mode==0 ? (coded_width + 15) & (~15) : coded_width;
ptr = srcC;
// mb_width = (coded_width+7)>>3;
// mb_height = (coded_height+7)>>3;
// fourmb_line = (mb_height+3)>>2;
// recon_width = (mb_width+1)&0xfffffffe;
mb_width = ((coded_width+15)&~15)>>4; //vdec's uvBuf is 32byte align, so uBuf and vBuf is 16byte align!
mb_height = ((coded_height+31)&~31)>>4;
twomb_line = (mb_height+1)>>1;
//recon_width = (mb_width+1)&0xfffffffe;
twomb_width = mb_width; //vdec mb32 is uv interleave, so uv_32 byte == u_16byte
if(twomb_line < 1 || twomb_width < 1)
{
loge("map32x32_to_yuv_C() fatal error! twomb_line=%d, twomb_width=%d", twomb_line, twomb_width);
}
//vdec mb32 uvBuf, one vdec_macro_block, extract u component, u's width and height.
vdecbuf_width = twomb_width*16;
vdecbuf_height = twomb_line*32;
if(vdecbuf_width > coded_width)
{
nWidthMatchFlag = 0;
if((vdecbuf_width - coded_width) != 8)
{
logw("fatal error! vdec_UVbuf_width=%d, gpu_UVbuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
}
else
{
//LOGV("(f:%s, l:%d) vdec_UVbuf_width=%d, gpu_UVbuf_width=%d, not match, gpu_uvBuf is 8byte align?", __FUNCTION__, __LINE__, vdecbuf_width, coded_width);
}
}
else if(vdecbuf_width == coded_width)
{
nWidthMatchFlag = 1;
}
else
{
logw("fatal error! vdec_UVbuf_width=%d <= gpu_UVbuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
nWidthMatchFlag = 0;
}
for(i=0;i<twomb_line-1;i++)
{
for(j=0;j<twomb_width-1;j++)
{
for(l=0;l<32;l++)
{
//first mb
m=i*32 + l; //line num
n= j*16; //byte num in dst_one_line
offset = m*dst_stride + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32;
}
}
//process last twomb_macroblock of one line, gpu buf must be 16 byte align or 8 byte align.
for(l=0;l<32;l++)
{
//first mb
m=i*32 + l; //line num
n= j*16; //byte num in dst_one_line
offset = m*dst_stride + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
if(nWidthMatchFlag)
{
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld2.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0}, [%[dst0_asm]] \n\t"
"vst1.8 {d1}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32;
}
}
//last twomb line, we process it alone
nLeftValidLine = coded_height - (twomb_line-1)*32; //uv height can be odd number,must be very careful!
if(nLeftValidLine!=32)
{
//LOGV("(f:%s, l:%d) hehehaha,gpu_UVBuf_extra_Height[%d] is not 32 align, coded_height[%d], twomb_line[%d]",
// __FUNCTION__, __LINE__, nLeftValidLine, coded_height, twomb_line);
}
for(j=0;j<twomb_width-1;j++) //macroblock(32*32) number in one line
{
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*32 + l; //line num
n= j*16; //byte num in dst_one_line
offset = m*dst_stride + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32; //32 byte in one process.
}
ptr += (32-nLeftValidLine)*32;
}
//process last macroblock of last line, gpu UVbuf must be 16byte align or 8 byte align
{ //last mb of last line
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*32 + l; //line num
n= j*16; //byte num in one line
offset = m*dst_stride + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
if(nWidthMatchFlag)
{
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld2.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0}, [%[dst0_asm]] \n\t"
"vst1.8 {d1}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32; //32 byte in one process.
}
ptr += (32-nLeftValidLine)*32;
}
}
/*******************************************************************************
Function name: map32x32_to_yuv_C_422
Description:
1. mb32_422 to yv12_420
2. so we discard one line in every two lines.
3. mb32_yuv422, vdec_macroblock is also 32*32.
Parameters:
Return:
Time: 2013/4/16
*******************************************************************************/
static void map32x32_to_yuv_C_422(int mode, unsigned char* srcC,unsigned char* tarCb,unsigned char* tarCr,unsigned int coded_width,unsigned int coded_height)
{
unsigned int i,j,l,m,n,k;
unsigned int mb_width,mb_height,twomb_line,twomb_width;
unsigned long offset;
unsigned char *ptr;
unsigned char *dst0_asm,*dst1_asm,*src_asm;
unsigned char line[16];
unsigned vdecbuf_width, vdecbuf_height;
int nWidthMatchFlag;
int nLeftValidLine; //in the bottom macroblock(32*32), the valid line is < 32.
ptr = srcC;
// mb_width = (coded_width+7)>>3;
// mb_height = (coded_height+7)>>3;
// twomb_line = (mb_height+1)>>1;
// recon_width = (mb_width+1)&0xfffffffe;
mb_width = ((coded_width+15)&~15)>>4; //vdec's uvBuf is 32byte align, so uBuf and vBuf is 16byte align!
mb_height = ((coded_height*2+31)&~31)>>4; //coded_height is gpu_buf's uv_height of yuv420, so uv_height of yuv422 must *2!
twomb_line = (mb_height+1)>>1;
//recon_width = (mb_width+1)&0xfffffffe;
twomb_width = mb_width; //vdec mb32 is uv interleave, so uv_32 byte == u_16byte
if(twomb_line < 1 || twomb_width < 1)
{
loge("map32x32_to_yuv_C_422() fatal error! twomb_line=%d, twomb_width=%d", twomb_line, twomb_width);
}
//vdec mb32 uvBuf, one vdec_macro_block, extract u component, u's width and height.
vdecbuf_width = twomb_width*16;
vdecbuf_height = twomb_line*32;
if(vdecbuf_width > coded_width)
{
nWidthMatchFlag = 0;
if((vdecbuf_width - coded_width) != 8)
{
logw("fatal error! vdec_UVbuf_width=%d, gpu_UVbuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
}
else
{
logv("vdec_UVbuf_width=%d, gpu_UVbuf_width=%d, not match, gpu_uvBuf is 8byte align?", vdecbuf_width, coded_width);
}
}
else if(vdecbuf_width == coded_width)
{
nWidthMatchFlag = 1;
}
else
{
logw("fatal error! vdec_UVbuf_width=%d <= gpu_UVbuf_width=%d, the program will crash!", vdecbuf_width, coded_width);
nWidthMatchFlag = 0;
}
for(i=0;i<twomb_line-1;i++)
{
for(j=0;j<twomb_width-1;j++)
{
for(l=0;l<16;l++)
{
//first mb
m=i*16 + l; //line num, because yub422->yuv420, so discard one line in every two lines, so is 16!
n= j*16; //byte num in dst_one_line
offset = m*coded_width + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32;
ptr += 32;
}
}
//process last twomb_macroblock of one line, gpu buf must be 16 byte align or 8 byte align.
for(l=0;l<16;l++)
{
//first mb
m=i*16 + l; //line num, because yub422->yuv420, so discard one line in every two lines, so is 16!
n= j*16; //byte num in dst_one_line
offset = m*coded_width + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
if(nWidthMatchFlag)
{
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld2.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0}, [%[dst0_asm]] \n\t"
"vst1.8 {d1}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32;
ptr += 32;
}
}
//last twomb line, we process it alone
nLeftValidLine = coded_height - (twomb_line-1)*16; //uv height can be odd number,must be very careful! because yuv422, so 32line equal to 16 line of yuv420
if(nLeftValidLine!=16)
{
//LOGV("(f:%s, l:%d) hehehaha,gpu_UVBuf_extra_Height[%d] is not 16 align, coded_height[%d], twomb_line[%d]",
// __FUNCTION__, __LINE__, nLeftValidLine, coded_height, twomb_line);
}
for(j=0;j<twomb_width-1;j++)
{
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*16 + l; //line num, because yub422->yuv420, so discard one line in every two lines, so is 16!
n= j*16; //byte num in dst_one_line
offset = m*coded_width + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
ptr += 32;
ptr += 32;
}
ptr += (16-nLeftValidLine)*32*2;
}
//process last twomb_macroblock of one line, gpu buf must be 16 byte align or 8 byte align.
{ //last mb of last line
for(l=0;l<nLeftValidLine;l++)
{
//first mb
m=i*16 + l; //line num, because yub422->yuv420, so discard one line in every two lines, so is 16!
n= j*16; //byte num in dst_one_line
offset = m*coded_width + n;
dst0_asm = tarCb + offset;
dst1_asm = tarCr+offset;
src_asm = ptr;
// for(k=0;k<16;k++)
// {
// dst0_asm[k] = src_asm[2*k];
// dst1_asm[k] = src_asm[2*k+1];
// }
if(nWidthMatchFlag)
{
asm volatile (
"vld2.8 {d0 - d3}, [%[src_asm]] \n\t"
"vst1.8 {d0,d1}, [%[dst0_asm]] \n\t"
"vst1.8 {d2,d3}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
else
{
asm volatile (
"vld2.8 {d0,d1}, [%[src_asm]] \n\t"
"vst1.8 {d0}, [%[dst0_asm]] \n\t"
"vst1.8 {d1}, [%[dst1_asm]] \n\t"
: [dst0_asm] "+r" (dst0_asm), [dst1_asm] "+r" (dst1_asm), [src_asm] "+r" (src_asm)
: //[srcY] "r" (srcY)
: "cc", "memory", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", "d24", "d28", "d29", "d30", "d31"
);
}
ptr += 32;
ptr += 32;
}
ptr += (16-nLeftValidLine)*32*2;
}
}
static void SoftwarePictureScaler(ScalerParameter *cdx_scaler_para)
{
map32x32_to_yuv_Y((unsigned char*)cdx_scaler_para->addr_y_in,
(unsigned char*)cdx_scaler_para->addr_y_out,
cdx_scaler_para->width_out,
cdx_scaler_para->height_out);
if (cdx_scaler_para->format_in == CONVERT_COLOR_FORMAT_YUV422MB)
map32x32_to_yuv_C_422(cdx_scaler_para->mode,
(unsigned char*)cdx_scaler_para->addr_c_in,
(unsigned char*)cdx_scaler_para->addr_u_out,
(unsigned char*)cdx_scaler_para->addr_v_out,
cdx_scaler_para->width_out / 2,
cdx_scaler_para->height_out / 2);
else
map32x32_to_yuv_C(cdx_scaler_para->mode,
(unsigned char*)cdx_scaler_para->addr_c_in,
(unsigned char*)cdx_scaler_para->addr_u_out,
(unsigned char*)cdx_scaler_para->addr_v_out,
cdx_scaler_para->width_out / 2,
cdx_scaler_para->height_out / 2);
return;
}
void TransformToYUVPlaner(VideoPicture *pict, void* ybuf)
{
ScalerParameter cdx_scaler_para;
int display_height;
int display_width;
int display_height_align;
int display_width_align;
int dst_c_stride;
int dst_y_size;
int dst_c_size;
int alloc_size;
int m_UseGPUbufferFlag = 0;
if(pict == NULL)
return;
display_height = pict->nBottomOffset - pict->nTopOffset;
display_width = pict->nRightOffset - pict->nLeftOffset;
if (pict->nHeight%2 != 0)
{
logw("display_height[%d] is odd number!!!", pict->nHeight);
}
//pict->display_height = (pict->display_height + 7) & (~7);
display_height_align = (display_height + 1) & (~1);
display_width_align = (display_width + 15) & (~15);
//#if (defined(__CHIP_VERSION_F23) || defined(__CHIP_VERSION_F51) || defined(__CHIP_VERSION_F50))
#if (1 == ADAPT_A10_GPU_RENDER)
//A10's GPU has a bug, we can avoid it
if(display_height_align%8 != 0)
{
if((display_width_align*display_height_align)%256 != 0)
{
display_height_align = (display_height_align+7)&~7;
}
}
#endif
dst_y_size = display_width_align * display_height_align;
if(m_UseGPUbufferFlag==1)
{
dst_c_stride = (display_width/2 + 15) & (~15);
cdx_scaler_para.mode = 0;
}
else
{
dst_c_stride = display_width/2;
cdx_scaler_para.mode = 1;
}
dst_c_size = dst_c_stride * (display_height_align/2);
alloc_size = dst_y_size + dst_c_size * 2;
cdx_scaler_para.format_in = CONVERT_COLOR_FORMAT_YUV420MB;
cdx_scaler_para.format_out = CONVERT_COLOR_FORMAT_YUV420PLANNER;
cdx_scaler_para.width_in = pict->nWidth;
cdx_scaler_para.height_in = pict->nHeight;
cdx_scaler_para.addr_y_in = (void*)pict->pData0; /*y*/
cdx_scaler_para.addr_c_in = (void*)pict->pData1; /*uv*/
#if 0
cedarx_cache_op(cdx_scaler_para.addr_y_in, cdx_scaler_para.addr_y_in+pict->size_y, CEDARX_DCACHE_FLUSH);
cedarx_cache_op(cdx_scaler_para.addr_c_in, cdx_scaler_para.addr_c_in+pict->size_u, CEDARX_DCACHE_FLUSH);
#endif
cdx_scaler_para.width_out = display_width_align;
cdx_scaler_para.height_out = display_height_align;
cdx_scaler_para.addr_y_out = (unsigned int)ybuf;
if(m_UseGPUbufferFlag==1)
{
cdx_scaler_para.addr_v_out = cdx_scaler_para.addr_y_out + dst_y_size;
cdx_scaler_para.addr_u_out = cdx_scaler_para.addr_v_out + dst_c_size;
}
else
{
cdx_scaler_para.addr_u_out = cdx_scaler_para.addr_y_out + dst_y_size;
cdx_scaler_para.addr_v_out = cdx_scaler_para.addr_u_out + dst_c_size;
}
//* use neon accelarator instruction to transform the pixel format, slow if buffer is not cached(DMA mode).
SoftwarePictureScaler(&cdx_scaler_para);
return;
}