annotate libvo/gtf.c @ 17670:f5f338e543b6

Fix rgb32tobgr16, rgb32to15, and rgb32tobgr15. All had the same problem that was fixed in rgb32to16 about a year ago: using only the first 8 bits of the 32-bit pixel.
author pacman
date Fri, 24 Feb 2006 09:52:59 +0000
parents d701716bfbbc
children 807aaa6415b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7069
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
1 /*
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
2 * Copyright (C) Rudolf Marek <r.marek@sh.cvut.cz> - Aug 2002
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
3 *
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
4 * You can redistribute this file under terms and conditions
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
5 * of GNU General Public licence v2.
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
6 *
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
7 * GTF calculations formulas are taken from GTF_V1R1.xls
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
8 * created by ANDY.MORRISH@NSC.COM
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
9 */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
10
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
11 //Version 0.4
15394
d701716bfbbc if define HAVE_ROUND do not define round again. patch by Steven M. Schultz <sms@2BSD.COM>
nplourde
parents: 7069
diff changeset
12 #include "config.h"
7069
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
13 #include <stdio.h>
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
14 #include <stdlib.h>
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
15 #include <math.h>
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
16 #include "gtf.h"
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
17
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
18 #undef GTF_DEBUG
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
19
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
20 #ifdef GTF_DEBUG
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
21 #define DEBUG_PRINTF(a,b) printf(a,b);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
22 #else
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
23 #define DEBUG_PRINTF(a,b)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
24 #endif
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
25
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
26 static GTF_constants GTF_given_constants = { 3.0,550.0,1,8,1.8,8,40,20,128,600 };
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
27
15394
d701716bfbbc if define HAVE_ROUND do not define round again. patch by Steven M. Schultz <sms@2BSD.COM>
nplourde
parents: 7069
diff changeset
28 #ifndef HAVE_ROUND
7069
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
29 static double round(double v)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
30 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
31 return floor(v + 0.5);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
32 }
15394
d701716bfbbc if define HAVE_ROUND do not define round again. patch by Steven M. Schultz <sms@2BSD.COM>
nplourde
parents: 7069
diff changeset
33 #endif
7069
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
34
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
35 static void GetRoundedConstants(GTF_constants *c)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
36 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
37 c->Vsync_need = round(GTF_given_constants.Vsync_need);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
38 c->min_Vsync_BP = GTF_given_constants.min_Vsync_BP;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
39 c->min_front_porch = round(GTF_given_constants.min_front_porch);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
40 c->char_cell_granularity = GTF_given_constants.char_cell_granularity;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
41 c->margin_width = GTF_given_constants.margin_width;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
42 c->sync_width = GTF_given_constants.sync_width;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
43 c->c = ((GTF_given_constants.c - GTF_given_constants.j)*(GTF_given_constants.k / 256)) + GTF_given_constants.j;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
44 c->j = GTF_given_constants.j;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
45 c->k = GTF_given_constants.k;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
46 c->m = (GTF_given_constants.k / 256) * GTF_given_constants.m;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
47 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
48
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
49 void GTF_calcTimings(double X,double Y,double freq, int type,
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
50 int want_margins, int want_interlace,struct VesaCRTCInfoBlock *result )
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
51 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
52 GTF_constants c;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
53 double RR, margin_top, margin_bottom, margin_left, margin_right;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
54 double estimated_H_period,sync_plus_BP,BP,interlace,V_total_lines_field;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
55 double estimated_V_field_rate,actual_H_period,actual_V_field_freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
56 double total_active_pixels, ideal_duty_cycle, blanking_time, H_total_pixels;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
57 double H_freq, pixel_freq,actual_V_frame_freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
58 double H_sync_start, H_sync_end, H_back_porch, H_front_porch, H_sync_width;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
59 double V_back_porch, V_front_porch, V_sync_start, V_sync_end,V_sync_width;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
60 double ideal_H_period;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
61 GetRoundedConstants(&c);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
62
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
63
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
64 pixel_freq = RR = freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
65
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
66 /* DETERMINE IF 1/2 LINE INTERLACE IS PRESENT */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
67
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
68 interlace = 0;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
69
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
70 if (want_interlace) {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
71 RR = RR * 2;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
72 Y=Y/2;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
73 interlace = 0.5;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
74 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
75
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
76 result->Flags = 0;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
77
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
78 if ((Y==300)||(Y==200)||(Y==240))
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
79 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
80 Y*=2;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
81 result->Flags = VESA_CRTC_DOUBLESCAN; /* TODO: check if mode support */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
82 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
83
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
84 /* DETERMINE NUMBER OF LINES IN V MARGIN */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
85 /* DETERMINE NUMBER OF PIXELS IN H MARGIN [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
86
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
87 margin_left = margin_right = 0;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
88 margin_top = margin_bottom = 0;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
89
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
90 if (want_margins) {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
91 margin_top = margin_bottom = (c.margin_width / 100) * Y;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
92 margin_left = round(( X* c.margin_width/100)/c.char_cell_granularity) \
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
93 * c.char_cell_granularity;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
94 margin_right = margin_left;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
95 DEBUG_PRINTF("margin_left_right : %f\n",margin_right)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
96 DEBUG_PRINTF("margin_top_bottom : %f\n",margin_top)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
97 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
98
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
99 /* FIND TOTAL NUMBER OF ACTIVE PIXELS (IMAGE + MARGIN) [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
100
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
101 total_active_pixels = margin_left + margin_right + X;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
102 DEBUG_PRINTF("total_active_pixels: %f\n",total_active_pixels)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
103
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
104 if (type == GTF_PF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
105 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
106 ideal_H_period = ((c.c-100)+(sqrt(((100-c.c)*(100-c.c) )+(0.4*c.m*(total_active_pixels + margin_left + margin_right) / freq))))/2/c.m*1000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
107
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
108 DEBUG_PRINTF("ideal_H_period: %f\n",ideal_H_period)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
109
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
110 /* FIND IDEAL BLANKING DUTY CYCLE FROM FORMULA [%] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
111 ideal_duty_cycle = c.c - (c.m * ideal_H_period /1000);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
112 DEBUG_PRINTF("ideal_duty_cycle: %f\n",ideal_duty_cycle)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
113
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
114 /* FIND BLANKING TIME (TO NEAREST CHAR CELL) [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
115
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
116 blanking_time = round(total_active_pixels * ideal_duty_cycle \
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
117 / (100-ideal_duty_cycle) / (2*c.char_cell_granularity)) \
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
118 * (2*c.char_cell_granularity);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
119 DEBUG_PRINTF("blanking_time : %f\n",blanking_time )
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
120
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
121 /* FIND TOTAL NUMBER OF PIXELS IN A LINE [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
122 H_total_pixels = total_active_pixels + blanking_time ;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
123 DEBUG_PRINTF("H_total_pixels: %f\n",H_total_pixels)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
124 H_freq = freq / H_total_pixels * 1000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
125 DEBUG_PRINTF("H_freq: %f\n",H_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
126 actual_H_period = 1000 / H_freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
127 DEBUG_PRINTF("actual_H_period: %f\n",actual_H_period)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
128 sync_plus_BP = round(H_freq * c.min_Vsync_BP/1000);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
129 // sync_plus_BP = round( freq / H_total_pixels * c.min_Vsync_BP);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
130
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
131 DEBUG_PRINTF("sync_plus_BP: %f\n",sync_plus_BP)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
132
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
133 } else if (type == GTF_VF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
134 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
135
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
136 /* ESTIMATE HORIZ. PERIOD [us] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
137
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
138 estimated_H_period = (( 1/RR ) - c.min_Vsync_BP/1000000 ) / (Y + (2 * margin_top) + c.min_front_porch + interlace) * 1000000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
139
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
140 DEBUG_PRINTF("estimated_H_period: %f\n",estimated_H_period)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
141
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
142 /* FIND NUMBER OF LINES IN (SYNC + BACK PORCH) [lines] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
143
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
144 sync_plus_BP = round( c.min_Vsync_BP / estimated_H_period );
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
145 DEBUG_PRINTF("sync_plus_BP: %f\n",sync_plus_BP)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
146
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
147 } else if (type == GTF_HF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
148 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
149 sync_plus_BP = round(freq * c.min_Vsync_BP/1000);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
150 DEBUG_PRINTF("sync_plus_BP: %f\n",sync_plus_BP)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
151 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
152
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
153
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
154
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
155 /* FIND TOTAL NUMBER OF LINES IN VERTICAL FIELD */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
156
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
157 V_total_lines_field = sync_plus_BP+interlace+margin_bottom+margin_top+Y+c.min_front_porch;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
158 DEBUG_PRINTF("V_total_lines_field : %f\n",V_total_lines_field )
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
159
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
160 if (type == GTF_VF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
161 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
162 /* ESTIMATE VERTICAL FIELD RATE [hz] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
163
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
164 estimated_V_field_rate = 1 / estimated_H_period / V_total_lines_field * 1000000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
165 DEBUG_PRINTF(" estimated_V_field_rate: %f\n", estimated_V_field_rate)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
166 /* FIND ACTUAL HORIZONTAL PERIOD [us] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
167
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
168 actual_H_period = estimated_H_period / (RR / estimated_V_field_rate);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
169 DEBUG_PRINTF("actual_H_period: %f\n",actual_H_period)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
170 /* FIND ACTUAL VERTICAL FIELD FREQUENCY [Hz] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
171
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
172 actual_V_field_freq = 1 / actual_H_period / V_total_lines_field * 1000000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
173 DEBUG_PRINTF("actual_V_field_freq: %f\n",actual_V_field_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
174
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
175 /* FIND IDEAL BLANKING DUTY CYCLE FROM FORMULA [%] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
176 ideal_duty_cycle = c.c - (c.m * actual_H_period /1000);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
177 DEBUG_PRINTF("ideal_duty_cycle: %f\n",ideal_duty_cycle)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
178 //if (type == GTF_VF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
179 //{
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
180 //moved
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
181 //}
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
182 } else if (type == GTF_HF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
183 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
184 /* FIND IDEAL BLANKING DUTY CYCLE FROM FORMULA [%] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
185 ideal_duty_cycle = c.c - (c.m / freq);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
186 DEBUG_PRINTF("ideal_duty_cycle: %f\n",ideal_duty_cycle)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
187 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
188
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
189 /* FIND BLANKING TIME (TO NEAREST CHAR CELL) [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
190
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
191 if (!(type == GTF_PF))
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
192 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
193 blanking_time = round(total_active_pixels * ideal_duty_cycle \
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
194 / (100-ideal_duty_cycle) / (2*c.char_cell_granularity)) \
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
195 * (2*c.char_cell_granularity);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
196 DEBUG_PRINTF("blanking_time : %f\n",blanking_time )
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
197 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
198 else
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
199 // if (type == GTF_PF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
200 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
201 actual_V_field_freq = H_freq / V_total_lines_field * 1000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
202 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
203
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
204 if (type == GTF_HF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
205 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
206 /* Hz */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
207 actual_V_field_freq = freq / V_total_lines_field * 1000;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
208 DEBUG_PRINTF("actual_V_field_freq: %f\n",actual_V_field_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
209 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
210
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
211
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
212 actual_V_frame_freq = actual_V_field_freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
213
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
214 /* FIND ACTUAL VERTICAL FRAME FREQUENCY [Hz]*/
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
215
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
216 if (want_interlace) actual_V_frame_freq = actual_V_field_freq / 2;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
217 DEBUG_PRINTF("actual_V_frame_freq: %f\n",actual_V_frame_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
218
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
219 // V_freq = actual_V_frame_freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
220 // DEBUG_PRINTF("V_freq %f\n",V_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
221
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
222
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
223 if (!(type == GTF_PF))
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
224 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
225 /* FIND TOTAL NUMBER OF PIXELS IN A LINE [pixels] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
226 H_total_pixels = total_active_pixels + blanking_time ;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
227 DEBUG_PRINTF("H_total_pixels: %f\n",H_total_pixels)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
228 if (type == GTF_VF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
229 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
230 /* FIND PIXEL FREQUENCY [Mhz] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
231 pixel_freq = H_total_pixels / actual_H_period ;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
232 DEBUG_PRINTF("pixel_freq: %f\n",pixel_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
233 } else if (type == GTF_HF)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
234 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
235 /* FIND PIXEL FREQUENCY [Mhz] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
236 pixel_freq = H_total_pixels * freq / 1000 ;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
237 DEBUG_PRINTF("pixel_freq: %f\n",pixel_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
238 actual_H_period = 1000/freq;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
239 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
240
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
241 /* FIND ACTUAL HORIZONTAL FREQUENCY [KHz] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
242
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
243 H_freq = 1000 / actual_H_period;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
244 DEBUG_PRINTF("H_freq %f\n",H_freq)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
245
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
246
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
247 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
248
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
249 /* FIND NUMBER OF LINES IN BACK PORCH [lines] */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
250
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
251 BP = sync_plus_BP - c.Vsync_need;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
252 DEBUG_PRINTF("BP: %f\n",BP)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
253
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
254 /*------------------------------------------------------------------------------------------------*/
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
255 /* FIND H SYNC WIDTH (TO NEAREST CHAR CELL) */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
256 H_sync_width = round(c.sync_width/100*H_total_pixels/c.char_cell_granularity)*c.char_cell_granularity;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
257 DEBUG_PRINTF("H_sync_width %f\n",H_sync_width)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
258
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
259 /* FIND FRONT H PORCH(TO NEAREST CHAR CELL) */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
260 H_front_porch = (blanking_time/2) - H_sync_width;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
261 DEBUG_PRINTF("H_front_porch %f\n",H_front_porch)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
262 /* FIND BACK H PORCH(TO NEAREST CHAR CELL) */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
263 H_back_porch = H_sync_width + H_front_porch;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
264 DEBUG_PRINTF("H_back_porch%f\n",H_back_porch)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
265
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
266 H_sync_start = H_total_pixels - (H_sync_width + H_back_porch);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
267 DEBUG_PRINTF("H_sync_start %f\n",H_sync_start)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
268 H_sync_end = H_total_pixels - H_back_porch;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
269 DEBUG_PRINTF("H_sync_end %f\n",H_sync_end)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
270
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
271 V_back_porch = interlace + BP;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
272 DEBUG_PRINTF("V_back_porch%f\n",V_back_porch)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
273 V_front_porch = interlace + c.min_front_porch;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
274 DEBUG_PRINTF("V_front_porch%f\n",V_front_porch)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
275
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
276 V_sync_width = c.Vsync_need;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
277 V_sync_start = V_total_lines_field - (V_sync_width + V_back_porch);
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
278 DEBUG_PRINTF("V_sync_start %f\n",V_sync_start)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
279 V_sync_end = V_total_lines_field - V_back_porch;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
280 DEBUG_PRINTF("V_sync_end %f\n",V_sync_end)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
281
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
282 result->hTotal = H_total_pixels;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
283 result-> hSyncStart = H_sync_start; /* Horizontal sync start in pixels */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
284 result-> hSyncEnd = H_sync_end; /* Horizontal sync end in pixels */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
285 result-> vTotal= V_total_lines_field; /* Vertical total in lines */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
286 result-> vSyncStart = V_sync_start; /* Vertical sync start in lines */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
287 result-> vSyncEnd = V_sync_end; /* Vertical sync end in lines */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
288 result-> Flags = (result->Flags)|VESA_CRTC_HSYNC_NEG; /* Flags (Interlaced, Double Scan etc) */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
289
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
290 if (want_interlace)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
291 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
292 result->Flags = (result->Flags) | VESA_CRTC_INTERLACED;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
293 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
294
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
295 result-> PixelClock = pixel_freq*1000000; /* Pixel clock in units of Hz */
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
296 result-> RefreshRate = actual_V_frame_freq*100;/* Refresh rate in units of 0.01 Hz*/
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
297
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
298 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
299
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents:
diff changeset
300