-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
155 lines (128 loc) · 2.77 KB
/
main.c
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
#include <unistd.h>
#include <math.h>
#include "ima.h"
Image *image;
#define ESCAPE 27
void Keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case ESCAPE:
exit(0);
break;
default:
fprintf(stderr, "Unused key\n");
}
}
void Mouse(int button, int state, int x, int y)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
break;
case GLUT_MIDDLE_BUTTON:
break;
case GLUT_RIGHT_BUTTON:
break;
}
glutPostRedisplay();
}
int Init(char *s)
{
image = (Image *)malloc(sizeof(Image));
if (image == NULL)
{
fprintf(stderr, "Out of memory\n");
return (-1);
}
if (ImageLoad_PPM(s, image) == -1)
return (-1);
printf("tailles %d %d\n", (int)image->sizeX, (int)image->sizeY);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glutReshapeWindow(image->sizeX, image->sizeY);
return (0);
}
int ReInit()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glutReshapeWindow(image->sizeX, image->sizeY);
return (0);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
image->data);
glFlush();
}
void Reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void menuFunc(int item)
{
char s[256];
switch (item)
{
case 0:
free(image);
exit(0);
break;
case 1:
printf("compression\n");
compression(image, 4);
printf("Taille de l image : %d %d\n", (int)image->sizeX, (int)image->sizeY);
Display();
break;
case 2:
printf("Entrer le nom pour l'image à sauvegarder (avec l'extension)\n");
scanf("%s", &s[0]);
imagesave_PPM(s, image);
break;
case 3:
printf("Taille de l image : %d %d\n", (int)image->sizeX, (int)image->sizeY);
break;
case 4:
décompression(image);
Display();
printf("décompression : \n");
default:
break;
}
}
int main(int argc, char **argv)
{
if (argc < 2)
{
fprintf(stderr, "Usage : palette nom_de_fichier\n");
exit(0);
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow("VPUP8");
Init(argv[1]);
glutCreateMenu(menuFunc);
glutAddMenuEntry("Quit", 0);
glutAddMenuEntry("compression", 1);
glutAddMenuEntry("Sauver", 2);
glutAddMenuEntry("Informations", 3);
glutAddMenuEntry("tab", 4);
glutAttachMenu(GLUT_LEFT_BUTTON);
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutMouseFunc(Mouse);
glutMainLoop();
return 1;
}