Тонирование
библ
Assembler | 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
| mmxProc PROC C USES ebx ecx edx rgb:DWORD, w:DWORD, h:DWORD, PR: DWORD, PG: DWORD, PB: DWORD
xor edx, edx
mov eax, w
mov ebx, h
mul ebx
mov len, eax
shl eax, 2
GETMEM pixels, eax
INVOKE GRAYSCALE, rgb, w, h, pr, pg, pb
mov esi, pixels
mov edi, rgb
mov ecx, len
rep movsd
FREEMEM pixels
xor edx, edx
mov eax, w
mov ebx, h
mul ebx
mov len, eax
mov eax, a
mov ebx, m
mov edx, rgb
movq mm0, QWORD PTR[eax]
movq mm1, QWORD PTR[ebx]
.WHILE ecx>0
movq mm2, QWORD PTR[edx]
pand mm2,mm1
por mm2,mm0
movq QWORD PTR[edx], mm2
add edx, 4
dec ecx
.ENDW
mov eax, 0
ret
mmxProc ENDP |
|
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
| extern "C" void* mmxLib(void*, int, void*, void*); // podklyuchenie biblioteki
#include "SDL.h"
#include "SDL_image.h"
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define WIDTH 1024
#define HEIGHT 768
#define DEPTH 32
#define image_width 480
#define image_height 480
SDL_Surface *screen, *image1, *image2, *image3;
SDL_Rect src, dest;
int img[image_width][image_height], b[2], c[2];
void putpixel(int x, int y, int color)
{
unsigned int *ptr = (unsigned int*)image2 -> pixels;
int lineoffset = y * (image2 -> pitch / 4);
ptr[lineoffset + x] = color;
}
int main(int argc, char *argv[]){
int level;
printf("Vvedite uroven teplogo filtra ot 0 do 4): ");
scanf("%d", &level);
switch (level){
case 0:{
b[0] = b[1] = 0x00000000;
c[0] = c[1] = 0x00ffffff;
break;
}
case 1:{
b[0] = b[1] = 0x11000000;
c[0] = c[1] = 0x00ffffff;
break;
}
case 2:{
b[0] = b[1] = 0x22000000;
c[0] = c[1] = 0x00ffffff;
break;
}
case 3:{
b[0] = b[1] = 0x33000000;
c[0] = c[1] = 0x00ffffff;
break;
}
case 4:{
b[0] = b[1] = 0xf0f0f0f0;
c[0] = c[1] = 0x0f0f0f0f;
break;
}
}
if (SDL_Init(SDL_INIT_VIDEO) != 0){
printf("Unable to initialize SDL: %sn", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE);
if (screen == NULL){
printf("Unable to set video mode: %sn", SDL_GetError());
return 1;
}
image1 = IMG_Load("mash2.png");
if (image1 == NULL) {
printf("Unable to load image");
return 1;
}
image2 = IMG_Load("orange2.png");
if (image2 == NULL){
printf("Unable to load image");
return 1;
}
image3 = IMG_Load("mash2.png");
if (image3 == NULL){
printf("Unable to load image");
return 1;
}
unsigned int *ptr = (unsigned int*)image2 -> pixels; // iz kartinki v massiv
for (int i=0; i < image_width; i++)
for (int j=0; j < image_height; j++)
img[i][j] = ptr[j * (image2 -> pitch / 4) + i];
mmxLib(img, image_width * image_height, b, c); // vizov biblioteki
for (int i=0; i < image_width; i++)
for (int j=0; j < image_height; j++)
putpixel(i, j, img[i][j]);
src.x = 0;
src.y = 0;
src.w = image1 -> w;
src.h = image1 -> h;
dest.x = 525;
dest.y = 100;
dest.w = image1 -> w;
dest.h = image1 -> h;
SDL_BlitSurface(image1, &src, screen, &dest);
src.w = image2->w;
src.h = image2->h;
dest.w = src.w;
dest.h = src.h;
dest.x = 525;
dest.y = 100;
SDL_BlitSurface(image2, &src, screen, &dest);
src.w = image3->w;
src.h = image3->h;
dest.w = src.w;
dest.h = src.h;
dest.x = 20;
dest.y = 100;
SDL_BlitSurface(image3, &src, screen, &dest);
SDL_UpdateRect(screen, 0, 0, 0, 0);
SDL_SaveBMP(screen,"image3.png");
//SDL_Delay(5000);
while (true){
SDL_Event event;
while (SDL_PollEvent(&event)){
if (event.key.keysym.sym == SDLK_ESCAPE)
return 0;
}
}
SDL_FreeSurface(image1);
SDL_FreeSurface(image2);
} |
|
Ч\Б
библ
Assembler | 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
| .686p
.mmx
.model FLAT, C
GlobalAlloc PROTO STDCALL :DWORD,:DWORD
GlobalFree PROTO STDCALL :DWORD
GETMEM MACRO PARAM1, PARAM2
push eax
push ecx
push edx
INVOKE GlobalAlloc, 0, PARAM2
mov PARAM1, eax
pop edx
pop ecx
pop eax
ENDM
FREEMEM MACRO PARAM
push eax
push ecx
push edx
INVOKE GlobalFree, PARAM
pop edx
pop ecx
pop eax
ENDM
.data
len DD 0
pixels DD 0
tmp DD 0
tmp2 DD 0
c0114 DD 0.114
c0587 DD 0.587
c0299 DD 0.299
a dd 77000000h
m dd 00ffffffh
.code
DLLMain PROC stdcall hInst: DWORD, flag: DWORD, noUse: DWORD
mov eax, 1
ret
DLLMain ENDP
GRAYSCALE PROC C USES eax ebx ecx edx esi edi RGB: DWORD, W: DWORD, H: DWORD, PR: DWORD, PG: DWORD, PB: DWORD
mov esi, RGB
mov edi, pixels
mov ebx, W
mov ecx, H
imul ebx, ecx
xor ecx, ecx
.WHILE ecx < ebx
lodsd
mov tmp, eax
; blue
xor edx, edx
mov dl, byte ptr tmp[0]
mov tmp2, edx
fld tmp2
fmul PB
fmul c0114
fstp tmp2
mov eax, tmp2
; green
mov dl, byte ptr tmp[1]
mov tmp2, edx
fld tmp2
fmul PG
fmul c0587
fstp tmp2
add eax, tmp2
; red
mov dl, byte ptr tmp[2]
mov tmp2, edx
fld tmp2
fmul PR
fmul c0299
fstp tmp2
add eax, tmp2
mov [edi+ecx*4][0], al
mov [edi+ecx*4][1], al
mov [edi+ecx*4][2], al
inc ecx
.ENDW
ret
GRAYSCALE ENDP
mmxProc PROC C USES ebx ecx edx rgb:DWORD, w:DWORD, h:DWORD, PR: DWORD, PG: DWORD, PB: DWORD
xor edx, edx
mov eax, w
mov ebx, h
mul ebx
mov len, eax
shl eax, 2
GETMEM pixels, eax
INVOKE GRAYSCALE, rgb, w, h, pr, pg, pb
mov esi, pixels
mov edi, rgb
mov ecx, len
rep movsd
FREEMEM pixels
xor edx, edx
mov eax, w
mov ebx, h
mul ebx
mov len, eax
mov eax, a
mov ebx, m
mov edx, rgb
movq mm0, QWORD PTR[eax]
movq mm1, QWORD PTR[ebx]
.WHILE ecx>0
movq mm2, QWORD PTR[edx]
pand mm2,mm1
por mm2,mm0
movq QWORD PTR[edx], mm2
add edx, 4
dec ecx
.ENDW
mov eax, 0
ret
mmxProc ENDP
end DLLMain |
|
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
| extern "C" void* mmxProc(void*, int, int, float, float, float);
#include <stdlib.h>
#include "SDL.h"
#include "SDL_image.h"
#define WIDTH 1366
#define HEIGHT 768
#define BITS 32
#define COLOR 0x006123af
#define IMAGENAME "sample2.png"
SDL_Surface *screen;
int a[WIDTH][HEIGHT];
int temp[WIDTH][HEIGHT];
int mmxCall(float prop_r, float prop_g, float prop_b) {
for(int i = 0; i < WIDTH; i++)
for(int j = 0; j < HEIGHT; j++)
temp[i][j] = a[i][j];
mmxProc(temp, WIDTH, HEIGHT, prop_r, prop_g, prop_b);
for(int i = 0; i < WIDTH; i++)
for(int j = 0; j < HEIGHT; j++)
a[i][j] = temp[i][j];
return 0;
}
void putpixel(int x, int y, int color) {
unsigned int *ptr = (unsigned int*)screen->pixels;
int lineoffset = y * (screen->pitch / 4);
ptr[lineoffset + x] = color;
}
void init() {
SDL_Surface *temp;
if(!(temp = IMG_Load(IMAGENAME))) {
fprintf(stderr, "IMG_Load: %s\n", IMG_GetError());
exit(1);
}
temp = SDL_ConvertSurface(temp, screen->format, SDL_HWSURFACE);
unsigned int *ptr = (unsigned int*)temp->pixels;
int start_i = (screen->w>temp->w)?(screen->w-temp->w)/2:0;
int start_j = (screen->h>temp->h)?(screen->h-temp->h)/2:0;
for (int i=0; i<temp->w; i++)
for (int j=0; j<temp->h; j++)
{
int lineoffset = j * (temp->pitch / 4);
a[i+start_i][j+start_j] = ptr[lineoffset + i];
}
SDL_FreeSurface(temp);
}
void render() {
if (SDL_LockSurface(screen) < 0)
return;
int tick = SDL_GetTicks();
for (int i=0; i<WIDTH; i++)
for (int j=0; j<HEIGHT; j++)
{
putpixel(i, j, a[i][j]);
}
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 0, 0, WIDTH, HEIGHT);
}
int main(int argc, char *argv[]) {
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(WIDTH, HEIGHT, BITS, /* SDL_FULLSCREEN| */ SDL_HWSURFACE);
if(screen == NULL)
{
fprintf(stderr, "Unable to set %dx%d video: %s\n", WIDTH, HEIGHT, SDL_GetError());
exit(1);
}
init();
while (true)
{
render();
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE) {
SDL_SaveBMP(screen, "result.bmp");
return 0;
}
else if (event.key.keysym.sym == SDLK_1)
mmxCall(1.0, 1.0, 1.0);
else if (event.key.keysym.sym == SDLK_2)
mmxCall(1.0, 0, 0);
else if (event.key.keysym.sym == SDLK_3)
mmxCall(0, 1.0, 0);
else if (event.key.keysym.sym == SDLK_4)
mmxCall(0, 0, 1.0);
else if (event.key.keysym.sym == SDLK_5)
mmxCall(1.0, 1.0, 0);
else if (event.key.keysym.sym == SDLK_6)
mmxCall(1.0, 0, 1.0);
else if (event.key.keysym.sym == SDLK_7)
mmxCall(0, 1.0, 1.0);
else if (event.key.keysym.sym == SDLK_8)
mmxCall(0.5, 0.5, 0.5);
else if (event.key.keysym.sym == SDLK_TAB)
init();
break;
case SDL_QUIT:
return(0);
}
}
}
return 0;
} |
|
0
|