출처: http://xiangxiang.tistory.com/entry/안드로이드-카메라-제어에서-컬백함수로-Bitmap-이-안들어-올때
1 static public void decodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height) {
2
3 final int frameSize = width * height;
4
5 for (int j = 0, yp = 0; j < height; j++) {
6 int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
7 for (int i = 0; i < width; i++, yp++) {
8
9 int y = (0xff & ((int) yuv420sp[yp])) - 16;
10 if (y < 0) y = 0;
11 if ((i & 1) == 0) {
12 v = (0xff & yuv420sp[uvp++]) - 128;
13 u = (0xff & yuv420sp[uvp++]) - 128;
14 }
15
16 int y1192 = 1192 * y;
17 int r = (y1192 + 1634 * v);
18 int g = (y1192 - 833 * v - 400 * u);
19 int b = (y1192 + 2066 * u);
20
21 if (r < 0) r = 0; else if (r > 262143) r = 262143;
22 if (g < 0) g = 0; else if (g > 262143) g = 262143;
23 if (b < 0) b = 0; else if (b > 262143) b = 262143;
24
25 rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);
26 }
27 }
28 }
29
30 // The int[] rgb buffer passed in should be at least width * height in length.
31
'IT_Programming > Android_Java' 카테고리의 다른 글
[펌] AsyncTask와 Activity or Fragment (0) | 2014.03.25 |
---|---|
[펌] FragmentManager, FragmentTransaction에 대해서! (0) | 2014.03.25 |
[펌] Bitmap 을 배열로 배열을 Bitmap 으로... (0) | 2014.03.25 |
[펌] Managing Bitmap Memory (0) | 2014.03.17 |
[펌][Android] Animation 정리 (0) | 2013.12.30 |