[cvs] / xvidcore / vfw / src / status.c Repository:
ViewVC logotype

Diff of /xvidcore/vfw/src/status.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Tue Jun 10 10:07:03 2003 UTC revision 1.1.2.1, Tue Jun 10 10:07:03 2003 UTC
# Line 0  Line 1 
1    /******************************************************************************
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     * $Id$
23     *
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    #define CLR_BG      0
36    #define CLR_FG      1
37    #define CLR_QUANT   2
38    
39    static void set_bic(RGBQUAD * rgb, int index, int r, int g, int b)
40    {
41        rgb[index].rgbRed = r;
42        rgb[index].rgbGreen = g;
43        rgb[index].rgbBlue = b;
44    }
45    
46    /*
47        draw graph into buffer
48    */
49    static void draw_graph(status_t *s)
50    {
51        unsigned int i,j;
52    
53        memset(s->buffer, CLR_BG, s->width*s->stride);
54    
55        for (j=0; j<s->height; j++)
56        for (i=0; i<31; i++)
57            s->buffer[ j*s->stride + i*s->width31 ] = CLR_FG;
58    
59        if (s->count[0]>0) {
60            for (i=0; i<31; i++) {
61                unsigned int j_height = (s->height-s->tm.tmHeight)*s->quant[i]/s->max_quant_frames;
62                if (j_height==0 && s->quant[i]>0) j_height=1;
63    
64                for(j=0; j < j_height; j++) {
65                    memset(s->buffer + (s->tm.tmHeight+j)*s->stride + i*s->width31 + 1,
66                            CLR_QUANT, s->width31-1);
67                }
68            }
69        }
70    }
71    
72    
73    static const char * number[31] = {
74        "1", "2", "3", "4", "5", "6", "7", "8", "9",
75        "10","11","12","13","14","15","16","17","18","19",
76        "20","21","22","23","24","25","26","27","28","29",
77        "30","31"
78    };
79    
80    
81    /* status window proc handlder */
82    
83    static BOOL CALLBACK status_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
84    {
85        status_t * s = (status_t*)GetWindowLong(hDlg, GWL_USERDATA);
86    
87            switch (uMsg)
88            {
89            case WM_INITDIALOG :
90                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
91                    s = (status_t*)lParam;
92    
93            s->hGraph = GetDlgItem(hDlg, IDC_STATUS_GRAPH);
94            s->hDc = GetDC(s->hGraph);
95            {
96                RECT rect;
97                GetWindowRect(s->hGraph, &rect);
98                s->width = rect.right - rect.left;
99                s->height = rect.bottom - rect.top;
100            }
101            s->width31 = s->width/31;
102            s->stride = (s->width/4+1)*4;
103    
104            s->buffer = malloc(s->width * s->stride);
105    
106            s->bi = malloc(sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
107            memset(s->bi, 0, sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD));
108    
109            s->bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
110            s->bi->bmiHeader.biWidth  = s->stride;
111            s->bi->bmiHeader.biHeight = s->height;
112            s->bi->bmiHeader.biPlanes = 1;
113            s->bi->bmiHeader.biBitCount = 8;
114            s->bi->bmiHeader.biCompression = BI_RGB;
115    
116            set_bic(s->bi->bmiColors, CLR_BG,       0,   0,   0);
117            set_bic(s->bi->bmiColors, CLR_FG,     128, 128, 128);
118            set_bic(s->bi->bmiColors, CLR_QUANT,    0, 255,   0);
119    
120            SelectObject(s->hDc, GetStockObject(SYSTEM_FONT));
121            SetBkColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_BG]);
122            SetTextColor(s->hDc, *(DWORD*)&s->bi->bmiColors[CLR_FG]);
123            GetTextMetrics(s->hDc, &s->tm);
124    
125            draw_graph(s);
126            SetTimer(hDlg, IDC_STATUS_GRAPH, 1000, NULL);    /* 1 second */
127                    break;
128    
129        case WM_DESTROY :
130            free(s->buffer);
131            free(s->bi);
132            KillTimer(hDlg, IDC_STATUS_GRAPH);
133            s->hDlg = NULL;
134            break;
135    
136        case WM_DRAWITEM :
137            if (wParam==IDC_STATUS_GRAPH) {
138                int i;
139    
140                /* copy buffer into dc */
141                SetDIBitsToDevice(s->hDc,
142                    0, 0, s->width, s->height,
143                    0, 0, 0, s->height,
144                    s->buffer, s->bi, DIB_RGB_COLORS);
145    
146                SetTextAlign(s->hDc, GetTextAlign(s->hDc)|TA_CENTER);
147    
148                for (i=0; i<31; i++) {
149                    TextOut(s->hDc, i*s->width31 + s->width/62,
150                        s->height-s->tm.tmHeight, number[i], strlen(number[i]));
151                }
152            }
153            break;
154    
155        case WM_TIMER :
156            if (wParam==IDC_STATUS_GRAPH) {
157    
158                SetDlgItemInt(hDlg, IDC_STATUS_I_NUM, s->count[1], FALSE);
159                SetDlgItemInt(hDlg, IDC_STATUS_P_NUM, s->count[2], FALSE);
160                SetDlgItemInt(hDlg, IDC_STATUS_B_NUM, s->count[3], FALSE);
161                SetDlgItemInt(hDlg, IDC_STATUS_NUM, s->count[0], FALSE);
162    
163                SetDlgItemInt(hDlg, IDC_STATUS_IQ_MIN, s->min_quant[1], FALSE);
164                SetDlgItemInt(hDlg, IDC_STATUS_IQ_MAX, s->max_quant[1], FALSE);
165                SetDlgItemInt(hDlg, IDC_STATUS_PQ_MIN, s->min_quant[2], FALSE);
166                SetDlgItemInt(hDlg, IDC_STATUS_PQ_MAX, s->max_quant[2], FALSE);
167                SetDlgItemInt(hDlg, IDC_STATUS_BQ_MIN, s->min_quant[3], FALSE);
168                SetDlgItemInt(hDlg, IDC_STATUS_BQ_MAX, s->max_quant[3], FALSE);
169                SetDlgItemInt(hDlg, IDC_STATUS_Q_MIN, s->min_quant[0], FALSE);
170                SetDlgItemInt(hDlg, IDC_STATUS_Q_MAX, s->max_quant[0], FALSE);
171    
172                SetDlgItemInt(hDlg, IDC_STATUS_IL_MIN, s->min_length[1], FALSE);
173                SetDlgItemInt(hDlg, IDC_STATUS_IL_MAX, s->max_length[1], FALSE);
174                if (s->count[1]>0)
175                    SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, s->tot_length[1]/s->count[1], FALSE);
176                else
177                    SetDlgItemInt(hDlg, IDC_STATUS_IL_AVG, 0, FALSE);
178                SetDlgItemInt(hDlg, IDC_STATUS_IL_TOT, s->tot_length[1]/1024, FALSE);
179                SetDlgItemInt(hDlg, IDC_STATUS_PL_MIN, s->min_length[2], FALSE);
180                SetDlgItemInt(hDlg, IDC_STATUS_PL_MAX, s->max_length[2], FALSE);
181                if (s->count[2]>0)
182                    SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, s->tot_length[2]/s->count[2], FALSE);
183                else
184                    SetDlgItemInt(hDlg, IDC_STATUS_PL_AVG, 0, FALSE);
185                SetDlgItemInt(hDlg, IDC_STATUS_PL_TOT, s->tot_length[2]/1024, FALSE);
186                SetDlgItemInt(hDlg, IDC_STATUS_BL_MIN, s->min_length[3], FALSE);
187                SetDlgItemInt(hDlg, IDC_STATUS_BL_MAX, s->max_length[3], FALSE);
188                if (s->count[3]>0)
189                    SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, s->tot_length[3]/s->count[3], FALSE);
190                else
191                    SetDlgItemInt(hDlg, IDC_STATUS_BL_AVG, 0, FALSE);
192                SetDlgItemInt(hDlg, IDC_STATUS_BL_TOT, s->tot_length[3]/1024, FALSE);
193                SetDlgItemInt(hDlg, IDC_STATUS_L_MIN, s->min_length[0], FALSE);
194                SetDlgItemInt(hDlg, IDC_STATUS_L_MAX, s->max_length[0], FALSE);
195                if (s->count[0]>0)
196                    SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, s->tot_length[0]/s->count[0], FALSE);
197                else
198                    SetDlgItemInt(hDlg, IDC_STATUS_L_AVG, 0, FALSE);
199                SetDlgItemInt(hDlg, IDC_STATUS_L_TOT, s->tot_length[0]/1024, FALSE);
200    
201                if (s->count[0]>0) {
202                    unsigned int kbits = 8*s->tot_length[0]/1000;
203                    double secs = (double)s->count[0]/s->fps;
204                   SetDlgItemInt(hDlg, IDC_STATUS_KBPS, (int)(kbits/secs), FALSE);
205                }else{
206                    SetDlgItemInt(hDlg, IDC_STATUS_KBPS, 0, FALSE);
207                }
208    
209                draw_graph(s);
210                InvalidateRect(s->hGraph, NULL, FALSE);
211            }
212            break;
213    
214        case WM_COMMAND :
215            if (LOWORD(wParam)==IDCANCEL) {
216                DestroyWindow(hDlg);
217            }
218            break;
219    
220        default :
221                    return FALSE;
222            }
223    
224            return TRUE;
225    }
226    
227    
228    /* destroy status window
229       (however if the auto-close box is unchecked, dont destroy) */
230    
231    void status_destroy(status_t *s)
232    {
233        if (s->hDlg && IsDlgButtonChecked(s->hDlg,IDC_STATUS_DESTROY)==BST_CHECKED) {
234            DestroyWindow(s->hDlg);
235        }
236    }
237    
238    
239    /* destroy status window, alwasys */
240    
241    void status_destroy_always(status_t *s)
242    {
243        if (s->hDlg) {
244            DestroyWindow(s->hDlg);
245        }
246    }
247    
248    
249    /* create status window */
250    void status_create(status_t * s, unsigned int fps_inc, unsigned int fps_base)
251    {
252        int i;
253    
254        s->fps = fps_base/fps_inc;
255    
256        memset(s->quant, 0, 31*sizeof(int));
257        s->max_quant_frames = 0;
258        for (i=0; i<4; i++) {
259            s->count[i] = 0;
260            s->min_quant[i] = s->max_quant[i] = 0;
261            s->min_length[i] = s->max_length[i] = s->tot_length[i] = 0;
262        }
263    
264        s->hDlg = CreateDialogParam(g_hInst,
265                                MAKEINTRESOURCE(IDD_STATUS),
266                                GetDesktopWindow(),
267                                status_proc, (LPARAM)s);
268    
269        ShowWindow(s->hDlg, SW_SHOW);
270    }
271    
272    
273    /* feed stats info into the window */
274    void status_update(status_t *s, int type, int length, int quant)
275    {
276        s->count[0]++;
277        s->count[type]++;
278    
279        if (s->min_quant[0]==0 || quant<s->min_quant[0]) s->min_quant[0] = quant;
280        if (s->max_quant[0]==0 || quant>s->max_quant[0]) s->max_quant[0] = quant;
281        if (s->min_quant[type]==0 || quant<s->min_quant[type]) s->min_quant[type] = quant;
282        if (s->max_quant[type]==0|| quant>s->max_quant[type]) s->max_quant[type] = quant;
283    
284        s->quant[quant-1]++;
285        if (s->quant[quant-1]>s->max_quant_frames)
286            s->max_quant_frames = s->quant[quant-1];
287    
288        if (s->min_length[0]==0 || length<s->min_length[0]) s->min_length[0] = length;
289        if (s->max_length[0]==0 || length>s->max_length[0]) s->max_length[0] = length;
290        if (s->min_length[type]==0 || length<s->min_length[type]) s->min_length[type] = length;
291        if (s->max_length[type]==0|| length>s->max_length[type]) s->max_length[type] = length;
292        s->tot_length[0] += length;
293        s->tot_length[type] += length;
294    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

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