40 #define NS(n) n < 0 ? (int)(n*65536.0-0.5+DBL_EPSILON) : (int)(n*65536.0+0.5)
41 #define CB(n) av_clip_uint8(n)
44 { { +0.7152, +0.0722, +0.2126 },
45 { -0.3850, +0.5000, -0.1150 },
46 { -0.4540, -0.0460, +0.5000 } },
47 { { +0.5900, +0.1100, +0.3000 },
48 { -0.3310, +0.5000, -0.1690 },
49 { -0.4210, -0.0790, +0.5000 } },
50 { { +0.5870, +0.1140, +0.2990 },
51 { -0.3313, +0.5000, -0.1687 },
52 { -0.4187, -0.0813, +0.5000 } },
53 { { +0.7010, +0.0870, +0.2120 },
54 { -0.3840, +0.5000, -0.1160 },
55 { -0.4450, -0.0550, +0.5000 } },
69 int yuv_convert[16][3][3];
76 #define OFFSET(x) offsetof(ColorMatrixContext, x)
77 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
129 for (i = 0; i < 3; i++)
130 for (j = 0; j < 3; j++)
131 cm[i][j] = yuv[i][0] * rgb[0][j] + yuv[i][1] * rgb[1][j] + yuv[i][2] * rgb[2][j];
137 double rgb_coeffd[4][3][3];
138 double yuv_convertd[16][3][3];
142 for (i = 0; i < 4; i++)
144 for (i = 0; i < 4; i++) {
145 for (j = 0; j < 4; j++) {
147 for (k = 0; k < 3; k++) {
161 static const char *
color_modes[] = {
"bt709",
"fcc",
"bt601",
"smpte240m"};
172 if (color->source == color->
dest) {
173 av_log(ctx,
AV_LOG_ERROR,
"Source and destination color space must not be identical\n");
177 color->
mode = color->source * 4 + color->
dest;
187 const unsigned char *
srcp = src->
data[0];
201 for (y = 0; y <
height; y++) {
202 for (x = 0; x <
width; x += 4) {
203 const int u = srcp[x + 0] - 128;
204 const int v = srcp[x + 2] - 128;
205 const int uvval = c2 * u + c3 * v + 1081344;
206 dstp[x + 0] =
CB((c4 * u + c5 * v + 8421376) >> 16);
207 dstp[x + 1] =
CB((65536 * (srcp[x + 1] - 16) + uvval) >> 16);
208 dstp[x + 2] =
CB((c6 * u + c7 * v + 8421376) >> 16);
209 dstp[x + 3] =
CB((65536 * (srcp[x + 3] - 16) + uvval) >> 16);
219 const unsigned char *srcpU = src->
data[1];
220 const unsigned char *srcpV = src->
data[2];
221 const unsigned char *srcpY = src->
data[0];
222 const int src_pitchY = src->
linesize[0];
223 const int src_pitchUV = src->
linesize[1];
226 unsigned char *dstpU = dst->
data[1];
227 unsigned char *dstpV = dst->
data[2];
228 unsigned char *dstpY = dst->
data[0];
229 const int dst_pitchY = dst->
linesize[0];
230 const int dst_pitchUV = dst->
linesize[1];
239 for (y = 0; y <
height; y++) {
240 for (x = 0; x <
width; x += 2) {
241 const int u = srcpU[x >> 1] - 128;
242 const int v = srcpV[x >> 1] - 128;
243 const int uvval = c2 * u + c3 * v + 1081344;
244 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
245 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
246 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
247 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
251 srcpU += src_pitchUV;
252 srcpV += src_pitchUV;
253 dstpU += dst_pitchUV;
254 dstpV += dst_pitchUV;
261 const unsigned char *srcpU = src->
data[1];
262 const unsigned char *srcpV = src->
data[2];
263 const unsigned char *srcpY = src->
data[0];
264 const unsigned char *srcpN = src->
data[0] + src->
linesize[0];
265 const int src_pitchY = src->
linesize[0];
266 const int src_pitchUV = src->
linesize[1];
269 unsigned char *dstpU = dst->
data[1];
270 unsigned char *dstpV = dst->
data[2];
271 unsigned char *dstpY = dst->
data[0];
273 const int dst_pitchY = dst->
linesize[0];
274 const int dst_pitchUV = dst->
linesize[1];
283 for (y = 0; y <
height; y += 2) {
284 for (x = 0; x <
width; x += 2) {
285 const int u = srcpU[x >> 1] - 128;
286 const int v = srcpV[x >> 1] - 128;
287 const int uvval = c2 * u + c3 * v + 1081344;
288 dstpY[x + 0] =
CB((65536 * (srcpY[x + 0] - 16) + uvval) >> 16);
289 dstpY[x + 1] =
CB((65536 * (srcpY[x + 1] - 16) + uvval) >> 16);
290 dstpN[x + 0] =
CB((65536 * (srcpN[x + 0] - 16) + uvval) >> 16);
291 dstpN[x + 1] =
CB((65536 * (srcpN[x + 1] - 16) + uvval) >> 16);
292 dstpU[x >> 1] =
CB((c4 * u + c5 * v + 8421376) >> 16);
293 dstpV[x >> 1] =
CB((c6 * u + c7 * v + 8421376) >> 16);
295 srcpY += src_pitchY << 1;
296 dstpY += dst_pitchY << 1;
297 srcpN += src_pitchY << 1;
298 dstpN += dst_pitchY << 1;
299 srcpU += src_pitchUV;
300 srcpV += src_pitchUV;
301 dstpU += dst_pitchUV;
302 dstpV += dst_pitchUV;
379 .
name =
"colormatrix",
384 .
inputs = colormatrix_inputs,
385 .
outputs = colormatrix_outputs,
386 .priv_class = &colormatrix_class,