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. */
28 /* FatalError implementation used by the server code we built in */
30 FatalError(const char *f, ...)
35 vfprintf(stderr, f, args);
40 /* xnfalloc implementation used by the server code we built in */
42 XNFalloc(unsigned long n)
48 perror("malloc failed");
54 /* xnfcalloc implementation used by the server code we built in */
56 XNFcalloc(unsigned long n)
62 perror("calloc failed");
69 * Quickly check wether this is a CVT standard mode.
72 CVTCheckStandard(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
77 if ((!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay)) ||
78 (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay)) ||
79 (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay)) ||
80 (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay)) ||
81 (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay)));
84 fprintf(stderr, "Warning: Aspect Ratio is not CVT standard.\n");
88 if ((VRefresh != 50.0) && (VRefresh != 60.0) &&
89 (VRefresh != 75.0) && (VRefresh != 85.0)) {
91 fprintf(stderr, "Warning: Refresh Rate is not CVT standard "
92 "(50, 60, 75 or 85Hz).\n");
100 * I'm not documenting --interlaced for obvious reasons, even though I did
101 * implement it. I also can't deny having looked at gtf here.
104 PrintUsage(char *Name)
106 fprintf(stderr, "\n");
107 fprintf(stderr, "usage: %s [-v|--verbose] [-r|--reduced] X Y [refresh]\n",
109 fprintf(stderr, "\n");
110 fprintf(stderr, " -v|--verbose : Warn about CVT standard adherance.\n");
111 fprintf(stderr, " -r|--reduced : Create a mode with reduced blanking "
112 "(default: normal blanking).\n");
113 fprintf(stderr, " X : Desired horizontal resolution "
114 "(multiple of 8, required).\n");
116 " Y : Desired vertical resolution (required).\n");
118 " refresh : Desired refresh rate (default: 60.0Hz).\n");
119 fprintf(stderr, "\n");
121 fprintf(stderr, "Calculates VESA CVT (Coordinated Video Timing) modelines"
122 " for use with X.\n");
129 PrintComment(DisplayModeRec * Mode, Bool CVT, Bool Reduced)
131 printf("# %dx%d %.2f Hz ", Mode->HDisplay, Mode->VDisplay, Mode->VRefresh);
135 ((float) Mode->HDisplay * Mode->VDisplay) / 1000000.0);
137 if (!(Mode->VDisplay % 3) &&
138 ((Mode->VDisplay * 4 / 3) == Mode->HDisplay))
140 else if (!(Mode->VDisplay % 9) &&
141 ((Mode->VDisplay * 16 / 9) == Mode->HDisplay))
143 else if (!(Mode->VDisplay % 10) &&
144 ((Mode->VDisplay * 16 / 10) == Mode->HDisplay))
146 else if (!(Mode->VDisplay % 4) &&
147 ((Mode->VDisplay * 5 / 4) == Mode->HDisplay))
149 else if (!(Mode->VDisplay % 9) &&
150 ((Mode->VDisplay * 15 / 9) == Mode->HDisplay))
161 printf("hsync: %.2f kHz; ", Mode->HSync);
162 printf("pclk: %.2f MHz", ((float) Mode->Clock) / 1000.0);
168 * Originally grabbed from xf86Mode.c.
170 * Ignoring the actual Mode->name, as the user will want something solid
174 PrintModeline(DisplayModePtr Mode, int HDisplay, int VDisplay, float VRefresh,
178 printf("Modeline \"%dx%dR\" ", HDisplay, VDisplay);
180 printf("Modeline \"%dx%d_%.2f\" ", HDisplay, VDisplay, VRefresh);
182 printf("%6.2f %i %i %i %i %i %i %i %i", Mode->Clock / 1000.,
183 Mode->HDisplay, Mode->HSyncStart, Mode->HSyncEnd, Mode->HTotal,
184 Mode->VDisplay, Mode->VSyncStart, Mode->VSyncEnd, Mode->VTotal);
186 if (Mode->Flags & V_INTERLACE)
187 printf(" interlace");
188 if (Mode->Flags & V_PHSYNC)
190 if (Mode->Flags & V_NHSYNC)
192 if (Mode->Flags & V_PVSYNC)
194 if (Mode->Flags & V_NVSYNC)
204 main(int argc, char *argv[])
206 DisplayModeRec *Mode;
207 int HDisplay = 0, VDisplay = 0;
208 float VRefresh = 0.0;
209 Bool Reduced = FALSE, Verbose = FALSE, IsCVT;
210 Bool Interlaced = FALSE;
213 if ((argc < 3) || (argc > 7)) {
218 /* This doesn't filter out bad flags properly. Bad flags get passed down
219 * to atoi/atof, which then return 0, so that these variables can get
220 * filled next time round. So this is just a cosmetic problem.
222 for (n = 1; n < argc; n++) {
223 if (!strcmp(argv[n], "-r") || !strcmp(argv[n], "--reduced"))
225 else if (!strcmp(argv[n], "-i") || !strcmp(argv[n], "--interlaced"))
227 else if (!strcmp(argv[n], "-v") || !strcmp(argv[n], "--verbose"))
229 else if (!strcmp(argv[n], "-h") || !strcmp(argv[n], "--help")) {
233 else if (!HDisplay) {
234 HDisplay = atoi(argv[n]);
240 else if (!VDisplay) {
241 VDisplay = atoi(argv[n]);
247 else if (!VRefresh) {
248 VRefresh = atof(argv[n]);
260 if (!HDisplay || !VDisplay) {
265 /* Default to 60.0Hz */
269 /* Horizontal timing is always a multiple of 8: round up. */
270 if (HDisplay & 0x07) {
276 if ((VRefresh / 60.0) != floor(VRefresh / 60.0)) {
278 "\nERROR: Multiple of 60Hz refresh rate required for "
279 " reduced blanking.\n");
285 IsCVT = CVTCheckStandard(HDisplay, VDisplay, VRefresh, Reduced, Verbose);
287 Mode = xf86CVTMode(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
289 PrintComment(Mode, IsCVT, Reduced);
290 PrintModeline(Mode, HDisplay, VDisplay, VRefresh, Reduced);