39 #define NS(n) n < 0 ? (int)(n*65536.0-0.5+DBL_EPSILON) : (int)(n*65536.0+0.5)
40 #define CB(n) av_clip_uint8(n)
43 { { +0.7152, +0.0722, +0.2126 },
44 { -0.3850, +0.5000, -0.1150 },
45 { -0.4540, -0.0460, +0.5000 } },
46 { { +0.5900, +0.1100, +0.3000 },
47 { -0.3310, +0.5000, -0.1690 },
48 { -0.4210, -0.0790, +0.5000 } },
49 { { +0.5870, +0.1140, +0.2990 },
50 { -0.3313, +0.5000, -0.1687 },
51 { -0.4187, -0.0813, +0.5000 } },
52 { { +0.7010, +0.0870, +0.2120 },
53 { -0.3840, +0.5000, -0.1160 },
54 { -0.4450, -0.0550, +0.5000 } },
58 int yuv_convert[16][3][3];
104 for (i = 0; i < 3; i++)
105 for (j = 0; j < 3; j++)
106 cm[i][j] = yuv[i][0] * rgb[0][j] + yuv[i][1] * rgb[1][j] + yuv[i][2] * rgb[2][j];
112 double rgb_coeffd[4][3][3];
113 double yuv_convertd[16][3][3];
117 for (i = 0; i < 4; i++)
119 for (i = 0; i < 4; i++) {
120 for (j = 0; j < 4; j++) {
122 for (k = 0; k < 3; k++) {
136 static const char *
color_modes[] = {
"bt709",
"FCC",
"bt601",
"smpte240m"};
154 if (sscanf(args,
"%255[^:]:%255[^:]", color->
src, color->
dst) != 2) {
168 if (color->
dest < 0) {
188 const unsigned char *srcp = src->
data[0];
189 const int src_pitch = src->
linesize[0];
192 unsigned char *dstp = dst->
data[0];
193 const int dst_pitch = dst->
linesize[0];
202 for (y = 0; y <
height; y++) {
203 for (x = 0; x <
width; x += 4) {
204 const int u = srcp[x + 0] - 128;
205 const int v = srcp[x + 2] - 128;
206 const int uvval = c2 * u + c3 * v + 1081344;
207 dstp[x + 0] =
CB((c4 * u + c5 * v + 8421376) >> 16);
208 dstp[x + 1] =
CB((65536 * (srcp[x + 1] - 16) + uvval) >> 16);
209 dstp[x + 2] =
CB((c6 * u + c7 * v + 8421376) >> 16);
210 dstp[x + 3] =
CB((65536 * (srcp[x + 3] - 16) + uvval) >> 16);
220 const unsigned char *srcpU = src->
data[1];
221 const unsigned char *srcpV = src->
data[2];
222 const unsigned char *srcpY = src->
data[0];
223 const int src_pitchY = src->
linesize[0];
224 const int src_pitchUV = src->
linesize[1];
227 unsigned char *dstpU = dst->
data[1];
228 unsigned char *dstpV = dst->
data[2];
229 unsigned char *dstpY = dst->
data[0];
230 const int dst_pitchY = dst->
linesize[0];
231 const int dst_pitchUV = dst->
linesize[1];
240 for (y = 0; y <
height; y++) {
241 for (x = 0; x <
width; x += 2) {
242 const int u = srcpU[x >> 1] - 128;
243 const int v = srcpV[x >> 1] - 128;
244 const int uvval = c2 * u + c3 * v + 1081344;
245 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
246 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
247 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
248 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
252 srcpU += src_pitchUV;
253 srcpV += src_pitchUV;
254 dstpU += dst_pitchUV;
255 dstpV += dst_pitchUV;
262 const unsigned char *srcpU = src->
data[1];
263 const unsigned char *srcpV = src->
data[2];
264 const unsigned char *srcpY = src->
data[0];
265 const unsigned char *srcpN = src->
data[0] + src->
linesize[0];
266 const int src_pitchY = src->
linesize[0];
267 const int src_pitchUV = src->
linesize[1];
270 unsigned char *dstpU = dst->
data[1];
271 unsigned char *dstpV = dst->
data[2];
272 unsigned char *dstpY = dst->
data[0];
274 const int dst_pitchY = dst->
linesize[0];
275 const int dst_pitchUV = dst->
linesize[1];
284 for (y = 0; y <
height; y += 2) {
285 for (x = 0; x <
width; x += 2) {
286 const int u = srcpU[x >> 1] - 128;
287 const int v = srcpV[x >> 1] - 128;
288 const int uvval = c2 * u + c3 * v + 1081344;
289 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
290 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
291 dstpN[x + 0] =
CB((65536 * (srcpN[x + 0] - 16) + uvval) >> 16);
292 dstpN[x + 1] =
CB((65536 * (srcpN[x + 1] - 16) + uvval) >> 16);
293 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
294 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
296 srcpY += src_pitchY << 1;
297 dstpY += dst_pitchY << 1;
298 srcpN += src_pitchY << 1;
299 dstpN += dst_pitchY << 1;
300 srcpU += src_pitchUV;
301 srcpV += src_pitchUV;
302 dstpU += dst_pitchUV;
303 dstpV += dst_pitchUV;
380 .
name =
"colormatrix",
386 .
inputs = colormatrix_inputs,
387 .
outputs = colormatrix_outputs,