Advertisement
Guest User

Untitled

a guest
May 8th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. #include <allegro.h>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <stdio.h>
  5.  
  6.  
  7. BITMAP *bmp;
  8. PALETTE pal;
  9. int tab[250][373];
  10. int tax[250][373];
  11.  float r,b,g, ir,ib,ig,L,bi,cz,p,bialy,czarny;
  12. void init();
  13. void deinit();
  14.  
  15. int main() {
  16.      
  17.     init();
  18.   r=0.3,g=0.59,b=0.11,ir,ib,ig,L,bialy=0,czarny=1,p;
  19.  
  20. bmp = load_bitmap("mona.bmp",0);
  21.   if (!bmp)
  22.     { allegro_message("Nie mozna otworzyc obrazu!");
  23.     exit(-1);}
  24.  
  25.  textout_ex(screen,font,"Obraz po binaryzacji!",50,80 ,makecol(0,0,0),-1);
  26.  
  27.  
  28. blit(bmp, screen, 0, 0,50,100, bmp->w, bmp->h);
  29. allegro_message("Bitmap size: (%dx%d)\n", bmp->w, bmp->h);
  30.  
  31. for (int i=0;i<250;i++)
  32. for (int j=0;j<373;j++)
  33. tab[i][j]=getpixel(bmp,i,j);          
  34.  
  35. asm(".intel_syntax noprefix \n" // Zmiana z AT&T na Intel składnie
  36.  
  37. "lea ebx,_tab[0][0] \n"
  38. "lea edx,_tax[0][0] \n"
  39. "mov ecx,93250 \n"
  40.  
  41.  
  42. "ety2: \n"
  43.  
  44.  
  45.  "call niebieski \n"
  46.   "call zielony \n"
  47.    "call czerwony \n"
  48.  
  49. ///////////////////
  50. //Obliczanie L
  51. "finit \n"
  52. //////////////////
  53.  
  54. //"fld dword ptr [_ib] \n"
  55.  
  56. "fld dword ptr [_ig] \n"
  57. "fld dword ptr [_ib] \n"
  58. "fadd st(0),st(1) \n"
  59.  
  60. "fld dword ptr [_ir] \n"
  61. "fadd st(0),st(1) \n"
  62. "fstp dword ptr [_p] \n"
  63.  
  64. "mov eax,_p \n"
  65.  
  66. "finit \n"
  67.  
  68.  
  69. //klasyfikowanie pixeli jako białych lub czarnych
  70. "cmp eax,50 \n"
  71.  
  72. "ja czarne \n"
  73.  
  74.  
  75. "fild dword ptr [_bialy] \n"
  76. "fstp dword ptr [edx] \n"
  77.  
  78.  
  79. "jmp dalej \n"
  80.  "czarne: \n"
  81.  
  82. "fild dword ptr [_czarny] \n"
  83.  
  84. "fstp dword ptr [edx] \n"
  85.  
  86. "dalej: \n"      
  87.  
  88.  
  89. "add ebx,4 \n"
  90. "add edx,4 \n"
  91. "loop ety2 \n"
  92. "jmp dalej2 \n"    
  93.  
  94. //niebieski
  95. "niebieski: \n"
  96. "finit \n"
  97.  
  98. "mov eax, [ebx] \n"
  99. "and eax, 0x0000FF \n"
  100.  
  101.  
  102.  "mov  _p, eax \n"
  103.  
  104. "fild dword ptr [_p] \n"
  105.  
  106.  
  107. "fld dword ptr [_b] \n"
  108.  
  109.  
  110. "fmul st(0),st(1) \n"
  111.  
  112.  
  113. "fstp dword ptr [_ib] \n"
  114. //koniec niebieskiego
  115. "ret \n"
  116.  
  117.  
  118. //zielony
  119. "zielony: \n"
  120.  
  121. "finit \n"
  122.  
  123. "mov eax, [ebx] \n"
  124. "and eax, 0x00FF00  \n"
  125.  
  126.  "mov _p, eax \n"
  127. "fild dword ptr [_p] \n"
  128. "fld dword ptr [_g] \n"
  129. "fmul st(0),st(1) \n"
  130.  
  131.  
  132. "fstp dword ptr [_ig] \n"
  133. //koniec zielonego
  134. "ret \n"
  135.  
  136.  
  137.  
  138. //czerwony
  139. "czerwony: \n"
  140. "finit \n"
  141. "mov eax, [ebx] \n"
  142. "and eax, 0xFF0000  \n"
  143.  "mov _p, eax \n"
  144.  
  145. "fild dword ptr [_p] \n"
  146. "fld dword ptr [_r] \n"
  147.  
  148. "fmul st(0),st(1) \n"
  149.  
  150.  
  151. "fstp dword ptr [_ir] \n"
  152. "ret \n"
  153. //koniec czerwonego
  154.  
  155. "dalej2: \n"
  156.  
  157.  
  158.  
  159. ".att_syntax \n");
  160.  
  161. for (int i=0;i<250;i++)
  162. for (int j=0;j<373;j++)
  163. {putpixel(bmp,i,j,tax[i][j]); }
  164. blit(bmp, screen, 0, 0,450,100, bmp->w, bmp->h);
  165.  
  166. allegro_message("binaryzacja");
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. //  while (!key[KEY_ESC]) {
  174.         /* put your code here */
  175. //  }
  176.  
  177.     deinit();
  178.     return 0;
  179. }
  180. END_OF_MAIN()
  181.  
  182. void init() {
  183.     int depth, res;
  184.     allegro_init();
  185. //   install_allegro(0, NULL, NULL);
  186.     depth = desktop_color_depth();
  187.     if (depth == 0) depth = 32;
  188.     set_color_depth(depth);
  189.     res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
  190. //  res = set_gfx_mode(0, 404, 404, 0, 0); 
  191.     if (res != 0) {
  192.         allegro_message(allegro_error);
  193.         exit(-1);
  194.     }
  195.     clear_to_color(screen,makecol(206,206,206));
  196.     install_timer();
  197.     install_keyboard();
  198.     install_mouse();
  199.     /* add other initializations here */
  200. }
  201.  
  202. void deinit() {
  203.     clear_keybuf();
  204.     /* add other deinitializations here */
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement