[FFmpeg-devel] [PATCH] FLIF16 GSOC Project Range Transformation YCoCg

Kartik kartikkhullar840 at gmail.com
Wed Mar 18 07:26:54 EET 2020


From: Kartik K. Khullar<kartikkhullar840 at gmail.com>

---
 FFmpeg/libavcodec/flif16transform.c | 53 +++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/FFmpeg/libavcodec/flif16transform.c b/FFmpeg/libavcodec/flif16transform.c
index e69de29..febf5e9 100644
--- a/FFmpeg/libavcodec/flif16transform.c
+++ b/FFmpeg/libavcodec/flif16transform.c
@@ -0,0 +1,53 @@
+#include <math.h>
+#include <stdint.h>
+
+//array of 2 elements is used as parameter because it represents min, max pair.
+void TransformYCoCg(int16_t *range[2], int16_t *crange[2], int16_t yval, int16_t coval){	
+	int max_temp;
+	if (range[1][0] > range[1][1]){
+		if (range[1][0] > range[1][2]){
+			max_temp = range[1][0];
+		}
+		else{
+			max_temp = range[1][2];
+		}
+	}
+	else{
+		max_temp  = range[1][1];
+	}
+	int origmax4 = max_temp / 4 + 1;
+	int newmax = 4*origmax4 - 1;
+	
+	//Updating color ranges
+	range[0][0] = 0;		//first channel minimum
+	range[1][0] = newmax;	//first channek maximum
+	range[0][1] = -newmax;	//second channel minimum
+	range[1][1] = newmax;	//second channel maximum
+	range[0][2] = -newmax;	//third channel minimum
+	range[1][2] = newmax;	//third channel maximum
+	
+	//Updating conditional range values
+	crange[0][0] = range[0][0];
+	crange[1][0] = range[1][0];
+	
+	if (yval < origmax4 - 1){
+		crange[0][1] = -3 + 4*yval;
+		crange[1][1] = 3 + 4*yval;
+		crange[0][2] = -2 - 2*yval;
+		crange[1][2] = 1 + 2 * yval - 2 * (abs(coval)/2);
+	}
+	else if (yval > 3*origmax4 - 1){
+		crange[0][1] = 4*(yval - newmax);
+		crange[1][1] = 4*(newmax - yval);
+		crange[0][2] = -2*(newmax - yval) + 2 * ((abs(coval)+1)/2);
+		crange[1][2] = 2*(newmax - yval);
+	}
+	else{	
+		crange[0][1] = -newmax;
+		crange[1][1] = newmax;
+		crange[0][2] = (((2*newmax - 2*yval - 2*abs(coval) + 1) < (2 * yval + 1)) ? 
+		(2*newmax - 2*yval - 2*abs(coval) + 1) : (2 * yval + 1)) / 2;
+		crange[1][2] = (2*(yval - newmax)) < (-2*yval - 1 + 2*(abs(coval)/2)) ? 
+		(2*(yval - newmax)) : (-2*yval - 1 + 2*(abs(coval)/2));
+	}
+}
\ No newline at end of file
-- 
2.20.1.windows.1



More information about the ffmpeg-devel mailing list