#include
#include
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
...
IStream* pJpegStream = NULL; //declare a memory stream
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pJpegStream);
GpBitmap* pBitmap = NULL;
unsigned char* dib = GetDib(); //get DIB or BMP data buffer
DllExports::GdipCreateBitmapFromGdiDib((LPBITMAPINFO)dib, dib + sizeof(BITMAPINFOHEADER), &pBitmap);
CLSID imageCLSID;
GetEncoderClsid(L"image/jpeg", &imageCLSID);
int jpegQuality = 100;
EncoderParameters encoderParams; //setup jpeg encoder parameters
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &jpegQuality;
//save jpeg into memory stream
DllExports::GdipSaveImageToStream(pBitmap, pJpegStream, &imageCLSID, &encoderParams);
LARGE_INTEGER lnOffset;
lnOffset.QuadPart = 0;
ULARGE_INTEGER ulnSize;
//determine memory stream length
pJpegStream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize);
pJpegStream->Seek(lnOffset, STREAM_SEEK_SET, NULL);
int encodedBytes = ulnSize.QuadPart;
//store jpeg memory stream into jpeg data buffer
pJpegStream->Read(racBuf_, ulnSize.QuadPart, NULL);
...
GdiplusShutdown(gdiplusToken);
2015 Go Ski!!!!!!
Last two days, we went to Perisher and had a fun ski weekend.
This is my achievement, 3106 vertical meters in 1.5 day, 23 lift rides.
This is my ski boots
Mt Perisher
Top of the Mt Perisher
ABO 2015 all finished, see you next year (June 7-12 2016)!
Programmably dislable Windows Firewall in C/C++
// firewall.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/********************************************************************++
Copyright (C) Microsoft. All Rights Reserved.
Abstract:
This C++ file includes sample code for disabling Windows Firewall
per profile using the Microsoft Windows Firewall APIs.
--********************************************************************/
#include
#include
#include
#pragma comment( lib, "ole32.lib" )
// Forward declarations
HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2);
int __cdecl main()
{
HRESULT hrComInit = S_OK;
HRESULT hr = S_OK;
INetFwPolicy2 *pNetFwPolicy2 = NULL;
// Initialize COM.
hrComInit = CoInitializeEx(
0,
COINIT_APARTMENTTHREADED
);
// Ignore RPC_E_CHANGED_MODE; this just means that COM has already been
// initialized with a different mode. Since we don't care what the mode is,
// we'll just use the existing mode.
if (hrComInit != RPC_E_CHANGED_MODE)
{
if (FAILED(hrComInit))
{
printf("CoInitializeEx failed: 0x%08lxn", hrComInit);
goto Cleanup;
}
}
// Retrieve INetFwPolicy2
hr = WFCOMInitialize(&pNetFwPolicy2);
if (FAILED(hr))
{
goto Cleanup;
}
// Disable Windows Firewall for the Domain profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_DOMAIN, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Domain: 0x%08lxn", hr);
goto Cleanup;
}
// Disable Windows Firewall for the Private profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_PRIVATE, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Private: 0x%08lxn", hr);
goto Cleanup;
}
// Disable Windows Firewall for the Public profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_PUBLIC, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Public: 0x%08lxn", hr);
goto Cleanup;
}
Cleanup:
// Release INetFwPolicy2
if (pNetFwPolicy2 != NULL)
{
pNetFwPolicy2->Release();
}
// Uninitialize COM.
if (SUCCEEDED(hrComInit))
{
CoUninitialize();
}
return 0;
}
// Instantiate INetFwPolicy2
HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2)
{
HRESULT hr = S_OK;
hr = CoCreateInstance(
__uuidof(NetFwPolicy2),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(INetFwPolicy2),
(void**)ppNetFwPolicy2);
if (FAILED(hr))
{
printf("CoCreateInstance for INetFwPolicy2 failed: 0x%08lxn", hr);
goto Cleanup;
}
Cleanup:
return hr;
}
Australian Badminton Open is coming
Some good source of online news TV Live streaming
Sky News
France 24
ABC News 24
CCTV America
Taiwan CTITV News
華視新聞Live Channel
台灣民視新聞HD直播
Who is coming 2015 BWF Australian Badminton Super Series?
According to ABO official web site, and their face book
男单:谌龙 林丹 王睁茗 田厚威 薛松
女单:李雪芮 王适娴 王仪涵 孙瑜 姚雪(Q)
男双:柴飚/洪炜 刘小龙/邱子瀚 傅海峰/张楠 康骏/蔡赟(Q) 鲁恺/刘成(Q)
女双:马晋/唐渊渟 田卿/汤金华 赵芸蕾/王晓理(R)
混双:徐晨/马晋 刘成/包宜鑫 鲁恺/黄雅琼
Maximize the output of your CPU (Keep your CPU in full power mode)
Recently I am working on UI decoding optimization. I found this program, Full Throttle Override, is very useful, and it can fully release the power of your CPU.
To balance of power consumption and performance, almost all x86 CPUs support either Cool’n’Quiet or SpeedStep or PowerNow! technology, which can dynamically adjust the CPU frequency based on the loading.
I found it’s pretty easy to implement Full Throttle Override and here is the core C++ code
void FullThrottle()
{
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
// For Vista and above
if (osvi.dwMajorVersion >= 6)
{
GUID *scheme;
PowerGetActiveScheme(NULL, &scheme);
PowerWriteACValueIndex(NULL
, scheme
, &GUID_PROCESSOR_SETTINGS_SUBGROUP
, &GUID_PROCESSOR_THROTTLE_MINIMUM
, 100);
PowerSetActiveScheme(NULL, scheme);
}
else
{
MessageBox(NULL, L"Not supported by your OS!",L"",0);
}
}
NSW state election day
Feel the power of parallel computing (OpenMP)
These two weeks, I am working on our product UI side to improve the performance of animation rendering. Previously, there is only one single thread to decode the animation line by line, and it takes around 50ms for the whole frame.
Now, I change the way of rendering, and let all lines parallel decode to fully take advantage of modern multi-core CPU.
Visual Studio natively supports OpenMP, it gives me a easy way to access this powerful tool.
To set this compiler option in the Visual Studio development environment
- Open the project’s Property Pages dialog box. For details, see How to: Open Project Property Pages.
- Expand the Configuration Properties node.
- Expand the C/C++ node.
- Select the Language property page.
- Modify the OpenMP Support property.
After some simple code update, surprisingly, I found that my frame decoding performance boosts 950% (almost 10 times faster), from 8 FPS to 76 FPS!
Let’s do simple test with the following code:
#define TEST_LENGTH 0x3fffffff
double mptest()
{
LARGE_INTEGER large_interger;
double dff;
__int64 c1, c2;
QueryPerformanceFrequency(&large_interger);
dff = large_interger.QuadPart;
//
unsigned char *test = new unsigned char[TEST_LENGTH];
QueryPerformanceCounter(&large_interger);
c1 = large_interger.QuadPart;
#pragma omp parallel for
for (int i = 0; i<TEST_LENGTH; i++)
{
test[i] = rand();
}
QueryPerformanceCounter(&large_interger);
c2 = large_interger.QuadPart;
delete test;
return (c2 - c1) * 1000.0f / dff;
}
double test()
{
LARGE_INTEGER large_interger;
double dff;
__int64 c1, c2;
QueryPerformanceFrequency(&large_interger);
dff = large_interger.QuadPart;
//
unsigned char *test = new unsigned char[TEST_LENGTH];
QueryPerformanceCounter(&large_interger);
c1 = large_interger.QuadPart;
for (int i = 0; i<TEST_LENGTH; i++)
{
test[i] = rand();
}
QueryPerformanceCounter(&large_interger);
c2 = large_interger.QuadPart;
delete test;
return (c2 - c1) * 1000.0f / dff;
}
int _tmain(int argc, _TCHAR* argv[])
{
printf("Random generation cost with MP %lfmsn", mptest());
printf("Random generation cost without MP %lfmsn", test());
_getch();
return 0;
}
Look at the huge difference!