Tuesday, December 31, 2013

Insert code to your blog

There is a nice web site we can use to format our code when posting online.
http://codeformatter.blogspot.com/

Example Code to use System C for fixed point

 /* fixed point examples */  
 #include "systemc.h"  
 #include <stdio.h>  
 int sc_main(int, char* []) {  
   float a = 1/3.0;  
   float b = 1/7.0;  
   float float_out;  
   sc_fixed <32, 4, SC_RND, SC_SAT> fixed_out0; // 32 bit, 4 bit integer, 28 fract  
   sc_fixed <16, 4, SC_RND, SC_SAT> fixed_out1; // 16 bit, 4 bit int, 12 bit fract  
   sc_fixed <8, 4, SC_RND, SC_SAT> fixed_out2; // 8 bit, 4 bit int;  
   printf(" fixed point example\n");  
   cout << " Hello world\n";  
   float_out = a + b;  
   fixed_out0 = a + b;  
   fixed_out1 = a + b;  
   fixed_out2 = a + b;  
   cout << " float_out is " << float_out << endl;  
   cout << " fixed_out0 is " << fixed_out0 << endl;  
   cout << " fixed_out1 is " << fixed_out1 << endl;  
   cout << " fixed_out2 is " << fixed_out2 << endl;  
   return 1;  
 }  

Use system c under visual studio 2013 express



The file is named systemc-2.3.0.tgz but it seems that I can only unzip under windows. Once copied to Linux system, need to make sure I changed “chmod +x …” for configure files, also need to make everything writable. Then follow the  install instruction step by step, it is all done.

For windows platform, find the directory called C:\work\systemc\systemc-2.3.0\msvc80, and use VS2013 to open the solution file, and choose to upgrade. The project won’t compile because of the following error: The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.

This is caused by sc_cmnhdr.h file definition for a workaround for MSVC6.0. need to replace the following line #define for if( false ); else for

With this:
#if defined(_MSC_VER) && (_MSC_VER == 1200)
#define for if( false ); else for
#endif

Then the project should compile.


Then in windows we can define environment variable SYSTEMC as C:\work\systemc\systemc-2.3.0
And set my own project files to use the following include file and library directories:
$(SYSTEMC)\src
$(SYSTEMC)\msvc80\systemc\debug


Monday, December 23, 2013

To close child windows, but not parent window

If an application wants to close all its child windows but not parent windows, the following code can help. In the parent window code:

HWND hwnd1 = FindWindowW(L"MyWindowClass2", L"Direct2D Video Window2");  // classname, and then windowname

PostMessage(hwnd1, WM_CLOSE, 0, NULL);


Then, in the child window code, need to implement the message handler to respond WM_CLOSE.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
       switch (message)
       {
              case WM_CLOSE:
                     DestroyWindow(hWnd);
                     break;
              case WM_DESTROY:
                     PostQuitMessage(0);
                     break;
              default:
                     return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
}

For clasname and window name, these can be defined when manually creating a child window using code, as follows:

ATOM CMyWindowExample::MyRegisterClass()
{
       WNDCLASSEX wcex;

       wcex.cbSize = sizeof(WNDCLASSEX);

       wcex.style                 = CS_HREDRAW | CS_VREDRAW;
       wcex.lpfnWndProc     = WndProc;
       wcex.cbClsExtra            = 0;
       wcex.cbWndExtra            = 0;
       wcex.hInstance             = GetModuleHandle(NULL);
       wcex.hIcon                 = LoadIcon(NULL, IDI_APPLICATION);
       wcex.hCursor         = LoadCursor(NULL, IDC_ARROW);
       wcex.hbrBackground   = NULL;
       wcex.lpszMenuName    = NULL;
       wcex.lpszClassName   = L"MyWindowClass1";
       wcex.hIconSm         = LoadIcon(NULL, IDI_APPLICATION);

       return RegisterClassEx(&wcex);
}


HWND CMyWindowExample::InitInstance(LPCWSTR windowName, int width, int height)
{
       int x = ::GetSystemMetrics(SM_CXSCREEN) / 2 - width / 2;
       int y = ::GetSystemMetrics(SM_CYSCREEN) / 2 - height / 2;

      
       m_hWnd = CreateWindow(L"MyWindowClass1", windowName, WS_OVERLAPPEDWINDOW, x, y, width, height, NULL, NULL, NULL, NULL);

        
    return m_hWnd;
}

Saturday, December 21, 2013

Windows SDK, DDK, Visual Studio2013

It looks like the installation of visual studio 2013, windows SDK 7, and WinDDK 7.1 is very smooth on Windows 7 64-bit system. But when I tried this on a Windows 8, I met quite a few problems. First the right order has to be Visual Studio 2013 Express edition first, and then Windows DDK. The windows DDK might fail and if that happens, check the environment variables in system. Most likely it is because the permission for TEMP variable is not set right. I just change the security to allow anyone can access this temporary directory, and that seems to solve the problem. When installing SDK, there is some other error message, saying return error 5100, etc. According the information from here: https://developer.mozilla.org/en-US/docs/Windows_SDK_versions, we need to de-select the documentation in Windows SDK page, and this seems to work too. 

Friday, December 20, 2013

Converting WCHAR* to CHAR*

size_t origsize = wcslen(wszName) + 1;
       size_t convertedChars = 0;
       const size_t newsize = origsize * 2;
       char strConcat[] = ".BLC"; // the same file name plus different extension name
       size_t strConcatsize = (strlen(strConcat) + 1) * 2;

       char *nstring = new char[newsize + strConcatsize];

       wcstombs_s(&convertedChars, nstring, newsize, wszName, _TRUNCATE);

       strcat_s((char*)nstring, newsize + strConcatsize, ( char*)strConcat);

Monday, December 09, 2013

VirtualDub and Avisynth


In VirtualDub, it is possible to open mp4 files using DirectShow filter. After install DShowInputDriver.vdplugin, then mp4 is supported in VirtualDub. When using script, i.e. generating test.avs script, can use the following lines:
DirectShowSource(“c:\test\test.mp4”)

After we install avisynth, we can write scripts to allow nonlinear editing. A typical script might look like

clip=AviSource(“c:\temp\test1.avi")
clip=ConvertToRGB32(clip)
vectors=videoprocessing1(clip, param=1)
clip=videoprocessing2(clip,vectors)
return clip


Thursday, December 05, 2013

How to generate class ID and IID? How to register and unregister COM or DirectShow filters?


Use tools in ...\Microsoft Visual Studio\Common\Tools\GUIDGEN.EXE

static const GUID CLSID_Direct2DVideoRenderer2 =
{ 0x949214bf, 0x32bf, 0x4610, { 0xb9, 0x5e, 0x93, 0xd0, 0xf2, 0xf, 0xbd, 0xff } };


// {34E5B77C-CCBA-4EC0-88B5-BABF6CF3A1D2}
static const GUID IID_IVideoRenderer2 =
{ 0xadad0828, 0xc31e, 0x4b64, { 0xa6, 0xfa, 0x57, 0x78, 0x57, 0x6d, 0x59, 0xeb } };

How to register or unregister COM or directshow filters?
C:\Windows\System32\regsvr32 D2DVideoRenderer.ax
C:\Windows\System32\regsvr32 /u D2DVideoRenderer.ax