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. */
29 * Quickly check wether this is a CVT standard mode.
32 CVTCheckStandard(int HDisplay
, int VDisplay
, float VRefresh
, Bool Reduced
,
37 if ((!(VDisplay
% 3) && ((VDisplay
* 4 / 3) == HDisplay
)) ||
38 (!(VDisplay
% 9) && ((VDisplay
* 16 / 9) == HDisplay
)) ||
39 (!(VDisplay
% 10) && ((VDisplay
* 16 / 10) == HDisplay
)) ||
40 (!(VDisplay
% 4) && ((VDisplay
* 5 / 4) == HDisplay
)) ||
41 (!(VDisplay
% 9) && ((VDisplay
* 15 / 9) == HDisplay
)))
45 fprintf(stderr
, "Warning: Aspect Ratio is not CVT standard.\n");
49 if ((VRefresh
!= 50.0) && (VRefresh
!= 60.0) &&
50 (VRefresh
!= 75.0) && (VRefresh
!= 85.0)) {
52 fprintf(stderr
, "Warning: Refresh Rate is not CVT standard "
53 "(50, 60, 75 or 85Hz).\n");
62 * I'm not documenting --interlaced for obvious reasons, even though I did
63 * implement it. I also can't deny having looked at gtf here.
66 PrintUsage(char *Name
)
68 fprintf(stderr
, "\n");
69 fprintf(stderr
, "usage: %s [-v|--verbose] [-r|--reduced] X Y [refresh]\n",
71 fprintf(stderr
, "\n");
72 fprintf(stderr
, " -v|--verbose : Warn about CVT standard adherance.\n");
73 fprintf(stderr
, " -r|--reduced : Create a mode with reduced blanking "
74 "(default: normal blanking).\n");
75 fprintf(stderr
, " X : Desired horizontal resolution "
76 "(multiple of 8, required).\n");
77 fprintf(stderr
, " Y : Desired vertical resolution (required).\n");
78 fprintf(stderr
, " refresh : Desired refresh rate (default: 60.0Hz).\n");
79 fprintf(stderr
, "\n");
81 fprintf(stderr
, "Calculates VESA CVT (Coordinated Video Timing) modelines"
82 " for use with X.\n");
90 PrintComment(DisplayModeRec
*Mode
, Bool CVT
, Bool Reduced
)
92 printf("# %dx%d %.2f Hz ", Mode
->HDisplay
, Mode
->VDisplay
, Mode
->VRefresh
);
96 ((float) Mode
->HDisplay
* Mode
->VDisplay
) / 1000000.0);
98 if (!(Mode
->VDisplay
% 3) &&
99 ((Mode
->VDisplay
* 4 / 3) == Mode
->HDisplay
))
101 else if (!(Mode
->VDisplay
% 9) &&
102 ((Mode
->VDisplay
* 16 / 9) == Mode
->HDisplay
))
104 else if (!(Mode
->VDisplay
% 10) &&
105 ((Mode
->VDisplay
* 16 / 10) == Mode
->HDisplay
))
107 else if (!(Mode
->VDisplay
% 4) &&
108 ((Mode
->VDisplay
* 5 / 4) == Mode
->HDisplay
))
110 else if (!(Mode
->VDisplay
% 9) &&
111 ((Mode
->VDisplay
* 15 / 9) == Mode
->HDisplay
))
121 printf("hsync: %.2f kHz; ", Mode
->HSync
);
122 printf("pclk: %.2f MHz", ((float ) Mode
->Clock
) / 1000.0);
129 * Originally grabbed from xf86Mode.c.
131 * Ignoring the actual Mode->name, as the user will want something solid
135 PrintModeline(DisplayModePtr Mode
, int HDisplay
, int VDisplay
, float VRefresh
,
139 printf("Modeline \"%dx%dR\" ", HDisplay
, VDisplay
);
141 printf("Modeline \"%dx%d_%.2f\" ", HDisplay
, VDisplay
, VRefresh
);
143 printf("%6.2f %i %i %i %i %i %i %i %i", Mode
->Clock
/1000., Mode
->HDisplay
,
144 Mode
->HSyncStart
, Mode
->HSyncEnd
, Mode
->HTotal
, Mode
->VDisplay
,
145 Mode
->VSyncStart
, Mode
->VSyncEnd
, Mode
->VTotal
);
147 if (Mode
->Flags
& V_INTERLACE
)
148 printf(" interlace");
149 if (Mode
->Flags
& V_PHSYNC
)
151 if (Mode
->Flags
& V_NHSYNC
)
153 if (Mode
->Flags
& V_PVSYNC
)
155 if (Mode
->Flags
& V_NVSYNC
)
166 main (int argc
, char *argv
[])
168 DisplayModeRec
*Mode
;
169 int HDisplay
= 0, VDisplay
= 0;
170 float VRefresh
= 0.0;
171 Bool Reduced
= FALSE
, Verbose
= FALSE
, IsCVT
;
172 Bool Interlaced
= FALSE
;
175 if ((argc
< 3) || (argc
> 7)) {
180 /* This doesn't filter out bad flags properly. Bad flags get passed down
181 * to atoi/atof, which then return 0, so that these variables can get
182 * filled next time round. So this is just a cosmetic problem.
184 for (n
= 1; n
< argc
; n
++) {
185 if (!strcmp(argv
[n
], "-r") || !strcmp(argv
[n
], "--reduced"))
187 else if (!strcmp(argv
[n
], "-i") || !strcmp(argv
[n
], "--interlaced"))
189 else if (!strcmp(argv
[n
], "-v") || !strcmp(argv
[n
], "--verbose"))
191 else if (!strcmp(argv
[n
], "-h") || !strcmp(argv
[n
], "--help")) {
194 } else if (!HDisplay
)
195 HDisplay
= atoi(argv
[n
]);
197 VDisplay
= atoi(argv
[n
]);
199 VRefresh
= atof(argv
[n
]);
206 if (!HDisplay
|| !VDisplay
) {
211 /* Default to 60.0Hz */
215 /* Horizontal timing is always a multiple of 8: round up. */
216 if (HDisplay
& 0x07) {
221 if (Reduced
&& (VRefresh
!= 60.0)) {
222 fprintf(stderr
, "\nERROR: 60Hz refresh rate required for reduced"
228 IsCVT
= CVTCheckStandard(HDisplay
, VDisplay
, VRefresh
, Reduced
, Verbose
);
230 Mode
= xf86CVTMode(HDisplay
, VDisplay
, VRefresh
, Reduced
, Interlaced
);
232 PrintComment(Mode
, IsCVT
, Reduced
);
233 PrintModeline(Mode
, HDisplay
, VDisplay
, VRefresh
, Reduced
);