minigui hdc 画图

这篇博客展示了如何使用minigui库和libyuv库在C语言中处理I420SP.raw格式的视频帧,将YUV 420p格式转换为RGB565,并在窗口中显示。程序读取文件,逐帧处理,计算FPS并更新显示。
#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值