2
* Copyright 2005-2006 Luc Verhaegen.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
* OTHER DEALINGS IN THE SOFTWARE.
24
/* Standalone VESA CVT standard timing modelines generator. */
27
#include "xf86Modes.h"
29
/* FatalError implementation used by the server code we built in */
31
FatalError(const char *f, ...)
36
vfprintf(stderr, f, args);
41
/* xnfalloc implementation used by the server code we built in */
43
XNFalloc(unsigned long n)
49
perror("malloc failed");
55
/* xnfcalloc implementation used by the server code we built in */
57
XNFcallocarray(size_t nmemb, size_t size)
61
r = calloc(nmemb, size);
63
perror("calloc failed");
70
* Quickly check wether this is a CVT standard mode.
73
CVTCheckStandard(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
78
if ((!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay)) ||
79
(!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay)) ||
80
(!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay)) ||
81
(!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay)) ||
82
(!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay)));
85
fprintf(stderr, "Warning: Aspect Ratio is not CVT standard.\n");
89
if ((VRefresh != 50.0) && (VRefresh != 60.0) &&
90
(VRefresh != 75.0) && (VRefresh != 85.0)) {
92
fprintf(stderr, "Warning: Refresh Rate is not CVT standard "
93
"(50, 60, 75 or 85Hz).\n");
101
* I'm not documenting --interlaced for obvious reasons, even though I did
102
* implement it. I also can't deny having looked at gtf here.
105
PrintUsage(char *Name)
107
fprintf(stderr, "\n");
108
fprintf(stderr, "usage: %s [-v|--verbose] [-r|--reduced] X Y [refresh]\n",
110
fprintf(stderr, "\n");
111
fprintf(stderr, " -v|--verbose : Warn about CVT standard adherance.\n");
112
fprintf(stderr, " -r|--reduced : Create a mode with reduced blanking "
113
"(default: normal blanking).\n");
114
fprintf(stderr, " X : Desired horizontal resolution "
115
"(multiple of 8, required).\n");
117
" Y : Desired vertical resolution (required).\n");
119
" refresh : Desired refresh rate (default: 60.0Hz).\n");
120
fprintf(stderr, "\n");
122
fprintf(stderr, "Calculates VESA CVT (Coordinated Video Timing) modelines"
123
" for use with X.\n");
130
PrintComment(DisplayModeRec * Mode, Bool CVT, Bool Reduced)
132
printf("# %dx%d %.2f Hz ", Mode->HDisplay, Mode->VDisplay, Mode->VRefresh);
136
((float) Mode->HDisplay * Mode->VDisplay) / 1000000.0);
138
if (!(Mode->VDisplay % 3) &&
139
((Mode->VDisplay * 4 / 3) == Mode->HDisplay))
141
else if (!(Mode->VDisplay % 9) &&
142
((Mode->VDisplay * 16 / 9) == Mode->HDisplay))
144
else if (!(Mode->VDisplay % 10) &&
145
((Mode->VDisplay * 16 / 10) == Mode->HDisplay))
147
else if (!(Mode->VDisplay % 4) &&
148
((Mode->VDisplay * 5 / 4) == Mode->HDisplay))
150
else if (!(Mode->VDisplay % 9) &&
151
((Mode->VDisplay * 15 / 9) == Mode->HDisplay))
162
printf("hsync: %.2f kHz; ", Mode->HSync);
163
printf("pclk: %.2f MHz", ((float) Mode->Clock) / 1000.0);
169
* Originally grabbed from xf86Mode.c.
171
* Ignoring the actual Mode->name, as the user will want something solid
175
PrintModeline(DisplayModePtr Mode, int HDisplay, int VDisplay, float VRefresh,
179
printf("Modeline \"%dx%dR\" ", HDisplay, VDisplay);
181
printf("Modeline \"%dx%d_%.2f\" ", HDisplay, VDisplay, VRefresh);
183
printf("%6.2f %i %i %i %i %i %i %i %i", Mode->Clock / 1000.,
184
Mode->HDisplay, Mode->HSyncStart, Mode->HSyncEnd, Mode->HTotal,
185
Mode->VDisplay, Mode->VSyncStart, Mode->VSyncEnd, Mode->VTotal);
187
if (Mode->Flags & V_INTERLACE)
188
printf(" interlace");
189
if (Mode->Flags & V_PHSYNC)
191
if (Mode->Flags & V_NHSYNC)
193
if (Mode->Flags & V_PVSYNC)
195
if (Mode->Flags & V_NVSYNC)
205
main(int argc, char *argv[])
207
DisplayModeRec *Mode;
208
int HDisplay = 0, VDisplay = 0;
209
float VRefresh = 0.0;
210
Bool Reduced = FALSE, Verbose = FALSE, IsCVT;
211
Bool Interlaced = FALSE;
214
if ((argc < 3) || (argc > 7)) {
219
/* This doesn't filter out bad flags properly. Bad flags get passed down
220
* to atoi/atof, which then return 0, so that these variables can get
221
* filled next time round. So this is just a cosmetic problem.
223
for (n = 1; n < argc; n++) {
224
if (!strcmp(argv[n], "-r") || !strcmp(argv[n], "--reduced"))
226
else if (!strcmp(argv[n], "-i") || !strcmp(argv[n], "--interlaced"))
228
else if (!strcmp(argv[n], "-v") || !strcmp(argv[n], "--verbose"))
230
else if (!strcmp(argv[n], "-h") || !strcmp(argv[n], "--help")) {
234
else if (!HDisplay) {
235
HDisplay = atoi(argv[n]);
241
else if (!VDisplay) {
242
VDisplay = atoi(argv[n]);
248
else if (!VRefresh) {
249
VRefresh = atof(argv[n]);
261
if (!HDisplay || !VDisplay) {
266
/* Default to 60.0Hz */
270
/* Horizontal timing is always a multiple of 8: round up. */
271
if (HDisplay & 0x07) {
277
if ((VRefresh / 60.0) != floor(VRefresh / 60.0)) {
279
"\nERROR: Multiple of 60Hz refresh rate required for "
280
" reduced blanking.\n");
286
IsCVT = CVTCheckStandard(HDisplay, VDisplay, VRefresh, Reduced, Verbose);
288
Mode = xf86CVTMode(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
290
PrintComment(Mode, IsCVT, Reduced);
291
PrintModeline(Mode, HDisplay, VDisplay, VRefresh, Reduced);