-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (117 loc) · 2.63 KB
/
main.cpp
File metadata and controls
137 lines (117 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <windows.h>
#include "render.h"
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dcompiler.lib")
static char className[256] = "testClassName";
static char title[256] = "testTitle";
static char file[256] = "test.yuv";
static int pic_width = 176;
static int pic_height = 144;
static FILE* pFile = NULL;
D3D11YUV420PRenderer* pPlayer = NULL;
HWND InitWindow();
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int DrawPic();
HWND InitWindow()
{
WNDCLASSEXA wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = NULL;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = "testMenuName";
wcex.lpszClassName = className;
wcex.hIconSm = NULL;
RegisterClassExA(&wcex);
HWND hWnd = CreateWindowA(className, title, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);
if (!hWnd)
{
return NULL;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return hWnd;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
if (pPlayer == NULL)
{
pPlayer = new D3D11YUV420PRenderer();
pPlayer->Initialize(hWnd, pic_width, pic_height);
SetTimer(hWnd, 1, 40, NULL);
}
break;
case WM_TIMER:
if (pPlayer != NULL)
{
DrawPic();
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
if (pPlayer != NULL)
{
delete pPlayer;
pPlayer = NULL;
}
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
{
pFile = fopen("test.yuv", "rb");
HWND hWnd = InitWindow();
if (hWnd == NULL)
{
return -1;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
fclose(pFile);
return 0;
}
int DrawPic()
{
if (pFile == NULL || pPlayer == NULL)
{
return -1;
}
int yuv_size = pic_width * pic_height * 3 / 2;
unsigned char* data = new unsigned char[yuv_size];
int ret = fread(data, yuv_size, 1, pFile);
if (ret > 0)
{
pPlayer->Render(data);
}
else
{
fseek(pFile, 0, SEEK_SET);
}
delete[] data;
return 0;
}