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