home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / OutputPad.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  20.8 KB  |  714 lines

  1. /* 
  2.  *  options.cpp    -  Controls FlasKMPEG options
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG 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, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG 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 GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #include "resource.h"
  25. #include "OutputPad.h"
  26. #include "PostProcessing.h"
  27. #include "RunState.h"
  28. #include "Auxiliary.h"
  29. #include "Canvas.h"
  30. #include "debug.h"
  31.  
  32. extern TRunState        rs;
  33. extern HINSTANCE        hInst;
  34.  
  35. #define NORMAL_FRAMECOLOR RGB(36, 90, 180)
  36. #define KEY_FRAMECOLOR RGB(78, 121, 220)
  37. #define KNOBCOLOR RGB(221, 159, 77)
  38. #define BACKGROUNDCOLOR RGB(60, 60, 60)
  39. #define PANELCOLOR RGB(80, 80, 80)
  40. #define WHITE RGB(255, 255, 255)
  41. #define RED RGB(255, 0, 0)
  42.  
  43.  
  44. ////////////////////////////////////////////////////////
  45. //             OUTPUT    PAD
  46. ////////////////////////////////////////////////////////
  47. LRESULT CALLBACK COutputPadDlg::DisplayProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
  48.  
  49.   HDC hDC;
  50.   PAINTSTRUCT lp;
  51.   LPCTSTR mousetype;
  52.  
  53. #define GET_X(lp)                        ((int)(short)LOWORD(lp))
  54. #define GET_Y(lp)                        ((int)(short)HIWORD(lp))
  55.  
  56.     switch (message)
  57.     {
  58.     case WM_ERASEBKGND:
  59.         return TRUE;
  60.         case WM_PAINT:
  61.       hDC= BeginPaint(hWnd, &lp);
  62.       Draw();
  63.       EndPaint(hWnd, &lp);
  64.             break;
  65.     case WM_MOVE:
  66.       Draw();
  67.       break;
  68.     case WM_MOUSEMOVE:
  69.       if( wParam&MK_LBUTTON ) {
  70.         if( pp.crop && m_cp.OnDrag( GET_X(lParam), GET_Y(lParam) ) ){
  71.  
  72.           if( m_cp.OnHover(  GET_X(lParam), GET_Y(lParam) , mousetype ) )
  73.             SetCursor( LoadCursor(NULL, mousetype));
  74.  
  75.           // parameters changed
  76.           TCropConfig cfg = *m_cp.GetConfig();
  77.           pp.cropLeftOffset = cfg.left;
  78.           pp.cropWidth      = cfg.right - cfg.left;
  79.           pp.cropTopOffset  = cfg.top;
  80.           pp.cropHeight     = cfg.bottom - cfg.top;
  81.     
  82.           m_bSettingsChanged = true;
  83.           Draw();
  84.  
  85.         } // !pp.crop || !m_cp.OnDrag
  86.         else if( pp.letterbox && m_lp.OnDrag( GET_X(lParam), GET_Y(lParam) ) )  {
  87.           if( m_lp.OnHover(  GET_X(lParam), GET_Y(lParam) , mousetype ) )
  88.             SetCursor( LoadCursor(NULL, mousetype));
  89.           // parameters changed
  90.           TLetterboxConfig cfg = *m_lp.GetConfig();
  91.           pp.letterboxLeft = cfg.left;
  92.           pp.letterboxRight = cfg.right;
  93.           pp.letterboxTop  = cfg.top;
  94.           pp.letterboxBottom  = cfg.bottom;
  95.     
  96.           m_bSettingsChanged = true;
  97.           Draw();
  98.         }
  99.       }
  100.       else { // !wParam&MK_LBUTTON
  101.         if( pp.crop && m_cp.OnHover(  GET_X(lParam), GET_Y(lParam) , mousetype ) )
  102.           SetCursor( LoadCursor(NULL, mousetype));
  103.         else if ( pp.letterbox && m_lp.OnHover(  GET_X(lParam), GET_Y(lParam) , mousetype ) )
  104.           SetCursor( LoadCursor(NULL, mousetype));
  105.         else
  106.           SetCursor( LoadCursor(NULL, IDC_ARROW));
  107.       }
  108.       break;
  109.     case WM_LBUTTONDOWN:
  110.       SetCapture(hWnd);
  111.       if( pp.crop )
  112.         if( m_cp.OnClick(  GET_X(lParam), GET_Y(lParam)  ) )
  113.           break;
  114.  
  115.       if( pp.letterbox )
  116.         if( m_lp.OnClick(  GET_X(lParam), GET_Y(lParam)  ) )
  117.           break;
  118.  
  119.  
  120.       break;
  121.     case WM_LBUTTONUP:
  122.       ReleaseCapture();
  123.       m_cp.OnRelease();
  124.       m_lp.OnRelease();
  125.       break;
  126.         case WM_COMMAND:
  127.  
  128.             break;
  129.     default:
  130.       return DefWindowProc(hWnd, message, wParam, lParam);
  131.       break;
  132.     }
  133.   return FALSE;
  134. }
  135.  
  136.  
  137. // Snap second window to the first
  138. void Snap(HWND win1, HWND win2){
  139.     RECT   rc;
  140.         // Get rect win1
  141.         GetWindowRect(win1, &rc);
  142.         // Set position of second window
  143.         WindowMove(win2, rc.left, rc.bottom );
  144.  
  145.  
  146. }
  147.  
  148.  
  149.  
  150. // EnableCrop : Enable crop buttons
  151. void COutputPadDlg::EnableCrop(){
  152.     DlgEnable(m_hDlg, CROP_TOPOFFSET_PLUS);
  153.     DlgEnable(m_hDlg, CROP_TOPOFFSET_MINUS);
  154.     DlgEnable(m_hDlg, CROP_HEIGHT_PLUS);
  155.     DlgEnable(m_hDlg, CROP_HEIGHT_MINUS);
  156.     DlgEnable(m_hDlg, CROP_LEFTOFFSET_PLUS);
  157.     DlgEnable(m_hDlg, CROP_LEFTOFFSET_MINUS);
  158.     DlgEnable(m_hDlg, CROP_WIDTH_PLUS);
  159.     DlgEnable(m_hDlg, CROP_WIDTH_MINUS);
  160.     DlgEnable(m_hDlg, WIDTH_MINUS1);
  161.     DlgEnable(m_hDlg, WIDTH_PLUS1);
  162.     DlgEnable(m_hDlg, HEIGHT_MINUS1);
  163.     DlgEnable(m_hDlg, HEIGHT_PLUS1);
  164. }
  165. // DisableCrop : Disable crop buttons
  166. void COutputPadDlg::DisableCrop(){
  167.     DlgDisable(m_hDlg, CROP_TOPOFFSET_PLUS);
  168.     DlgDisable(m_hDlg, CROP_TOPOFFSET_MINUS);
  169.     DlgDisable(m_hDlg, CROP_HEIGHT_PLUS);
  170.     DlgDisable(m_hDlg, CROP_HEIGHT_MINUS);
  171.     DlgDisable(m_hDlg, CROP_LEFTOFFSET_PLUS);
  172.     DlgDisable(m_hDlg, CROP_LEFTOFFSET_MINUS);
  173.     DlgDisable(m_hDlg, CROP_WIDTH_PLUS);
  174.     DlgDisable(m_hDlg, CROP_WIDTH_MINUS);
  175.     DlgDisable(m_hDlg, WIDTH_MINUS1);
  176.     DlgDisable(m_hDlg, WIDTH_PLUS1);
  177.     DlgDisable(m_hDlg, HEIGHT_MINUS1);
  178.     DlgDisable(m_hDlg, HEIGHT_PLUS1);
  179. }
  180.  
  181. void COutputPadDlg::EnableLetterbox(){
  182.     DlgEnable(m_hDlg, LETTERBOX_TOP_PLUS);
  183.     DlgEnable(m_hDlg, LETTERBOX_TOP_MINUS);
  184.     DlgEnable(m_hDlg, LETTERBOX_BOTTOM_PLUS);
  185.     DlgEnable(m_hDlg, LETTERBOX_BOTTOM_MINUS);
  186.     DlgEnable(m_hDlg, LETTERBOX_LEFT_PLUS);
  187.     DlgEnable(m_hDlg, LETTERBOX_LEFT_MINUS);
  188.     DlgEnable(m_hDlg, LETTERBOX_RIGHT_PLUS);
  189.     DlgEnable(m_hDlg, LETTERBOX_RIGHT_MINUS);
  190. }
  191. void COutputPadDlg::DisableLetterbox(){
  192.     DlgDisable(m_hDlg, LETTERBOX_TOP_PLUS);
  193.     DlgDisable(m_hDlg, LETTERBOX_TOP_MINUS);
  194.     DlgDisable(m_hDlg, LETTERBOX_BOTTOM_PLUS);
  195.     DlgDisable(m_hDlg, LETTERBOX_BOTTOM_MINUS);
  196.     DlgDisable(m_hDlg, LETTERBOX_LEFT_PLUS);
  197.     DlgDisable(m_hDlg, LETTERBOX_LEFT_MINUS);
  198.     DlgDisable(m_hDlg, LETTERBOX_RIGHT_PLUS);
  199.     DlgDisable(m_hDlg, LETTERBOX_RIGHT_MINUS);
  200. }
  201.  
  202. void COutputPadDlg::UpdatePadButtons()
  203. {
  204.   DlgCheck(m_hDlg, ASPECT_CHECK, pp.doAR);
  205.   DlgCheck(m_hDlg, IDC_LETTERBOX, pp.letterbox);
  206.   DlgCheck(m_hDlg, IDC_CROP, pp.crop);
  207.  
  208.   DlgCheck( m_hDlg, IDC_CROP, pp.crop );
  209.   DlgCheck( m_hDlg, IDC_LETTERBOX, pp.letterbox );
  210.  
  211.  
  212.   DlgCheck( m_hDlg, IDC_DEINTERLACE, pp.deinterlace );
  213.   DlgCheck( m_hDlg, IDC_VIDEOCONTROLCHECK, pp.videocontrols );
  214.   DlgEnable( m_hDlg, IDC_BRIGHTSLIDER, pp.videocontrols );
  215.   
  216.   SendDlgItemMessage(m_hDlg, IDC_BRIGHTSLIDER, TBM_SETPOS, (WPARAM) (BOOL)true,(LPARAM) (LONG)pp.brightness );
  217. }
  218.  
  219.  
  220. static COutputPadDlg *gDlg;
  221.  
  222. static LRESULT CALLBACK DlgProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  223. {
  224.   return gDlg->DlgProc(hWnd, message, wParam, lParam);
  225. }
  226.  
  227. static LRESULT CALLBACK DisplayProcHook(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  228. {
  229.   return gDlg->DisplayProc(hWnd, message, wParam, lParam);
  230. }
  231.  
  232.  
  233. COutputPadDlg::COutputPadDlg( HWND hParentWnd, HWND hMainControl, HINSTANCE hInst)
  234.   m_hDlg = NULL;
  235.   m_hParentWnd = hParentWnd; m_hInst = hInst;
  236.   m_hMainControl = hMainControl;
  237.   gDlg = this;
  238.   m_nFrameCount =0;
  239. }
  240.  
  241. bool COutputPadDlg::Show(TPPost *pPPost, FlPPReceiver *ppRec )
  242. {
  243.   if(!pPPost || !ppRec )
  244.     return false;
  245.  
  246.   if(m_hDlg)
  247.     return true;
  248.  
  249.   m_nFrameCount = 0;
  250.  
  251.   m_pReceiver = ppRec;
  252.  
  253.   ppc = pp = *pPPost;
  254.  
  255.   m_hDlg = CreateDialog( m_hInst, MAKEINTRESOURCE(DLG_OUTPUT_PAD), m_hParentWnd, (DLGPROC) DlgProcHook );
  256.  
  257.   ShowWindow( m_hDlg, SW_SHOW );
  258.  
  259.   return true;
  260. }
  261.  
  262. bool COutputPadDlg::Hide()
  263.   if(!m_hDlg)
  264.     return false;
  265.   
  266.   if(m_pVideoRenderer) {
  267.     delete m_pVideoRenderer;
  268.     m_pVideoRenderer = NULL;
  269.   }
  270.   m_pp.Stop();
  271.   DestroyWindow(m_hDlg);
  272.   DestroyWindow(m_hDisplay);
  273.   m_hDisplay = NULL;
  274.   m_hDlg = NULL;
  275.   return true;
  276. }
  277.  
  278. void COutputPadDlg::SetupTooltips()
  279. {
  280.   HINSTANCE hInst = rs.hInst;
  281.  
  282. #define ATTACH(id, title, text){ DlgAttachToolTip( hInst, m_hDlg, id, title, text); }
  283.  
  284.  
  285.   // Play controls
  286.   ATTACH( IDC_CROP, "Crop", "Crops the video\n\rUse the mouse to setup\n\rthe cropping area." )
  287.   ATTACH( IDC_LETTERBOX, "Letterbox", "Applies courtains to the video\n\rUse the mouse to setup\n\rthe areas." )
  288.   ATTACH( IDC_DEINTERLACE, "Play", "Plays video." )
  289.   ATTACH( ASPECT_CHECK, "Keep Aspect Ratio", "Maintains aspect ratio of source." )
  290.   ATTACH( IDC_VIDEOCONTROLCHECK, "Brightness", "Use the slider\n\rto modify video brightness." )
  291.   ATTACH( IDC_RESET, "Reset", "Resets to default settings" )
  292.   ATTACH( R_OUTPUT_PAD_OUTPUTSIZE, "Resize", "Resizes the video" )
  293.  
  294.  
  295. #undef ATTACH
  296. }
  297. void COutputPadDlg::SetWindows(HWND hParentWnd, HWND hMainControl )
  298. {
  299.   m_hParentWnd = hParentWnd;
  300.   m_hMainControl = hMainControl;
  301. }
  302.  
  303. void COutputPadDlg::PositionWindows( bool bExcludeOutputPad )
  304. {
  305.   // Position video window
  306.     RECT rcDesktop, rcVideo, rcPad, rcControl, rcMain;
  307.     GetWindowRect( GetDesktopWindow(), &rcDesktop);
  308.   GetWindowRect( m_hDisplay, &rcVideo );
  309.   GetWindowRect( m_hDlg, &rcPad );
  310.   GetWindowRect( m_hMainControl, &rcControl );
  311.   GetWindowRect( m_hParentWnd, &rcMain );
  312.  
  313.   // Setup video window next to main window
  314.   int width = rcVideo.right - rcVideo.left;
  315.   
  316.   if( (rcMain.right + 5 + width) > (rcDesktop.right-rcDesktop.left) )
  317.     WindowMove( m_hDisplay, rcDesktop.right - width - 5, rcMain.top + 25 );
  318.   else
  319.     WindowMove( m_hDisplay, rcMain.right +10, rcMain.top + 25 );
  320.   GetWindowRect( m_hDisplay, &rcVideo );
  321.  
  322.   // Setup control window below video
  323.   WindowMove( m_hMainControl, rcControl.left, rcVideo.bottom + 10 );
  324.   GetWindowRect( m_hMainControl, &rcControl );
  325.  
  326.   // Setup toolbar next to control
  327.   if( bExcludeOutputPad == false )
  328.     WindowMove( m_hDlg, rcControl.right +5, rcControl.top );
  329.   
  330.  // SetWindowPos( m_hDlg, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE );
  331.  
  332. }
  333.  
  334. LRESULT CALLBACK COutputPadDlg::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  335. {
  336.   ATOM at;
  337.   FlPostProcess postpr;
  338.   
  339.   switch (message)
  340.   {
  341.         case WM_INITDIALOG:
  342.       m_hDlg = hDlg;
  343.       
  344.       SetupTooltips();
  345.       // Initialize strings
  346.       SetText(hDlg, GS(OUTPUT_PAD_TITLE));
  347.       // Crop
  348.       DlgSetText(hDlg, IDC_CROP, GS(OUTPUT_PAD_CROP) );
  349.       DlgSetText(hDlg, OPT_OUTPAD_TOPOFFSET, GS(OPT_OUTPAD_TOPOFFSET));
  350.       DlgSetText(hDlg, OPT_OUTPAD_CROPHEIGHT, GS(OPT_OUTPAD_CROPHEIGHT));
  351.       DlgSetText(hDlg, OPT_OUTPAD_LEFTOFFSET, GS(OPT_OUTPAD_LEFTOFFSET));
  352.       DlgSetText(hDlg, OPT_OUTPAD_CROPWIDTH, GS(OPT_OUTPAD_CROPWIDTH));
  353.       // Output Size
  354.       DlgSetText(hDlg, R_OUTPUT_PAD_OUTPUTSIZE, GS(OUTPUT_PAD_OUTPUTSIZE));
  355.       DlgSetText(hDlg, OPT_OUTPAD_WIDTH, GS(OPT_OUTPAD_WIDTH));
  356.       DlgSetText(hDlg, OPT_OUTPAD_HEIGHT, GS(OPT_OUTPAD_HEIGHT));
  357.       DlgSetText(hDlg, IDOK , GS(OUTPUT_PAD_HIDE));
  358.       
  359.       DlgSetText(hDlg, IDC_LETTERBOX, GS(OUTPUT_PAD_LETTERBOX));
  360.       DlgSetText(hDlg, OPT_OUTPAD_LETTERBOX_TOP, GS(OPT_OUTPAD_LETTERBOX_TOP));
  361.       DlgSetText(hDlg, OPT_OUTPAD_LETTERBOX_BOTTOM, GS(OPT_OUTPAD_LETTERBOX_BOTTOM));
  362.       DlgSetText(hDlg, OPT_OUTPAD_LETTERBOX_LEFT, GS(OPT_OUTPAD_LETTERBOX_LEFT));
  363.       DlgSetText(hDlg, OPT_OUTPAD_LETTERBOX_RIGHT, GS(OPT_OUTPAD_LETTERBOX_RIGHT));
  364.       //Reset
  365.       DlgSetText(hDlg, IDC_RESET, GS(OUTPUT_PAD_RESET));
  366.       
  367.       // Set brightness trackbar
  368.       SendDlgItemMessage(hDlg, IDC_BRIGHTSLIDER, TBM_SETRANGE, (WPARAM) TRUE,(LPARAM) MAKELONG(0, 255)); 
  369.       
  370.       //Set crop checkbox
  371.       UpdatePadButtons();
  372.       
  373.       
  374.       // Register class for window
  375.       WNDCLASSEX csex;
  376.       memset( &csex, 0, sizeof WNDCLASSEX );
  377.       csex.style = 0;
  378.       csex.cbSize = sizeof WNDCLASSEX;
  379.       csex.lpfnWndProc = DisplayProcHook;
  380.       csex.hInstance = hInst;
  381.       csex.hbrBackground = 0;
  382.       csex.lpszClassName = "SimpleWindow";
  383.       
  384.       at = RegisterClassEx( &csex );
  385.       
  386.       // Create display window
  387.       m_hDisplay = CreateWindow( "SimpleWindow", "Video Panel Pad", WS_BORDER ,
  388.                                   0,0, 100, 100, m_hParentWnd, 
  389.                                   NULL, hInst, NULL );
  390.       
  391.       // Set as toolbar windows
  392.       SetWindowLong( hDlg, GWL_EXSTYLE, WS_EX_TOOLWINDOW );
  393.       SetWindowLong( m_hDisplay, GWL_EXSTYLE, WS_EX_TOOLWINDOW );
  394.       
  395.       
  396.       
  397.       WindowShow( m_hDisplay );
  398.       Snap(hDlg, m_hDisplay);
  399.       
  400.       // Start postprocessing for the first time
  401.       ppc.crop = 0;
  402.       m_pp.Set(&ppc);
  403.       m_pp.Start();
  404.       m_bSettingsChanged = true;
  405.       WindowClientResize( m_hDisplay, m_pp.GetWidth(), m_pp.GetHeight() );    
  406.       PositionWindows();
  407.       return TRUE;
  408.     case WM_MOVE:
  409.       //Snap(hDlg, m_hDisplay);
  410.       break;
  411.     case WM_HSCROLL:
  412.       int nPos;
  413.       switch( LOWORD(wParam) ) {
  414.         case TB_THUMBTRACK:
  415.           nPos = SendDlgItemMessage(hDlg, IDC_BRIGHTSLIDER, TBM_GETPOS, 0, 0);
  416.           pp.brightness = nPos;
  417.           m_bSettingsChanged = true;
  418.           Draw();
  419.           break;
  420.       }
  421.       break;
  422.     case WM_COMMAND:
  423.       if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
  424.       {
  425.         DestroyWindow(m_hDisplay);
  426.         DestroyWindow(m_hDlg);
  427.         return LOWORD(wParam) == IDOK ? TRUE : FALSE;
  428.       }
  429.  
  430.       switch (LOWORD(wParam)) {
  431.         case WIDTH_PLUS:
  432.         case WIDTH_MINUS:
  433.         case HEIGHT_PLUS:
  434.         case HEIGHT_MINUS:
  435.           if( pp.bResize == false ) {
  436.             pp.resHeight = rs.video->GetHeight();
  437.             pp.resWidth  = rs.video->GetWidth();
  438.             pp.bResize = true;
  439.           }
  440.           break;
  441.       }
  442.  
  443.       switch (LOWORD(wParam)){
  444.         case IDC_VIDEOCONTROLCHECK:
  445.           pp.videocontrols = DlgIsChecked( hDlg, IDC_VIDEOCONTROLCHECK );
  446.           UpdatePadButtons();
  447.         case IDC_DEINTERLACE:
  448.           pp.deinterlace = DlgIsChecked( hDlg, IDC_DEINTERLACE );
  449.           break;
  450.         case IDC_RESET:
  451.           pp.crop            = 0;
  452.           pp.cropWidth      = rs.video->pictureWidth;
  453.           pp.cropHeight     = rs.video->pictureHeight;
  454.           pp.cropLeftOffset = 0;
  455.           pp.cropTopOffset  = 0;
  456.         
  457.           pp.letterbox       = 0;
  458.           pp.letterboxBottom = 0;
  459.           pp.letterboxLeft   = 0;
  460.           pp.letterboxRight  = 0;
  461.           pp.letterboxTop    = 0;
  462.         
  463.           pp.deinterlace = 0;
  464.           pp.doAR = false;
  465.         
  466.           pp.videocontrols  = false;
  467.           pp.brightness     = 128;
  468.         
  469.           pp.bResize         = false;
  470.           pp.resWidth        = rs.video->pictureWidth;
  471.           pp.resHeight       = rs.video->pictureHeight;
  472.  
  473.        
  474.           UpdatePadButtons();
  475.           break;
  476.         case IDC_CROP:
  477.           pp.crop=DlgIsChecked(hDlg, IDC_CROP);
  478.           if(pp.crop){
  479.             pp.cropWidth      = m_pp.GetWidth();
  480.             pp.cropHeight     = m_pp.GetHeight();
  481.             pp.cropLeftOffset = 0;
  482.             pp.cropTopOffset  = 0;
  483.           }
  484.           else {
  485.             // if crop is turned off, we must set resWidth/Height to
  486.             // multiples of 16
  487.             pp.resHeight = 16 * ( pp.resHeight / 16 );
  488.             pp.resWidth = 16 * (pp.resWidth / 16 );
  489.           }
  490.         
  491.           UpdatePadButtons();
  492.           break;
  493.         
  494.         case IDC_LETTERBOX:
  495.           pp.letterbox=DlgIsChecked(hDlg, IDC_LETTERBOX);
  496.           if(pp.letterboxBottom<=0 &&
  497.             pp.letterboxLeft  <=0 && 
  498.             pp.letterboxRight <=0 &&
  499.             pp.letterboxTop   <=0){
  500.             pp.letterboxBottom =0;
  501.             pp.letterboxLeft   =0;
  502.             pp.letterboxRight  =0;
  503.             pp.letterboxTop    =0;
  504.           }
  505.         
  506.           UpdatePadButtons();
  507.           break;
  508.         case ASPECT_CHECK:
  509.           pp.doAR = DlgIsChecked(hDlg, ASPECT_CHECK);
  510.           if (pp.doAR) {
  511.             pp.letterbox = false;
  512.             if (pp.outAR & (AR_43|AR_169))
  513.               pp.crop = false;
  514.           }
  515.         
  516.           UpdatePadButtons();
  517.           break;
  518.         
  519.         case WIDTH_PLUS:
  520.           pp.resWidth+=16;
  521.           if( !CheckVideoParameters(&pp) ) pp.resWidth-=16;
  522.           break;
  523.         case WIDTH_MINUS:
  524.           pp.resWidth-=16;
  525.           if( pp.crop && pp.cropWidth>pp.resWidth ) pp.cropWidth = pp.resWidth;
  526.           if( !CheckVideoParameters(&pp) ) pp.resWidth+=16;
  527.           break;
  528.         case HEIGHT_PLUS:
  529.           pp.resHeight+=16;
  530.           if( !CheckVideoParameters(&pp) ) pp.resHeight-=16;
  531.           break;
  532.         case HEIGHT_MINUS:
  533.           pp.resHeight-=16;
  534.           if( pp.crop && pp.cropHeight>pp.resHeight ) pp.cropHeight = pp.resHeight;
  535.           if( !CheckVideoParameters(&pp) ) pp.resHeight+=16;
  536.           break;
  537.       }
  538.       m_bSettingsChanged = true;
  539.  
  540.       ppc = pp;
  541.       ppc.crop = 0;
  542.       m_pp.Set( &ppc );
  543.       postpr.Set( &pp );
  544.  
  545.       WindowClientResize( m_hDisplay, m_pp.GetWidth(), m_pp.GetHeight() );
  546.       WindowClientResize( m_hParentWnd, postpr.GetWidth() , postpr.GetHeight() );
  547.       Draw();
  548.  
  549.       switch( LOWORD(wParam) )
  550.       {
  551.         case WIDTH_PLUS:
  552.         case WIDTH_MINUS:
  553.         case HEIGHT_PLUS:
  554.         case HEIGHT_MINUS:
  555.         case IDC_RESET:
  556.           PositionWindows( true );
  557.           break;
  558.       }
  559.       break;
  560.     case WM_DESTROY:
  561.       // hold the lock while stopping the post processing
  562.       CFlAutoLock lock(&m_csGlobal);
  563.       m_pp.Stop();
  564.       m_hDlg = NULL;
  565.       break;
  566.   }
  567.   return FALSE;
  568. }
  569.  
  570.  
  571. int COutputPadDlg::PutFrame( CFrame *fr )
  572. {
  573.   CFlAutoLock lock(&m_csGlobal);
  574.  
  575.   if(m_hDlg)
  576.     frIn = *fr;  
  577.   
  578.   Draw();
  579.   
  580.   return 0;
  581. }
  582.  
  583. void COutputPadDlg::Draw()
  584. {
  585.   char        szTemp[256];
  586.   int width, height;
  587.  
  588.   if(!m_hDlg)
  589.     return;
  590.   
  591.   CFlAutoLock lock(&m_csGlobal);
  592.  
  593.   if( m_bSettingsChanged )
  594.   {
  595.     m_pp.Stop();
  596.     ppc = pp;
  597.     ppc.crop = 0;
  598.     m_pp.Set(&ppc);
  599.     m_pp.Start();
  600.     m_cv.Initialize( m_hDisplay, m_pp.GetWidth(), m_pp.GetHeight() );
  601.     m_bSettingsChanged = false;
  602.  
  603.     m_pReceiver->PutPPSettings(&pp);
  604.  
  605.     TCropConfig cfg;
  606.     cfg.left = pp.cropLeftOffset;
  607.     cfg.right = pp.cropLeftOffset + pp.cropWidth;
  608.     
  609.     cfg.top = pp.cropTopOffset;
  610.     cfg.bottom = pp.cropTopOffset + pp.cropHeight;
  611.  
  612.     TLetterboxConfig lcfg;
  613.     lcfg.bottom = pp.letterboxBottom;
  614.     lcfg.top    = pp.letterboxTop;
  615.     lcfg.left   = pp.letterboxLeft;
  616.     lcfg.right  = pp.letterboxRight;
  617.  
  618.     m_cp.SetConfig( m_pp.GetWidth(), m_pp.GetHeight(), &cfg);
  619.     m_lp.SetConfig( m_pp.GetWidth(), m_pp.GetHeight(), &lcfg);
  620.   }
  621.     width = m_pp.GetWidth();
  622.     height = m_pp.GetHeight();
  623.  
  624.   if( !width || !height )
  625.     return;
  626.  
  627.   //Postprocess
  628.   frOut.Set( width, height, FRAME_YV12 );
  629.   frRgb.Set( width, height, FRAME_RGB32 );
  630.  
  631.   m_pp.Process( &frIn, &frOut );
  632.  
  633.   frRgb.SetFrame( &frOut );
  634.  
  635.   m_cv.DrawRGB32( frRgb.GetBuffer(), 
  636.                   frRgb.GetWidth(), frRgb.GetHeight(), 0, 0);
  637.  
  638.  
  639.  
  640.   if (pp.crop) 
  641.   {
  642.     m_cv.DrawRectangle( pp.cropLeftOffset,
  643.                        pp.cropTopOffset,
  644.                        pp.cropLeftOffset+pp.cropWidth,
  645.                        pp.cropTopOffset+pp.cropHeight,
  646.                        0, 2, RGB(255,255,255), false);
  647.   }
  648.  
  649.   if (pp.letterbox) 
  650.   {
  651.     int startx, starty;
  652.     startx = pp.letterboxLeft;
  653.     m_cv.DrawLine( startx, 0, 
  654.                    startx, height-1,
  655.                   RED );
  656.  
  657.     startx = width - pp.letterboxRight - 1;
  658.     m_cv.DrawLine( startx, 0,
  659.                    startx, height-1,
  660.                    RED );
  661.  
  662.     starty = pp.letterboxTop;
  663.     m_cv.DrawLine( 0, starty,
  664.                    width-1, starty, RED );
  665.  
  666.     starty = height - pp.letterboxBottom - 1;
  667.     m_cv.DrawLine( 0, starty, 
  668.                    width-1, starty, RED );
  669.  
  670.   }
  671.  
  672.   long lw = width, lh = height;
  673.     if (pp.letterbox) 
  674.   {
  675.         lw -= (pp.letterboxLeft + pp.letterboxRight);
  676.         lh -=  (pp.letterboxTop + pp.letterboxBottom);
  677.     }
  678.     sprintf(szTemp, "Resize %d x %d -> %d x %d", frIn.GetWidth(), frIn.GetHeight(),
  679.                           lw, lh);
  680.  
  681.   m_cv.DrawText( szTemp, 3, 3, WHITE );
  682.  
  683.   if (!pp.doAR){
  684.     sprintf( szTemp, "AR input %.03f output %.03f", 1.0/pp.iDAR, (double)width / (double)height);
  685.   }
  686.   else{
  687.     sprintf( szTemp, "AR input %.03f output %s", 1.0/pp.iDAR,
  688.             (pp.outAR & AR_169 ? "16:9 var. pixel" : 
  689.             (pp.outAR & AR_43 ? "4:3 var. pixel" : "1:1 square pixel")));
  690.   }
  691.   
  692.   m_cv.DrawText( szTemp, 3, 20, WHITE );
  693.  
  694.     if(pp.crop)
  695.   {
  696.         sprintf(szTemp, "Crop left/right %d/%d, top/bottom %d/%d -> %d x %d",
  697.                         pp.cropLeftOffset, 
  698.                         frOut.GetWidth()-pp.cropWidth-pp.cropLeftOffset,
  699.                         pp.cropTopOffset,
  700.                         frOut.GetHeight()-pp.cropHeight-pp.cropTopOffset,
  701.                         pp.cropWidth, pp.cropHeight);
  702.         
  703.     m_cv.DrawText( szTemp, 3, 37, WHITE );
  704.     }
  705.   
  706.   m_cv.DrawCanvas(0,0);
  707.  
  708.  
  709. }
  710.  
  711.  
  712.