📄 rhdv3.c
字号:
//###//#//#//####include <stdio.h>#include <stdlib.h>#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "rhduvc.h"static BITMAP bmp,bmp1;unsigned char *localbmpbuf;int sizeofimage;static GAL_Overlay *overlay;#define IDC_CAPTURE 101#define IDC_SAVEBMP 102#define IDC_PROCESS 103#define IDC_SAVEPROCED 104#define IDC_EXIT 105#define VID_W 320#define VID_H 240#define orifile "/tmp/original.yuv"#define procfile "/tmp/proced.yuv"static DLGTEMPLATE DlgProcess ={ WS_BORDER, WS_EX_NOCLOSEBOX, 430, 30, 200, 400, " ", 0, 0, 5, NULL, 0};static CTRLDATA CtrlProcess[] ={ { "button", WS_VISIBLE | BS_DEFPUSHBUTTON | BS_CHECKED | WS_GROUP, 50,20,90,30, IDC_CAPTURE, "采集图像", 0 }, { "button", WS_VISIBLE | BS_DEFPUSHBUTTON , 50,100,90,30, IDC_SAVEBMP, "保存图像", 0 }, { "button", WS_VISIBLE | BS_DEFPUSHBUTTON |WS_TABSTOP, 50,180,90,30, IDC_PROCESS, "处理图像", 0 }, { "button", WS_VISIBLE | BS_DEFPUSHBUTTON |WS_TABSTOP, 50,260,90,30, IDC_SAVEPROCED, "保存结果", 0 }, { "button", WS_VISIBLE | BS_DEFPUSHBUTTON |WS_TABSTOP, 50,340,90,30, IDC_EXIT, "退出", 0 },};void FillBitmap(BITMAP *bmp){bmp->bmType = 0;bmp->bmBitsPerPixel = 16;bmp->bmBytesPerPixel = 2;bmp->bmAlpha = 0;bmp->bmColorKey = 0;bmp->bmWidth = VID_W;bmp->bmHeight = VID_H;bmp->bmPitch = VID_W*2;bmp->bmBits = NULL;bmp->bmAlphaPixelFormat = NULL;} void rgbtoblue(unsigned char *bmpptr,int size){ int i; for(i=0;i<size;i=i+2) {// printf("i=%d , *(bmpptr+i)=%x ",i,*(bmpptr+i));// printf(" *(bmpptr+i+1)=%x ",*(bmpptr+i+1)); if( *(bmpptr+i) > 0xaf ) { *(bmpptr+i) =0xff; *(bmpptr+i+1) = 0xff; } else { *(bmpptr+i) =0x00 ; *(bmpptr+i+1)= 0x00; }// printf(" *(bmpptr+i)=%x ",*(bmpptr+i));// printf(" *(bmpptr+i+1)=%x \n",*(bmpptr+i+1)); }}static int MyProc(HWND hDlg,int message,WPARAM wParam,LPARAM lParam){ HDC hdc; HWND hWnd; FILE *fp; Uint32 overlay_format; switch (message) { case MSG_INITDIALOG: return 1; case MSG_COMMAND: switch(wParam) { case IDC_CAPTURE: get_a_frame(localbmpbuf,sizeofimage); get_a_frame(localbmpbuf,sizeofimage); get_a_frame(localbmpbuf,sizeofimage); hWnd=GetParent(hDlg); hdc = BeginPaint (hWnd); overlay_format = GAL_YUY2_OVERLAY; overlay = CreateYUVOverlay(320, 240, overlay_format, hdc); if ( overlay == NULL ) { fprintf(stderr, "Couldn't create overlay!\n"); exit(1); }// printf("create YUV overlay Success!\n"); LockYUVOverlay(overlay);// time(&nowtime);// printf("nowtime : %ld\n",nowtime); memcpy(overlay->pixels[0],localbmpbuf,sizeofimage);// time(&nowtime);// printf("after get_a_frame: %ld\n",nowtime); UnlockYUVOverlay (overlay); RECT rc={20,20,340,260}; DisplayYUVOverlay(overlay, &rc); EndPaint(hWnd, hdc); return 0; case IDC_SAVEBMP: fp = fopen(orifile, "w"); if(!fp) return -1;// printf("the size of image : %d \n",sizeofimage); fwrite(localbmpbuf, sizeofimage, 1, fp); fclose(fp); return 0; case IDC_PROCESS: rgbtoblue(localbmpbuf,sizeofimage); bmp1.bmBits = localbmpbuf; hWnd=GetParent(hDlg); hdc = BeginPaint (hWnd); FillBoxWithBitmap (hdc, 20,20+VID_H,VID_W,VID_H,&bmp1); EndPaint(hWnd, hdc); return 0; case IDC_SAVEPROCED: fp = fopen(procfile, "w"); if(!fp) return -1; fwrite(localbmpbuf, sizeofimage, 1, fp); fclose(fp); return 0; case IDC_EXIT: printf("EXIT PUSHDOWN!\n"); EndDialog (hDlg, wParam); break; } break; } return DefaultDialogProc (hDlg, message, wParam, lParam);}static int MyWinProc(HWND hWnd, int message, WPARAM wParam,LPARAM lParam){ switch (message) { case MSG_CLOSE: FreeYUVOverlay (overlay); UnloadBitmap (&bmp); printf("MSG_CLOSE!\n"); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}int MiniGUIMain (int argc, const char* argv[]){ HWND hMainWnd; MAINWINCREATE CreateInfo; open_device (); init_device (); start_capturing (); localbmpbuf = calloc(VID_W*VID_H*2,1); #ifdef _LITE_VERSION SetDesktopRect(0, 0, 640, 480);#endif CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION; CreateInfo.dwExStyle = WS_EX_NOCLOSEBOX; CreateInfo.spCaption = " RHD视觉控制系统"; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor(0); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = MyWinProc; CreateInfo.lx = 0; CreateInfo.ty = 0; CreateInfo.rx = 640; CreateInfo.by = 480; CreateInfo.iBkColor = PIXEL_lightwhite; CreateInfo.dwAddData = 0; CreateInfo.hHosting = HWND_DESKTOP; hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) { printf("Main Windows Created error!\n"); return -1; } ShowWindow (hMainWnd, SW_SHOWNORMAL);
/* while (GetMessage(&Msg, hMainWnd)) { TranslateMessage(&Msg); DispatchMessage(&Msg); }*/ FillBitmap(&bmp); FillBitmap(&bmp1); sizeofimage=VID_W*VID_H*bmp.bmBytesPerPixel; if((localbmpbuf=(unsigned char*)calloc(1,sizeofimage)) == NULL) { printf("calloc err! ----localbmpbuf\n"); return -1; } DlgProcess.controls = CtrlProcess; DialogBoxIndirectParam (&DlgProcess, hMainWnd, MyProc, 0L); free(localbmpbuf); DestroyAllControls(hMainWnd); printf("MSG_CLOSE!\n"); DestroyMainWindow (hMainWnd); MainWindowThreadCleanup (hMainWnd); stop_capturing (); uninit_device (); close_device (); exit(0);}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -