1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include <X11/extensions/Xvlib.h>
33 #include <X11/extensions/XvMClib.h>
35 #include <vl/vl_compositor.h>
37 #include "xvmc_private.h"
39 #define XV_BRIGHTNESS "XV_BRIGHTNESS"
40 #define XV_CONTRAST "XV_CONTRAST"
41 #define XV_SATURATION "XV_SATURATION"
42 #define XV_HUE "XV_HUE"
43 #define XV_COLORSPACE "XV_COLORSPACE"
45 static const XvAttribute attributes
[] = {
46 { XvGettable
| XvSettable
, -1000, 1000, XV_BRIGHTNESS
},
47 { XvGettable
| XvSettable
, -1000, 1000, XV_CONTRAST
},
48 { XvGettable
| XvSettable
, -1000, 1000, XV_SATURATION
},
49 { XvGettable
| XvSettable
, -1000, 1000, XV_HUE
},
50 { XvGettable
| XvSettable
, 0, 1, XV_COLORSPACE
}
54 XvAttribute
* XvMCQueryAttributes(Display
*dpy
, XvMCContext
*context
, int *number
)
56 XvMCContextPrivate
*context_priv
;
59 assert(dpy
&& number
);
61 if (!context
|| !context
->privData
)
64 context_priv
= context
->privData
;
66 result
= malloc(sizeof(attributes
));
70 memcpy(result
, attributes
, sizeof(attributes
));
71 *number
= sizeof(attributes
) / sizeof(XvAttribute
);
73 XVMC_MSG(XVMC_TRACE
, "[XvMC] Returning %d attributes for context %p.\n", *number
, context
);
79 Status
XvMCSetAttribute(Display
*dpy
, XvMCContext
*context
, Atom attribute
, int value
)
81 XvMCContextPrivate
*context_priv
;
87 if (!context
|| !context
->privData
)
88 return XvMCBadContext
;
90 context_priv
= context
->privData
;
92 attr
= XGetAtomName(dpy
, attribute
);
94 return XvMCBadContext
;
96 if (strcmp(attr
, XV_BRIGHTNESS
))
97 context_priv
->procamp
.brightness
= value
/ 1000.0f
;
98 else if (strcmp(attr
, XV_CONTRAST
))
99 context_priv
->procamp
.contrast
= value
/ 1000.0f
+ 1.0f
;
100 else if (strcmp(attr
, XV_SATURATION
))
101 context_priv
->procamp
.saturation
= value
/ 1000.0f
+ 1.0f
;
102 else if (strcmp(attr
, XV_HUE
))
103 context_priv
->procamp
.hue
= value
/ 1000.0f
;
104 else if (strcmp(attr
, XV_COLORSPACE
))
105 context_priv
->color_standard
= value
?
106 VL_CSC_COLOR_STANDARD_BT_601
:
107 VL_CSC_COLOR_STANDARD_BT_709
;
113 context_priv
->color_standard
,
114 &context_priv
->procamp
, true, csc
116 vl_compositor_set_csc_matrix(&context_priv
->compositor
, csc
);
118 XVMC_MSG(XVMC_TRACE
, "[XvMC] Set attribute %s to value %d.\n", attr
, value
);
124 Status
XvMCGetAttribute(Display
*dpy
, XvMCContext
*context
, Atom attribute
, int *value
)
126 XvMCContextPrivate
*context_priv
;
131 if (!context
|| !context
->privData
)
132 return XvMCBadContext
;
134 context_priv
= context
->privData
;
136 attr
= XGetAtomName(dpy
, attribute
);
138 return XvMCBadContext
;
140 if (strcmp(attr
, XV_BRIGHTNESS
))
141 *value
= context_priv
->procamp
.brightness
* 1000;
142 else if (strcmp(attr
, XV_CONTRAST
))
143 *value
= context_priv
->procamp
.contrast
* 1000 - 1000;
144 else if (strcmp(attr
, XV_SATURATION
))
145 *value
= context_priv
->procamp
.saturation
* 1000 + 1000;
146 else if (strcmp(attr
, XV_HUE
))
147 *value
= context_priv
->procamp
.hue
* 1000;
148 else if (strcmp(attr
, XV_COLORSPACE
))
149 *value
= context_priv
->color_standard
== VL_CSC_COLOR_STANDARD_BT_709
;
153 XVMC_MSG(XVMC_TRACE
, "[XvMC] Got value %d for attribute %s.\n", *value
, attr
);