[svn] / branches / dev-api-4 / xvidcore / vfw / src / status.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/vfw/src/status.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1319 - (view) (download)

1 : suxen_drol 1061 /******************************************************************************
2 :     *
3 :     * XviD Video-for-Windows Frontend
4 :     * Quantizer histogram and encoding status window
5 :     *
6 :     * Copyright (C) 2003 Peter Ross <pross@xvid.org>
7 :     *
8 :     * This program is free software; you can redistribute it and/or modify
9 :     * it under the terms of the GNU General Public License as published by
10 :     * the Free Software Foundation; either version 2 of the License, or
11 :     * (at your option) any later version.
12 :     *
13 :     * This program is distributed in the hope that it will be useful,
14 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     * GNU General Public License for more details.
17 :     *
18 :     * You should have received a copy of the GNU General Public License
19 :     * along with this program; if not, write to the Free Software
20 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     *
22 : syskin 1319 * $Id: status.c,v 1.1.2.3 2004-01-22 14:43:39 syskin Exp $
23 : suxen_drol 1061 *
24 :     *****************************************************************************/
25 :    
26 :    
27 :     #include <windows.h>
28 :     #include "resource.h"
29 :     #include "codec.h"
30 :     #include "status.h"
31 :    
32 :     #include "debug.h"
33 :    
34 :    
35 : syskin 1319 #define CLR_BG 0
36 :     #define CLR_FG 1
37 :     #define CLR_QUANT_I 2
38 :     #define CLR_QUANT_P 3
39 :     #define CLR_QUANT_B 4
40 : suxen_drol 1061
41 :     static void set_bic(RGBQUAD * rgb, int index, int r, int g, int b)
42 :     {
43 : syskin 1319 rgb[index].rgbRed = r;
44 :     rgb[index].rgbGreen = g;
45 :     rgb[index].rgbBlue = b;
46 : suxen_drol 1061 }
47 :    
48 :     /*
49 : syskin 1319 draw graph into buffer
50 : suxen_drol 1061 */
51 :     static void draw_graph(status_t *s)
52 :     {
53 : syskin 1319 unsigned int i,j;
54 : suxen_drol 1061
55 : syskin 1319 memset(s->buffer, CLR_BG, s->width*s->stride);
56 : suxen_drol 1061
57 : syskin 1319 for (j=0; j<s->height; j++)
58 :     for (i=0; i<31; i++)
59 :     s->buffer[ j*s->stride + i*s->width31 ] = CLR_FG;
60 : suxen_drol 1061
61 : syskin 1319 if (s->count[0]>0) {
62 :     for (i=0; i<31; i++) {
63 :     /* i-vops */
64 :     unsigned int j_height = (s->height-s->tm.tmHeight)*s->quant[0][i]/s->max_quant_frames;
65 :     if (j_height==0 && s->quant[1][i]>0) j_height=1;
66 : suxen_drol 1061
67 : syskin 1319 for(j=0; j < j_height; j++) {
68 :     memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
69 :     CLR_QUANT_I, s->width31-1);
70 :     }
71 :     /* p/s-vops */
72 :     j_height += (s->height-s->tm.tmHeight)*s->quant[1][i]/s->max_quant_frames;
73 :     if (j_height==0 && s->quant[1][i]>0) j_height=1;
74 :    
75 :     for(; j < j_height; j++) {
76 :     memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
77 :     CLR_QUANT_P, s->width31-1);
78 :     }
79 :     /* b-vops */
80 :     j_height += (s->height-s->tm.tmHeight)*s->quant[2][i]/s->max_quant_frames;
81 :     if (j_height==0 && s->quant[2][i]>0) j_height=1;
82 :    
83 :     for(; j < j_height; j++) {
84 :     memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
85 :     CLR_QUANT_B, s->width31-1);
86 :     }
87 :     }
88 :     }
89 : suxen_drol 1061 }
90 :    
91 :    
92 :     static const char * number[31] = {
93 : syskin 1319 "1", "2", "3", "4", "5", "6", "7", "8", "9",
94 :     "10","11","12","13","14","15","16","17","18","19",
95 :     "20","21","22","23","24","25","26","27","28","29",
96 :     "30","31"
97 : suxen_drol 1061 };
98 :    
99 :    
100 :     /* status window proc handlder */
101 :    
102 :     static BOOL CALLBACK status_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
103 :     {
104 : syskin 1319 status_t * s = (status_t*)GetWindowLong(hDlg, GWL_USERDATA);
105 : suxen_drol 1061
106 :     switch (uMsg)
107 :     {
108 :     case WM_INITDIALOG :
109 :     SetWindowLong(hDlg, GWL_USERDATA, lParam);
110 :     s = (status_t*)lParam;
111 : syskin 1319
112 :     s->hGraph = GetDlgItem(hDlg, IDC_STATUS_GRAPH);
113 :     s->hDc = GetDC(s->hGraph);
114 :     {
115 :     RECT rect;
116 :     GetWindowRect(s->hGraph, &rect);
117 :     s->width = rect.right - rect.left;
118 :     s->height = rect.bottom - rect.top;
119 :     }
120 :     s->width31 = s->width/31;
121 :     s->stride = (s->width/4+1)*4;
122 : suxen_drol 1061
123 : syskin 1319 s->buffer = malloc(s->width * s->stride);
124 : suxen_drol 1061
125 : syskin 1319 s->bi = malloc(sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
126 :     memset(s->bi, 0, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
127 : suxen_drol 1061
128 : syskin 1319 s->bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
129 :     s->bi->bmiHeader.biWidth = s->stride;
130 :     s->bi->bmiHeader.biHeight = s->height;
131 :     s->bi->bmiHeader.biPlanes = 1;
132 :     s->bi->bmiHeader.biBitCount = 8;
133 :     s->bi->bmiHeader.biCompression = BI_RGB;
134 : suxen_drol 1061
135 : syskin 1319 set_bic(s->bi->bmiColors, CLR_BG, 0, 0, 0);
136 :     set_bic(s->bi->bmiColors, CLR_FG, 128, 128, 128);
137 :     set_bic(s->bi->bmiColors, CLR_QUANT_I, 255, 0, 0);
138 :     set_bic(s->bi->bmiColors, CLR_QUANT_P, 0, 0, 255);
139 :     set_bic(s->bi->bmiColors, CLR_QUANT_B, 0, 192, 0);
140 : suxen_drol 1061
141 : syskin 1319 SelectObject(s->hDc, GetStockObject(SYSTEM_FONT));
142 :     SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);
143 :     SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);
144 :     GetTextMetrics(s->hDc, &s->tm);
145 : suxen_drol 1061
146 : syskin 1319 draw_graph(s);
147 :     SetTimer(hDlg, IDC_STATUS_GRAPH, 1000, NULL); /* 1 second */
148 : suxen_drol 1061 break;
149 :    
150 : syskin 1319 case WM_DESTROY :
151 :     free(s->buffer);
152 :     free(s->bi);
153 :     KillTimer(hDlg, IDC_STATUS_GRAPH);
154 :     s->hDlg = NULL;
155 :     break;
156 : suxen_drol 1061
157 : syskin 1319 case WM_DRAWITEM :
158 :     if (wParam==IDC_STATUS_GRAPH) {
159 :     int i;
160 : suxen_drol 1061
161 : syskin 1319 /* copy buffer into dc */
162 :     SetDIBitsToDevice(s->hDc,
163 :     0, 0, s->width, s->height,
164 :     0, 0, 0, s->height,
165 :     s->buffer, s->bi, DIB_RGB_COLORS);
166 : suxen_drol 1061
167 : syskin 1319 SetTextAlign(s->hDc, GetTextAlign(s->hDc)|TA_CENTER);
168 : suxen_drol 1061
169 : syskin 1319 for (i=0; i<31; i++) {
170 :     TextOut(s->hDc, i*s->width31 + s->width/62,
171 :     s->height-s->tm.tmHeight, number[i], strlen(number[i]));
172 :     }
173 :     }
174 :     break;
175 : suxen_drol 1061
176 : syskin 1319 case WM_TIMER :
177 :     if (wParam==IDC_STATUS_GRAPH) {
178 : suxen_drol 1061
179 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, s->count[1], FALSE);
180 :     SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, s->count[2], FALSE);
181 :     SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, s->count[3], FALSE);
182 :     SetDlgItemInt(hDlg, IDC_STATUS_NUM, s->count[0], FALSE);
183 :    
184 :     SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);
185 :     SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);
186 :     SetDlgItemInt(hDlg, IDC_STATUS_PQ_MIN, s->min_quant[2], FALSE);
187 :     SetDlgItemInt(hDlg, IDC_STATUS_PQ_MAX, s->max_quant[2], FALSE);
188 :     SetDlgItemInt(hDlg, IDC_STATUS_BQ_MIN, s->min_quant[3], FALSE);
189 :     SetDlgItemInt(hDlg, IDC_STATUS_BQ_MAX, s->max_quant[3], FALSE);
190 :     SetDlgItemInt(hDlg, IDC_STATUS_Q_MIN, s->min_quant[0], FALSE);
191 :     SetDlgItemInt(hDlg, IDC_STATUS_Q_MAX, s->max_quant[0], FALSE);
192 : suxen_drol 1061
193 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);
194 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);
195 :     if (s->count[1]>0)
196 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, s->tot_length[1]/s->count[1], FALSE);
197 :     else
198 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);
199 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, s->tot_length[1]/1024, FALSE);
200 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);
201 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);
202 :     if (s->count[2]>0)
203 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, s->tot_length[2]/s->count[2], FALSE);
204 :     else
205 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);
206 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, s->tot_length[2]/1024, FALSE);
207 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);
208 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);
209 :     if (s->count[3]>0)
210 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, s->tot_length[3]/s->count[3], FALSE);
211 :     else
212 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);
213 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, s->tot_length[3]/1024, FALSE);
214 :     SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);
215 :     SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);
216 :     if (s->count[0]>0)
217 :     SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, s->tot_length[0]/s->count[0], FALSE);
218 :     else
219 :     SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);
220 :     SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, s->tot_length[0]/1024, FALSE);
221 : suxen_drol 1061
222 : syskin 1319 if (s->count[0]>0) {
223 :     uint64_t kbits = 8*s->tot_length[0]/1000;
224 :     double secs = (double)s->count[0]/s->fps;
225 :     SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);
226 :     }else{
227 :     SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);
228 :     }
229 : suxen_drol 1061
230 : syskin 1319 draw_graph(s);
231 :     InvalidateRect(s->hGraph, NULL, FALSE);
232 :     }
233 :     break;
234 : suxen_drol 1061
235 : syskin 1319 case WM_COMMAND :
236 :     if (LOWORD(wParam)==IDCANCEL) {
237 :     DestroyWindow(hDlg);
238 :     }
239 :     break;
240 : suxen_drol 1061
241 : syskin 1319 default :
242 : suxen_drol 1061 return FALSE;
243 :     }
244 :    
245 :     return TRUE;
246 :     }
247 :    
248 :    
249 :     /* destroy status window
250 :     (however if the auto-close box is unchecked, dont destroy) */
251 :    
252 :     void status_destroy(status_t *s)
253 :     {
254 : syskin 1319 if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_STATUS_DESTROY)==BST_CHECKED) {
255 :     DestroyWindow(s->hDlg);
256 :     }
257 : suxen_drol 1061 }
258 :    
259 :    
260 :     /* destroy status window, alwasys */
261 :    
262 :     void status_destroy_always(status_t *s)
263 :     {
264 : syskin 1319 if (s->hDlg) {
265 :     DestroyWindow(s->hDlg);
266 :     }
267 : suxen_drol 1061 }
268 :    
269 :    
270 :     /* create status window */
271 :     void status_create(status_t * s, unsigned int fps_inc, unsigned int fps_base)
272 :     {
273 : syskin 1319 int i;
274 : suxen_drol 1061
275 : syskin 1319 s->fps = fps_base/fps_inc;
276 : suxen_drol 1061
277 : syskin 1319 memset(s->quant, 0, 31*sizeof(int));
278 :     s->max_quant_frames = 0;
279 :     for (i=0; i<4; i++) {
280 :     s->count[i] = 0;
281 :     s->min_quant[i] = s->max_quant[i] = 0;
282 :     s->min_length[i] = s->max_length[i] = 0;
283 :     s->tot_length[i] = 0;
284 :     }
285 : suxen_drol 1061
286 : syskin 1319 s->hDlg = CreateDialogParam(g_hInst,
287 :     MAKEINTRESOURCE(IDD_STATUS),
288 :     GetDesktopWindow(),
289 :     status_proc, (LPARAM)s);
290 : suxen_drol 1061
291 : syskin 1319 ShowWindow(s->hDlg, SW_SHOW);
292 : suxen_drol 1061 }
293 :    
294 :    
295 :     /* feed stats info into the window */
296 :     void status_update(status_t *s, int type, int length, int quant)
297 :     {
298 : syskin 1114 if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */
299 : syskin 1319 s->count[0]++;
300 :     s->count[type]++;
301 : suxen_drol 1061
302 : syskin 1319 if (s->min_quant[0]==0 || quant<s->min_quant[0]) s->min_quant[0] = quant;
303 :     if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant;
304 :     if (s->min_quant[type]==0 || quant<s->min_quant[type]) s->min_quant[type] = quant;
305 :     if (s->max_quant[type]==0|| quant>s->max_quant[type]) s->max_quant[type] = quant;
306 : suxen_drol 1061
307 : syskin 1319 s->quant[type-1][quant-1]++;
308 :     if (s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1] > s->max_quant_frames)
309 :     s->max_quant_frames = s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1];
310 : suxen_drol 1061
311 : syskin 1319 if (s->min_length[0]==0 || length<s->min_length[0]) s->min_length[0] = length;
312 :     if (s->max_length[0]==0 || length>s->max_length[0]) s->max_length[0] = length;
313 :     if (s->min_length[type]==0 || length<s->min_length[type]) s->min_length[type] = length;
314 :     if (s->max_length[type]==0|| length>s->max_length[type]) s->max_length[type] = length;
315 :     s->tot_length[0] += length;
316 :     s->tot_length[type] += length;
317 : suxen_drol 1061 }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4