~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/tmndec/win.c

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 
  2 
  3 
  4 
  5 
  6 /************************************************************************
  7  *
  8  *  win.c, display routines for Win32 for tmndecode (H.263 decoder)
  9  *
 10  ************************************************************************/
 11 
 12 /* Disclaimer of Warranty
 13  * 
 14  * These software programs are available to the user without any license fee
 15  * or royalty on an "as is" basis. The University of British Columbia
 16  * disclaims any and all warranties, whether express, implied, or
 17  * statuary, including any implied warranties or merchantability or of
 18  * fitness for a particular purpose.  In no event shall the
 19  * copyright-holder be liable for any incidental, punitive, or
 20  * consequential damages of any kind whatsoever arising from the use of
 21  * these programs.
 22  * 
 23  * This disclaimer of warranty extends to the user of these programs and
 24  * user's customers, employees, agents, transferees, successors, and
 25  * assigns.
 26  * 
 27  * The University of British Columbia does not represent or warrant that the
 28  * programs furnished hereunder are free of infringement of any
 29  * third-party patents.
 30  * 
 31  * Commercial implementations of H.263, including shareware, are subject to
 32  * royalty fees to patent holders.  Many of these patents are general
 33  * enough such that they are unavoidable regardless of implementation
 34  * design.
 35  * 
 36  */
 37 
 38 
 39 
 40 /* Copyright ¨ 1996 Intel Corporation All Rights Reserved
 41  * 
 42  * Permission is granted to use, copy and distribute the software in this
 43  * file for any purpose and without fee, provided, that the above
 44  * copyright notice and this statement appear in all copies.  Intel makes
 45  * no representations about the suitability of this software for any
 46  * purpose.  This software is provided "AS IS."
 47  * 
 48  * Intel specifically disclaims all warranties, express or implied, and all
 49  * liability, including consequential and other indirect damages, for the
 50  * use of this software, including liability for infringement of any
 51  * proprietary rights, and including the warranties of merchantability and
 52  * fitness for a particular purpose.  Intel does not assume any
 53  * responsibility for any errors which may appear in this software nor any
 54  * responsibility to update it.  */
 55 
 56 /************************************************************************
 57  * These routines were written by Intel Architecture Labs (IAL)
 58  *
 59  * v1 : Michael Third
 60  * v2 : Karl (removed unnecessary code, collected routines in one file)
 61  *           (moved and changed parts of message loop)
 62  *           (changed YUVtoRGB routine)
 63  *           (added synchronization with events
 64  *           instead of empty while loop)
 65  ************************************************************************/
 66 
 67 #include "config.h"
 68 #include "tmndec.h"
 69 #include "global.h"
 70 #include "win.h"
 71 
 72 #ifdef WINDOWS
 73 
 74 /* vdinit.c */
 75 
 76 T_VDWINDOW vdWindow;
 77 
 78 int initDisplay (int pels, int lines)
 79 {
 80   int errFlag = 0;
 81 
 82   init_dither_tab ();
 83   errFlag |= InitDisplayWindowThread (pels, lines);
 84 
 85   return errFlag;
 86 }
 87 
 88 
 89 int InitDisplayWindowThread (int width, int height)
 90 {
 91   int errFlag = 0;
 92 
 93   /* now modify the couple that need it */
 94   vdWindow.width = width;
 95   vdWindow.height = height;
 96   vdWindow.biHeader.biWidth = vdWindow.width;
 97   vdWindow.biHeader.biHeight = vdWindow.height;
 98   vdWindow.biHeader.biSize = sizeof (BITMAPINFOHEADER);
 99   vdWindow.biHeader.biCompression = BI_RGB;
100   vdWindow.biHeader.biPlanes = 1;
101   vdWindow.biHeader.biBitCount = 24;
102 
103 
104   vdWindow.biHeader.biSizeImage = 3 * vdWindow.width * vdWindow.height;
105   vdWindow.imageIsReady = FALSE;
106 
107   /* allocate the memory needed to hold the RGB and visualization
108    * information */
109   vdWindow.bufRGB = (unsigned char *) malloc (3 * vdWindow.width * vdWindow.height);
110 
111   /* Create synchronization event */
112   vdWindow.hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
113 
114   vdWindow.hThread =
115     CreateThread (
116                   NULL,
117                   0,
118                   (LPTHREAD_START_ROUTINE) DisplayWinMain,
119                   (LPVOID) NULL,
120                   0,
121                   &(vdWindow.dwThreadID)
122     );
123 
124   if (vdWindow.hThread == NULL)
125   {
126     errFlag = 1;
127     return errFlag;
128   }
129   return errFlag;
130 }
131 
132 
133 /* vddraw.c */
134 
135 int displayImage (unsigned char *lum, unsigned char *Cr, unsigned char *Cb)
136 {
137   int errFlag = 0;
138   DWORD dwRetVal;
139 
140   /* wait until we have finished drawing the last frame */
141   if (vdWindow.windowDismissed == FALSE)
142   {
143     vdWindow.src[0] = lum;
144     vdWindow.src[1] = Cb;
145     vdWindow.src[2] = Cr;
146 
147 
148     vdWindow.imageIsReady = TRUE;
149     /* Post message to drawing thread's window to draw frame */
150     PostMessage (vdWindow.hWnd, VIDEO_DRAW_FRAME, (WPARAM) NULL, (LPARAM) NULL);
151 
152     /* wait until the frame has been drawn */
153     dwRetVal = WaitForSingleObject (vdWindow.hEvent, INFINITE);
154 
155   }
156   return errFlag;
157 }
158 
159 
160 int DrawDIB ()
161 {
162   int errFlag = 0;
163 
164   errFlag |=
165     DrawDibDraw (
166                  vdWindow.hDrawDib,
167                  vdWindow.hDC,
168                  0,
169                  0,
170                  vdWindow.zoom * vdWindow.width,
171                  vdWindow.zoom * vdWindow.height,
172                  &vdWindow.biHeader,
173                  vdWindow.bufRGB,
174                  0,
175                  0,
176                  vdWindow.width,
177                  vdWindow.height,
178                  DDF_SAME_DRAW
179     );
180 
181 
182   return errFlag;
183 }
184 
185 
186 
187 
188 /* vdwinman.c */
189 
190 void DisplayWinMain (void *dummy)
191 {
192   int errFlag = 0;
193   DWORD dwStyle;
194 
195   vdWindow.wc.style = CS_BYTEALIGNWINDOW;
196   vdWindow.wc.lpfnWndProc = MainWndProc;
197   vdWindow.wc.cbClsExtra = 0;
198   vdWindow.wc.cbWndExtra = 0;
199   vdWindow.wc.hInstance = 0;
200   vdWindow.wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
201   vdWindow.wc.hCursor = LoadCursor (NULL, IDC_ARROW);
202   vdWindow.wc.hbrBackground = GetStockObject (WHITE_BRUSH);
203   vdWindow.wc.lpszMenuName = NULL;
204   vdWindow.zoom = 1;
205   strcpy (vdWindow.lpszAppName, "H.263 Display");
206   vdWindow.wc.lpszClassName = vdWindow.lpszAppName;
207 
208   RegisterClass (&vdWindow.wc);
209 
210 
211   dwStyle = WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
212 
213   vdWindow.hWnd =
214     CreateWindow (vdWindow.lpszAppName,
215                   vdWindow.lpszAppName,
216                   dwStyle,
217                   CW_USEDEFAULT,
218                   CW_USEDEFAULT,
219                   vdWindow.width + 6,
220                   vdWindow.height + 25,
221                   NULL,
222                   NULL,
223                   0,
224                   NULL
225     );
226 
227   if (vdWindow.hWnd == NULL)
228     ExitThread (errFlag = 1);
229 
230   ShowWindow (vdWindow.hWnd, SW_SHOWNOACTIVATE);
231   UpdateWindow (vdWindow.hWnd);
232 
233   /* Message loop for display window's thread */
234   while (GetMessage (&(vdWindow.msg), NULL, 0, 0))
235   {
236     TranslateMessage (&(vdWindow.msg));
237     DispatchMessage (&(vdWindow.msg));
238   }
239 
240   ExitThread (0);
241 }
242 
243 
244 LRESULT APIENTRY MainWndProc (HWND hWnd, UINT msg, UINT wParam, LONG lParam)
245 {
246   LPMINMAXINFO lpmmi;
247 
248   switch (msg)
249   {
250     case VIDEO_BEGIN:
251       vdWindow.hDC = GetDC (vdWindow.hWnd);
252       vdWindow.hDrawDib = DrawDibOpen ();
253       vdWindow.zoom = 1;
254       vdWindow.oldzoom = 0;
255       DrawDibBegin (
256                     vdWindow.hDrawDib,
257                     vdWindow.hDC,
258                     2 * vdWindow.width,
259                     2 * vdWindow.height,
260                     &vdWindow.biHeader,
261                     vdWindow.width,
262                     vdWindow.height,
263                     0
264         );
265       /*SetEvent (vdWindow.hEvent);*/
266       vdWindow.windowDismissed = FALSE;
267       ReleaseDC (vdWindow.hWnd, vdWindow.hDC);
268       break;
269     case VIDEO_DRAW_FRAME:
270       vdWindow.hDC = GetDC (vdWindow.hWnd);
271       ConvertYUVtoRGB (
272                        vdWindow.src[0],
273                        vdWindow.src[1],
274                        vdWindow.src[2],
275                        vdWindow.bufRGB,
276                        vdWindow.width,
277                        vdWindow.height
278         );
279       /* draw the picture onto the screen */
280       DrawDIB ();
281       SetEvent (vdWindow.hEvent);
282       ReleaseDC (vdWindow.hWnd, vdWindow.hDC);
283       break;
284     case VIDEO_END:
285       /* Window has been closed.  The following lines handle the cleanup. */
286       vdWindow.hDC = GetDC (vdWindow.hWnd);
287       DrawDibEnd (vdWindow.hDrawDib);
288       DrawDibClose (vdWindow.hDrawDib);
289       ReleaseDC (vdWindow.hWnd, vdWindow.hDC);
290 
291       vdWindow.windowDismissed = TRUE;
292       PostQuitMessage (0);
293       break;
294 
295     case WM_CREATE:
296       PostMessage (hWnd, VIDEO_BEGIN, 0, 0);
297       break;
298     case WM_SIZE:
299       switch (wParam)
300       {
301         case SIZE_MAXIMIZED:
302           vdWindow.zoom = 2;
303           break;
304         case SIZE_MINIMIZED:
305           vdWindow.oldzoom = vdWindow.zoom;
306           break;
307         case SIZE_RESTORED:
308           if (vdWindow.oldzoom)
309           {
310             vdWindow.zoom = vdWindow.oldzoom;
311             vdWindow.oldzoom = 0;
312           } else
313             vdWindow.zoom = 1;
314           break;
315         case SIZE_MAXHIDE:
316           break;
317         case SIZE_MAXSHOW:
318           break;
319       }
320       PostMessage (hWnd, WM_PAINT, 0, 0);
321       break;
322     case WM_GETMINMAXINFO:
323       lpmmi = (LPMINMAXINFO) lParam;
324 
325       GetWindowRect (hWnd, &vdWindow.rect);
326       lpmmi->ptMaxPosition.x = vdWindow.rect.left;
327       lpmmi->ptMaxPosition.y = vdWindow.rect.top;
328 
329       lpmmi->ptMaxSize.x = 2 * (vdWindow.width) + 6;
330       lpmmi->ptMaxSize.y = 2 * (vdWindow.height) + 25;
331       break;
332     case WM_DESTROY:
333       /* Window has been closed.  The following lines handle the cleanup. */
334       DrawDibEnd (vdWindow.hDrawDib);
335       ReleaseDC (vdWindow.hWnd, vdWindow.hDC);
336       DrawDibClose (vdWindow.hDrawDib);
337 
338       vdWindow.windowDismissed = TRUE;
339       PostQuitMessage (0);
340       break;
341     case WM_PAINT:
342       if (vdWindow.imageIsReady)
343       {
344         vdWindow.hDC = GetDC (vdWindow.hWnd);
345         DrawDIB ();
346         ReleaseDC (vdWindow.hWnd, vdWindow.hDC);
347       }
348       break;
349 
350   }
351   return DefWindowProc (hWnd, msg, wParam, lParam);
352 }
353 
354 
355 
356 /* vdclose.c */
357 
358 int closeDisplay ()
359 {
360   int errFlag = 0;
361 
362   if (vdWindow.hWnd)
363   {
364     PostMessage (vdWindow.hWnd, VIDEO_END, (WPARAM) NULL, (LPARAM) NULL);
365     while (vdWindow.windowDismissed == FALSE)
366       ;
367   }
368   if (vdWindow.hEvent)
369     CloseHandle (vdWindow.hEvent);
370 
371   if (vdWindow.hThread)
372     CloseHandle (vdWindow.hThread);
373 
374   free (vdWindow.bufRGB);
375 
376   return errFlag;
377 }
378 
379 
380 
381 
382 #endif
383 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.