summaryrefslogtreecommitdiff
path: root/v3/fake-pipeline2/util.c (plain)
blob: 690f853d23029d41ceb912f263b4e6430683ef7c
1#include <utils/Log.h>
2
3#include "util.h"
4#ifndef ALIGN
5#define ALIGN(b,w) (((b)+((w)-1))/(w)*(w))
6#endif
7
8static inline void yuv_to_rgb24(unsigned char y,unsigned char u,unsigned char v,unsigned char *rgb)
9{
10 register int r,g,b;
11 int rgb24;
12
13 r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
14 g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u -128) ) >> 10;
15 b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
16
17 r = r > 255 ? 255 : r < 0 ? 0 : r;
18 g = g > 255 ? 255 : g < 0 ? 0 : g;
19 b = b > 255 ? 255 : b < 0 ? 0 : b;
20
21 rgb24 = (int)((r << 16) | (g << 8)| b);
22
23 *rgb = (unsigned char)r;
24 rgb++;
25 *rgb = (unsigned char)g;
26 rgb++;
27 *rgb = (unsigned char)b;
28}
29
30void yuyv422_to_rgb24(unsigned char *buf, unsigned char *rgb, int width, int height)
31{
32 int x,y,z=0;
33 int blocks;
34
35 blocks = (width * height) * 2;
36
37 for (y = 0,z = 0; y < blocks; y += 4,z += 6) {
38 unsigned char Y1, Y2, U, V;
39
40 Y1 = buf[y + 0];
41 U = buf[y + 1];
42 Y2 = buf[y + 2];
43 V = buf[y + 3];
44
45 yuv_to_rgb24(Y1, U, V, &rgb[z]);
46 yuv_to_rgb24(Y2, U, V, &rgb[z + 3]);
47 }
48}
49
50void nv21_to_rgb24(unsigned char *buf, unsigned char *rgb, int width, int height)
51{
52 int x,y,z = 0;
53 int h,w;
54 int blocks;
55 unsigned char Y1, Y2, U, V;
56
57 blocks = (width * height) * 2;
58
59 for (h = 0, z = 0; h < height; h += 2) {
60 for (y = 0; y < width * 2; y += 2) {
61
62 Y1 = buf[ h * width + y + 0];
63 V = buf[ blocks/2 + h * width/2 + y % width + 0 ];
64 Y2 = buf[ h * width + y + 1];
65 U = buf[ blocks/2 + h * width/2 + y % width + 1 ];
66
67 yuv_to_rgb24(Y1, U, V, &rgb[z]);
68 yuv_to_rgb24(Y2, U, V, &rgb[z + 3]);
69 z += 6;
70 }
71 }
72}
73
74void nv21_memcpy_align32(unsigned char *dst, unsigned char *src, int width, int height)
75{
76 int stride = (width + 31) & ( ~31);
77 int w, h;
78 for (h = 0; h < height* 3/2; h++)
79 {
80 memcpy( dst, src, width);
81 dst += width;
82 src += stride;
83 }
84}
85
86void yv12_memcpy_align32(unsigned char *dst, unsigned char *src, int width, int height)
87{
88 int new_width = (width + 63) & ( ~63);
89 int stride;
90 int w, h;
91 for (h = 0; h < height; h++)
92 {
93 memcpy( dst, src, width);
94 dst += width;
95 src += new_width;
96 }
97 stride = ALIGN( width/2, 16);
98 for (h = 0; h < height; h++)
99 {
100 memcpy( dst, src, width/2);
101 dst += stride;
102 src += new_width/2;
103 }
104}
105
106