-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVITest-THREE.cpp
243 lines (203 loc) · 6.3 KB
/
AVITest-THREE.cpp
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// **********************************************************************
// PUCRS/FACIN
// COMPUTAÇÃO GRÁFICA
//
// Arquivo: AVITest.cpp
//
// Programa de testes para carga de Imagens e vídeos AVI
//
// Este programa deve ser compilador junto com a classe "ImageClass",
// que está implementada no arquivo "ImageClass.cpp"
//
// Para a carga das imagens este programa utiliza a biblioteca
// IM http://www.tecgraf.puc-rio.br/im de autoria de Antonio Scuri
//
// Marcio Serolli Pinho
// 12/08/2003
// **********************************************************************
#include <cstdlib>
#include <iostream>
using namespace std;
#include "AVIClass.h"
#include "AplicadorDeFiltros.h"
int filtrosOn = false;
bool watchAll;
AplicadorDeFiltros filtros;
AVIClass Video, Video2;
int minX = 100;
int maxX = 500;
int minY = 100;
int maxY = 400;
// **********************************************************************
// void init(void)
// Inicializa os parâmetros globais de OpenGL
//
// **********************************************************************
void init(void)
{
cout << "Init..." ;
glClearColor(0.0f, 0.0f, 1.0f, 1.0f); // Fundo de tela preto
imFormatRegisterAVI();
Video2.openVideoFile("videos_professor\\1.avi");
//imFormatRegisterWMV();
if(Video.openVideoFile("videos_professor\\1.avi") == 0)
//if(Video.openVideoFile("Videos\\video_original.avi") == 0)
{
cout << "Problemas na abertura do video" << endl;
}
else cout << "Abertura OK ! - Nro de Frames:" << Video.getTotalFrames() << endl;
cout << "Dimensoes do Video:" << Video.SizeX() << " x " << Video.SizeY() <<endl;
cout << "Fim." << endl;
}
// **********************************************************************
// void reshape( int w, int h )
// trata o redimensionamento da janela OpenGL
//
// **********************************************************************
void reshape( int w, int h )
{
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
gluOrtho2D(0,w,0,h);
// Set the clipping volume
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// **********************************************************************
// void CalculaNivelDeZoom(float &ZoomH, float &ZoomV)
//
//
// **********************************************************************
void CalculaNivelDeZoom(float &ZoomH, float &ZoomV)
{
ZoomH = (float)glutGet(GLUT_WINDOW_WIDTH)/Video.SizeX();
ZoomV = (float)glutGet(GLUT_WINDOW_HEIGHT)/Video.SizeY();
}
// **********************************************************************
// void display( void )
//
//
// **********************************************************************
int frame = 1;
void display( void )
{
unsigned char r,g,b;
int loadFrameOK;
float ZoomH, ZoomV;
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10,10,-10,10,-1,1);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
loadFrameOK = Video.loadImageFrame(frame);
Video2.loadImageFrame(frame);
// avança o nro do frame
frame ++;
cout << "Frame: " << frame << endl;
// se atingiu o final do vídeo, então recomeça
if (frame == Video.getTotalFrames())
{
cout << "Ver todo o video: " << watchAll << endl;
frame = 0;
// getchar();
return;
}
if (loadFrameOK)
{
Video.SetPos(-10,-10);
Video2.SetPos(-10,-10);
// Acerta o zoom da imagem para que ocupe toda a janela
CalculaNivelDeZoom(ZoomH, ZoomV);
Video.SetZoomH(ZoomH);
Video2.SetZoomH(ZoomH);
Video.SetZoomV(ZoomV);
Video2.SetZoomV(ZoomV);
// Executa filtros
if (filtrosOn)
{
filtros.TonsDeCinza(&Video);
filtros.Limiarizacao(&Video, 34, 255, 0, 0, 255, 255, 255);
//filtros.BaldeDeTinta(&Video, 10, 10, 0, 255, 0);
}
// Apresenta o video
Video.Display();
}
else cout << "Erro..." << endl;
glutSwapBuffers();
// Se watchAll for 'true', executa o display() até o video acabar
if(watchAll == true){
display();
}
}
// **********************************************************************
// void keyboard ( unsigned char key, int x, int y )
//
//
// **********************************************************************
void keyboard ( unsigned char key, int x, int y )
{
switch ( key )
{
case 'f': filtrosOn = !filtrosOn;
break;
case 'w': watchAll = !watchAll;
break;
case ' ':
break;
case 27: // Termina o programa qdo
Video.closeVideoFile();
exit ( 0 ); // a tecla ESC for pressionada
break;
default:
break;
}
glutPostRedisplay();
}
// **********************************************************************
// void arrow_keys ( int a_keys, int x, int y )
//
//
// **********************************************************************
void arrow_keys ( int a_keys, int x, int y )
{
switch ( a_keys )
{
case GLUT_KEY_UP: // When Up Arrow Is Pressed...
break;
case GLUT_KEY_DOWN: // When Down Arrow Is Pressed...
break;
default:
break;
}
}
// **********************************************************************
// void main ( int argc, char** argv )
//
//
// **********************************************************************
int main ( int argc, char** argv )
{
init ();
filtros = AplicadorDeFiltros();
glutInit ( &argc, argv );
glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
glutInitWindowPosition (300,10);
// Define o tamanho da janela gráfica do programa
glutInitWindowSize ( 640, 480);
glutCreateWindow ( "AVI Loader - v2.0" );
glutDisplayFunc ( display );
glutReshapeFunc ( reshape );
glutKeyboardFunc ( keyboard );
glutSpecialFunc ( arrow_keys );
//glutIdleFunc ( display );
MessageBox(NULL, "Pressione a barra de espaço para avancar o vídeo.", "Mensagem", MB_OK);
cout << "Pressione a barra de espaço para avancar o vídeo." << endl;
glutMainLoop ();
cout <<"FIM\n";
return 0;
}