[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 1325 - (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 1325 * $Id: status.c,v 1.1.2.4 2004-01-23 11:03:48 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 : syskin 1325 if (j_height==0 && s->quant[0][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 : syskin 1325 "0","1","2","3","4","5","6","7","8","9",
95 :     "0","1","2","3","4","5","6","7","8","9",
96 :     "0","1"
97 : suxen_drol 1061 };
98 :    
99 : syskin 1325 static double
100 :     avg_quant(int quants[31], int min, int max, char* buf)
101 :     {
102 :     int i, sum = 0, count = 0;
103 :     for (i = min; i <= max && i > 0; i++) {
104 :     sum += i*quants[i-1];
105 :     count += quants[i-1];
106 :     }
107 : suxen_drol 1061
108 : syskin 1325 if (count != 0) {
109 :     double avg = (double)sum/(double)count;
110 :     sprintf(buf, "%.2f", avg);
111 :     return avg;
112 :     } else {
113 :     buf[0] = 0;
114 :     return 0.0;
115 :     }
116 :     }
117 :    
118 : suxen_drol 1061 /* status window proc handlder */
119 :    
120 :     static BOOL CALLBACK status_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
121 :     {
122 : syskin 1319 status_t * s = (status_t*)GetWindowLong(hDlg, GWL_USERDATA);
123 : suxen_drol 1061
124 :     switch (uMsg)
125 :     {
126 :     case WM_INITDIALOG :
127 :     SetWindowLong(hDlg, GWL_USERDATA, lParam);
128 :     s = (status_t*)lParam;
129 : syskin 1319
130 :     s->hGraph = GetDlgItem(hDlg, IDC_STATUS_GRAPH);
131 :     s->hDc = GetDC(s->hGraph);
132 :     {
133 :     RECT rect;
134 :     GetWindowRect(s->hGraph, &rect);
135 :     s->width = rect.right - rect.left;
136 :     s->height = rect.bottom - rect.top;
137 :     }
138 :     s->width31 = s->width/31;
139 :     s->stride = (s->width/4+1)*4;
140 : suxen_drol 1061
141 : syskin 1319 s->buffer = malloc(s->width * s->stride);
142 : suxen_drol 1061
143 : syskin 1319 s->bi = malloc(sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
144 :     memset(s->bi, 0, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
145 : suxen_drol 1061
146 : syskin 1319 s->bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
147 :     s->bi->bmiHeader.biWidth = s->stride;
148 :     s->bi->bmiHeader.biHeight = s->height;
149 :     s->bi->bmiHeader.biPlanes = 1;
150 :     s->bi->bmiHeader.biBitCount = 8;
151 :     s->bi->bmiHeader.biCompression = BI_RGB;
152 : suxen_drol 1061
153 : syskin 1319 set_bic(s->bi->bmiColors, CLR_BG, 0, 0, 0);
154 :     set_bic(s->bi->bmiColors, CLR_FG, 128, 128, 128);
155 :     set_bic(s->bi->bmiColors, CLR_QUANT_I, 255, 0, 0);
156 :     set_bic(s->bi->bmiColors, CLR_QUANT_P, 0, 0, 255);
157 :     set_bic(s->bi->bmiColors, CLR_QUANT_B, 0, 192, 0);
158 : suxen_drol 1061
159 : syskin 1325 SelectObject(s->hDc, GetStockObject(DEFAULT_GUI_FONT));
160 : syskin 1319 SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);
161 :     SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);
162 :     GetTextMetrics(s->hDc, &s->tm);
163 : suxen_drol 1061
164 : syskin 1319 draw_graph(s);
165 :     SetTimer(hDlg, IDC_STATUS_GRAPH, 1000, NULL); /* 1 second */
166 : suxen_drol 1061 break;
167 :    
168 : syskin 1319 case WM_DESTROY :
169 :     free(s->buffer);
170 :     free(s->bi);
171 :     KillTimer(hDlg, IDC_STATUS_GRAPH);
172 :     s->hDlg = NULL;
173 :     break;
174 : suxen_drol 1061
175 : syskin 1319 case WM_DRAWITEM :
176 :     if (wParam==IDC_STATUS_GRAPH) {
177 :     int i;
178 : suxen_drol 1061
179 : syskin 1319 /* copy buffer into dc */
180 :     SetDIBitsToDevice(s->hDc,
181 :     0, 0, s->width, s->height,
182 :     0, 0, 0, s->height,
183 :     s->buffer, s->bi, DIB_RGB_COLORS);
184 : suxen_drol 1061
185 : syskin 1319 SetTextAlign(s->hDc, GetTextAlign(s->hDc)|TA_CENTER);
186 : suxen_drol 1061
187 : syskin 1319 for (i=0; i<31; i++) {
188 :     TextOut(s->hDc, i*s->width31 + s->width/62,
189 :     s->height-s->tm.tmHeight, number[i], strlen(number[i]));
190 :     }
191 :     }
192 :     break;
193 : suxen_drol 1061
194 : syskin 1319 case WM_TIMER :
195 :     if (wParam==IDC_STATUS_GRAPH) {
196 : syskin 1325 double avg_q; char buf[16];
197 : suxen_drol 1061
198 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, (unsigned int)s->count[1], FALSE);
199 :     SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, (unsigned int)s->count[2], FALSE);
200 :     SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, (unsigned int)s->count[3], FALSE);
201 :     SetDlgItemInt(hDlg, IDC_STATUS_NUM, (unsigned int)s->count[0], FALSE);
202 : syskin 1319
203 :     SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);
204 :     SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);
205 :     SetDlgItemInt(hDlg, IDC_STATUS_PQ_MIN, s->min_quant[2], FALSE);
206 :     SetDlgItemInt(hDlg, IDC_STATUS_PQ_MAX, s->max_quant[2], FALSE);
207 :     SetDlgItemInt(hDlg, IDC_STATUS_BQ_MIN, s->min_quant[3], FALSE);
208 :     SetDlgItemInt(hDlg, IDC_STATUS_BQ_MAX, s->max_quant[3], FALSE);
209 :     SetDlgItemInt(hDlg, IDC_STATUS_Q_MIN, s->min_quant[0], FALSE);
210 :     SetDlgItemInt(hDlg, IDC_STATUS_Q_MAX, s->max_quant[0], FALSE);
211 : suxen_drol 1061
212 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);
213 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);
214 :     if (s->count[1]>0)
215 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, (unsigned int)(s->tot_length[1]/s->count[1]), FALSE);
216 : syskin 1319 else
217 :     SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);
218 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, (unsigned int)(s->tot_length[1]/1024), FALSE);
219 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);
220 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);
221 :     if (s->count[2]>0)
222 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, (unsigned int)(s->tot_length[2]/s->count[2]), FALSE);
223 : syskin 1319 else
224 :     SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);
225 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, (unsigned int)(s->tot_length[2]/1024), FALSE);
226 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);
227 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);
228 :     if (s->count[3]>0)
229 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, (unsigned int)(s->tot_length[3]/s->count[3]), FALSE);
230 : syskin 1319 else
231 :     SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);
232 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, (unsigned int)(s->tot_length[3]/1024), FALSE);
233 : syskin 1319 SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);
234 :     SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);
235 :     if (s->count[0]>0)
236 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, (int)(s->tot_length[0]/s->count[0]), FALSE);
237 : syskin 1319 else
238 :     SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);
239 : syskin 1325 SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, (unsigned int)(s->tot_length[0]/1024), FALSE);
240 : suxen_drol 1061
241 : syskin 1319 if (s->count[0]>0) {
242 :     uint64_t kbits = 8*s->tot_length[0]/1000;
243 :     double secs = (double)s->count[0]/s->fps;
244 :     SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);
245 :     }else{
246 :     SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);
247 :     }
248 : suxen_drol 1061
249 : syskin 1325 avg_q = avg_quant(s->quant[0], s->min_quant[1], s->max_quant[1], buf) * s->count[1];
250 :     SetDlgItemText(hDlg, IDC_STATUS_IQ_AVG, buf);
251 :    
252 :     avg_q += avg_quant(s->quant[1], s->min_quant[2], s->max_quant[2], buf) * s->count[2];
253 :     SetDlgItemText(hDlg, IDC_STATUS_PQ_AVG, buf);
254 :    
255 :     avg_q += avg_quant(s->quant[2], s->min_quant[3], s->max_quant[3], buf) * s->count[3];
256 :     SetDlgItemText(hDlg, IDC_STATUS_BQ_AVG, buf);
257 :    
258 :     if (s->count[0] != 0) avg_q /= (double)s->count[0];
259 :     sprintf(buf, "%.2f", avg_q);
260 :     SetDlgItemText(hDlg, IDC_STATUS_Q_AVG, buf);
261 :    
262 : syskin 1319 draw_graph(s);
263 :     InvalidateRect(s->hGraph, NULL, FALSE);
264 :     }
265 :     break;
266 : suxen_drol 1061
267 : syskin 1319 case WM_COMMAND :
268 :     if (LOWORD(wParam)==IDCANCEL) {
269 :     DestroyWindow(hDlg);
270 :     }
271 :     break;
272 : suxen_drol 1061
273 : syskin 1319 default :
274 : suxen_drol 1061 return FALSE;
275 :     }
276 :    
277 :     return TRUE;
278 :     }
279 :    
280 :    
281 :     /* destroy status window
282 :     (however if the auto-close box is unchecked, dont destroy) */
283 :    
284 :     void status_destroy(status_t *s)
285 :     {
286 : syskin 1319 if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_STATUS_DESTROY)==BST_CHECKED) {
287 :     DestroyWindow(s->hDlg);
288 :     }
289 : suxen_drol 1061 }
290 :    
291 :    
292 :     /* destroy status window, alwasys */
293 :    
294 :     void status_destroy_always(status_t *s)
295 :     {
296 : syskin 1319 if (s->hDlg) {
297 :     DestroyWindow(s->hDlg);
298 :     }
299 : suxen_drol 1061 }
300 :    
301 :    
302 :     /* create status window */
303 :     void status_create(status_t * s, unsigned int fps_inc, unsigned int fps_base)
304 :     {
305 : syskin 1319 int i;
306 : suxen_drol 1061
307 : syskin 1319 s->fps = fps_base/fps_inc;
308 : suxen_drol 1061
309 : syskin 1325 memset(s->quant[0], 0, 31*sizeof(int));
310 :     memset(s->quant[1], 0, 31*sizeof(int));
311 :     memset(s->quant[2], 0, 31*sizeof(int));
312 : syskin 1319 s->max_quant_frames = 0;
313 :     for (i=0; i<4; i++) {
314 :     s->count[i] = 0;
315 :     s->min_quant[i] = s->max_quant[i] = 0;
316 :     s->min_length[i] = s->max_length[i] = 0;
317 :     s->tot_length[i] = 0;
318 :     }
319 : suxen_drol 1061
320 : syskin 1319 s->hDlg = CreateDialogParam(g_hInst,
321 :     MAKEINTRESOURCE(IDD_STATUS),
322 :     GetDesktopWindow(),
323 :     status_proc, (LPARAM)s);
324 : suxen_drol 1061
325 : syskin 1319 ShowWindow(s->hDlg, SW_SHOW);
326 : suxen_drol 1061 }
327 :    
328 : syskin 1325 static char
329 :     type2char(int type)
330 :     {
331 :     if (type==XVID_TYPE_IVOP)
332 :     return 'I';
333 :     if (type==XVID_TYPE_PVOP)
334 :     return 'P';
335 :     if (type==XVID_TYPE_BVOP)
336 :     return 'B';
337 :     return 'S';
338 :     }
339 : suxen_drol 1061
340 : syskin 1325 static void
341 :     status_debugoutput(status_t *s, int type, int length, int quant)
342 :     {
343 :     if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_SHOWINTERNALS)==BST_CHECKED) {
344 :     LRESULT litem;
345 :     char buf[128];
346 :     sprintf(buf, "[%6d] ->%c q:%2d (%6d b)",
347 :     (unsigned int)(s->count[0]), type2char(type), quant, length);
348 :    
349 :     SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_ADDSTRING, 0, (LPARAM)(LPSTR)buf);
350 :    
351 :     litem = SendDlgItemMessage (s->hDlg, IDC_DEBUGOUTPUT, LB_GETCOUNT, 0, 0L);
352 :    
353 :     if (litem > 12)
354 :     litem = SendDlgItemMessage (s->hDlg,IDC_DEBUGOUTPUT, LB_DELETESTRING, 0, 0L);
355 :    
356 :     SendDlgItemMessage(s->hDlg,IDC_DEBUGOUTPUT, LB_SETCURSEL, (WORD)(litem-1), 0L);
357 :     }
358 :     }
359 :    
360 : suxen_drol 1061 /* feed stats info into the window */
361 :     void status_update(status_t *s, int type, int length, int quant)
362 :     {
363 : syskin 1319 s->count[0]++;
364 :     s->count[type]++;
365 : suxen_drol 1061
366 : syskin 1325 status_debugoutput(s, type, length, quant);
367 :    
368 :     if (type == 4) type = 2; /* XVID_TYPE_SVOP to XVID_TYPE_PVOP */
369 :    
370 : syskin 1319 if (s->min_quant[0]==0 || quant<s->min_quant[0]) s->min_quant[0] = quant;
371 :     if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant;
372 :     if (s->min_quant[type]==0 || quant<s->min_quant[type]) s->min_quant[type] = quant;
373 :     if (s->max_quant[type]==0|| quant>s->max_quant[type]) s->max_quant[type] = quant;
374 : suxen_drol 1061
375 : syskin 1319 s->quant[type-1][quant-1]++;
376 :     if (s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1] > s->max_quant_frames)
377 :     s->max_quant_frames = s->quant[0][quant-1] + s->quant[1][quant-1] + s->quant[2][quant-1];
378 : suxen_drol 1061
379 : syskin 1319 if (s->min_length[0]==0 || length<s->min_length[0]) s->min_length[0] = length;
380 :     if (s->max_length[0]==0 || length>s->max_length[0]) s->max_length[0] = length;
381 :     if (s->min_length[type]==0 || length<s->min_length[type]) s->min_length[type] = length;
382 :     if (s->max_length[type]==0|| length>s->max_length[type]) s->max_length[type] = length;
383 :     s->tot_length[0] += length;
384 :     s->tot_length[type] += length;
385 : suxen_drol 1061 }

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