Android平台YUV420SP到RGB565的转换

	/**
	 * @param yuvDataArray
	 * @param width 
	 * @param height
	 * @return int[] : ARGB array
	 * @throws NullPointerException
	 * @throws IllegalArgumentException
	 */

	private static int[] decodeYUV(byte[] yuvDataArray, int width, int height) 
			throws NullPointerException, IllegalArgumentException {
		
		int size = width * height;
		
		if(yuvDataArray == null)
			throw new NullPointerException("buffer yuvDataArray is null");
		if(yuvDataArray.length < size)
			throw new IllegalArgumentException("buffer yuvDataArray size"
					+ yuvDataArray.length
					+ "< minium " + size * 3 / 2);
		int[] out = new int[size];
		int i, j;
		int Y, Cr = 0, Cb = 0;
		for(j = 0; j < height; j++) {
			int pixelIdx = j * width;
			int jDiv2 = j >> 1;
		
			for(i = 0; i < width; i++) {
				Y = yuvDataArray[pixelIdx];
				if(Y < 0) 
					Y += 255;
				if((i & 0x1) != 1) {
					int cOff = size + jDiv2 * width + (i >> 1) *2;
					Cb = yuvDataArray[cOff];
					if(Cb < 0) {
						Cb += 127;
					} else {
						Cb -= 128;
					}
					Cr = yuvDataArray[cOff + 1];
					if(Cr < 0) {
						Cr += 127;
					} else {
						Cr -= 128;
					}
				}
				
				int R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);
				if(R < 0) {
					R = 0;
				} else if(R > 255) {
					R = 255;
				}
				
				int G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1) + (Cr >> 3) + (Cr >> 4) + (Cr >> 5);
				if(G < 0) {
					G = 0;
				} else if(G > 255) {
					G = 255;
				}
				
				int B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);
				if(B < 0) {
					B = 0;
				} else if(B > 255) {
					B = 255;
				}
				
				out[pixelIdx++] = 0xff000000 + (B << 16) + (G << 8) + R;
			}
		}
		return out;
	}