-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
145 lines (107 loc) · 3.29 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
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
int func(char *a, char* b, int contrast, int tryb);
#ifdef __cplusplus
}
#endif
const int WIDTH = 640, HEIGHT = 360;
int newContrast = 0;
int wybor = 2;
const int maxContrast = 255;
const int minContrast = -255;
size_t fileSize;
char *fileData = NULL;
char output[250000];
void LoadBmp(const char *fileName)
{
if (fileData != NULL)
{
free(fileData);
fileData = NULL;
}
FILE *file = fopen(fileName, "rb");
if (file)
{
fseek(file, 0, SEEK_END);
fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
fileData = malloc(sizeof(char) * fileSize);
fread(fileData, sizeof(char), fileSize, file);
}
else printf("Error opening the file\n");
fclose(file);
}
int main( int argc, char *argv[] )
{
LoadBmp("test.bmp");
SDL_Surface *imageSurface = NULL;
SDL_Surface *windowSurface = NULL;
if ( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
printf("ERROR\n");
}
SDL_Window *window = SDL_CreateWindow( "Program", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI );
windowSurface = SDL_GetWindowSurface( window );
if ( NULL == window )
{
printf("ERROR\n");
return EXIT_FAILURE;
}
SDL_Event windowEvent;
SDL_RWops *data = SDL_RWFromMem(fileData, fileSize);
imageSurface = SDL_LoadBMP_RW(data, 0);
if( imageSurface == NULL )
{
printf("ERROR\n");
}
while ( 1 )
{
if ( SDL_PollEvent( &windowEvent ) )
{
if (SDL_KEYDOWN == windowEvent.type)
{
switch (windowEvent.key.keysym.sym)
{
case SDLK_LEFT: newContrast = --newContrast < minContrast ? minContrast : newContrast; break;
case SDLK_RIGHT: newContrast = ++newContrast > maxContrast ? maxContrast : newContrast; break;
case SDLK_UP: wybor = wybor == 0 ? 1 : 0; break;
}
printf(" %d ", newContrast);
func(fileData, output, newContrast, wybor);
SDL_FillRect(windowSurface, NULL, 0x000000);
SDL_RWops *data = SDL_RWFromMem(output, 151646);
printf("TEST %d\n", output);
/*FILE *file = fopen("test.bmp", "wb");
printf("BegFile\n");
fwrite(fileData, sizeof(char), newW*newH*4+138, file);
printf("EndFile\n");
fclose(file);
printf("close file\n");
printf("TEST3\n");*/
imageSurface = SDL_LoadBMP_RW(data, 0);
//printf("test2\n");*/
}
else if ( SDL_QUIT == windowEvent.type )
{
break;
//LoadBmp("dst.bmp");
//SDL_RWops *data = SDL_RWFromMem(fileData, fileSize);
//imageSurface = SDL_LoadBMP_RW(data, 0);
//
}
}
SDL_BlitSurface( imageSurface, NULL, windowSurface, NULL );
SDL_UpdateWindowSurface( window );
}
SDL_FreeSurface( imageSurface );
SDL_FreeSurface( windowSurface );
imageSurface = NULL;
windowSurface = NULL;
SDL_DestroyWindow( window );
SDL_Quit( );
return EXIT_SUCCESS;
}