#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h> /* for strerror */
#include <sys/time.h> // for gettimeofday()
#include <unistd.h>
#include "libyuv.h"
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/ctrl/static.h>
long getTime(void)
{
struct timeval start;
gettimeofday( &start, NULL );
return (start.tv_sec*1000000+start.tv_usec);
}
HWND text;
char showText[50] = {"hello"};
static int IdleWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_CREATE:
{
printf("IdleWinProc crete\n");
/*text = CreateWindowEx (CTRL_STATIC,
"",
WS_VISIBLE,
WS_EX_NONE,
100,
0, 0, 240, 40, hWnd,0);
ShowWindow(text, SW_SHOWNORMAL);*/
break;
}
case MSG_IDLE:
{
//printf("IdleWinProc idle=%d\n",getTime()/1000);
//SetWindowText(text,showText);
break;
}
case MSG_DESTROY:
DestroyAllControls (hWnd);
return 0;
case MSG_CLOSE:
PostQuitMessage (hWnd);
DestroyMainWindow (hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
void * IdleTask(void*)
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
printf("idletask start\n");
CreateInfo.dwStyle = WS_VISIBLE;
CreateInfo.dwExStyle = WS_EX_TRANSPARENT;
CreateInfo.spCaption = "hello";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor (IDC_ARROW);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = IdleWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 240;//GetGDCapability(HDC_SCREEN, GDCAP_HPIXEL);
CreateInfo.by = 320;//GetGDCapability(HDC_SCREEN, GDCAP_VPIXEL);
CreateInfo.iBkColor = PIXEL_lightgray;
CreateInfo.dwAddData = 0;
CreateInfo.dwReserved = 0;
CreateInfo.hHosting = HWND_DESKTOP;
BITMAP mBitMap;
//LoadBitmapFromFile(HDC_SCREEN,&mBitMap,"./res/image/fr1.bmp");
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return NULL;
//ShowWindow (hMainWnd, SW_SHOWNORMAL);
int i = 0;
int w = 160;
int h = 160;
int yuv_size = w*h*3/2;
unsigned char rgb_bug[w*h*3];
//yuv 420p
unsigned char yuv_buf[yuv_size];
memset(yuv_buf,0,yuv_size);
memset(rgb_bug,0,w*h*3);
FILE* file = fopen("./I420SP.raw", "rb");
if (NULL == file)
{
printf("open file fail,%s\n",strerror(errno));
}
//save 1.yuv
//fwrite(yuv_buf, yuv_size, 1, file);
//fclose(file);
//exit(0);
printf("yuv_size=%d\n",yuv_size);
fseek(file, 0, SEEK_END);
long file_size = ftell(file);
printf("get file fize%s,size=%ld\n",strerror(errno),file_size);
fseek(file, 0, SEEK_SET);//文件内位置定位到文件头
int cnt = file_size/yuv_size;
int time,diff;
while (GetMessage(&Msg, hMainWnd))
for(i =0;i < cnt;i++)
{
time = getTime();
memset(yuv_buf,0,yuv_size);
memset(rgb_bug,0,w*h*3);
fseek(file, yuv_size*i, SEEK_SET);
fread(yuv_buf,1 , yuv_size, file );
libyuv::NV12ToRGB565(yuv_buf,w,&yuv_buf[w*h],w,rgb_bug,w * 2, w,h);
InitBitmap(HDC_SCREEN,w,h,w*2,rgb_bug,&mBitMap);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
HDC hdc = GetClientDC(hMainWnd);
FillBoxWithBitmap(hdc,0,0,240,280,&mBitMap);
EndPaint(hMainWnd,hdc);
diff = getTime()-time;
//printf("process one frame cost time=%d\n",diff);
if(diff < 33000)usleep(33000-diff);
sprintf(showText,"FPS:%d ",1000000/(getTime()-time));
//printf("process one frame cost time=%d,fps=%s\n",diff,showText);
//SetWindowText(text,showText);
//ShowWindow(text,SW_SHOW);
}
printf("idletask end\n");
MainWindowThreadCleanup (hMainWnd);
return NULL;
}
int main(int argc, const char* argv[])
{
printf("main start\n");
InitGUI(argc,argv);
pthread_t m_pSeekerThread = 0;
pthread_create (&m_pSeekerThread, NULL, IdleTask, NULL);
//pthread_create (&m_pSeekerThread, NULL, TextTask, NULL);
while(1);
printf("main end\n");
return 0;
}
#include <stdlib.h>
#include <string.h>
#include <errno.h> /* for strerror */
#include <sys/time.h> // for gettimeofday()
#include <unistd.h>
#include "libyuv.h"
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/ctrl/static.h>
long getTime(void)
{
struct timeval start;
gettimeofday( &start, NULL );
return (start.tv_sec*1000000+start.tv_usec);
}
HWND text;
char showText[50] = {"hello"};
static int IdleWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_CREATE:
{
printf("IdleWinProc crete\n");
/*text = CreateWindowEx (CTRL_STATIC,
"",
WS_VISIBLE,
WS_EX_NONE,
100,
0, 0, 240, 40, hWnd,0);
ShowWindow(text, SW_SHOWNORMAL);*/
break;
}
case MSG_IDLE:
{
//printf("IdleWinProc idle=%d\n",getTime()/1000);
//SetWindowText(text,showText);
break;
}
case MSG_DESTROY:
DestroyAllControls (hWnd);
return 0;
case MSG_CLOSE:
PostQuitMessage (hWnd);
DestroyMainWindow (hWnd);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
void * IdleTask(void*)
{
MSG Msg;
HWND hMainWnd;
MAINWINCREATE CreateInfo;
printf("idletask start\n");
CreateInfo.dwStyle = WS_VISIBLE;
CreateInfo.dwExStyle = WS_EX_TRANSPARENT;
CreateInfo.spCaption = "hello";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor (IDC_ARROW);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = IdleWinProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 240;//GetGDCapability(HDC_SCREEN, GDCAP_HPIXEL);
CreateInfo.by = 320;//GetGDCapability(HDC_SCREEN, GDCAP_VPIXEL);
CreateInfo.iBkColor = PIXEL_lightgray;
CreateInfo.dwAddData = 0;
CreateInfo.dwReserved = 0;
CreateInfo.hHosting = HWND_DESKTOP;
BITMAP mBitMap;
//LoadBitmapFromFile(HDC_SCREEN,&mBitMap,"./res/image/fr1.bmp");
hMainWnd = CreateMainWindow (&CreateInfo);
if (hMainWnd == HWND_INVALID)
return NULL;
//ShowWindow (hMainWnd, SW_SHOWNORMAL);
int i = 0;
int w = 160;
int h = 160;
int yuv_size = w*h*3/2;
unsigned char rgb_bug[w*h*3];
//yuv 420p
unsigned char yuv_buf[yuv_size];
memset(yuv_buf,0,yuv_size);
memset(rgb_bug,0,w*h*3);
FILE* file = fopen("./I420SP.raw", "rb");
if (NULL == file)
{
printf("open file fail,%s\n",strerror(errno));
}
//save 1.yuv
//fwrite(yuv_buf, yuv_size, 1, file);
//fclose(file);
//exit(0);
printf("yuv_size=%d\n",yuv_size);
fseek(file, 0, SEEK_END);
long file_size = ftell(file);
printf("get file fize%s,size=%ld\n",strerror(errno),file_size);
fseek(file, 0, SEEK_SET);//文件内位置定位到文件头
int cnt = file_size/yuv_size;
int time,diff;
while (GetMessage(&Msg, hMainWnd))
for(i =0;i < cnt;i++)
{
time = getTime();
memset(yuv_buf,0,yuv_size);
memset(rgb_bug,0,w*h*3);
fseek(file, yuv_size*i, SEEK_SET);
fread(yuv_buf,1 , yuv_size, file );
libyuv::NV12ToRGB565(yuv_buf,w,&yuv_buf[w*h],w,rgb_bug,w * 2, w,h);
InitBitmap(HDC_SCREEN,w,h,w*2,rgb_bug,&mBitMap);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
HDC hdc = GetClientDC(hMainWnd);
FillBoxWithBitmap(hdc,0,0,240,280,&mBitMap);
EndPaint(hMainWnd,hdc);
diff = getTime()-time;
//printf("process one frame cost time=%d\n",diff);
if(diff < 33000)usleep(33000-diff);
sprintf(showText,"FPS:%d ",1000000/(getTime()-time));
//printf("process one frame cost time=%d,fps=%s\n",diff,showText);
//SetWindowText(text,showText);
//ShowWindow(text,SW_SHOW);
}
printf("idletask end\n");
MainWindowThreadCleanup (hMainWnd);
return NULL;
}
int main(int argc, const char* argv[])
{
printf("main start\n");
InitGUI(argc,argv);
pthread_t m_pSeekerThread = 0;
pthread_create (&m_pSeekerThread, NULL, IdleTask, NULL);
//pthread_create (&m_pSeekerThread, NULL, TextTask, NULL);
while(1);
printf("main end\n");
return 0;
}