Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- #include <cstdlib>
- #include <iostream>
- #include <stdio.h>
- BITMAP *bmp;
- PALETTE pal;
- int tab[250][373];
- int tax[250][373];
- float r,b,g, ir,ib,ig,L,bi,cz,p,bialy,czarny;
- void init();
- void deinit();
- int main() {
- init();
- r=0.3,g=0.59,b=0.11,ir,ib,ig,L,bialy=0,czarny=1,p;
- bmp = load_bitmap("mona.bmp",0);
- if (!bmp)
- { allegro_message("Nie mozna otworzyc obrazu!");
- exit(-1);}
- textout_ex(screen,font,"Obraz po binaryzacji!",50,80 ,makecol(0,0,0),-1);
- blit(bmp, screen, 0, 0,50,100, bmp->w, bmp->h);
- allegro_message("Bitmap size: (%dx%d)\n", bmp->w, bmp->h);
- for (int i=0;i<250;i++)
- for (int j=0;j<373;j++)
- tab[i][j]=getpixel(bmp,i,j);
- asm(".intel_syntax noprefix \n" // Zmiana z AT&T na Intel składnie
- "lea ebx,_tab[0][0] \n"
- "lea edx,_tax[0][0] \n"
- "mov ecx,93250 \n"
- "ety2: \n"
- "call niebieski \n"
- "call zielony \n"
- "call czerwony \n"
- ///////////////////
- //Obliczanie L
- "finit \n"
- //////////////////
- //"fld dword ptr [_ib] \n"
- "fld dword ptr [_ig] \n"
- "fld dword ptr [_ib] \n"
- "fadd st(0),st(1) \n"
- "fld dword ptr [_ir] \n"
- "fadd st(0),st(1) \n"
- "fstp dword ptr [_p] \n"
- "mov eax,_p \n"
- "finit \n"
- //klasyfikowanie pixeli jako białych lub czarnych
- "cmp eax,50 \n"
- "ja czarne \n"
- "fild dword ptr [_bialy] \n"
- "fstp dword ptr [edx] \n"
- "jmp dalej \n"
- "czarne: \n"
- "fild dword ptr [_czarny] \n"
- "fstp dword ptr [edx] \n"
- "dalej: \n"
- "add ebx,4 \n"
- "add edx,4 \n"
- "loop ety2 \n"
- "jmp dalej2 \n"
- //niebieski
- "niebieski: \n"
- "finit \n"
- "mov eax, [ebx] \n"
- "and eax, 0x0000FF \n"
- "mov _p, eax \n"
- "fild dword ptr [_p] \n"
- "fld dword ptr [_b] \n"
- "fmul st(0),st(1) \n"
- "fstp dword ptr [_ib] \n"
- //koniec niebieskiego
- "ret \n"
- //zielony
- "zielony: \n"
- "finit \n"
- "mov eax, [ebx] \n"
- "and eax, 0x00FF00 \n"
- "mov _p, eax \n"
- "fild dword ptr [_p] \n"
- "fld dword ptr [_g] \n"
- "fmul st(0),st(1) \n"
- "fstp dword ptr [_ig] \n"
- //koniec zielonego
- "ret \n"
- //czerwony
- "czerwony: \n"
- "finit \n"
- "mov eax, [ebx] \n"
- "and eax, 0xFF0000 \n"
- "mov _p, eax \n"
- "fild dword ptr [_p] \n"
- "fld dword ptr [_r] \n"
- "fmul st(0),st(1) \n"
- "fstp dword ptr [_ir] \n"
- "ret \n"
- //koniec czerwonego
- "dalej2: \n"
- ".att_syntax \n");
- for (int i=0;i<250;i++)
- for (int j=0;j<373;j++)
- {putpixel(bmp,i,j,tax[i][j]); }
- blit(bmp, screen, 0, 0,450,100, bmp->w, bmp->h);
- allegro_message("binaryzacja");
- // while (!key[KEY_ESC]) {
- /* put your code here */
- // }
- deinit();
- return 0;
- }
- END_OF_MAIN()
- void init() {
- int depth, res;
- allegro_init();
- // install_allegro(0, NULL, NULL);
- depth = desktop_color_depth();
- if (depth == 0) depth = 32;
- set_color_depth(depth);
- res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
- // res = set_gfx_mode(0, 404, 404, 0, 0);
- if (res != 0) {
- allegro_message(allegro_error);
- exit(-1);
- }
- clear_to_color(screen,makecol(206,206,206));
- install_timer();
- install_keyboard();
- install_mouse();
- /* add other initializations here */
- }
- void deinit() {
- clear_keybuf();
- /* add other deinitializations here */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement