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 VMWARE 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
)
58 assert(dpy
&& number
);
60 if (!context
|| !context
->privData
)
63 result
= malloc(sizeof(attributes
));
67 memcpy(result
, attributes
, sizeof(attributes
));
68 *number
= sizeof(attributes
) / sizeof(XvAttribute
);
70 XVMC_MSG(XVMC_TRACE
, "[XvMC] Returning %d attributes for context %p.\n", *number
, context
);
76 Status
XvMCSetAttribute(Display
*dpy
, XvMCContext
*context
, Atom attribute
, int value
)
78 XvMCContextPrivate
*context_priv
;
84 if (!context
|| !context
->privData
)
85 return XvMCBadContext
;
87 context_priv
= context
->privData
;
89 attr
= XGetAtomName(dpy
, attribute
);
91 return XvMCBadContext
;
93 if (strcmp(attr
, XV_BRIGHTNESS
) == 0)
94 context_priv
->procamp
.brightness
= value
/ 1000.0f
;
95 else if (strcmp(attr
, XV_CONTRAST
) == 0)
96 context_priv
->procamp
.contrast
= value
/ 1000.0f
+ 1.0f
;
97 else if (strcmp(attr
, XV_SATURATION
) == 0)
98 context_priv
->procamp
.saturation
= value
/ 1000.0f
+ 1.0f
;
99 else if (strcmp(attr
, XV_HUE
) == 0)
100 context_priv
->procamp
.hue
= value
/ 1000.0f
;
101 else if (strcmp(attr
, XV_COLORSPACE
) == 0)
102 context_priv
->color_standard
= value
?
103 VL_CSC_COLOR_STANDARD_BT_601
:
104 VL_CSC_COLOR_STANDARD_BT_709
;
110 context_priv
->color_standard
,
111 &context_priv
->procamp
, true, &csc
113 vl_compositor_set_csc_matrix(&context_priv
->cstate
, (const vl_csc_matrix
*)&csc
, 1.0f
, 0.0f
);
115 XVMC_MSG(XVMC_TRACE
, "[XvMC] Set attribute %s to value %d.\n", attr
, value
);
121 Status
XvMCGetAttribute(Display
*dpy
, XvMCContext
*context
, Atom attribute
, int *value
)
123 XvMCContextPrivate
*context_priv
;
128 if (!context
|| !context
->privData
)
129 return XvMCBadContext
;
131 context_priv
= context
->privData
;
133 attr
= XGetAtomName(dpy
, attribute
);
135 return XvMCBadContext
;
137 if (strcmp(attr
, XV_BRIGHTNESS
) == 0)
138 *value
= context_priv
->procamp
.brightness
* 1000;
139 else if (strcmp(attr
, XV_CONTRAST
) == 0)
140 *value
= context_priv
->procamp
.contrast
* 1000 - 1000;
141 else if (strcmp(attr
, XV_SATURATION
) == 0)
142 *value
= context_priv
->procamp
.saturation
* 1000 + 1000;
143 else if (strcmp(attr
, XV_HUE
) == 0)
144 *value
= context_priv
->procamp
.hue
* 1000;
145 else if (strcmp(attr
, XV_COLORSPACE
) == 0)
146 *value
= context_priv
->color_standard
== VL_CSC_COLOR_STANDARD_BT_709
;
150 XVMC_MSG(XVMC_TRACE
, "[XvMC] Got value %d for attribute %s.\n", *value
, attr
);