summaryrefslogtreecommitdiff
path: root/v3/fake-pipeline2/util.c (plain)
blob: 1314d7cd9b5d9df6b21258e87819e92b5d341d34
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
74