소스 검색

Implement color decoding in YUV

Martijn Braam 4 년 전
부모
커밋
78d9e03f38
1개의 변경된 파일7개의 추가작업 그리고 7개의 파일을 삭제
  1. 7 7
      quickpreview.c

+ 7 - 7
quickpreview.c

@@ -84,7 +84,7 @@ void quick_debayer(const uint8_t *source, uint8_t *destination,
 }
 
 
-// YUV format to RGB, currently only extracts the Y channel for a grayscale preview
+// YUV 4:2:2 to RGB conversion
 void quick_yuv2rgb(const uint8_t *source, uint8_t *destination,
 		uint32_t pix_fmt, int width, int height, int skip)
 {
@@ -109,13 +109,13 @@ void quick_yuv2rgb(const uint8_t *source, uint8_t *destination,
 				V = source[i+3];
 				break;
 		}
-		destination[j] = Y1;
-		destination[j+1] = Y1;
-		destination[j+2] = Y1;
+		destination[j] = 1.164f * Y1 + 1.596f * (V - 128);
+		destination[j+1] = 1.164f * Y1 - 0.813f * (V - 128) - 0.391f * (U - 128);
+		destination[j+2] = 1.164f * Y1 + 2.018f * (U - 128);
 		j += 3;
-		destination[j] = Y2;
-		destination[j+1] = Y2;
-		destination[j+2] = Y2;
+		destination[j] = 1.164f * Y2 + 1.596f * (V - 128);
+		destination[j+1] = 1.164f * Y2 - 0.813f * (V - 128) - 0.391f * (U - 128);
+		destination[j+2] = 1.164f * Y2 + 2.018f * (U - 128);
 		j += 3;
 
 		i += pixelsize * skip * 2;