[关闭]
@lonelinsky 2015-12-08T11:25:50.000000Z 字数 752 阅读 720

ARGB_8888 to YUV_420

code java


  1. public static byte[] colorconvertRGB_IYUV_I420(int[] aRGB, int width, int height) {
  2. final int frameSize = width * height;
  3. final int chromasize = frameSize / 4;
  4. int yIndex = 0;
  5. int uIndex = frameSize;
  6. int vIndex = frameSize + chromasize;
  7. byte [] yuv = new byte[width*height*3/2];
  8. int a, R, G, B, Y, U, V;
  9. int index = 0;
  10. for (int j = 0; j < height; j++) {
  11. for (int i = 0; i < width; i++) {
  12. //a = (aRGB[index] & 0xff000000) >> 24; //not using it right now
  13. R = (aRGB[index] & 0xff0000) >> 16;
  14. G = (aRGB[index] & 0xff00) >> 8;
  15. B = (aRGB[index] & 0xff) >> 0;
  16. Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
  17. U = (( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
  18. V = (( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
  19. yuv[yIndex++] = (byte) ((Y < 0) ? 0 : ((Y > 255) ? 255 : Y));
  20. if (j % 2 == 0 && index % 2 == 0)
  21. {
  22. yuv[uIndex++] = (byte)((U < 0) ? 0 : ((U > 255) ? 255 : U));
  23. yuv[vIndex++] = (byte)((V < 0) ? 0 : ((V > 255) ? 255 : V));
  24. }
  25. index ++;
  26. }
  27. }
  28. return yuv;
  29. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注