Subversion Repositories Kolibri OS

Rev

Rev 7861 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. format MS COFF
  2. public EXPORTS
  3. section '.flat' code readable align 16
  4.  
  5. include '../../../../macros.inc'
  6. include '../../../../proc32.inc'
  7.  
  8. ;-----------------------------------------------------------------------------
  9. mem.alloc   dd ? ;äã­ªæ¨ï ¤«ï ¢ë¤¥«¥­¨ï ¯ ¬ïâ¨
  10. mem.free    dd ? ;äã­ªæ¨ï ¤«ï ®á¢®¡®¦¤¥­¨ï ¯ ¬ïâ¨
  11. mem.realloc dd ? ;äã­ªæ¨ï ¤«ï ¯¥à¥à á¯à¥¤¥«¥­¨ï ¯ ¬ïâ¨
  12. dll.load    dd ?
  13.  
  14. BUF_STRUCT_SIZE equ 21
  15. buf2d_data equ dword[edi] ;¤ ­­ë¥ ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  16. buf2d_w equ dword[edi+8] ;è¨à¨­  ¡ãä¥à 
  17. buf2d_h equ dword[edi+12] ;¢ëá®â  ¡ãä¥à 
  18. buf2d_l equ word[edi+4]
  19. buf2d_t equ word[edi+6] ;®âáâ㯠ᢥàåã
  20. buf2d_size_lt equ dword[edi+4] ;®âáâ㯠᫥¢  ¨ á¯à ¢  ¤«ï ¡ãä¥à 
  21. buf2d_color equ dword[edi+16] ;梥â ä®­  ¡ãä¥à 
  22. buf2d_bits equ byte[edi+20] ;ª®«¨ç¥á⢮ ¡¨â ¢ 1-© â®çª¥ ¨§®¡à ¦¥­¨ï
  23.  
  24. struct buf_2d_header
  25.         img_data dd ?
  26.         left dw ? ;+4 left
  27.         top dw ? ;+6 top
  28.         size_x dd ? ;+8 w
  29.         size_y dd ? ;+12 h
  30.         color dd ? ;+16 color
  31.         bit_pp db ? ;+21 bit in pixel
  32. ends
  33.  
  34. macro swap v1, v2 {
  35.   push v1
  36.   push v2
  37.   pop v1
  38.   pop v2
  39. }
  40.  
  41. ;ä« £¨, ¤«ï ä㭪樨 ®¡à¥§ ­¨ï ¡ãä¥à 
  42. BUF2D_OPT_CROP_TOP equ 1 ;®¡à¥§ª  ᢥàåã
  43. BUF2D_OPT_CROP_LEFT equ 2 ;®¡à¥§ª  á«¥¢ 
  44. BUF2D_OPT_CROP_BOTTOM equ 4 ;®¡à¥§ª  á­¨§ã
  45. BUF2D_OPT_CROP_RIGHT equ 8 ;®¡à¥§ª  á¯à ¢ 
  46. BUF2D_BIT_OPT_CROP_TOP equ 0
  47. BUF2D_BIT_OPT_CROP_LEFT equ 1
  48. BUF2D_BIT_OPT_CROP_BOTTOM equ 2
  49. BUF2D_BIT_OPT_CROP_RIGHT equ 3
  50.  
  51. ;input:
  52. ; eax = 㪠§ â¥«ì ­  äã­ªæ¨î ¢ë¤¥«¥­¨ï ¯ ¬ïâ¨
  53. ; ebx = ... ®á¢®¡®¦¤¥­¨ï ¯ ¬ïâ¨
  54. ; ecx = ... ¯¥à¥à á¯à¥¤¥«¥­¨ï ¯ ¬ïâ¨
  55. ; edx = ... § £à㧪¨ ¡¨¡«¨®â¥ª¨ (¯®ª  ­¥ ¨á¯®«ì§ã¥âáï)
  56. align 16
  57. lib_init:
  58.         mov dword[mem.alloc], eax
  59.         mov dword[mem.free], ebx
  60.         mov dword[mem.realloc], ecx
  61.         mov dword[dll.load], edx
  62.         ret
  63.  
  64. include 'fun_draw.inc' ;ä㭪樨 à¨á®¢ ­¨ï ¢ ¡ãä¥à¥
  65.  
  66. ;ᮧ¤ ­¨¥ ¡ãä¥à 
  67. align 4
  68. proc buf_create, buf_struc:dword
  69.         pushad
  70.         mov edi,dword[buf_struc]
  71.         mov ecx,buf2d_w
  72.         mov ebx,buf2d_h
  73.         imul ecx,ebx
  74.         cmp buf2d_bits,24
  75.         jne @f
  76.                 lea ecx,[ecx+ecx*2] ; 24 bit = 3
  77.                 ;;;inc ecx ;§ ¯ á­®© ¡ ©â ¢ ª®­æ¥ ¡ãä¥à , çâ®-¡ë ­¥ £«î稫¨ ­¥ª®â®àë¥ ä㭪樨 ­  ¨§®¡à ¦¥­¨ïå ªà â­ëå 4Š
  78.         @@:
  79.         cmp buf2d_bits,32
  80.         jne @f
  81.                 shl ecx,2 ; 32 bit = 4
  82.         @@:
  83.         invoke mem.alloc,ecx
  84.         mov buf2d_data,eax
  85.  
  86.         stdcall buf_clear,edi,buf2d_color ;®ç¨á⪠ ¡ãä¥à  ä®­®¢ë¬ 梥⮬
  87.         popad
  88.         ret
  89. endp
  90.  
  91. ;ᮧ¤ ­¨¥ ¡ãä¥à  ­  ®á­®¢¥ ¨§®¡à ¦¥­¨ï rgb
  92. align 4
  93. proc buf_create_f_img, buf_struc:dword, rgb_data:dword
  94.         pushad
  95.         mov edi,dword[buf_struc]
  96.         mov ecx,buf2d_w
  97.         cmp ecx,1
  98.         jl .error
  99.         mov ebx,buf2d_h
  100.         cmp ebx,1
  101.         jl .error
  102.         imul ecx,ebx
  103.         cmp buf2d_bits,24
  104.         jne @f
  105.                 lea ecx,[ecx+ecx*2] ; 24 bit = 3
  106.         @@:
  107.         cmp buf2d_bits,32
  108.         jne @f
  109.                 shl ecx,2 ; 32 bit = 4
  110.         @@:
  111.         invoke mem.alloc,ecx
  112.         mov buf2d_data,eax
  113.  
  114.         cmp buf2d_bits,24
  115.         jne @f
  116.                 cld
  117.                 mov esi,[rgb_data]
  118.                 or esi,esi
  119.                 jz @f
  120.                 mov edi,eax ;eax=buf2d_data
  121.                 rep movsb ;ª®¯¨à㥬 ¡¨âë ¨§®¡à ¦¥­¨ï ¢ ¡ãä¥à
  122.                 jmp .end_create
  123.         @@:
  124.                 stdcall buf_clear,edi,buf2d_color ;®ç¨á⪠ ¡ãä¥à  ä®­®¢ë¬ 梥⮬
  125.                 jmp .end_create
  126.         .error:
  127.                 stdcall print_err,sz_buf2d_create_f_img,txt_err_size_0
  128.         .end_create:
  129.         popad
  130.         ret
  131. endp
  132.  
  133. ;äã­ªæ¨ï ¤«ï ®¡à¥§ ­¨ï ¡ãä¥à®¢ 8 ¨ 24 ¡¨â­ëå, ¯® § ¤ ­®¬ã 梥âã.
  134. ;¯ à ¬¥âà opt § ¤ ¥âáï ª®¬¡¨­ æ¨¥© ª®­áâ ­â:
  135. ; BUF2D_OPT_CROP_TOP - ®¡à¥§ª  ᢥàåã
  136. ; BUF2D_OPT_CROP_LEFT - ®¡à¥§ª  á«¥¢ 
  137. ; BUF2D_OPT_CROP_BOTTOM - ®¡à¥§ª  á­¨§ã
  138. ; BUF2D_OPT_CROP_RIGHT - ®¡à¥§ª  á¯à ¢ 
  139. align 4
  140. proc buf_crop_color, buf_struc:dword, color:dword, opt:dword
  141. locals
  142.         crop_r dd ?
  143. endl
  144.         pushad
  145.         mov edi,dword[buf_struc]
  146.         cmp buf2d_bits,24
  147.         jne .24end_f
  148.  
  149.         bt dword[opt],BUF2D_BIT_OPT_CROP_BOTTOM
  150.         jae .24no_crop_bottom
  151.                 mov eax,dword[color]
  152.                 mov edx,eax ;ax = colors - r,g
  153.                 shr edx,16 ;dl = color - b
  154.                 mov ecx,buf2d_h
  155.                 cmp ecx,1
  156.                 jle .24no_crop_bottom ;¯à®¢¥à塞 ­  á«ãç © ¥á«¨ ¢ëá®â  ¡ãä¥à  1 ¯¨ªá¥«ì
  157.                 mov ebx,buf2d_w
  158.                 imul ecx,ebx
  159.                 lea esi,[ecx+ecx*2] ;esi=3*ecx
  160.                 add esi,buf2d_data
  161.                 cld
  162.                 @@:
  163.                         sub esi,3
  164.                         cmp word[esi],ax
  165.                         jne @f
  166.                         cmp byte[esi+2],dl
  167.                         jne @f
  168.                         loop @b
  169.                 @@:
  170.                 lea ebx,[ebx+ebx*2]
  171.                 xor edx,edx
  172.                 mov eax,buf2d_h
  173.                 imul eax,ebx
  174.                 add eax,buf2d_data ;eax - 㪠§ â¥«ì ­  ª®­¥æ ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  175.                 @@:
  176.                         add esi,ebx
  177.                         cmp esi,eax
  178.                         jge @f
  179.                         inc edx ;¢ëç¨á«ï¥¬ ç¨á«® ¯®«­ëå áâப ¤«ï ®¡à¥§ ­¨ï
  180.                         loop @b
  181.                 @@:
  182.                 cmp edx,0
  183.                 je .24no_crop_bottom
  184.                         cmp edx,buf2d_h
  185.                         jge .24no_crop_bottom ;çâ®-¡ë ­¥ ¯®«ãç¨âì ¯ãá⮩ ¡ãä¥à
  186.                         sub buf2d_h,edx ;㬥­ìè ¥¬ ¢ëá®âã ¡ãä¥à 
  187.                         mov ecx,buf2d_h
  188.                         imul ecx,ebx ;ecx = ­®¢ë© à §¬¥à ¨§®¡à ¦¥­¨ï
  189.                         invoke mem.realloc,buf2d_data,ecx
  190.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  191.         .24no_crop_bottom:
  192.  
  193.         bt dword[opt],BUF2D_BIT_OPT_CROP_TOP
  194.         jae .24no_crop_top
  195.                 mov eax,dword[color]
  196.                 mov edx,eax ;ax = colors - r,g
  197.                 shr edx,16 ;dl = color - b
  198.                 mov esi,buf2d_data
  199.                 mov ecx,buf2d_h
  200.                 cmp ecx,1
  201.                 jle .24no_crop_top ;¯à®¢¥à塞 ­  á«ãç © ¥á«¨ ¢ëá®â  ¡ãä¥à  1 ¯¨ªá¥«ì
  202.                 dec ecx ;¯à¨ ®¡à¥§ ­¨¨ ¤®«¦­  ®áâ âìáï ¬¨­¨¬ã¬ 1-­  áâப  ¯¨ªá¥«¥©
  203.                 mov ebx,buf2d_w
  204.                 imul ecx,ebx
  205.                 cld
  206.                 @@:
  207.                         cmp word[esi],ax
  208.                         jne @f
  209.                         cmp byte[esi+2],dl
  210.                         jne @f
  211.                         add esi,3
  212.                         loop @b
  213.                 @@:
  214.                 lea ebx,[ebx+ebx*2]
  215.                 xor edx,edx
  216.                 @@:
  217.                         sub esi,ebx
  218.                         cmp esi,buf2d_data
  219.                         jl @f
  220.                         inc edx ;¢ëç¨á«ï¥¬ ç¨á«® ¯®«­ëå áâப ¤«ï ®¡à¥§ ­¨ï
  221.                         loop @b
  222.                 @@:
  223.                 cmp edx,0
  224.                 je .24no_crop_top
  225.                         xor eax,eax
  226.                         sub eax,edx
  227.                         mov ebx,buf2d_h
  228.                         sub ebx,edx
  229.                         stdcall buf_offset_h, edi, eax, edx, ebx ;ᤢ¨£ ¥¬ ¨§®¡à ¦¥­¨¥ ¢ ¡ãä¥à¥ ¢¢¥àå (eax<0)
  230.                         sub buf2d_h,edx ;㬥­ìè ¥¬ ¢ëá®âã ¡ãä¥à 
  231.                         mov ecx,buf2d_h
  232.                         add buf2d_t,dx ;ᤢ¨£ ¥¬ ®âáâ㯠¢­¨§, ­  ç¨á«® ®¡à¥§ ­­ëå áâப
  233.                         mov ebx,buf2d_w
  234.                         imul ecx,ebx
  235.                         lea ecx,[ecx+ecx*2]
  236.                         invoke mem.realloc,buf2d_data,ecx
  237.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  238.         .24no_crop_top:
  239.  
  240.         bt dword[opt],BUF2D_BIT_OPT_CROP_RIGHT
  241.         jae .24no_crop_right
  242.                 mov eax,dword[color]
  243.                 mov edx,eax ;ax = colors - r,g
  244.                 shr edx,16 ;dl = color - b
  245.                 mov ebx,buf2d_w
  246.                 cmp ebx,1
  247.                 jle .24no_crop_right ;­  á«ãç © ¥á«¨ è¨à¨­  ¡ãä¥à  1 ¯¨ªá¥«ì
  248.                 lea ebx,[ebx+ebx*2]
  249.                 mov esi,ebx
  250.                 imul esi,buf2d_h
  251.                 add esi,buf2d_data ;esi - 㪠§ â¥«ì ­  ª®­¥æ ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  252.                 mov dword[crop_r],0
  253.                 cld
  254.                 .24found_beg_right:
  255.                 sub esi,3 ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢«¥¢®
  256.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  257.                 @@:
  258.                         cmp word[esi],ax
  259.                         jne .24found_right
  260.                         cmp byte[esi+2],dl
  261.                         jne .24found_right
  262.                         sub esi,ebx ;¯à룠¥¬ ­  ¢¥àå­îî áâபã
  263.                         loop @b
  264.                 inc dword[crop_r]
  265.  
  266.                 mov ecx,buf2d_w
  267.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  268.                 cmp dword[crop_r],ecx
  269.                 jge .24found_right
  270.  
  271.                 sub esi,3 ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢«¥¢®
  272.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  273.                 @@:
  274.                         add esi,ebx ;¯à룠¥¬ ­  ­¨¦­îî áâபã
  275.                         cmp word[esi],ax
  276.                         jne .24found_right
  277.                         cmp byte[esi+2],dl
  278.                         jne .24found_right
  279.                         loop @b
  280.                 inc dword[crop_r]
  281.  
  282.                 mov ecx,buf2d_w
  283.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  284.                 cmp dword[crop_r],ecx
  285.                 jl .24found_beg_right
  286.  
  287.                 .24found_right:
  288.                 cmp dword[crop_r],0
  289.                 je .24no_crop_right
  290.                         mov ecx,buf2d_w
  291.                         sub ecx,dword[crop_r]
  292.                         stdcall img_rgb_crop_r, buf2d_data, buf2d_w, ecx, buf2d_h ;®¡à¥§ ¥¬ ¡ãä¥à, ¯® ­®¢®¬ã à §¬¥àã
  293.                         mov buf2d_w,ecx ;áâ ¢¨¬ ­®¢ãî è¨à¨­ã ¤«ï ¡ãä¥à 
  294.                         mov ebx,buf2d_h
  295.                         imul ecx,ebx
  296.                         lea ecx,[ecx+ecx*2]
  297.                         invoke mem.realloc,buf2d_data,ecx
  298.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  299.         .24no_crop_right:
  300.  
  301.         bt dword[opt],BUF2D_BIT_OPT_CROP_LEFT
  302.         jae .24no_crop_left
  303.                 mov eax,dword[color]
  304.                 mov edx,eax ;ax = colors - r,g
  305.                 shr edx,16 ;dl = color - b
  306.                 mov ebx,buf2d_w
  307.                 cmp ebx,1
  308.                 jle .24no_crop_left ;­  á«ãç © ¥á«¨ è¨à¨­  ¡ãä¥à  1 ¯¨ªá¥«ì
  309.                 lea ebx,[ebx+ebx*2]
  310.                 mov esi,buf2d_data ;esi - 㪠§ â¥«ì ­  ­ ç®«® ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  311.                 mov dword[crop_r],0
  312.                 cld
  313.                 .24found_beg_left:
  314.  
  315.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  316.                 @@:
  317.                         cmp word[esi],ax
  318.                         jne .24found_left
  319.                         cmp byte[esi+2],dl
  320.                         jne .24found_left
  321.                         add esi,ebx ;¯à룠¥¬ ­  ­¨¦­îî áâபã
  322.                         loop @b
  323.                 inc dword[crop_r]
  324.                 add esi,3 ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢¯à ¢®
  325.  
  326.                 mov ecx,buf2d_w
  327.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  328.                 cmp dword[crop_r],ecx
  329.                 jge .24found_left
  330.  
  331.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  332.                 @@:
  333.                         sub esi,ebx ;¯à룠¥¬ ­  ¢¥àå­îî áâபã
  334.                         cmp word[esi],ax
  335.                         jne .24found_left
  336.                         cmp byte[esi+2],dl
  337.                         jne .24found_left
  338.                         loop @b
  339.                 inc dword[crop_r]
  340.                 add esi,3 ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢¯à ¢®
  341.  
  342.                 mov ecx,buf2d_w
  343.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  344.                 cmp dword[crop_r],ecx
  345.                 jl .24found_beg_left
  346.  
  347.                 .24found_left:
  348.                 cmp dword[crop_r],0
  349.                 je .24no_crop_left
  350.                         mov ecx,buf2d_w
  351.                         sub ecx,dword[crop_r]
  352.                         stdcall img_rgb_crop_l, buf2d_data, buf2d_w, ecx, buf2d_h ;®¡à¥§ ¥¬ ¡ãä¥à, ¯® ­®¢®¬ã à §¬¥àã
  353.                         mov buf2d_w,ecx ;áâ ¢¨¬ ­®¢ãî è¨à¨­ã ¤«ï ¡ãä¥à 
  354.                         mov ebx,buf2d_h
  355.                         imul ecx,ebx
  356.                         lea ecx,[ecx+ecx*2]
  357.                         invoke mem.realloc,buf2d_data,ecx
  358.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  359.                         mov eax,dword[crop_r]
  360.                         add buf2d_l,ax
  361.         .24no_crop_left:
  362.  
  363.         .24end_f:
  364.  
  365.  
  366.         cmp buf2d_bits,8
  367.         jne .8end_f
  368.  
  369.         bt dword[opt],BUF2D_BIT_OPT_CROP_BOTTOM
  370.         jae .8no_crop_bottom
  371.                 mov eax,dword[color]
  372.                 mov esi,buf2d_data
  373.                 mov ecx,buf2d_h
  374.                 cmp ecx,1
  375.                 jle .8no_crop_bottom ;¯à®¢¥à塞 ­  á«ãç © ¥á«¨ ¢ëá®â  ¡ãä¥à  1 ¯¨ªá¥«ì
  376.                 mov ebx,buf2d_w
  377.                 imul ecx,ebx
  378.                 mov esi,ecx
  379.                 add esi,buf2d_data
  380.                 cld
  381.                 @@:
  382.                         dec esi
  383.                         cmp byte[esi],al
  384.                         jne @f
  385.                         loop @b
  386.                 @@:
  387.                 xor edx,edx
  388.                 mov eax,buf2d_h
  389.                 imul eax,ebx
  390.                 add eax,buf2d_data ;eax - 㪠§ â¥«ì ­  ª®­¥æ ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  391.                 @@:
  392.                         add esi,ebx
  393.                         cmp esi,eax
  394.                         jge @f
  395.                         inc edx
  396.                         loop @b
  397.                 @@:
  398.                 cmp edx,0
  399.                 je .8no_crop_bottom
  400.                         cmp edx,buf2d_h
  401.                         jge .8no_crop_bottom ;çâ®-¡ë ­¥ ¯®«ãç¨âì ¯ãá⮩ ¡ãä¥à
  402.                         sub buf2d_h,edx ;㬥­ìè ¥¬ ¢ëá®âã ¡ãä¥à 
  403.                         mov ecx,buf2d_h
  404.                         imul ecx,ebx ;ecx = ­®¢ë© à §¬¥à ¨§®¡à ¦¥­¨ï
  405.                         invoke mem.realloc,buf2d_data,ecx
  406.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  407.         .8no_crop_bottom:
  408.  
  409.         bt dword[opt],BUF2D_BIT_OPT_CROP_TOP
  410.         jae .8no_crop_top
  411.                 mov eax,dword[color]
  412.                 mov esi,buf2d_data
  413.                 mov ecx,buf2d_h
  414.                 cmp ecx,1
  415.                 jle .8no_crop_top ;¯à®¢¥à塞 ­  á«ãç © ¥á«¨ ¢ëá®â  ¡ãä¥à  1 ¯¨ªá¥«ì
  416.                 dec ecx ;¯à¨ ®¡à¥§ ­¨¨ ¤®«¦­  ®áâ âìáï ¬¨­¨¬ã¬ 1-­  áâப  ¯¨ªá¥«¥©
  417.                 mov ebx,buf2d_w
  418.                 imul ecx,ebx
  419.                 cld
  420.                 @@:
  421.                         cmp byte[esi],al
  422.                         jne @f
  423.                         inc esi
  424.                         loop @b
  425.                 @@:
  426.                 xor edx,edx
  427.                 @@:
  428.                         sub esi,ebx
  429.                         cmp esi,buf2d_data
  430.                         jl @f
  431.                         inc edx
  432.                         loop @b
  433.                 @@:
  434.                 cmp edx,0
  435.                 je .8no_crop_top
  436.                         xor eax,eax
  437.                         sub eax,edx
  438.                         mov ebx,buf2d_h
  439.                         sub ebx,edx
  440.                         stdcall buf_offset_h, edi, eax, edx, ebx
  441.                         mov ecx,buf2d_h
  442.                         sub ecx,edx
  443.                         mov buf2d_h,ecx ;㬥­ìè ¥¬ ¢ëá®âã ¡ãä¥à 
  444.                         add buf2d_t,dx ;ᤢ¨£ ¥¬ ®âáâ㯠¢­¨§, ­  ç¨á«® ®¡à¥§ ­­ëå áâப
  445.                         mov ebx,buf2d_w
  446.                         imul ecx,ebx
  447.                         invoke mem.realloc,buf2d_data,ecx
  448.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  449.         .8no_crop_top:
  450.  
  451.         bt dword[opt],BUF2D_BIT_OPT_CROP_RIGHT
  452.         jae .8no_crop_right
  453.                 mov eax,dword[color]
  454.                 mov ebx,buf2d_w
  455.                 cmp ebx,1
  456.                 jle .8no_crop_right ;­  á«ãç © ¥á«¨ è¨à¨­  ¡ãä¥à  1 ¯¨ªá¥«ì
  457.                 mov esi,ebx
  458.                 imul esi,buf2d_h
  459.                 add esi,buf2d_data ;esi - 㪠§ â¥«ì ­  ª®­¥æ ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  460.                 xor edx,edx
  461.                 cld
  462.  
  463.                 .8found_beg:
  464.                 dec esi ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢«¥¢®
  465.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  466.                 @@:
  467.                         cmp byte[esi],al
  468.                         jne .8found
  469.                         sub esi,ebx ;¯à룠¥¬ ­  ¢¥àå­îî áâபã
  470.                         loop @b
  471.                 inc edx
  472.                 mov ecx,buf2d_w
  473.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  474.                 cmp edx,ecx
  475.                 jge .8found
  476.  
  477.                 dec esi ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢«¥¢®
  478.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  479.                 @@:
  480.                         add esi,ebx ;¯à룠¥¬ ­  ­¨¦­îî áâபã
  481.                         cmp byte[esi],al
  482.                         jne .8found
  483.                         loop @b
  484.                 inc edx
  485.  
  486.                 mov ecx,buf2d_w
  487.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  488.                 cmp edx,ecx
  489.                 jl .8found_beg
  490.  
  491.                 .8found:
  492.                 cmp edx,0
  493.                 je .8no_crop_right
  494.                         mov ecx,buf2d_w
  495.                         sub ecx,edx
  496.                         stdcall img_gray_crop_r, buf2d_data, buf2d_w, ecx, buf2d_h ;®¡à¥§ ¥¬ ¡ãä¥à, ¯® ­®¢®¬ã à §¬¥àã
  497.                         mov buf2d_w,ecx ;áâ ¢¨¬ ­®¢ãî è¨à¨­ã ¤«ï ¡ãä¥à 
  498.                         mov ebx,buf2d_h
  499.                         imul ecx,ebx
  500.                         invoke mem.realloc,buf2d_data,ecx
  501.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  502.         .8no_crop_right:
  503.  
  504.         bt dword[opt],BUF2D_BIT_OPT_CROP_LEFT
  505.         jae .8no_crop_left
  506.                 mov eax,dword[color]
  507.                 mov ebx,buf2d_w
  508.                 cmp ebx,1
  509.                 jle .8no_crop_left ;­  á«ãç © ¥á«¨ è¨à¨­  ¡ãä¥à  1 ¯¨ªá¥«ì
  510.                 mov esi,buf2d_data ;esi - 㪠§ â¥«ì ­  ­ ç®«® ¡ãä¥à  ¨§®¡à ¦¥­¨ï
  511.                 mov edx,0
  512.                 cld
  513.                 .8found_beg_left:
  514.  
  515.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  516.                 @@:
  517.                         cmp word[esi],ax
  518.                         jne .8found_left
  519.                         add esi,ebx ;¯à룠¥¬ ­  ­¨¦­îî áâபã
  520.                         loop @b
  521.                 inc edx
  522.                 inc esi ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢¯à ¢®
  523.  
  524.                 mov ecx,buf2d_w
  525.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  526.                 cmp edx,ecx
  527.                 jge .8found_left
  528.  
  529.                 mov ecx,buf2d_h ;¢®ááâ ­®¢«¥­¨¥ ecx ¤«ï ­®¢®£® 横« 
  530.                 @@:
  531.                         sub esi,ebx ;¯à룠¥¬ ­  ¢¥àå­îî áâபã
  532.                         cmp word[esi],ax
  533.                         jne .8found_left
  534.                         loop @b
  535.                 inc edx
  536.                 inc esi ;¤¢¨£ ¥¬áï ­  1-­ã ª®«®­ªã ¢¯à ¢®
  537.  
  538.                 mov ecx,buf2d_w
  539.                 dec ecx ;1 ª®«®­ª  ­  § ¯ á
  540.                 cmp edx,ecx
  541.                 jl .8found_beg_left
  542.  
  543.                 .8found_left:
  544.                 cmp edx,0
  545.                 je .8no_crop_left
  546.                         mov ecx,buf2d_w
  547.                         sub ecx,edx
  548.                         stdcall img_gray_crop_l, buf2d_data, buf2d_w, ecx, buf2d_h ;®¡à¥§ ¥¬ ¡ãä¥à, ¯® ­®¢®¬ã à §¬¥àã
  549.                         mov buf2d_w,ecx ;áâ ¢¨¬ ­®¢ãî è¨à¨­ã ¤«ï ¡ãä¥à 
  550.                         mov ebx,buf2d_h
  551.                         imul ecx,ebx
  552.                         invoke mem.realloc,buf2d_data,ecx
  553.                         mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  554.                         mov eax,edx
  555.                         add buf2d_l,ax
  556.         .8no_crop_left:
  557.  
  558.         .8end_f:
  559.  
  560.         popad
  561.         ret
  562. endp
  563.  
  564. ;®¡à¥§ ¥¬ 梥⭮¥ ¨§®¡à ¦¥­¨¥ á ¯à ¢®© áâ®à®­ë
  565. ;input:
  566. ;data_rgb - pointer to rgb data
  567. ;size_w_old - width img in pixels
  568. ;size_w_new - new width img in pixels
  569. ;size_h - height img in pixels
  570. align 4
  571. proc img_rgb_crop_r, data_rgb:dword, size_w_old:dword, size_w_new:dword, size_h:dword
  572.         pushad
  573.         mov eax, dword[size_w_old]
  574.         lea eax, dword[eax+eax*2] ;eax = width(old) * 3(rgb)
  575.         mov ebx, dword[size_w_new]
  576.         lea ebx, dword[ebx+ebx*2] ;ebx = width(new) * 3(rgb)
  577.         mov edx, dword[size_h]
  578.         mov edi, dword[data_rgb] ;edi - ¯®«ã砥⠤ ­­ë¥
  579.         mov esi, edi
  580.         add edi, ebx
  581.         add esi, eax
  582.         cld
  583.         @@:
  584.                 dec edx ;㬥­ìè ¥¬ áç¥â稪 ®áâ ¢è¨åáï áâப ­  1
  585.                 cmp edx,0
  586.                 jle @f
  587.                 mov ecx, ebx
  588.                 rep movsb ;¯¥à¥­®á (ª®¯¨à®¢ ­¨¥) áâப¨ ¯¨ªá¥«¥©
  589.                 add esi,eax ;¯¥à¥å®¤ ­  ­®¢ãî áâà®çªã ¨§®¡à ¦¥­¨ï
  590.                 sub esi,ebx
  591.                 jmp @b
  592.         @@:
  593.         popad
  594.         ret
  595. endp
  596.  
  597. ;®¡à¥§ ¥¬ á¥à®¥ ¨§®¡à ¦¥­¨¥ á ¯à ¢®© áâ®à®­ë
  598. ;input:
  599. ;data_gray - pointer to gray data
  600. ;size_w_old - width img in pixels
  601. ;size_w_new - new width img in pixels
  602. ;size_h - height img in pixels
  603. align 4
  604. proc img_gray_crop_r, data_gray:dword, size_w_old:dword, size_w_new:dword, size_h:dword
  605.         pushad
  606.         mov eax, dword[size_w_old]
  607.         mov ebx, dword[size_w_new]
  608.         mov edx, dword[size_h]
  609.         mov edi, dword[data_gray] ;edi - ¯®«ã砥⠤ ­­ë¥
  610.         mov esi, edi
  611.         add edi, ebx
  612.         add esi, eax
  613.         cld
  614.         @@:
  615.                 dec edx ;㬥­ìè ¥¬ áç¥â稪 ®áâ ¢è¨åáï áâப ­  1
  616.                 cmp edx,0
  617.                 jle @f
  618.                 mov ecx, ebx
  619.                 rep movsb ;¯¥à¥­®á (ª®¯¨à®¢ ­¨¥) áâப¨ ¯¨ªá¥«¥©
  620.                 add esi,eax ;¯¥à¥å®¤ ­  ­®¢ãî áâà®çªã ¨§®¡à ¦¥­¨ï
  621.                 sub esi,ebx
  622.                 jmp @b
  623.         @@:
  624.         popad
  625.         ret
  626. endp
  627.  
  628. ;®¡à¥§ ¥¬ 梥⭮¥ ¨§®¡à ¦¥­¨¥ á «¥¢®© áâ®à®­ë
  629. ;input:
  630. ;data_rgb - pointer to rgb data
  631. ;size_w_old - width img in pixels
  632. ;size_w_new - new width img in pixels
  633. ;size_h - height img in pixels
  634. align 4
  635. proc img_rgb_crop_l, data_rgb:dword, size_w_old:dword, size_w_new:dword, size_h:dword
  636.         pushad
  637.         mov edi,dword[data_rgb]
  638.         mov esi,edi
  639.         mov eax,dword[size_w_old]
  640.         mov ebx,dword[size_w_new]
  641.         cmp eax,ebx
  642.         jle .end_f ;áâ àë© à §¬¥à ¨§®¡à ¦¥­¨ï ­¥ ¬®¦¥â ¡ëâì ¬¥­ìè¥ ­®¢®£® (¯à¨ ãá«®¢¨¨ ®¡à¥§ ­¨ï ª à⨭ª¨)
  643.                 lea eax,[eax+eax*2]
  644.                 lea ebx,[ebx+ebx*2]
  645.                 sub eax,ebx
  646.                 mov edx,dword[size_h] ;¢ëá®â  ¨§®¡à ¦¥­¨ï
  647.                 cld
  648.                 @@:
  649.                         add esi,eax
  650.                         mov ecx,ebx
  651.                         rep movsb
  652.                         dec edx
  653.                         cmp edx,0
  654.                         jg @b
  655.         .end_f:
  656.         popad
  657.         ret
  658. endp
  659.  
  660. ;®¡à¥§ ¥¬ á¥à®¥ ¨§®¡à ¦¥­¨¥ á «¥¢®© áâ®à®­ë
  661. ;input:
  662. ;data_gray - pointer to gray data
  663. ;size_w_old - width img in pixels
  664. ;size_w_new - new width img in pixels
  665. ;size_h - height img in pixels
  666. align 4
  667. proc img_gray_crop_l, data_gray:dword, size_w_old:dword, size_w_new:dword, size_h:dword
  668.         pushad
  669.         mov edi,dword[data_gray]
  670.         mov esi,edi
  671.         mov eax,dword[size_w_old]
  672.         mov ebx,dword[size_w_new]
  673.         cmp eax,ebx
  674.         jle .end_f ;áâ àë© à §¬¥à ¨§®¡à ¦¥­¨ï ­¥ ¬®¦¥â ¡ëâì ¬¥­ìè¥ ­®¢®£® (¯à¨ ãá«®¢¨¨ ®¡à¥§ ­¨ï ª à⨭ª¨)
  675.                 sub eax,ebx
  676.                 mov edx,dword[size_h] ;¢ëá®â  ¨§®¡à ¦¥­¨ï
  677.                 cld
  678.                 @@:
  679.                         add esi,eax
  680.                         mov ecx,ebx
  681.                         rep movsb
  682.                         dec edx
  683.                         cmp edx,0
  684.                         jg @b
  685.         .end_f:
  686.         popad
  687.         ret
  688. endp
  689.  
  690. ;hoffs - ª®««¨ç¥á⢮ ¯¨ªá¥«¥© ­  ª®âàë¥ ¯®¤­¨¬ ¥âáï/®¯ã᪠¥âáï ¨§®¡à ¦¥­¨¥
  691. ;img_t - ¢ëá®â , á ª®â®à®© ­ ç¨­ ¥âáï ¤¢¨£ îé ïáï ç áâì ¨§®¡à ¦¥­¨ï
  692. align 4
  693. proc buf_offset_h, buf_struc:dword, hoffs:dword, img_t:dword, img_h:dword ;ᤢ¨£ ¥â ¨§®¡à ¦¥­¨¥ ¯® ¢ëá®â¥
  694.         pushad
  695.         mov edi,dword[buf_struc]
  696.         cmp buf2d_bits,24
  697.         jne .end_move_24
  698.  
  699.         mov eax,[hoffs]
  700.         cmp eax,0
  701.         je .end_move_24
  702.                 mov ebx,buf2d_w
  703.                 mov edx,dword[img_t]
  704.                         mov ecx,dword[img_h] ;ecx - ¢ëá®â  ᤢ¨£ ¥¬ëå ¤ ­­ëå
  705.                         cmp ecx,buf2d_h
  706.                         jge .end_f ;®è¨¡®ç­®¥ ãá«®¢¨¥, ¢ëá®â  ¨§®¡à ¦¥­¨ï ¬¥­ìè¥ ç¥¬ ¢ëá®â  ᤢ¨£ ¥¬®£® ¨§®¡à ¦¥­¨ï
  707.                         imul ecx,ebx ;ecx - ª®««¨ç¥á⢮ ¯¨ªá¥«¥© ¢ ᤢ¨£ ¥¬ëå ¤ ­­ëå
  708.                         lea ecx,[ecx+ecx*2]
  709.                 imul ebx,edx
  710.                 lea ebx,[ebx+ebx*2]
  711.                 mov esi,buf2d_data
  712.                 add esi,ebx
  713.  
  714.                 add edx,eax ;edx = img_t+hoffs (hoffs<0)
  715.                 mov ebx,buf2d_w
  716.                 imul ebx,edx
  717.                 lea ebx,[ebx+ebx*2]
  718.                 mov edi,buf2d_data ;¯®§¨æ¨ï, ªã¤  ¡ã¤¥â ¤¢¨£ âìáï ¨§®¡à ¦¥­¨¥
  719.                 add edi,ebx
  720.  
  721.                 cmp eax,0
  722.                 jg .move_down_24
  723.                         ;¤¢¨£ ¥¬ ¨§®¡à ¦¥­¨¥ ¢¢¥àå
  724.                         cld
  725.                         rep movsb
  726.                         jmp .end_f
  727.                 .move_down_24:
  728.                         ;¤¢¨£ ¥¬ ¨§®¡à ¦¥­¨¥ ¢­¨§
  729.                         add esi,ecx
  730.                         dec esi
  731.                         add edi,ecx
  732.                         dec edi
  733.                         std
  734.                         rep movsb
  735.                         jmp .end_f
  736.         .end_move_24:
  737.  
  738. ;stdcall print_err,sz_buf2d_offset_h,txt_err_n24b
  739.  
  740.         cmp buf2d_bits,8
  741.         jne .end_move_8
  742.  
  743.         mov eax,[hoffs]
  744.         cmp eax,0
  745.         je .end_move_8
  746.                 ;¤¢¨£ ¥¬ ¨§®¡à ¦¥­¨¥ ¢¢¥àå
  747.                 mov ebx,buf2d_w
  748.                 mov edx,dword[img_t]
  749.                         mov ecx,dword[img_h] ;ecx - ¢ëá®â  ᤢ¨£ ¥¬ëå ¤ ­­ëå
  750.                         cmp ecx,buf2d_h
  751.                         jge .end_f ;®è¨¡®ç­®¥ ãá«®¢¨¥, ¢ëá®â  ¨§®¡à ¦¥­¨ï ¬¥­ìè¥ ç¥¬ ¢ëá®â  ᤢ¨£ ¥¬®£® ¨§®¡à ¦¥­¨ï
  752.                         imul ecx,ebx ;ecx - ª®««¨ç¥á⢮ ¯¨ªá¥«¥© ¢ ᤢ¨£ ¥¬ëå ¤ ­­ëå
  753.                 imul ebx,edx
  754.                 mov esi,buf2d_data
  755.                 add esi,ebx
  756.  
  757.                 add edx,eax ;edx = img_t+hoffs (hoffs<0)
  758.                 mov ebx,buf2d_w
  759.                 imul ebx,edx
  760.                 mov edi,buf2d_data ;¯®§¨æ¨ï, ªã¤  ¡ã¤¥â ¤¢¨£ âìáï ¨§®¡à ¦¥­¨¥
  761.                 add edi,ebx
  762.  
  763.                 cmp eax,0
  764.                 jg .move_down_8
  765.                         cld
  766.                         rep movsb
  767.                         jmp .end_f
  768.                 .move_down_8:
  769.                         ;¤¢¨£ ¥¬ ¨§®¡à ¦¥­¨¥ ¢­¨§
  770.                         add esi,ecx
  771.                         dec esi
  772.                         add edi,ecx
  773.                         dec edi
  774.                         std
  775.                         rep movsb
  776.                         jmp .end_f
  777.         .end_move_8:
  778.  
  779.         .end_f:
  780.         popad
  781.         ret
  782. endp
  783.  
  784. align 4
  785. proc buf_delete, buf_struc:dword
  786.         push eax edi
  787.         mov edi,dword[buf_struc]
  788.         invoke mem.free,buf2d_data
  789.         pop edi eax
  790.         ret
  791. endp
  792.  
  793. ;input:
  794. ; new_w - ­®¢ ï è¨à¨­  (¥á«¨ 0 â® ­¥ ¬¥­ï¥âáï)
  795. ; new_h - ­®¢ ï ¢ëá®â  (¥á«¨ 0 â® ­¥ ¬¥­ï¥âáï)
  796. ; options - ¯ à ¬¥âàë ¨§¬¥­¥­¨ï ¡ãä¥à  (1 - ¨§¬¥­ïâì à §¬¥à ¡ãä¥à ,
  797. ;    2 - ¨§¬¥­ïâì ¨§®¡à ¦¥­¨¥ ¢ ¡ãä¥à¥, 3 - ¨§¬¥­ïâì ¡ãä¥à ¨ ¨§®¡à ¦¥­¨¥)
  798. align 4
  799. proc buf_resize, buf_struc:dword, new_w:dword, new_h:dword, options:dword
  800.         pushad
  801.         mov edi,dword[buf_struc]
  802.         cmp buf2d_bits,8
  803.         jne .8bit
  804.                 bt dword[options],1 ;ᦠ⨥ ¨§®¡à.
  805.                 jnc @f
  806.                         ;...
  807.                 @@:
  808.                 bt dword[options],0 ;¨§¬¥­. ¡ãä¥à
  809.                 jnc .end_f
  810.                         ;...
  811.                 jmp .end_f
  812.         .8bit:
  813.         cmp buf2d_bits,24
  814.         jne .24bit
  815.                 bt dword[options],1 ;ᦠ⨥ ¨§®¡à.
  816.                 jnc .24_end_r
  817.                         mov eax,dword[new_w]
  818.                         cmp eax,1
  819.                         jl @f
  820.                         cmp eax,buf2d_w
  821.                         jge @f
  822.                                 ;ᦠ⨥ ¯® è¨à¨­¥
  823.                                 stdcall img_rgb24_wresize, buf2d_data,buf2d_w,buf2d_h,eax
  824.                                 jmp .24_r_h
  825.                         @@:
  826.                         mov eax,buf2d_w
  827.                         .24_r_h: ;eax - è¨à¨­  ¡ãä¥à  ¨«¨ è¨à¨­  ᦠ⮣® ¨§®¡à ¦¥­¨ï
  828.                         mov ebx,dword[new_h]
  829.                         cmp ebx,1
  830.                         jl @f
  831.                         cmp ebx,buf2d_h
  832.                         jge @f
  833.                                 ;ᦠ⨥ ¯® ¢ëá®â¥
  834.                                 stdcall img_rgb24_hresize, buf2d_data,eax,buf2d_h,ebx
  835.                         @@:
  836.                 .24_end_r:
  837.                 bt dword[options],0 ;¨§¬¥­. ¡ãä¥à
  838.                 jnc .end_f
  839.                 mov eax,dword[new_w]
  840.                 cmp eax,1
  841.                 jl @f
  842.                         mov buf2d_w,eax
  843.                 @@:
  844.                 mov ecx,buf2d_w
  845.                 mov eax,dword[new_h]
  846.                 cmp eax,1
  847.                 jl @f
  848.                         mov buf2d_h,eax
  849.                 @@:
  850.                 mov ebx,buf2d_h
  851.                 imul ecx,ebx
  852.                 lea ecx,[ecx+ecx*2] ; 24 bit = 3
  853.                 invoke mem.realloc,buf2d_data,ecx ;¨§¬¥­ï¥¬ ¯ ¬ïâì § ­¨¬ ¥¬ãî ¡ãä¥à®¬
  854.                 mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  855.         .24bit:
  856.         .end_f:
  857.         popad
  858.         ret
  859. endp
  860.  
  861. align 4
  862. rot_table: ;â ¡«¨æ  ¤«ï 㪠§ ­¨ï ­  ¯®¤ä㭪樨 ¤«ï ¯®¢®à®â®¢
  863.         dd buf_rotate.8b90,buf_rotate.24b90,buf_rotate.32b90,\
  864.         buf_rotate.8b180,buf_rotate.24b180,buf_rotate.32b180
  865.  
  866. ;¯®¢®à®â ¨§®¡à ¦¥­¨ï ­  90 ¨«¨ 180 £à ¤ãᮢ
  867. align 4
  868. proc buf_rotate, buf_struc:dword, angle:dword
  869. locals
  870.         n_data dd ?
  871.         dec_h dd ? ;ç¨á«® ¡ ©â, ¤«ï 㬥­ì襭¨ï ª®®à¤¨­ âë y
  872. endl
  873.         pushad
  874.         mov edi,[buf_struc]
  875.         mov ebx,buf2d_w
  876.         mov ecx,buf2d_h
  877.  
  878.         lea eax,[rot_table]
  879.         cmp dword[angle],90 ;¯à®¢¥àª  㣫  ¯®¢®à®â 
  880.         je .beg_0
  881.         cmp dword[angle],180
  882.         jne @f
  883.                 add eax,12
  884.                 jmp .beg_0
  885.         @@:
  886.         jmp .end_f
  887.         .beg_0: ;¯à®¢¥àª  ¡¨â­®á⨠¡ãä¥à 
  888.         cmp buf2d_bits,8
  889.         jne @f
  890.                 jmp dword[eax]
  891.         @@:
  892.         cmp buf2d_bits,24
  893.         jne @f
  894.                 add eax,4
  895.                 jmp dword[eax]
  896.         @@:
  897.         cmp buf2d_bits,32
  898.         jne @f
  899.                 add eax,8
  900.                 jmp dword[eax]
  901.         @@:
  902.         jmp .end_f
  903.  
  904.         .8b90: ;¯®¢®à®â 8 ¡¨â­®£® ¡ãä¥à  ­  90 £à ¤ãᮢ
  905.                 mov edx,ecx ;edx - buf_h
  906.                 imul ecx,ebx
  907.                 invoke mem.alloc,ecx ;¢ë¤¥«ï¥¬ ¢à¥¬¥­­ãî ¯ ¬ïâì
  908.                 cmp eax,0
  909.                 je .end_f
  910.                 mov [n_data],eax
  911.                 mov [dec_h],ecx
  912.                 inc dword[dec_h]
  913.  
  914.                 ;copy buf --> mem
  915.                 mov edi,[buf_struc]
  916.                 mov esi,buf2d_data
  917.                 mov edi,eax ;[n_data]
  918.                 dec edx ;ª®à¥ªâ¨à㥬 edx ­  1 ¡ ©â, ¤«ï ª®¬¯¥­á æ¨¨ ᤢ¨£  ¢ movsb
  919.                 add edi,edx
  920.                 xor eax,eax
  921.                 cld
  922.                 .cycle_0:
  923.                         movsb
  924.                         add edi,edx
  925.                         inc eax
  926.                         cmp eax,ebx
  927.                         jl @f
  928.                                 xor eax,eax
  929.                                 sub edi,[dec_h]
  930.                         @@:
  931.                         loop .cycle_0
  932.  
  933.                 ;change buf_w <---> buf_h
  934.                 mov esi,[n_data]
  935.                 mov edi,[buf_struc]
  936.                 mov edi,buf2d_data
  937.                 mov ecx,ebx
  938.                 inc edx ;¨á¯à ¢«ï¥¬ ᪮४â¨à®¢ ­­ë© edx
  939.                 imul ecx,edx
  940.                 ;copy buf <-- mem
  941.                 ;cld
  942.                 rep movsb
  943.                 invoke mem.free,[n_data]
  944.                 jmp .change_w_h
  945.         .24b90: ;¯®¢®à®â 24 ¡¨â­®£® ¡ãä¥à  ­  90 £à ¤ãᮢ
  946.                 mov esi,ecx
  947.                 imul esi,ebx
  948.                 lea ecx,[ecx+ecx*2]
  949.                 mov edx,ecx ;edx - buf_h * 3
  950.                 imul ecx,ebx
  951.                 invoke mem.alloc,ecx ;¢ë¤¥«ï¥¬ ¢à¥¬¥­­ãî ¯ ¬ïâì
  952.                 cmp eax,0
  953.                 je .end_f
  954.                 mov [n_data],eax
  955.                 mov [dec_h],ecx
  956.                 add dword[dec_h],3
  957.  
  958.                 ;copy buf --> mem
  959.                
  960.                 mov edi,[buf_struc]
  961.                 mov ecx,esi
  962.                 mov esi,buf2d_data
  963.                 mov edi,eax ;[n_data]
  964.                 sub edx,3 ;ª®à¥ªâ¨à㥬 edx ­  3 ¡ ©â , ¤«ï ª®¬¯¥­á æ¨¨ ᤢ¨£ 
  965.                 add edi,edx
  966.                 xor eax,eax
  967.                 cld
  968.                 .cycle_1:
  969.                         movsw
  970.                         movsb
  971.                         add edi,edx
  972.                         inc eax
  973.                         cmp eax,ebx
  974.                         jl @f
  975.                                 xor eax,eax
  976.                                 sub edi,[dec_h]
  977.                         @@:
  978.                         loop .cycle_1
  979.  
  980.                 ;copy buf <-- mem
  981.                 mov esi,[n_data]
  982.                 mov edi,[buf_struc]
  983.                 mov edi,buf2d_data
  984.                 mov ecx,ebx
  985.                 add edx,3 ;¨á¯à ¢«ï¥¬ ᪮४â¨à®¢ ­­ë© edx
  986.                 imul ecx,edx
  987.                 ;cld
  988.                 rep movsb
  989.                 invoke mem.free,[n_data]
  990.                 jmp .change_w_h
  991.         .32b90: ;¯®¢®à®â 32 ¡¨â­®£® ¡ãä¥à  ­  90 £à ¤ãᮢ
  992.                 shl ecx,2
  993.                 mov edx,ecx ;edx - buf_h * 4
  994.                 imul ecx,ebx
  995.                 invoke mem.alloc,ecx ;¢ë¤¥«ï¥¬ ¢à¥¬¥­­ãî ¯ ¬ïâì
  996.                 cmp eax,0
  997.                 je .end_f
  998.                 mov [n_data],eax
  999.                 mov [dec_h],ecx
  1000.                 add dword[dec_h],4
  1001.  
  1002.                 ;copy buf --> mem
  1003.                 mov edi,[buf_struc]
  1004.                 shr ecx,2
  1005.                 mov esi,buf2d_data
  1006.                 mov edi,eax ;[n_data]
  1007.                 sub edx,4 ;ª®à¥ªâ¨à㥬 edx ­  4 ¡ ©â , ¤«ï ª®¬¯¥­á æ¨¨ ᤢ¨£  ¢ movsd
  1008.                 add edi,edx
  1009.                 xor eax,eax
  1010.                 cld
  1011.                 .cycle_2:
  1012.                         movsd
  1013.                         add edi,edx
  1014.                         inc eax
  1015.                         cmp eax,ebx
  1016.                         jl @f
  1017.                                 xor eax,eax
  1018.                                 sub edi,[dec_h]
  1019.                         @@:
  1020.                         loop .cycle_2
  1021.  
  1022.                 ;copy buf <-- mem
  1023.                 mov esi,[n_data]
  1024.                 mov edi,[buf_struc]
  1025.                 mov edi,buf2d_data
  1026.                 mov ecx,ebx
  1027.                 add edx,4 ;¨á¯à ¢«ï¥¬ ᪮४â¨à®¢ ­­ë© edx
  1028.                 imul ecx,edx
  1029.                 shr ecx,2
  1030.                 ;cld
  1031.                 rep movsd
  1032.                 invoke mem.free,[n_data]
  1033.                 ;jmp .change_w_h
  1034.         .change_w_h: ;change buf_w <---> buf_h
  1035.                 mov edi,[buf_struc]
  1036.                 mov eax,buf2d_w
  1037.                 mov ebx,buf2d_h
  1038.                 mov buf2d_h,eax
  1039.                 mov buf2d_w,ebx
  1040.                 jmp .end_f
  1041.         .8b180: ;¯®¢®à®â 8 ¡¨â­®£® ¡ãä¥à  ­  180 £à ¤ãᮢ
  1042.                 mov edi,buf2d_data
  1043.                 mov esi,edi
  1044.                 imul ecx,ebx
  1045.                 add esi,ecx
  1046.                 dec esi
  1047.                 shr ecx,1 ;ecx - ç¨á«® ¯¨ªá¥«¥© ¡ãä¥à  : 2
  1048.                 std
  1049.                 @@:
  1050.                         lodsb
  1051.                         mov ah,byte[edi]
  1052.                         mov byte[esi+1],ah
  1053.                         mov byte[edi],al
  1054.                         inc edi
  1055.                         loop @b
  1056.                         jmp .end_f
  1057.         .24b180: ;¯®¢®à®â 24 ¡¨â­®£® ¡ãä¥à  ­  180 £à ¤ãᮢ
  1058.                 mov esi,buf2d_data
  1059.                 mov edi,esi
  1060.                 imul ecx,ebx
  1061.                 mov eax,ecx
  1062.                 lea ecx,[ecx+ecx*2]
  1063.                 add edi,ecx
  1064.                 sub edi,3
  1065.                 shr eax,1
  1066.                 mov ecx,eax ;ecx - ç¨á«® ¯¨ªá¥«¥© ¡ãä¥à  : 2
  1067.                 cld
  1068.                 @@:
  1069.                         lodsw
  1070.                         mov edx,eax
  1071.                         lodsb
  1072.                         mov bx,word[edi]
  1073.                         mov word[esi-3],bx
  1074.                         mov bl,byte[edi+2]
  1075.                         mov byte[esi-1],bl
  1076.                         mov byte[edi+2],al
  1077.                         mov word[edi],dx
  1078.                         sub edi,3
  1079.                         loop @b
  1080.                         jmp .end_f
  1081.         .32b180: ;¯®¢®à®â 32 ¡¨â­®£® ¡ãä¥à  ­  180 £à ¤ãᮢ
  1082.                 mov edi,buf2d_data
  1083.                 mov esi,edi
  1084.                 imul ecx,ebx
  1085.                 shl ecx,2
  1086.                 add esi,ecx
  1087.                 sub esi,4
  1088.                 shr ecx,3 ;ecx - ç¨á«® ¯¨ªá¥«¥© ¡ãä¥à  : 2
  1089.                 std
  1090.                 @@:
  1091.                         lodsd
  1092.                         mov ebx,dword[edi]
  1093.                         mov dword[esi+4],ebx
  1094.                         mov dword[edi],eax
  1095.                         add edi,4
  1096.                         loop @b
  1097.                 ;jmp .end_f
  1098.  
  1099.         .end_f:
  1100.         popad
  1101.         ret
  1102. endp
  1103.  
  1104. align 4
  1105. proc buf_flip_h, buf_struc:dword
  1106. pushad
  1107.         mov edi,[buf_struc]
  1108.         cmp buf2d_bits,24
  1109.         jne .end_24
  1110.                 mov esi,buf2d_data
  1111.                 mov eax,buf2d_w
  1112.                 mov ecx,eax
  1113.                 shr ecx,1
  1114.                 dec eax
  1115.                 lea eax,[eax+eax*2]
  1116.                 mov ebx,buf2d_h
  1117.                 mov edi,esi            
  1118.                 add esi,eax
  1119.                 add eax,3
  1120.                 cld
  1121.                 .cycle_24:
  1122.                 push ecx edi esi
  1123. align 4
  1124.                 @@:
  1125.                         ;swap word[edi] <-> word[esi]
  1126.                         mov dx,[edi]
  1127.                         movsw
  1128.                         mov [esi-2],dx
  1129.                         ;swap byte[edi] <-> byte[esi]
  1130.                         mov dl,[edi]
  1131.                         movsb
  1132.                         mov [esi-1],dl
  1133.                         sub esi,6
  1134.                 loop @b
  1135.                 pop esi edi ecx
  1136.                 add edi,eax
  1137.                 add esi,eax
  1138.                 dec ebx
  1139.                 or ebx,ebx
  1140.                 jnz .cycle_24
  1141.                 jmp .end_32
  1142.         .end_24:
  1143.         cmp buf2d_bits,32
  1144.         jne .end_32
  1145.                 mov esi,buf2d_data
  1146.                 mov eax,buf2d_w
  1147.                 dec eax
  1148.                 shl eax,2
  1149.                 mov ebx,buf2d_h
  1150.                 mov edi,esi
  1151.                 add esi,eax
  1152.                 add eax,4
  1153.                 cld
  1154.                 .cycle_32:
  1155.                 mov ecx,eax
  1156.                 shr ecx,3
  1157.                 push edi esi
  1158. align 4
  1159.                 @@:
  1160.                         ;swap dword[edi] <-> dword[esi]
  1161.                         mov edx,[edi]
  1162.                         movsd
  1163.                         mov [esi-4],edx
  1164.                         sub esi,8
  1165.                 loop @b
  1166.                 pop esi edi
  1167.                 add edi,eax
  1168.                 add esi,eax
  1169.                 dec ebx
  1170.                 or ebx,ebx
  1171.                 jnz .cycle_32
  1172.         .end_32:
  1173. popad
  1174.         ret
  1175. endp
  1176.  
  1177. ;®âà §¨âì ¯® ¢¥à⨪ «¨ (¢¥àå ¨ ­¨§ ¬¥­ïîâáï ¬¥áâ ¬¨)
  1178. align 4
  1179. proc buf_flip_v, buf_struc:dword
  1180. locals
  1181.         line_pix dd ? ;ª®«. ¯¨ªá¥«¥© ¢ «¨­¨¨ ¡ãä¥à 
  1182.         line_2byte dd ? ;ª®«. ¡ ©â ¢ «¨­¨¨ ¡ãä¥à  * 2
  1183. endl
  1184.         pushad
  1185.         mov edi,[buf_struc]
  1186.         cmp buf2d_bits,24
  1187.         jne .end_24
  1188.                 mov edx,buf2d_w
  1189.                 mov [line_pix],edx
  1190.                 mov ebx,buf2d_h
  1191.                 lea edx,[edx+edx*2]
  1192.                 mov esi,edx
  1193.                 imul esi,ebx
  1194.                 sub esi,edx
  1195.                 add esi,buf2d_data ;㪠§ â¥«ì ­  ­¨¦­îî «¨­¨î
  1196.                 shr ebx,1 ;ª®«. «¨­¥©­ëå 横«®¢
  1197.                 shl edx,1
  1198.                 mov [line_2byte],edx
  1199.                 mov edi,buf2d_data
  1200.                 xchg edi,esi
  1201.                 cld
  1202.                 .flip_24:
  1203.                 cmp ebx,0
  1204.                 jle .end_32 ;§¤¥áì ¢ë室 ¨§ ä㭪樨 (¯®â®¬ã .end_24 ­¥ ¯®¤å®¤¨â)
  1205.                 mov ecx,[line_pix]
  1206. align 4
  1207.                 @@:
  1208.                         lodsw
  1209.                         mov dx,word[edi]
  1210.                         mov word[esi-2],dx
  1211.                         stosw
  1212.                         lodsb
  1213.                         mov ah,byte[edi]
  1214.                         mov byte[esi-1],ah
  1215.                         stosb
  1216.                         loop @b
  1217.                 sub edi,[line_2byte]
  1218.                 dec ebx
  1219.                 jmp .flip_24
  1220.         .end_24:
  1221.         cmp buf2d_bits,32
  1222.         jne .end_32
  1223.                 mov edx,buf2d_w
  1224.                 mov [line_pix],edx
  1225.                 mov ebx,buf2d_h
  1226.                 shl edx,2
  1227.                 mov esi,edx
  1228.                 imul esi,ebx
  1229.                 sub esi,edx
  1230.                 add esi,buf2d_data ;㪠§ â¥«ì ­  ­¨¦­îî «¨­¨î
  1231.                 shr ebx,1 ;ª®«. «¨­¥©­ëå 横«®¢
  1232.                 shl edx,1
  1233.                 mov [line_2byte],edx
  1234.                 mov edi,buf2d_data
  1235.                 xchg edi,esi
  1236.                 cld
  1237.                 .flip_32:
  1238.                 cmp ebx,0
  1239.                 jle .end_32
  1240.                 mov ecx,[line_pix]
  1241. align 4
  1242.                 @@:
  1243.                         lodsd
  1244.                         mov edx,dword[edi]
  1245.                         mov dword[esi-4],edx
  1246.                         stosd
  1247.                         loop @b
  1248.                 sub edi,[line_2byte]
  1249.                 dec ebx
  1250.                 jmp .flip_32
  1251.         .end_32:
  1252.         popad
  1253.         ret
  1254. endp
  1255.  
  1256. ;description:
  1257. ; ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® è¨à¨­¥ ¢ 2 à §  (à §¬¥àë ¡ãä¥à  ­¥ ¬¥­ïîâáï)
  1258. align 4
  1259. proc buf_img_wdiv2, buf_struc:dword
  1260.         pushad
  1261.         mov edi,dword[buf_struc]
  1262.         cmp buf2d_bits,8
  1263.         jne @f
  1264.                 mov eax,buf2d_w
  1265.                 mov ecx,buf2d_h
  1266.                 imul ecx,eax
  1267.                 stdcall img_8b_wdiv2, buf2d_data,ecx
  1268.         @@:
  1269.         cmp buf2d_bits,24
  1270.         jne @f
  1271.                 mov eax,buf2d_w
  1272.                 mov ecx,buf2d_h
  1273.                 imul ecx,eax
  1274.                 stdcall img_rgb24_wdiv2, buf2d_data,ecx
  1275.         @@:
  1276.         cmp buf2d_bits,32
  1277.         jne @f
  1278.                 mov eax,buf2d_w
  1279.                 mov ecx,buf2d_h
  1280.                 imul ecx,eax
  1281.                 stdcall img_rgba32_wdiv2, buf2d_data,ecx
  1282.         @@:
  1283.         popad
  1284.         ret
  1285. endp
  1286.  
  1287. ;input:
  1288. ;data_8b - pointer to rgb data
  1289. ;size - count img pixels (size img data / 3(rgb) )
  1290. align 4
  1291. proc img_8b_wdiv2 data_8b:dword, size:dword
  1292.         mov eax,dword[data_8b]
  1293.         mov ecx,dword[size] ;ecx = size
  1294.         cld
  1295.         @@: ;§ â¥¬­¥­¨¥ æ¢¥â  ¯¨ªá¥«¥©
  1296.                 shr byte[eax],1
  1297.                 inc eax
  1298.                 loop @b
  1299.  
  1300.         mov eax,dword[data_8b]
  1301.         mov ecx,dword[size] ;ecx = size
  1302.         shr ecx,1
  1303.         @@: ;á«®¦¥­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1304.                 mov bl,byte[eax+1] ;ª®¯¨à㥬 梥â á®á¥¤­¥£® ¯¨ªá¥«ï
  1305.                 add byte[eax],bl
  1306.                 add eax,2
  1307.                 loop @b
  1308.  
  1309.         mov eax,dword[data_8b]
  1310.         inc eax
  1311.         mov ebx,eax
  1312.         inc ebx
  1313.         mov ecx,dword[size] ;ecx = size
  1314.         shr ecx,1
  1315.         dec ecx ;«¨è­¨© ¯¨ªá¥«ì
  1316.         @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1317.                 mov dl,byte[ebx]
  1318.                 mov byte[eax],dl
  1319.  
  1320.                 inc eax
  1321.                 add ebx,2
  1322.                 loop @b
  1323.         ret
  1324. endp
  1325.  
  1326. ;input:
  1327. ;data_rgb - pointer to rgb data
  1328. ;size - count img pixels (size img data / 3(rgb) )
  1329. align 4
  1330. proc img_rgb24_wdiv2 data_rgb:dword, size:dword
  1331.   mov eax,dword[data_rgb]
  1332.   mov ecx,dword[size] ;ecx = size
  1333.   lea ecx,[ecx+ecx*2]
  1334.   cld
  1335.   @@: ;§ â¥¬­¥­¨¥ æ¢¥â  ¯¨ªá¥«¥©
  1336.                 shr byte[eax],1
  1337.                 inc eax
  1338.                 loop @b
  1339.  
  1340.   mov eax,dword[data_rgb]
  1341.   mov ecx,dword[size] ;ecx = size
  1342.   shr ecx,1
  1343.   @@: ;á«®¦¥­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1344.                 mov bx,word[eax+3] ;ª®¯¨à㥬 梥â á®á¥¤­¥£® ¯¨ªá¥«ï
  1345.                 add word[eax],bx
  1346.                 mov bl,byte[eax+5] ;ª®¯¨à㥬 梥â á®á¥¤­¥£® ¯¨ªá¥«ï
  1347.                 add byte[eax+2],bl
  1348.                 add eax,6 ;=2*3
  1349.                 loop @b
  1350.  
  1351.   mov eax,dword[data_rgb]
  1352.   add eax,3
  1353.   mov ebx,eax
  1354.   add ebx,3
  1355.   mov ecx,dword[size] ;ecx = size
  1356.   shr ecx,1
  1357.   dec ecx ;«¨è­¨© ¯¨ªá¥«ì
  1358.   @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1359.                 mov edx,dword[ebx]
  1360.                 mov word[eax],dx
  1361.                 shr edx,16
  1362.                 mov byte[eax+2],dl
  1363.  
  1364.                 add eax,3
  1365.                 add ebx,6
  1366.                 loop @b
  1367.   ret
  1368. endp
  1369.  
  1370. ;input:
  1371. ;data_rgba - pointer to rgba data
  1372. ;size - count img pixels (size img data / 4(rgba) )
  1373. align 4
  1374. proc img_rgba32_wdiv2 data_rgba:dword, size:dword
  1375.         mov eax,dword[data_rgba]
  1376.  
  1377.         mov eax,dword[data_rgba]
  1378.         mov ebx,eax
  1379.         add ebx,4
  1380.         mov ecx,dword[size] ;ecx = size
  1381.         shr ecx,1
  1382.         @@: ;ᬥ訢 ­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1383.                 call combine_colors_1
  1384.                 mov [eax],edx
  1385.                 add eax,8 ;=2*4
  1386.                 add ebx,8
  1387.                 loop @b
  1388.  
  1389.         mov eax,dword[data_rgba]
  1390.         add eax,4
  1391.         mov ebx,eax
  1392.         add ebx,4
  1393.         mov ecx,dword[size] ;ecx = size
  1394.         shr ecx,1
  1395.         dec ecx ;«¨è­¨© ¯¨ªá¥«ì
  1396.         @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1397.                 mov edx,dword[ebx]
  1398.                 mov dword[eax],edx
  1399.  
  1400.                 add eax,4
  1401.                 add ebx,8
  1402.                 loop @b
  1403.         ret
  1404. endp
  1405.  
  1406. ;description:
  1407. ; ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® ¢ëá®â¥ ¢ 2 à §  (¢ëá®â  ¡ãä¥à  ­¥ ¬¥­ï¥âáï)
  1408. align 4
  1409. proc buf_img_hdiv2, buf_struc:dword
  1410.         pushad
  1411.         mov edi,dword[buf_struc]
  1412.         cmp buf2d_bits,8
  1413.         jne @f
  1414.                 mov eax,buf2d_w
  1415.                 mov ecx,buf2d_h
  1416.                 imul ecx,eax
  1417.                 stdcall img_8b_hdiv2, buf2d_data,ecx,eax
  1418.                 jmp .end_f ;edi ¯®àâ¨âáï ¢ ä㭪樨, ¯®â®¬ã ¨á¯®«ì§®¢ ­¨¥ buf2d_bits ®¯ á­®
  1419.         @@:
  1420.         cmp buf2d_bits,24
  1421.         jne @f
  1422.                 mov eax,buf2d_w
  1423.                 mov ecx,buf2d_h
  1424.                 imul ecx,eax
  1425.                 stdcall img_rgb24_hdiv2, buf2d_data,ecx,eax
  1426.                 jmp .end_f
  1427.         @@:
  1428.         cmp buf2d_bits,32
  1429.         jne @f
  1430.                 mov eax,buf2d_w
  1431.                 mov ecx,buf2d_h
  1432.                 imul ecx,eax
  1433.                 shl eax,2
  1434.                 stdcall img_rgba32_hdiv2, buf2d_data,ecx,eax
  1435.                 ;jmp .end_f
  1436.         @@:
  1437.         .end_f:
  1438.         popad
  1439.         ret
  1440. endp
  1441.  
  1442. ;input:
  1443. ;data_8b - pointer to 8 bit data
  1444. ;size - count img pixels (size img data)
  1445. ;size_w - width img in pixels
  1446. align 4
  1447. proc img_8b_hdiv2, data_8b:dword, size:dword, size_w:dword
  1448.  
  1449.         mov eax,dword[data_8b] ;eax =
  1450.         mov ecx,dword[size]
  1451.         cld
  1452.         @@: ;§ â¥¬­¥­¨¥ æ¢¥â  ¯¨ªá¥«¥©
  1453.                 shr byte[eax],1
  1454.                 inc eax
  1455.                 loop @b
  1456.  
  1457.         mov eax,dword[data_8b] ;eax =
  1458.         mov esi,dword[size_w]
  1459.         mov ebx,esi
  1460.         add ebx,eax
  1461.         mov ecx,dword[size]  ;ecx = size
  1462.         shr ecx,1
  1463.         xor edi,edi
  1464.         @@: ;á«®¦¥­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1465.                 mov dl,byte[ebx] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1466.                 add byte[eax],dl
  1467.  
  1468.                 inc eax
  1469.                 inc ebx
  1470.                 inc edi
  1471.                 cmp edi,dword[size_w]
  1472.                 jl .old_line
  1473.                         add eax,esi
  1474.                         add ebx,esi
  1475.                         xor edi,edi
  1476.                 .old_line:
  1477.                 loop @b
  1478.  
  1479.  
  1480.         mov eax,dword[data_8b] ;eax =
  1481.         add eax,esi ;esi = width*3(rgb)
  1482.         mov ebx,eax
  1483.         add ebx,esi
  1484.         mov ecx,dword[size] ;ecx = size
  1485.         shr ecx,1
  1486.         sub ecx,dword[size_w] ;«¨è­ïï áâப  ¯¨ªá¥«¥©
  1487.         xor edi,edi
  1488.         @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1489.                 mov dl,byte[ebx] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1490.                 mov byte[eax],dl
  1491.  
  1492.                 inc eax
  1493.                 inc ebx
  1494.                 inc edi
  1495.                 cmp edi,dword[size_w]
  1496.                 jl .old_line_2
  1497.                         add ebx,esi
  1498.                         xor edi,edi
  1499.                 .old_line_2:
  1500.                 loop @b
  1501.         ret
  1502. endp
  1503.  
  1504. ;input:
  1505. ;data_rgb - pointer to rgb data
  1506. ;size - count img pixels (size img data / 3(rgb) )
  1507. ;size_w - width img in pixels
  1508. align 4
  1509. proc img_rgb24_hdiv2, data_rgb:dword, size:dword, size_w:dword
  1510.  
  1511.   mov eax,dword[data_rgb] ;eax =
  1512.   mov ecx,dword[size]     ;ecx = size
  1513.   lea ecx,[ecx+ecx*2]
  1514.   cld
  1515.   @@: ;§ â¥¬­¥­¨¥ æ¢¥â  ¯¨ªá¥«¥©
  1516.     shr byte[eax],1
  1517.     inc eax
  1518.     loop @b
  1519.  
  1520.   mov eax,dword[data_rgb] ;eax =
  1521.   mov esi,dword[size_w]
  1522.   lea esi,[esi+esi*2] ;esi = width*3(rgb)
  1523.   mov ebx,esi
  1524.   add ebx,eax
  1525.   mov ecx,dword[size]  ;ecx = size
  1526.   shr ecx,1
  1527.   xor edi,edi
  1528.   @@: ;á«®¦¥­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1529.     mov dx,word[ebx] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1530.     add word[eax],dx
  1531.     mov dl,byte[ebx+2] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1532.     add byte[eax+2],dl
  1533.  
  1534.     add eax,3
  1535.     add ebx,3
  1536.     inc edi
  1537.     cmp edi,dword[size_w]
  1538.     jl .old_line
  1539.       add eax,esi
  1540.       add ebx,esi
  1541.       xor edi,edi
  1542.     .old_line:
  1543.     loop @b
  1544.  
  1545.   mov eax,dword[data_rgb] ;eax =
  1546.   add eax,esi ;esi = width*3(rgb)
  1547.   mov ebx,eax
  1548.   add ebx,esi
  1549.   mov ecx,dword[size] ;ecx = size
  1550.   shr ecx,1
  1551.   sub ecx,dword[size_w] ;«¨è­ïï áâப  ¯¨ªá¥«¥©
  1552.   xor edi,edi
  1553.   @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1554.     mov edx,dword[ebx] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1555.     mov word[eax],dx
  1556.     shr edx,16
  1557.     mov byte[eax+2],dl
  1558.  
  1559.     add eax,3
  1560.     add ebx,3
  1561.     inc edi
  1562.     cmp edi,dword[size_w]
  1563.     jl .old_line_2
  1564.       add ebx,esi
  1565.       xor edi,edi
  1566.     .old_line_2:
  1567.     loop @b
  1568.   ret
  1569. endp
  1570.  
  1571. ;input:
  1572. ;data_rgba - pointer to rgba data
  1573. ;size - count img pixels (size img data / 4(rgba) )
  1574. ;size_w_b - width img in bytes
  1575. align 4
  1576. proc img_rgba32_hdiv2, data_rgba:dword, size:dword, size_w_b:dword
  1577.  
  1578.         mov eax,dword[data_rgba] ;eax =
  1579.         mov ebx,dword[size_w_b]
  1580.         add ebx,eax
  1581.         mov ecx,dword[size]  ;ecx = size
  1582.         shr ecx,1
  1583.         xor edi,edi
  1584.         @@: ;ᬥ訢 ­¨¥ 梥⮢ ¯¨ªá¥«¥©
  1585.                 call combine_colors_1
  1586.                 mov dword[eax],edx
  1587.  
  1588.                 add eax,4
  1589.                 add ebx,4
  1590.                 add edi,4
  1591.                 cmp edi,dword[size_w_b]
  1592.                 jl .old_line
  1593.                         add eax,dword[size_w_b]
  1594.                         add ebx,dword[size_w_b]
  1595.                         xor edi,edi
  1596.                 .old_line:
  1597.                 loop @b
  1598.  
  1599.         mov eax,dword[data_rgba] ;eax =
  1600.         mov ebx,dword[size_w_b]
  1601.         add eax,ebx
  1602.         add ebx,eax
  1603.         mov ecx,dword[size] ;ecx = size
  1604.         shl ecx,1
  1605.         sub ecx,dword[size_w_b] ;«¨è­ïï áâப  ¯¨ªá¥«¥©
  1606.         shr ecx,2
  1607.         xor edi,edi
  1608.         @@: ;¯®¤¦ â¨¥ ¯¨ªá¥«¥©
  1609.                 mov edx,dword[ebx] ;ª®¯¨à㥬 梥⠭¨¦­¥£® ¯¨ªá¥«ï
  1610.                 mov dword[eax],edx
  1611.  
  1612.                 add eax,4
  1613.                 add ebx,4
  1614.                 add edi,4
  1615.                 cmp edi,dword[size_w_b]
  1616.                 jl .old_line_2
  1617.                         add ebx,dword[size_w_b]
  1618.                         xor edi,edi
  1619.                 .old_line_2:
  1620.                 loop @b
  1621.         ret
  1622. endp
  1623.  
  1624. ;input:
  1625. ; eax - 㪠§ â¥«ì ­  32-¡¨â­ë© 梥â
  1626. ; ebx - 㪠§ â¥«ì ­  32-¡¨â­ë© 梥â
  1627. ;output:
  1628. ; edx - 32-¡¨â­ë© 梥â ᬥ蠭­ë© á ãç¥â®¬ ¯à®§à ç­®áâ¨
  1629. ;destroy:
  1630. ; esi
  1631. align 4
  1632. proc combine_colors_1 uses ecx edi
  1633. locals
  1634.         c_blye dd ?
  1635.         c_green dd ?
  1636.         c_red dd ?
  1637. endl           
  1638.         movzx edi,byte[eax+3]
  1639.         cmp edi,255
  1640.         je .c0z
  1641.         movzx esi,byte[ebx+3]
  1642.         cmp esi,255
  1643.         je .c1z
  1644.         cmp edi,esi
  1645.         je .c0_c1
  1646.  
  1647.         ;¯¥à¥¢®à ç¨¢ ¥¬ §­ ç¥­¨ï ¯à®§à ç­®á⥩
  1648.         neg edi
  1649.         add edi,256
  1650.         neg esi
  1651.         add esi,256
  1652.  
  1653.         movzx ecx,byte[eax]
  1654.         imul ecx,edi
  1655.         mov [c_blye],ecx
  1656.         movzx ecx,byte[ebx]
  1657.         imul ecx,esi
  1658.         add [c_blye],ecx
  1659.  
  1660.         movzx ecx,byte[eax+1]
  1661.         imul ecx,edi
  1662.         mov [c_green],ecx
  1663.         movzx ecx,byte[ebx+1]
  1664.         imul ecx,esi
  1665.         add [c_green],ecx
  1666.  
  1667.         movzx ecx,byte[eax+2]
  1668.         imul ecx,edi
  1669.         mov [c_red],ecx
  1670.         movzx ecx,byte[ebx+2]
  1671.         imul ecx,esi
  1672.         add [c_red],ecx
  1673.  
  1674. push eax ebx
  1675.         xor ebx,ebx
  1676.         mov eax,[c_red]
  1677.         xor edx,edx
  1678.         mov ecx,edi
  1679.         add ecx,esi
  1680.         div ecx
  1681.         mov bl,al
  1682.         shl ebx,16
  1683.         mov eax,[c_green]
  1684.         xor edx,edx
  1685.         div ecx
  1686.         mov bh,al
  1687.         mov eax,[c_blye]
  1688.         xor edx,edx
  1689.         div ecx
  1690.         mov bl,al
  1691.  
  1692.         shr ecx,1
  1693.         ;¯¥à¥¢®à ç¨¢ ¥¬ §­ ç¥­¨ï ¯à®§à ç­®áâ¨
  1694.         neg ecx
  1695.         add ecx,256
  1696.  
  1697.         shl ecx,24
  1698.         add ebx,ecx
  1699.         mov edx,ebx
  1700. pop ebx eax
  1701.  
  1702.         jmp .end_f
  1703.         .c0_c1: ;¥á«¨ ¯à®§à ç­®á⨠®¡®¨å 梥⮢ ᮢ¯ ¤ îâ
  1704.                 mov edx,[eax]
  1705.                 shr edx,1
  1706.                 and edx,011111110111111101111111b
  1707.                 mov esi,[ebx]
  1708.                 shr esi,1
  1709.                 and esi,011111110111111101111111b
  1710.                 add edx,esi
  1711.                 ror edi,8 ;¯¥à¥¬¥é ¥¬ §­ ç¥­¨¥ ¯à®§à ç­®á⨠¢ áâ à訩 ¡ ©â edi
  1712.                 or edx,edi
  1713.                 jmp .end_f
  1714.         .c0z: ;¥á«¨ 梥⠢ eax ¯à®§à ç­ë©
  1715.                 mov edx,[ebx]
  1716.                 movzx edi,byte[ebx+3]
  1717.                 jmp @f
  1718.         .c1z: ;¥á«¨ 梥⠢ ebx ¯à®§à ç­ë©
  1719.                 mov edx,[eax]
  1720.         @@:
  1721.                 add edi,255 ;¤¥« ¥¬ 梥⠭  ¯®«®¢¨­ã ¯à®§à ç­ë¬
  1722.                 shr edi,1
  1723.                 cmp edi,255
  1724.                 jle @f
  1725.                         mov edi,255 ;¬ ªá¨¬ «ì­ ï ¯à®§à ç­®áâì ­¥ ¡®«¥¥ 255
  1726.                 @@:
  1727.                 shl edi,24
  1728.                 and edx,0xffffff ;á­¨¬ ¥¬ áâ àãî ¯à®§à ç­®áâì
  1729.                 add edx,edi
  1730.         .end_f:
  1731.         ret
  1732. endp
  1733.  
  1734. ;description:
  1735. ; ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® è¨à¨­¥ (à §¬¥àë ¡ãä¥à  ­¥ ¬¥­ïîâáï)
  1736. ;input:
  1737. ; data_rgb - pointer to rgb data
  1738. ; size_w - width img in pixels
  1739. ; size_h - height img in pixels
  1740. ; size_w_new - new width img in pixels
  1741. align 16
  1742. proc img_rgb24_wresize, data_rgb:dword, size_w:dword, size_h:dword, size_w_new:dword
  1743. locals
  1744.         pr dd 0
  1745.         pg dd 0
  1746.         pb dd 0
  1747.         img_n dd ? ;㪠§ â¥«ì ­  ¤ ­­ë¥ ­®¢®£® ¨§®¡à ¦¥­¨ï
  1748.         lines dd ?
  1749. endl
  1750. pushad
  1751. ;eax - delta for inp. img
  1752. ;ebx - delta for outp. img
  1753. ;esi - pointer to data_rgb
  1754.         mov esi,[data_rgb]
  1755.         mov [img_n],esi
  1756.         mov eax,[size_h]
  1757.         mov [lines],eax
  1758. align 4
  1759.         .cycyle_0:
  1760.         mov eax,[size_w_new]
  1761.         mov ecx,[size_w]
  1762.         mov ebx,ecx
  1763. align 4
  1764.         .cycyle_1:
  1765.                 cmp eax,ebx
  1766.                 jg .else_0
  1767.                         ;ª®¯¨àã¥¬ë© ¯¨ªá¥«ì ¬ ªá¨¬ «ì­® ¢«¨ï¥â ­  १ã«ìâ â
  1768.                         ;­ ª ¯«¨¢ ¥¬ rgb ¤«ï ¨­â¥à¯®«ï樨 ¯¨ªá¥«¥©
  1769.                         mov edx,[size_w_new]
  1770.                         movzx edi,byte[esi]
  1771.                         imul edi,edx
  1772.                         add [pb],edi
  1773.                         movzx edi,byte[esi+1]
  1774.                         imul edi,edx
  1775.                         add [pg],edi
  1776.                         movzx edi,byte[esi+2]
  1777.                         imul edi,edx
  1778.                         add [pr],edi
  1779.                         cmp eax,ebx
  1780.                         je .d2_add
  1781.                         jmp .if_0_end
  1782.                 .else_0:
  1783.                         ;ª®¯¨àã¥¬ë© ¯¨ªá¥«ì ¯®¯ ¤¥â ­  £à ­¨æã ¯¨ªá¥«¥©
  1784.                         mov edx,ebx
  1785.                         sub edx,eax
  1786.                         add edx,[size_w_new]
  1787.                         movzx edi,byte[esi]
  1788.                         imul edi,edx
  1789.                         add [pb],edi
  1790.                         movzx edi,byte[esi+1]
  1791.                         imul edi,edx
  1792.                         add [pg],edi
  1793.                         movzx edi,byte[esi+2]
  1794.                         imul edi,edx
  1795.                         add [pr],edi
  1796.                         ;á®å࠭塞 £®â®¢®¥ rgb
  1797.                         .d2_add:
  1798.                         push eax
  1799.                                 mov edi,[img_n]
  1800.                                 mov eax,[pb]
  1801.                                 xor edx,edx
  1802.                                 div dword[size_w] ;eax /= [size_w]
  1803.                                 stosb
  1804.                                 mov eax,[pg]
  1805.                                 xor edx,edx
  1806.                                 div dword[size_w] ;eax /= [size_w]
  1807.                                 stosb
  1808.                                 mov eax,[pr]
  1809.                                 xor edx,edx
  1810.                                 div dword[size_w] ;eax /= [size_w]
  1811.                                 stosb
  1812.                         pop eax
  1813.                         add dword[img_n],3 ;next pixel
  1814.                         ;®¡­®¢«ï¥¬ rgb ¤«ï ­®¢®£® ¯¨ªá¥«ï
  1815.                         mov edx,eax
  1816.                         sub edx,ebx
  1817.                         movzx edi,byte[esi]
  1818.                         imul edi,edx
  1819.                         mov [pb],edi
  1820.                         movzx edi,byte[esi+1]
  1821.                         imul edi,edx
  1822.                         mov [pg],edi
  1823.                         movzx edi,byte[esi+2]
  1824.                         imul edi,edx
  1825.                         mov [pr],edi
  1826.                         add ebx,[size_w]
  1827.                 .if_0_end:
  1828.                 add eax,[size_w_new]
  1829.                 add esi,3 ;next pixel
  1830.                 dec ecx
  1831.                 jnz .cycyle_1
  1832.         dec dword[lines]
  1833.         jnz .cycyle_0
  1834. popad
  1835.         ret
  1836. endp
  1837.  
  1838. ;description:
  1839. ; ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® ¢ëá®â¥ (à §¬¥àë ¡ãä¥à  ­¥ ¬¥­ïîâáï)
  1840. ;input:
  1841. ; data_rgb - pointer to rgb data
  1842. ; size_w - width img in pixels
  1843. ; size_h - height img in pixels
  1844. ; size_h_new - new height img in pixels
  1845. align 16
  1846. proc img_rgb24_hresize, data_rgb:dword, size_w:dword, size_h:dword, size_h_new:dword
  1847. locals
  1848.         pr dd 0
  1849.         pg dd 0
  1850.         pb dd 0
  1851.         img_n dd ? ;㪠§ â¥«ì ­  ¤ ­­ë¥ ­®¢®£® ¨§®¡à ¦¥­¨ï
  1852.         cols dd ?
  1853.         lin_b dd ? ;à §¬¥à «¨­¨¨ ¨§®¡à ¦¥­¨ï ¢ ¡ ©â å
  1854.         data_n dd ? ;㪠§ â¥«ì ­  ¤ ­­ë¥ ¤«ï ­®¢®£® á⮫¡æ  ¯¨ªá¥«¥©
  1855. endl
  1856. pushad
  1857. ;eax - delta for inp. img
  1858. ;ebx - delta for outp. img
  1859. ;esi - pointer to data_rgb
  1860.         mov esi,[data_rgb]
  1861.         mov [data_n],esi
  1862.         mov eax,[size_w]
  1863.         mov [cols],eax
  1864.         lea eax,[eax+eax*2]
  1865.         mov [lin_b],eax
  1866. align 4
  1867.         .cycyle_0:
  1868.         mov eax,[size_h_new]
  1869.         mov ecx,[size_h]
  1870.         mov ebx,ecx
  1871.         mov esi,[data_n]
  1872.         mov [img_n],esi
  1873.         add dword[data_n],3 ;¯¥à¥å®¤ ­  á«¥¤ãî騩 á⮫¡¥æ ¯¨ªá¥«¥©
  1874. align 4
  1875.         .cycyle_1:
  1876.                 cmp eax,ebx
  1877.                 jg .else_0
  1878.                         ;ª®¯¨àã¥¬ë© ¯¨ªá¥«ì ¬ ªá¨¬ «ì­® ¢«¨ï¥â ­  १ã«ìâ â
  1879.                         ;­ ª ¯«¨¢ ¥¬ rgb ¤«ï ¨­â¥à¯®«ï樨 ¯¨ªá¥«¥©
  1880.                         mov edx,[size_h_new]
  1881.                         movzx edi,byte[esi]
  1882.                         imul edi,edx
  1883.                         add [pb],edi
  1884.                         movzx edi,byte[esi+1]
  1885.                         imul edi,edx
  1886.                         add [pg],edi
  1887.                         movzx edi,byte[esi+2]
  1888.                         imul edi,edx
  1889.                         add [pr],edi
  1890.                         cmp eax,ebx
  1891.                         je .d2_add
  1892.                         jmp .if_0_end
  1893.                 .else_0:
  1894.                         ;ª®¯¨àã¥¬ë© ¯¨ªá¥«ì ¯®¯ ¤¥â ­  £à ­¨æã ¯¨ªá¥«¥©
  1895.                         mov edx,ebx
  1896.                         sub edx,eax
  1897.                         add edx,[size_h_new]
  1898.                         movzx edi,byte[esi]
  1899.                         imul edi,edx
  1900.                         add [pb],edi
  1901.                         movzx edi,byte[esi+1]
  1902.                         imul edi,edx
  1903.                         add [pg],edi
  1904.                         movzx edi,byte[esi+2]
  1905.                         imul edi,edx
  1906.                         add [pr],edi
  1907.                         ;á®å࠭塞 £®â®¢®¥ rgb
  1908.                         .d2_add:
  1909.                         push eax
  1910.                                 mov edi,[img_n]
  1911.                                 mov eax,[pb]
  1912.                                 xor edx,edx
  1913.                                 div dword[size_h] ;eax /= [size_h]
  1914.                                 stosb
  1915.                                 mov eax,[pg]
  1916.                                 xor edx,edx
  1917.                                 div dword[size_h] ;eax /= [size_h]
  1918.                                 stosb
  1919.                                 mov eax,[pr]
  1920.                                 xor edx,edx
  1921.                                 div dword[size_h] ;eax /= [size_h]
  1922.                                 stosb
  1923.                         pop eax
  1924.                         mov edx,[lin_b]
  1925.                         add dword[img_n],edx ;next pixel
  1926.                         ;®¡­®¢«ï¥¬ rgb ¤«ï ­®¢®£® ¯¨ªá¥«ï
  1927.                         mov edx,eax
  1928.                         sub edx,ebx
  1929.                         movzx edi,byte[esi]
  1930.                         imul edi,edx
  1931.                         mov [pb],edi
  1932.                         movzx edi,byte[esi+1]
  1933.                         imul edi,edx
  1934.                         mov [pg],edi
  1935.                         movzx edi,byte[esi+2]
  1936.                         imul edi,edx
  1937.                         mov [pr],edi
  1938.                         add ebx,[size_h]
  1939.                 .if_0_end:
  1940.                 add eax,[size_h_new]
  1941.                 add esi,[lin_b] ;next pixel
  1942.                 dec ecx
  1943.                 jnz .cycyle_1
  1944.         dec dword[cols]
  1945.         jnz .cycyle_0
  1946. popad
  1947.         ret
  1948. endp
  1949.  
  1950. ;¯à¥®¡à §®¢ ­¨¥ ¡ãä¥à  ¨§ 24-¡¨â­®£® ¢ 8-¡¨â­ë©
  1951. ; spectr - ®¯à¥¤¥«ï¥â ª ª®© ᯥªâà ¡à âì ¯à¨ ¯à¥®¡à §®¢ ­¨¨ 0-ᨭ¨©, 1-§¥«¥­ë©, 2-ªà á­ë©
  1952. align 4
  1953. proc buf_conv_24_to_8, buf_struc:dword, spectr:dword
  1954.         pushad
  1955.         mov edi,dword[buf_struc]
  1956.         cmp buf2d_bits,24
  1957.         jne .error0
  1958.                 mov eax,buf2d_w
  1959.                 cmp eax,1
  1960.                 jl .error1
  1961.                 mov ecx,buf2d_h
  1962.                 cmp ecx,1
  1963.                 jl .error1
  1964.                 imul ecx,eax
  1965.                 mov esi,ecx
  1966.                 ;ebx - ¯ ¬ïâì ¨§ ª®â®à®© ª®¯¨àã¥âáï
  1967.                 ;edx - ¯ ¬ïâì ªã¤  ª®¯¨àã¥âáï
  1968.                 mov edx,buf2d_data
  1969.                 mov ebx,edx
  1970.                 cmp [spectr],3
  1971.                 jge @f
  1972.                         add ebx,[spectr]
  1973.                 @@:
  1974.                         mov al,byte[ebx]
  1975.                         mov byte[edx],al
  1976.                         add ebx,3
  1977.                         inc edx
  1978.                         loop @b
  1979.                 mov buf2d_bits,8
  1980.                 invoke mem.realloc,buf2d_data,esi ;㬥­ìè ¥¬ ¯ ¬ïâì § ­¨¬ ¥¬ãî ¡ãä¥à®¬
  1981.                 jmp .end_conv
  1982.         .error0:
  1983.                 stdcall print_err,sz_buf2d_conv_24_to_8,txt_err_n24b
  1984.                 jmp .end_conv
  1985.         .error1:
  1986.                 stdcall print_err,sz_buf2d_conv_24_to_8,txt_err_size_0
  1987.         .end_conv:
  1988.         popad
  1989.         ret
  1990. endp
  1991.  
  1992. ;¯à¥®¡à §®¢ ­¨¥ ¡ãä¥à  ¨§ 24-¡¨â­®£® ¢ 32-¡¨â­ë©
  1993. align 4
  1994. proc buf_conv_24_to_32, buf_struc:dword, buf_str8:dword
  1995.         pushad
  1996.         mov edi,dword[buf_struc]
  1997.         cmp buf2d_bits,24
  1998.         jne .error1
  1999.                 mov ecx,buf2d_w
  2000.                 mov ebx,buf2d_h
  2001.                 imul ebx,ecx
  2002.                 mov ecx,ebx ;ecx = size  8 b
  2003.                 shl ebx,2   ;ebx = size 32 b
  2004.                 invoke mem.realloc,buf2d_data,ebx ;㢥«¨ç¨¢ ¥¬ ¯ ¬ïâì § ­¨¬ ¥¬ãî ¡ãä¥à®¬
  2005.                 mov buf2d_data,eax ;­  á«ãç © ¥á«¨ ¨§¬¥­¨«áï 㪠§ â¥«ì ­  ¤ ­­ë¥
  2006.                 mov buf2d_bits,32
  2007.                 mov edx,ebx ;edx = size 32 b
  2008.                 sub ebx,ecx ;ebx = size 24 b
  2009.                 mov eax,ecx
  2010.                 ;eax - à §¬¥à  8 ¡¨â­ëå ¤ ­­ëå
  2011.                 ;ebx - à §¬¥à 24 ¡¨â­ëå ¤ ­­ëå
  2012.                 ;edx - à §¬¥à 32 ¡¨â­ëå ¤ ­­ëå
  2013.                 add ebx,buf2d_data
  2014.                 add edx,buf2d_data
  2015.                 mov edi,dword[buf_str8]
  2016.                 cmp buf2d_bits,8
  2017.                 jne .error2
  2018.                 add eax,buf2d_data
  2019.                 mov edi,edx
  2020.                 ;eax - 㪠§ â¥«ì ­  ª®­¥æ  8 ¡¨â­ëå ¤ ­­ëå
  2021.                 ;ebx - 㪠§ â¥«ì ­  ª®­¥æ 24 ¡¨â­ëå ¤ ­­ëå
  2022.                 ;edi - 㪠§ â¥«ì ­  ª®­¥æ 32 ¡¨â­ëå ¤ ­­ëå
  2023.                 @@:
  2024.                         sub edi,4 ;®â­¨¬ ¥¬ ¢ ­ ç «¥ 横« ,
  2025.                         sub ebx,3 ; ¯®â®¬ã, ç⮠㪠§ â¥«¨ áâ®ïâ
  2026.                         dec eax   ; §  ¯à¥¤¥« ¬¨ ¡ãä¥à®¢
  2027.                         mov edx,dword[ebx]
  2028.                         mov dword[edi],edx
  2029.                         mov dl,byte[eax]
  2030.                         mov byte[edi+3],dl
  2031.                         loop @b
  2032.  
  2033.                 jmp .end_conv
  2034.         .error1:
  2035.                 stdcall print_err,sz_buf2d_conv_24_to_32,txt_err_n24b
  2036.                 jmp .end_conv
  2037.         .error2:
  2038.                 stdcall print_err,sz_buf2d_conv_24_to_32,txt_err_n8b
  2039.         .end_conv:
  2040.         popad
  2041.         ret
  2042. endp
  2043.  
  2044. ;äã­ªæ¨ï ª®¯¨àã¥â ¨§®¡à ¦¥­¨¥ ¨§ ¡ãä¥à  buf_source (24b|32b) ¢ buf_destination (24b)
  2045. ; 㪠§ë¢ îâáï ª®®à¤¨­ âë ¢áâ ¢ª¨ ¡ãä¥à  buf_source ®â­®á¨â¥«ì­® buf_destination
  2046. ; ¯à®§à ç­®áâì ¯à¨ ª®¯¨à®¢ ­¨¨ ­¥ ãç¨â뢠¥âáï
  2047. align 4
  2048. proc buf_bit_blt, buf_destination:dword, coord_x:dword, coord_y:dword, buf_source:dword
  2049.         locals
  2050.                 lost_bytes dd ? ;ç¨á«® ¯®â¥àï­­ëå ¡ ©â®¢ ¢ áâப¥ ª®¯¨à㥬®£® ¨§®¡à ¦¥­ï (â¥å çâ® ­¥ ¢« §ïâ ¢ ¡ãä¥à)
  2051.         endl
  2052.         pushad
  2053.  
  2054.         mov edi,[buf_source]
  2055.         cmp buf2d_bits,24
  2056.         je .sou24
  2057.         cmp buf2d_bits,32
  2058.         je .sou32
  2059.                 jmp .copy_end ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2060.  
  2061.         .sou24: ;¢ ¨áâ®ç­¨ª¥ 24 ¡¨â­ ï ª à⨭ª 
  2062.         mov eax,buf2d_w
  2063.         mov edx,buf2d_h ;¢ëá®â  ª®¯¨à㥬®© ª à⨭ª¨
  2064.         mov esi,buf2d_data ;¤ ­­ë¥ ª®¯¨à㥬®© ª à⨭ª¨
  2065.  
  2066.         mov edi,[buf_destination]
  2067.         cmp buf2d_bits,24
  2068.         jne .copy_end ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2069.         mov ebx,[coord_x] ;¢ ebx ¢à¥¬¥­­® áâ ¢¨¬ ®âáâ㯠¨§®¡à ¦¥­¨ï (¤«ï ¯à®¢¥àª¨)
  2070.         cmp ebx,buf2d_w   ;¯à®¢¥à塞 ¢« §¨â «¨ ¨§®¡à ¦¥­¨¥ ¯® è¨à¨­¥
  2071.         jge .copy_end     ;¥á«¨ ¨§®¡à ¦¥­¨¥ ¯®«­®áâìî ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã
  2072.                 mov ebx,buf2d_h ;ebx - ¢ëá®â  ®á­®¢­®£® ¡ãä¥à 
  2073.                 mov ecx,[coord_y]
  2074.                 cmp ecx,0
  2075.                 jge @f
  2076.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<0 (1-ï ­ áâனª )
  2077.                         add edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨
  2078.                         cmp edx,0
  2079.                         jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî ­ ¤ ¢¥àå­¥© £à ­¨æ¥© ¡ãä¥à  (coord_y<0 ¨ |coord_y|>buf_source.h)
  2080.                         neg ecx
  2081.                         imul ecx,eax
  2082.                         lea ecx,[ecx+ecx*2] ;¯® 3 ¡ ©â  ­  ¯¨ªá¥«ì
  2083.                         add esi,ecx ;ᤢ¨£ ¥¬ 㪠§ â¥«ì á ª®¯¨à㥬묨 ¤ ­­ë¬¨, á ãç¥â®¬ ¯à®¯ã襭®© ç áâ¨
  2084.                         xor ecx,ecx ;®¡­ã«ï¥¬ ª®®à¤¨­ âã coord_y
  2085.                 @@:
  2086.                 cmp ecx,ebx
  2087.                 jge .copy_end ;¥á«¨ ª®®à¤¨­ â  'y' ¡®«ìè¥ ¢ëá®âë ¡ãä¥à 
  2088.                 add ecx,edx ;ecx - ­¨¦­ïï ª®®à¤¨­ â  ª®¯¨à㥬®© ª à⨭ª¨
  2089.                 cmp ecx,ebx
  2090.                 jle @f
  2091.                         sub ecx,ebx
  2092.                         sub edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨, ¢ á«ãç¥ ª®£¤  ®­  ¢ë« §¨â §  ­¨¦­îî £à ­¨æã
  2093.                 @@:
  2094.                 mov ebx,buf2d_w
  2095.                 mov ecx,[coord_y] ;ecx ¨á¯®«ì§ã¥¬ ¤«ï ¢à¥¬¥­­ëå 楫¥©
  2096.                 cmp ecx,0
  2097.                 jg .end_otr_c_y_24
  2098.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<=0 (2-ï ­ áâனª )
  2099.                         mov ecx,[coord_x]
  2100.                         jmp @f
  2101.                 .end_otr_c_y_24:
  2102.                 imul ecx,ebx
  2103.                 add ecx,[coord_x]
  2104.                 @@:
  2105.                 lea ecx,[ecx+ecx*2]
  2106.                 add ecx,buf2d_data
  2107.                 sub ebx,eax
  2108.                 mov edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2109.  
  2110.         mov dword[lost_bytes],0
  2111.         mov ecx,[coord_x]
  2112.         cmp ecx,0
  2113.         jge @f
  2114.                 neg ecx
  2115.                 cmp eax,ecx ;eax - è¨à¨­  ª®¯¨à㥬®© ª à⨭ª¨
  2116.                 jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî §  «¥¢®© £à ­¨æ¥© ¡ãä¥à  (coord_x<0 ¨ |coord_x|>buf_source.w)
  2117.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2118.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2119.                 lea ecx,[ecx+ecx*2]
  2120.                 mov [lost_bytes],ecx
  2121.                 add esi,ecx
  2122.                 add edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2123.                 xor ecx,ecx
  2124.         @@:
  2125.         cmp ecx,ebx
  2126.         jle @f
  2127.                 sub ecx,ebx
  2128.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2129.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2130.                 lea ecx,[ecx+ecx*2] ;ecx - ç¨á«® ¯¨ªá¥«¥© ¢ 1-© áâப¥ ª à⨭ª¨, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî áâ®à®­ã
  2131.                 add [lost_bytes],ecx
  2132.         @@:
  2133.  
  2134.         lea eax,[eax+eax*2] ;ª®««¨ç¥á⢮ ¡ ©â ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2135.         lea ebx,[ebx+ebx*2] ;ª®««¨ç¥á⢮ ¡ ©â ¢ 1-© áâப¥ ¡ãä¥à  ¬¨­ãá ç¨á«® ¡ ©â ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2136.  
  2137.         cld
  2138.         cmp [lost_bytes],0
  2139.         jg .copy_1
  2140.         .copy_0: ;¯à®á⮥ ª®¯¨à®¢ ­¨¥
  2141.                 mov ecx,eax
  2142.                 rep movsb
  2143.                 add edi,ebx
  2144.                 dec edx
  2145.                 cmp edx,0
  2146.                 jg .copy_0
  2147.         jmp .copy_end
  2148.         .copy_1: ;­¥ ¯à®á⮥ ª®¯¨à®¢ ­¨¥ (ª à⨭ª  ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã)
  2149.                 mov ecx,eax
  2150.                 rep movsb
  2151.                 add edi,ebx
  2152.                 add esi,[lost_bytes] ;¤®¡ ¢«ï¥¬ ¡ ©âë, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî £à ­¨æã
  2153.                 dec edx
  2154.                 cmp edx,0
  2155.                 jg .copy_1
  2156.         jmp .copy_end
  2157.  
  2158.         .sou32: ;¢ ¨áâ®ç­¨ª¥ 32 ¡¨â­ ï ª à⨭ª 
  2159.         mov eax,buf2d_w
  2160.         mov edx,buf2d_h ;¢ëá®â  ª®¯¨à㥬®© ª à⨭ª¨
  2161.         mov esi,buf2d_data ;¤ ­­ë¥ ª®¯¨à㥬®© ª à⨭ª¨
  2162.  
  2163.         mov edi,[buf_destination]
  2164.         cmp buf2d_bits,24
  2165.         jne .copy_end ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2166.         mov ebx,[coord_x] ;¢ ebx ¢à¥¬¥­­® áâ ¢¨¬ ®âáâ㯠¨§®¡à ¦¥­¨ï (¤«ï ¯à®¢¥àª¨)
  2167.         cmp ebx,buf2d_w   ;¯à®¢¥à塞 ¢« §¨â «¨ ¨§®¡à ¦¥­¨¥ ¯® è¨à¨­¥
  2168.         jge .copy_end     ;¥á«¨ ¨§®¡à ¦¥­¨¥ ¯®«­®áâìî ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã
  2169.                 mov ebx,buf2d_h ;ebx - ¢ëá®â  ®á­®¢­®£® ¡ãä¥à 
  2170.                 mov ecx,[coord_y]
  2171.                 cmp ecx,0
  2172.                 jge @f
  2173.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<0 (1-ï ­ áâனª )
  2174.                         add edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨
  2175.                         cmp edx,0
  2176.                         jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî ­ ¤ ¢¥àå­¥© £à ­¨æ¥© ¡ãä¥à  (coord_y<0 ¨ |coord_y|>buf_source.h)
  2177.                         neg ecx
  2178.                         imul ecx,eax
  2179.                         shl ecx,2 ;¯® 4 ¡ ©â  ­  ¯¨ªá¥«ì
  2180.                         add esi,ecx ;ᤢ¨£ ¥¬ 㪠§ â¥«ì á ª®¯¨à㥬묨 ¤ ­­ë¬¨, á ãç¥â®¬ ¯à®¯ã襭®© ç áâ¨
  2181.                         xor ecx,ecx ;®¡­ã«ï¥¬ ª®®à¤¨­ âã coord_y
  2182.                 @@:
  2183.                 cmp ecx,ebx
  2184.                 jge .copy_end ;¥á«¨ ª®®à¤¨­ â  'y' ¡®«ìè¥ ¢ëá®âë ¡ãä¥à 
  2185.                 add ecx,edx ;ecx - ­¨¦­ïï ª®®à¤¨­ â  ª®¯¨à㥬®© ª à⨭ª¨
  2186.                 cmp ecx,ebx
  2187.                 jle @f
  2188.                         sub ecx,ebx
  2189.                         sub edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨, ¢ á«ãç¥ ª®£¤  ®­  ¢ë« §¨â §  ­¨¦­îî £à ­¨æã
  2190.                 @@:
  2191.                 mov ebx,buf2d_w
  2192.                 ;mov ecx,ebx ;ecx ¨á¯®«ì§ã¥¬ ¤«ï ¢à¥¬¥­­ëå 楫¥©
  2193.                 ;imul ecx,[coord_y]
  2194.                 ;add ecx,[coord_x]
  2195.                 mov ecx,[coord_y] ;ecx ¨á¯®«ì§ã¥¬ ¤«ï ¢à¥¬¥­­ëå 楫¥©
  2196.                 cmp ecx,0
  2197.                 jg .end_otr_c_y_32
  2198.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<=0 (2-ï ­ áâனª )
  2199.                         mov ecx,[coord_x]
  2200.                         jmp @f
  2201.                 .end_otr_c_y_32:
  2202.                 imul ecx,ebx
  2203.                 add ecx,[coord_x]
  2204.                 @@:
  2205.                 lea ecx,[ecx+ecx*2]
  2206.                 add ecx,buf2d_data
  2207.                 sub ebx,eax
  2208.                 mov edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2209.  
  2210.         mov dword[lost_bytes],0
  2211.         mov ecx,[coord_x]
  2212.         cmp ecx,0
  2213.         jge @f
  2214.                 neg ecx
  2215.                 cmp eax,ecx ;eax - è¨à¨­  ª®¯¨à㥬®© ª à⨭ª¨
  2216.                 jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî §  «¥¢®© £à ­¨æ¥© ¡ãä¥à  (coord_x<0 ¨ |coord_x|>buf_source.w)
  2217.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2218.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2219.                 shl ecx,2
  2220.                 mov [lost_bytes],ecx
  2221.                 add esi,ecx
  2222.                 add edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2223.                 xor ecx,ecx
  2224.         @@:
  2225.         cmp ecx,ebx
  2226.         jle @f
  2227.                 sub ecx,ebx
  2228.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2229.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2230.                 shl ecx,2 ;ecx - ç¨á«® ¯¨ªá¥«¥© ¢ 1-© áâப¥ ª à⨭ª¨, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî áâ®à®­ã
  2231.                 add [lost_bytes],ecx
  2232.         @@:
  2233.  
  2234.         ;eax - ª®««¨ç¥á⢮ ¯¨ªá¥«¥© ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2235.         lea ebx,[ebx+ebx*2] ;ª®««¨ç¥á⢮ ¡ ©â ¢ 1-© áâப¥ ¡ãä¥à  ¬¨­ãá ç¨á«® ¡ ©â ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2236.  
  2237.         cld
  2238.         cmp [lost_bytes],0
  2239.         jg .copy_3
  2240.         .copy_2: ;¯à®á⮥ ª®¯¨à®¢ ­¨¥
  2241.                 mov ecx,eax
  2242.                 @@:
  2243.                         movsw
  2244.                         movsb
  2245.                         inc esi
  2246.                         loop @b
  2247.                 add edi,ebx
  2248.                 dec edx
  2249.                 cmp edx,0
  2250.                 jg .copy_2
  2251.         jmp .copy_end
  2252.         .copy_3: ;­¥ ¯à®á⮥ ª®¯¨à®¢ ­¨¥ (ª à⨭ª  ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã)
  2253.                 mov ecx,eax
  2254.                 @@:
  2255.                         movsw
  2256.                         movsb
  2257.                         inc esi
  2258.                         loop @b
  2259.                 add edi,ebx
  2260.                 add esi,[lost_bytes] ;¤®¡ ¢«ï¥¬ ¡ ©âë, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî £à ­¨æã
  2261.                 dec edx
  2262.                 cmp edx,0
  2263.                 jg .copy_3
  2264.  
  2265.         .copy_end:
  2266.         popad
  2267.         ret
  2268. endp
  2269.  
  2270. ;input:
  2271. ; esi = pointer to color1 + transparent (32b)
  2272. ; edi = pointer to background color2 (24b)
  2273. ;output:
  2274. ; [edi] = combine color (24b)
  2275. align 4
  2276. combine_colors_0:
  2277.         push ax cx
  2278.         movzx cx,byte[esi+3] ;pro
  2279.         cmp cx,255
  2280.         je .end_f
  2281.         or cx,cx
  2282.         jnz @f
  2283.                 mov ax,[esi]
  2284.                 mov [edi],ax
  2285.                 mov al,[esi+2]
  2286.                 mov [edi+2],al
  2287.                 jmp .end_f
  2288. align 4
  2289.         @@:
  2290.         inc cx
  2291.         push bx dx
  2292.         mov bx,0x0100 ;---get transparent---
  2293.         sub bx,cx ;256-pro
  2294.         ;---blye---
  2295.         movzx ax,byte[esi]
  2296.         imul ax,bx
  2297.         movzx dx,byte[edi]
  2298.         imul dx,cx
  2299.         add ax,dx
  2300.         mov byte[edi],ah
  2301.         ;---green---
  2302.         movzx ax,byte[esi+1]
  2303.         imul ax,bx
  2304.         movzx dx,byte[edi+1]
  2305.         imul dx,cx
  2306.         add ax,dx
  2307.         mov byte[edi+1],ah
  2308.         ;---red---
  2309.         movzx ax,byte[esi+2]
  2310.         imul ax,bx
  2311.         movzx dx,byte[edi+2]
  2312.         imul dx,cx
  2313.         add ax,dx
  2314.         mov byte[edi+2],ah
  2315.         pop dx bx
  2316. .end_f:
  2317.         pop cx ax
  2318.         ret
  2319.  
  2320. ;äã­ªæ¨ï ª®¯¨àã¥â ¨§®¡à ¦¥­¨¥ ¨§ ¡ãä¥à  buf_source (32b) ¢ buf_destination (24b)
  2321. ; 㪠§ë¢ îâáï ª®®à¤¨­ âë ¢áâ ¢ª¨ ¡ãä¥à  buf_source ®â­®á¨â¥«ì­® buf_destination
  2322. ; ¯à¨ ª®¯¨à®¢ ­¨¨ ãç¨â뢠¥âáï ¯à®§à ç­®áâì
  2323. align 4
  2324. proc buf_bit_blt_transp, buf_destination:dword, coord_x:dword, coord_y:dword, buf_source:dword
  2325.         locals
  2326.                 lost_bytes dd ? ;ç¨á«® ¯®â¥àï­­ëå ¡ ©â®¢ ¢ áâப¥ ª®¯¨à㥬®£® ¨§®¡à ¦¥­ï (â¥å çâ® ­¥ ¢« §ïâ ¢ ¡ãä¥à)
  2327.         endl
  2328.         pushad
  2329.  
  2330.         mov edi,[buf_source]
  2331.         cmp buf2d_bits,32
  2332.         jne .copy_end ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2333.         mov eax,buf2d_w
  2334.         mov edx,buf2d_h ;¢ëá®â  ª®¯¨à㥬®© ª à⨭ª¨
  2335.         mov esi,buf2d_data ;¤ ­­ë¥ ª®¯¨à㥬®© ª à⨭ª¨
  2336.  
  2337.         mov edi,[buf_destination]
  2338.         cmp buf2d_bits,24
  2339.         jne .copy_end ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2340.                 mov ebx,buf2d_h ;ebx - ¢ëá®â  ®á­®¢­®£® ¡ãä¥à 
  2341.                 mov ecx,[coord_y]
  2342.                 cmp ecx,0
  2343.                 jge @f
  2344.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<0 (1-ï ­ áâனª )
  2345.                         add edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨
  2346.                         cmp edx,0
  2347.                         jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî ­ ¤ ¢¥àå­¥© £à ­¨æ¥© ¡ãä¥à  (coord_y<0 ¨ |coord_y|>buf_source.h)
  2348.                         neg ecx
  2349.                         imul ecx,eax
  2350.                         shl ecx,2 ;¯® 4 ¡ ©â  ­  ¯¨ªá¥«ì
  2351.                         add esi,ecx ;ᤢ¨£ ¥¬ 㪠§ â¥«ì á ª®¯¨à㥬묨 ¤ ­­ë¬¨, á ãç¥â®¬ ¯à®¯ã襭®© ç áâ¨
  2352.                         xor ecx,ecx ;®¡­ã«ï¥¬ ª®®à¤¨­ âã coord_y
  2353.                 @@:
  2354.                 cmp ecx,ebx
  2355.                 jge .copy_end ;¥á«¨ ª®®à¤¨­ â  'y' ¡®«ìè¥ ¢ëá®âë ¡ãä¥à 
  2356.                 add ecx,edx ;ecx - ­¨¦­ïï ª®®à¤¨­ â  ª®¯¨à㥬®© ª à⨭ª¨
  2357.                 cmp ecx,ebx
  2358.                 jle @f
  2359.                         sub ecx,ebx
  2360.                         sub edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨, ¢ á«ãç¥ ª®£¤  ®­  ¢ë« §¨â §  ­¨¦­îî £à ­¨æã
  2361.                 @@:
  2362.                 mov ebx,buf2d_w
  2363.                 mov ecx,ebx ;ecx ¨á¯®«ì§ã¥¬ ¤«ï ¢à¥¬¥­­ëå 楫¥©
  2364.                 cmp [coord_y],0
  2365.                 jg .end_otr_c_y
  2366.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<=0 (2-ï ­ áâனª )
  2367.                         mov ecx,[coord_x]
  2368.                         jmp @f
  2369.                 .end_otr_c_y:
  2370.                 imul ecx,[coord_y]
  2371.                 add ecx,[coord_x]
  2372.                 @@:
  2373.                 lea ecx,[ecx+ecx*2]
  2374.                 add ecx,buf2d_data
  2375.                 sub ebx,eax
  2376.                 mov edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2377.  
  2378.         mov dword[lost_bytes],0
  2379.         mov ecx,[coord_x]
  2380.         cmp ecx,0
  2381.         jge @f
  2382.                 neg ecx
  2383.                 cmp eax,ecx ;eax - è¨à¨­  ª®¯¨à㥬®© ª à⨭ª¨
  2384.                 jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî §  «¥¢®© £à ­¨æ¥© ¡ãä¥à  (coord_x<0 ¨ |coord_x|>buf_source.w)
  2385.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2386.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2387.                 shl ecx,2
  2388.                 mov [lost_bytes],ecx
  2389.                 add esi,ecx
  2390.                 shr ecx,2
  2391.                 lea ecx,[ecx+ecx*2]
  2392.                 add edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2393.                 xor ecx,ecx
  2394.         @@:
  2395.         cmp ecx,ebx
  2396.         jle @f
  2397.                 sub ecx,ebx
  2398.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2399.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2400.                 shl ecx,2 ;ecx - ç¨á«® ¯¨ªá¥«¥© ¢ 1-© áâப¥ ª à⨭ª¨, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî áâ®à®­ã
  2401.                 add [lost_bytes],ecx
  2402.         @@:
  2403.  
  2404.         lea ebx,[ebx+ebx*2] ;ª®««¨ç¥á⢮ ¡ ©â ¢ 1-© áâப¥ ¡ãä¥à  ¬¨­ãá ç¨á«® ¡ ©â ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2405.  
  2406.         cld
  2407.         cmp [lost_bytes],0
  2408.         jg .copy_1
  2409.         .copy_0: ;¯à®á⮥ ª®¯¨à®¢ ­¨¥
  2410.                 mov ecx,eax
  2411.                 @@:
  2412.                         call combine_colors_0
  2413.                         add edi,3
  2414.                         add esi,4
  2415.                         loop @b
  2416.                 add edi,ebx
  2417.                 dec edx
  2418.                 cmp edx,0
  2419.                 jg .copy_0
  2420.         jmp .copy_end
  2421.         .copy_1: ;­¥ ¯à®á⮥ ª®¯¨à®¢ ­¨¥ (ª à⨭ª  ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã)
  2422.                 mov ecx,eax
  2423.                 @@:
  2424.                         call combine_colors_0
  2425.                         add edi,3
  2426.                         add esi,4
  2427.                         loop @b
  2428.                 add edi,ebx
  2429.                 add esi,[lost_bytes] ;¤®¡ ¢«ï¥¬ ¡ ©âë, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî £à ­¨æã
  2430.                 dec edx
  2431.                 cmp edx,0
  2432.                 jg .copy_1
  2433.  
  2434.         .copy_end:
  2435.         popad
  2436.         ret
  2437. endp
  2438.  
  2439. ;input:
  2440. ; ebx - color1 (24b)
  2441. ; esi = pointer to transparent (8b)
  2442. ; edi = pointer to background color2 (24b)
  2443. ;output:
  2444. ; [edi] = combine color (24b)
  2445. align 4
  2446. combine_colors_2:
  2447.         push ebx cx
  2448.         movzx cx,byte[esi] ;pro
  2449.         cmp cx,255
  2450.         je .end_f
  2451.         or cx,cx
  2452.         jnz @f
  2453.                 mov [edi],bx
  2454.                 shr ebx,16
  2455.                 mov [edi+2],bl
  2456.                 jmp .end_f
  2457. align 4
  2458.         @@:
  2459.         inc cx
  2460.         push ax dx si
  2461.         mov si,0x0100 ;---get transparent---
  2462.         sub si,cx ;256-pro
  2463.  
  2464.                 ;---blye---
  2465.                 movzx ax,bl
  2466.                 shr ebx,8
  2467.                 imul ax,si
  2468.                 movzx dx,byte[edi]
  2469.                 imul dx,cx
  2470.                 add ax,dx
  2471.                 mov byte[edi],ah
  2472.                 ;---green---
  2473.                 movzx ax,bl
  2474.                 shr ebx,8
  2475.                 imul ax,si
  2476.                 movzx dx,byte[edi+1]
  2477.                 imul dx,cx
  2478.                 add ax,dx
  2479.                 mov byte[edi+1],ah
  2480.                 ;---red---
  2481.                 movzx ax,bl
  2482.                 imul ax,si
  2483.                 movzx dx,byte[edi+2]
  2484.                 imul dx,cx
  2485.                 add ax,dx
  2486.                 mov byte[edi+2],ah
  2487.         pop si dx ax
  2488. .end_f:
  2489.         pop cx ebx
  2490.         ret
  2491.  
  2492. ;äã­ªæ¨ï ª®¯¨àã¥â ¨§®¡à ¦¥­¨¥ ¨§ ¡ãä¥à  buf_source (8b) ¢ buf_destination (24b)
  2493. ; 㪠§ë¢ îâáï ª®®à¤¨­ âë ¢áâ ¢ª¨ ¡ãä¥à  buf_source ®â­®á¨â¥«ì­® buf_destination
  2494. align 4
  2495. proc buf_bit_blt_alpha, buf_destination:dword, coord_x:dword, coord_y:dword, buf_source:dword, color:dword
  2496.         locals
  2497.                 lost_bytes dd ? ;ç¨á«® ¯®â¥àï­­ëå ¡ ©â®¢ ¢ áâப¥ ª®¯¨à㥬®£® ¨§®¡à ¦¥­ï (â¥å çâ® ­¥ ¢« §ïâ ¢ ¡ãä¥à)
  2498.                 dest_w_bytes dd ? ;ª®««¨ç¥á⢮ ¡ ©â ¢ ¡ãä¥à¥ ¯à¨¥¬­¨ª¥ ¯® è¨à¨­¥ - è¨à¨­  ¢áâ ¢«ï¥¬®© ª à⨭ª¨
  2499.         endl
  2500.         pushad
  2501.  
  2502.         mov edi,[buf_source]
  2503.         cmp buf2d_bits,8
  2504.         jne .error1 ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2505.         mov eax,buf2d_w ;è¨à¨­  ª®¯¨à㥬®© ª à⨭ª¨
  2506.         mov edx,buf2d_h ;¢ëá®â  ª®¯¨à㥬®© ª à⨭ª¨
  2507.         mov esi,buf2d_data ;¤ ­­ë¥ ª®¯¨à㥬®© ª à⨭ª¨
  2508.  
  2509.         mov edi,[buf_destination]
  2510.         cmp buf2d_bits,24
  2511.         jne .error2 ;ä®à¬ â ¡ãä¥à  ­¥ ¯®®¤¥à¦¨¢ ¥âáï
  2512.         mov ebx,[coord_x] ;¢ ebx ¢à¥¬¥­­® áâ ¢¨¬ ®âáâ㯠¨§®¡à ¦¥­¨ï (¤«ï ¯à®¢¥àª¨)
  2513.         cmp ebx,buf2d_w   ;¯à®¢¥à塞 ¢« §¨â «¨ ¨§®¡à ¦¥­¨¥ ¯® è¨à¨­¥
  2514.         jge .copy_end     ;¥á«¨ ¨§®¡à ¦¥­¨¥ ¯®«­®áâìî ¢ë« §¨â §  ¯à ¢ãî áâ®à®­ã
  2515.                 mov ebx,buf2d_h ;ebx - ¢ëá®â  ®á­®¢­®£® ¡ãä¥à 
  2516.                 mov ecx,[coord_y]
  2517.                 cmp ecx,0
  2518.                 jge @f
  2519.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<0 (1-ï ­ áâனª )
  2520.                         add edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨
  2521.                         cmp edx,0
  2522.                         jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî ­ ¤ ¢¥àå­¥© £à ­¨æ¥© ¡ãä¥à  (coord_y<0 ¨ |coord_y|>buf_source.h)
  2523.                         neg ecx
  2524.                         imul ecx,eax
  2525.                         add esi,ecx ;ᤢ¨£ ¥¬ 㪠§ â¥«ì á ª®¯¨à㥬묨 ¤ ­­ë¬¨, á ãç¥â®¬ ¯à®¯ã襭®© ç áâ¨
  2526.                         xor ecx,ecx ;®¡­ã«ï¥¬ ª®®à¤¨­ âã coord_y
  2527.                 @@:
  2528.                 cmp ecx,ebx
  2529.                 jge .copy_end ;¥á«¨ ª®®à¤¨­ â  'y' ¡®«ìè¥ ¢ëá®âë ¡ãä¥à 
  2530.                 add ecx,edx ;ecx - ­¨¦­ïï ª®®à¤¨­ â  ª®¯¨à㥬®© ª à⨭ª¨
  2531.                 cmp ecx,ebx
  2532.                 jle @f
  2533.                         sub ecx,ebx
  2534.                         sub edx,ecx ;㬥­ìè ¥¬ ¢ëá®âã ª®¯¨à㥬®© ª à⨭ª¨, ¢ á«ãç¥ ª®£¤  ®­  ¢ë« §¨â §  ­¨¦­îî £à ­¨æã
  2535.                 @@:
  2536.                 mov ebx,buf2d_w
  2537.                 mov ecx,[coord_y] ;ecx ¨á¯®«ì§ã¥¬ ¤«ï ¢à¥¬¥­­ëå 楫¥©
  2538.                 cmp ecx,0
  2539.                 jg .end_otr_c_y
  2540.                         ;¥á«¨ ª®®à¤¨­ â  coord_y<=0 (2-ï ­ áâனª )
  2541.                         mov ecx,[coord_x]
  2542.                         jmp @f
  2543.                 .end_otr_c_y:
  2544.                 imul ecx,ebx
  2545.                 add ecx,[coord_x]
  2546.                 @@:
  2547.                 lea ecx,[ecx+ecx*2]
  2548.                 add ecx,buf2d_data ;buf2d_data ¤ ­­ë¥ ®á­®¢­®£® ¡ãä¥à 
  2549.                 sub ebx,eax ;ebx - è¨à¨­  ®á­®¢­®£® ¡ãä¥à  ¬¨­ãá è¨à¨­  à¨á㥬®£® ¡ãä¥à 
  2550.                 mov edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2551.  
  2552.         mov dword[lost_bytes],0
  2553.         mov ecx,[coord_x]
  2554.         cmp ecx,0
  2555.         jge @f
  2556.                 neg ecx
  2557.                 cmp eax,ecx ;eax - è¨à¨­  ª®¯¨à㥬®© ª à⨭ª¨
  2558.                 jle .copy_end ;¥á«¨ ª®¯¨à㥬®¥ ¨§®¡à ¦¥­¨¥ ­ å®¤¨âáï ¯®«­®áâìî §  «¥¢®© £à ­¨æ¥© ¡ãä¥à  (coord_x<0 ¨ |coord_x|>buf_source.w)
  2559.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2560.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2561.                 mov [lost_bytes],ecx
  2562.                 add esi,ecx
  2563.                 lea ecx,[ecx+ecx*2]
  2564.                 add edi,ecx ;edi 㪠§ â¥«ì ­  ¤ ­­ë¥ ¡ãä¥à , ªã¤  ¡ã¤¥â ¯à®¨§¢®¤¨âáï ª®¯¨à®¢ ­¨¥
  2565.                 xor ecx,ecx
  2566.         @@:
  2567.         cmp ecx,ebx
  2568.         jle @f
  2569.                 sub ecx,ebx
  2570.                 sub eax,ecx ;㪮à ç¨¢ ¥¬ ª®¯¨à㥬ãî áâபã
  2571.                 add ebx,ecx ;㤫¨­­ï¥¬ áâப㠤«ï ᤢ¨£  £« ¢­®© ª à⨭ª¨ ¡ãä¥à 
  2572.                 ;ecx - ç¨á«® ¯¨ªá¥«¥© ¢ 1-© áâப¥ ª à⨭ª¨, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî áâ®à®­ã
  2573.                 add [lost_bytes],ecx
  2574.         @@:
  2575.  
  2576.         lea ebx,[ebx+ebx*2] ;ª®««¨ç¥á⢮ ¡ ©â ¢ 1-© áâப¥ ¡ãä¥à  ¬¨­ãá ç¨á«® ¡ ©â ¢ 1-© áâப¥ ª®¯¨à㥬®© ª à⨭ª¨
  2577.         mov [dest_w_bytes],ebx
  2578.         mov ebx,[color]
  2579.  
  2580.         cld
  2581.         cmp dword[lost_bytes],0
  2582.         jg .copy_1
  2583.         .copy_0: ;¯à®á⮥ ª®¯¨à®¢ ­¨¥
  2584.                 mov ecx,eax
  2585.                 @@:
  2586.                         call combine_colors_2
  2587.                         add edi,3
  2588.                         inc esi
  2589.                         loop @b
  2590.                 add edi,[dest_w_bytes]
  2591.                 dec edx
  2592.                 cmp edx,0
  2593.                 jg .copy_0
  2594.         jmp .copy_end
  2595.         .copy_1: ;­¥ ¯à®á⮥ ª®¯¨à®¢ ­¨¥ (ª à⨭ª  ¢ë« §¨â §  «¥¢ãî ¨/¨«¨ ¯à ¢ãî áâ®à®­ã)
  2596.                 mov ecx,eax
  2597.                 @@:
  2598.                         call combine_colors_2
  2599.                         add edi,3
  2600.                         inc esi
  2601.                         loop @b
  2602.                 add edi,[dest_w_bytes]
  2603.                 add esi,[lost_bytes] ;¤®¡ ¢«ï¥¬ ¡ ©âë, ª®â®àë¥ ¢ë« §ïâ §  ¯à ¢ãî £à ­¨æã
  2604.                 dec edx
  2605.                 cmp edx,0
  2606.                 jg .copy_1
  2607.  
  2608.         jmp .copy_end
  2609.         .error1:
  2610.                 stdcall print_err,sz_buf2d_bit_blt_alpha,txt_err_n8b
  2611.                 jmp .copy_end
  2612.         .error2:
  2613.                 stdcall print_err,sz_buf2d_bit_blt_alpha,txt_err_n24b
  2614.         .copy_end:
  2615.         popad
  2616.         ret
  2617. endp
  2618.  
  2619. align 4
  2620. proc print_err, fun:dword, mes:dword ;¢ë¢®¤¨¬ á®®¡é¥­¨¥ ®¡ 訡ª¥ ­  ¤®áªã ®â« ¤ª¨
  2621.         pushad
  2622.         mov eax,63
  2623.         mov ebx,1
  2624.  
  2625.         mov esi,[fun]
  2626.         @@:
  2627.                 mov cl,byte[esi]
  2628.                 int 0x40
  2629.                 inc esi
  2630.                 cmp byte[esi],0
  2631.                 jne @b
  2632.         mov cl,':'
  2633.         int 0x40
  2634.         mov cl,' '
  2635.         int 0x40
  2636.         mov esi,[mes]
  2637.         @@:
  2638.                 mov cl,byte[esi]
  2639.                 int 0x40
  2640.                 inc esi
  2641.                 cmp byte[esi],0
  2642.                 jne @b
  2643.         popad
  2644.         ret
  2645. endp
  2646.  
  2647. ;䨫ìâà
  2648. align 4
  2649. proc buf_filter_dither, buffer:dword, algor:dword
  2650.         pushad
  2651.         mov edi,[buffer]
  2652.         cmp buf2d_bits,24
  2653.         jne .error
  2654.                 mov edx,buf2d_w
  2655.                 mov esi,buf2d_h
  2656.                 mov edi,buf2d_data
  2657. ;edi - pointer to 24bit bitmap
  2658. ;edx - x size
  2659. ;esi - y size
  2660.                 lea   edx,[edx+edx*2]
  2661.                 imul  esi,edx
  2662.  
  2663.                 ;®¯à¥¤¥«ï¥¬ ª ª®©  «£®à¨â¬ ¨á¯®«ì§®¢ âì
  2664.                 cmp dword[algor],0
  2665.                 jne @f
  2666.                         call dither_0
  2667.                         jmp .dither_end
  2668.                 @@:
  2669.                 cmp dword[algor],1
  2670.                 jne @f
  2671.                         call dither_1
  2672.                         jmp .dither_end
  2673.                 @@:
  2674.                 cmp dword[algor],2
  2675.                 jne @f
  2676.                         call dither_2
  2677.                         jmp .dither_end
  2678.                 @@:
  2679.                 cmp dword[algor],3
  2680.                 jne @f
  2681.                         call dither_3
  2682.                         jmp .dither_end
  2683.                 @@:
  2684.                 call dither_4
  2685.                 jmp .dither_end
  2686.         .error:
  2687.                 stdcall print_err,sz_buf2d_filter_dither,txt_err_n24b
  2688.         .dither_end:
  2689.         popad
  2690.         ret
  2691. endp
  2692.  
  2693. align 16
  2694. dither_0: ; Sierra Filter Lite algorithm
  2695. newp_0:   ; Dithering cycle
  2696.         xor   ebx,ebx ; At first threshold
  2697.         movzx ecx,byte[edi]
  2698.         cmp   cl,255
  2699.         je    newp_0.next
  2700.         test  cl,cl
  2701.         jz    newp_0.next
  2702.         jns   @f
  2703.         dec   ebx
  2704.         sub   ecx,255
  2705. @@:
  2706.         mov   [edi],bl               ; putpixel
  2707.  
  2708.         sar   ecx,1                  ; error/2
  2709.         ;adc   ecx,0                  ; round to integer
  2710.  
  2711.         movzx eax,byte[edi+3]        ; pixel (x+1;y)
  2712.         add   eax,ecx                ; add error/2 to (x+1;y)
  2713.         jge   @f                     ; check_overflow
  2714.         xor   eax,eax
  2715.         jmp   .ok
  2716. @@:
  2717.         cmp   eax,255
  2718.         jle   .ok
  2719.         or    al,255
  2720. .ok:
  2721.         mov   [edi+3],al             ; putpixel
  2722.  
  2723.         sar   ecx,1                  ; error/4
  2724.         adc   ecx,0                  ; round to integer
  2725.  
  2726.         movzx eax,byte[edi+edx-3]    ; pixel (x-1;y+1)
  2727.         add   eax,ecx                ; add error/4 to (x-1;y+1)
  2728.         jge   @f                     ; check_overflow
  2729.         xor   eax,eax
  2730.         jmp   .ok1
  2731. @@:
  2732.         cmp   eax,255
  2733.         jle   .ok1
  2734.         or    al,255
  2735. .ok1:
  2736.         mov   [edi+edx-3],al         ; putpixel
  2737.  
  2738.         movzx eax,byte[edi+edx]      ; pixel (x;y+1)
  2739.         add   eax,ecx                ; add error/4 to (x;y+1)
  2740.         jge   @f                     ; check_overflow
  2741.         xor   eax,eax
  2742.         jmp   .ok2
  2743. @@:
  2744.         cmp   eax,255
  2745.         jle   .ok2
  2746.         or    al,255
  2747. .ok2:
  2748.         mov   [edi+edx],al           ; putpixel
  2749.  
  2750. .next:
  2751.         inc   edi
  2752.         dec   esi
  2753.         jnz   newp_0
  2754.         ret
  2755.  
  2756. align 16
  2757. dither_1: ; Floyd-Steinberg algorithm
  2758. newp_1:   ; Dithering cycle
  2759.         xor   ebx,ebx ; At first threshold
  2760.         movzx ecx,byte[edi]
  2761.         cmp   cl,255
  2762.         je    newp_1.next
  2763.         test  cl,cl
  2764.         jz    newp_1.next
  2765.         jns   @f
  2766.         dec   ebx
  2767.         sub   ecx,255
  2768. @@:
  2769.         mov   [edi],bl               ; putpixel
  2770.  
  2771.         sar   ecx,4                  ; error/16
  2772.         adc   ecx,0                  ; round to integer
  2773.         mov   ebx,ecx
  2774.  
  2775.         movzx eax,byte[edi+edx+3]    ; pixel (x+1;y+1)
  2776.         add   eax,ecx                ; add error/16 to (x+1;y+1)
  2777.         jge   @f                     ; check_overflow
  2778.         xor   eax,eax
  2779.         jmp   .ok
  2780. @@:
  2781.         cmp   eax,255
  2782.         jle   .ok
  2783.         or    al,255
  2784. .ok:
  2785.         mov   [edi+edx+3],al         ;putpixel
  2786.  
  2787.         imul  ecx,3
  2788.         movzx eax,byte[edi+edx-3]    ; pixel (x-1;y+1)
  2789.         add   eax,ecx                ; add 3*error/16 to (x-1;y+1)
  2790.         jge   @f                     ; check_overflow
  2791.         xor   eax,eax
  2792.         jmp   .ok1
  2793. @@:
  2794.         cmp   eax,255
  2795.         jle   .ok1
  2796.         or    al,255
  2797. .ok1:
  2798.         mov   [edi+edx-3],al         ;putpixel
  2799.  
  2800.         mov   ecx,ebx
  2801.         imul  ecx,5
  2802.         movzx eax,byte[edi+edx]      ; pixel (x;y+1)
  2803.         add   eax,ecx                ; add 5*error/16 to (x;y+1)
  2804.         jge   @f                     ; check_overflow
  2805.         xor   eax,eax
  2806.         jmp   .ok2
  2807. @@:
  2808.         cmp   eax,255
  2809.         jle   .ok2
  2810.         or    al,255
  2811. .ok2:
  2812.         mov   [edi+edx],al           ;putpixel
  2813.  
  2814.         mov   ecx,ebx
  2815.         imul  ecx,7
  2816.         movzx eax,byte[edi+3]        ; pixel (x+1;y)
  2817.         add   eax,ecx                ; add 7*error/16 to (x+1;y)
  2818.         jge   @f                     ; check_overflow
  2819.         xor   eax,eax
  2820.         jmp   .ok3
  2821. @@:
  2822.         cmp   eax,255
  2823.         jle   .ok3
  2824.         or    al,255
  2825. .ok3:
  2826.         mov   [edi+3],al             ;putpixel
  2827.  
  2828. .next:
  2829.         inc  edi
  2830.         dec  esi
  2831.         jnz  newp_1
  2832.         ret
  2833.  
  2834. align 16
  2835. dither_2: ; Burkes algorithm
  2836. newp_2:   ; Dithering cycle
  2837.         xor   ebx,ebx ; At first threshold
  2838.         movsx ecx,byte[edi]
  2839.         cmp   cl,255
  2840.         je    newp_2.next
  2841.         test  cl,cl
  2842.         jz    newp_2.next
  2843.         jns   @f
  2844.         dec   ebx
  2845. @@:
  2846.         mov   [edi],bl               ; putpixel
  2847.  
  2848.         sar   ecx,2                  ; error/4
  2849.         adc   ecx,0                  ; round to integer
  2850.  
  2851.         movzx eax,byte[edi+3]        ; pixel (x+1;y)
  2852.         add   eax,ecx                ; add error/4 to (x+1;y)
  2853.         jge   @f                     ; check_overflow
  2854.         xor   eax,eax
  2855.         jmp   .ok
  2856. @@:
  2857.         cmp   eax,255
  2858.         jle   .ok
  2859.         or    al,255
  2860. .ok:
  2861.         mov   [edi+3],al             ; putpixel
  2862.  
  2863.         movzx eax,byte[edi+edx]      ; pixel (x;y+1)
  2864.         add   eax,ecx                ; add error/4 to (x;y+1)
  2865.         jge   @f                     ; check_overflow
  2866.         xor   eax,eax
  2867.         jmp   .ok1
  2868. @@:
  2869.         cmp   eax,255
  2870.         jle   .ok1
  2871.         or    al,255
  2872. .ok1:
  2873.         mov   [edi+edx],al           ; putpixel
  2874.  
  2875.         sar   ecx,1                  ; error/8
  2876.         adc   ecx,0                  ; round to integer
  2877.  
  2878.         movzx eax,byte[edi+6]        ; pixel (x+2;y)
  2879.         add   eax,ecx                ; add error/8 to (x+2;y)
  2880.         jge   @f                     ; check_overflow
  2881.         xor   eax,eax
  2882.         jmp   .ok2
  2883. @@:
  2884.         cmp   eax,255
  2885.         jle   .ok2
  2886.         or    al,255
  2887. .ok2:
  2888.         mov   [edi+6],al             ; putpixel
  2889.  
  2890.         movzx eax,byte[edi+edx-3]    ; pixel (x-1;y+1)
  2891.         add   eax,ecx                ; add error/8 to (x-1;y+1)
  2892.         jge   @f                     ; check_overflow
  2893.         xor   eax,eax
  2894.         jmp   .ok3
  2895. @@:
  2896.         cmp   eax,255
  2897.         jle   .ok3
  2898.         or    al,255
  2899. .ok3:
  2900.         mov   [edi+edx-3],al         ; putpixel
  2901.  
  2902.         movzx eax,byte[edi+edx+3]    ; pixel (x+1;y+1)
  2903.         add   eax,ecx                ; add error/8 to (x+1;y+1)
  2904.         jge   @f                     ; check_overflow
  2905.         xor   eax,eax
  2906.         jmp   .ok4
  2907. @@:
  2908.         cmp   eax,255
  2909.         jle   .ok4
  2910.         or    al,255
  2911. .ok4:
  2912.         mov   [edi+edx+3],al         ; putpixel
  2913.  
  2914.         sar   ecx,1                  ; error/16
  2915.         ;adc   ecx,0                  ; round to integer
  2916.  
  2917.         movzx eax,byte[edi+edx-6]    ; pixel (x-2;y+1)
  2918.         add   eax,ecx                ; add error/16 to (x-2;y+1)
  2919.         jge   @f                     ; check_overflow
  2920.         xor   eax,eax
  2921.         jmp   .ok5
  2922. @@:
  2923.         cmp   eax,255
  2924.         jle   .ok5
  2925.         or    al,255
  2926. .ok5:
  2927.         mov   [edi+edx-6],al         ; putpixel
  2928.  
  2929.         movzx eax,byte[edi+edx+6]    ; pixel (x+2;y+1)
  2930.         add   eax,ecx                ; add error/16 to (x+2;y+1)
  2931.         jge   @f                     ; check_overflow
  2932.         xor   eax,eax
  2933.         jmp   .ok6
  2934. @@:
  2935.         cmp   eax,255
  2936.         jle   .ok6
  2937.         or    al,255
  2938. .ok6:
  2939.         mov   [edi+edx+6],al         ; putpixel
  2940.  
  2941. .next:
  2942.         inc   edi
  2943.         dec   esi
  2944.         jnz   newp_2
  2945.         ret
  2946.  
  2947.  
  2948. align 16
  2949. dither_3:                        ; Heavyiron_mod algorithm
  2950.  newp_3:                         ; Dithering cycle
  2951.     xor   ebx,ebx                ; At first threshold
  2952.     movzx ecx,byte[edi]
  2953.     cmp   cl,255
  2954.     je   .next
  2955.     test  cl,cl
  2956.     jz    .next
  2957.     jns   @f
  2958.     dec   ebx
  2959.     sub   ecx,255
  2960.   @@:
  2961.     mov   [edi],bl               ; putpixel
  2962.  
  2963.     sar   ecx,2                  ; error/4
  2964.  
  2965.     movzx eax,byte[edi+3]        ; pixel (x+1;y)
  2966.     add   eax,ecx                ; add error/4 to (x+1;y)
  2967.     jge   @f                     ; check_overflow
  2968.     xor   eax,eax
  2969.     jmp   .ok
  2970.   @@:
  2971.     cmp   eax,255
  2972.     jle   .ok
  2973.     or    al,255
  2974.   .ok:
  2975.     mov   [edi+3],al             ; putpixel
  2976.  
  2977.     movzx eax,byte[edi+edx-3]    ; pixel (x-1;y+1)
  2978.     add   eax,ecx                ; add error/4 to (x-1;y+1)
  2979.     jge   @f                     ; check_overflow
  2980.     xor   eax,eax
  2981.     jmp   .ok1
  2982.   @@:
  2983.     cmp   eax,255
  2984.     jle   .ok1
  2985.     or    al,255
  2986.   .ok1:
  2987.     mov   [edi+edx-3],al         ; putpixel
  2988.  
  2989.     movzx eax,byte[edi+edx]      ; pixel (x;y+1)
  2990.     add   eax,ecx                ; add error/4 to (x;y+1)
  2991.     jge   @f                     ; check_overflow
  2992.     xor   eax,eax
  2993.     jmp   .ok2
  2994.   @@:
  2995.     cmp   eax,255
  2996.     jle   .ok2
  2997.     or    al,255
  2998.   .ok2:
  2999.     mov   [edi+edx],al           ; putpixel
  3000.  
  3001.   .next:
  3002.     inc   edi
  3003.     dec   esi
  3004.     jnz   newp_3
  3005.     ret
  3006.  
  3007. align 16
  3008. dither_4:                        ; Atkinson algorithm
  3009.  newp_4:                         ; Dithering cycle
  3010.  
  3011.     xor   ebx,ebx                ; At first threshold
  3012.     movsx ecx,byte[edi]
  3013.     cmp   cl,255
  3014.     je   .next
  3015.     test  cl,cl
  3016.     jz    .next
  3017.     jns   @f
  3018.     dec   ebx
  3019.   @@:
  3020.     mov   [edi],bl               ; putpixel
  3021.  
  3022.     sar   ecx,3                  ; error/8
  3023.  
  3024.     movzx eax,byte[edi+3]        ; pixel (x+1;y)
  3025.     add   eax,ecx                ; add error/8 to (x+1;y)
  3026.     jge   @f                     ; check_overflow
  3027.     xor   eax,eax
  3028.     jmp   .ok
  3029.   @@:
  3030.     cmp   eax,255
  3031.     jle   .ok
  3032.     or    al,255
  3033.   .ok:
  3034.     mov   [edi+3],al             ; putpixel
  3035.  
  3036.     movzx eax,byte[edi+edx]      ; pixel (x;y+1)
  3037.     add   eax,ecx                ; add error/8 to (x;y+1)
  3038.     jge   @f                     ; check_overflow
  3039.     xor   eax,eax
  3040.     jmp   .ok1
  3041.   @@:
  3042.     cmp   eax,255
  3043.     jle   .ok1
  3044.     or    al,255
  3045.   .ok1:
  3046.     mov   [edi+edx],al           ; putpixel
  3047.  
  3048.     movzx eax,byte[edi+6]        ; pixel (x+2;y)
  3049.     add   eax,ecx                ; add error/8 to (x+2;y)
  3050.     jge   @f                     ; check_overflow
  3051.     xor   eax,eax
  3052.     jmp   .ok2
  3053.   @@:
  3054.     cmp   eax,255
  3055.     jle   .ok2
  3056.     or    al,255
  3057.   .ok2:
  3058.     mov   [edi+6],al             ; putpixel
  3059.  
  3060.     movzx eax,byte[edi+edx-3]    ; pixel (x-1;y+1)
  3061.     add   eax,ecx                ; add error/8 to (x-1;y+1)
  3062.     jge   @f                     ; check_overflow
  3063.     xor   eax,eax
  3064.     jmp   .ok3
  3065.   @@:
  3066.     cmp   eax,255
  3067.     jle   .ok3
  3068.     or    al,255
  3069.   .ok3:
  3070.     mov   [edi+edx-3],al         ; putpixel
  3071.  
  3072.     movzx eax,byte[edi+edx+3]    ; pixel (x+1;y+1)
  3073.     add   eax,ecx                ; add error/8 to (x+1;y+1)
  3074.     jge   @f                     ; check_overflow
  3075.     xor   eax,eax
  3076.     jmp   .ok4
  3077.   @@:
  3078.     cmp   eax,255
  3079.     jle   .ok4
  3080.     or    al,255
  3081.   .ok4:
  3082.     mov   [edi+edx+3],al         ; putpixel
  3083.  
  3084.  
  3085.     movzx eax,byte[edi+edx+edx]    ; pixel (x;y+2)
  3086.     add   eax,ecx                ; add error/8 to (x;y+2)
  3087.     jge   @f                     ; check_overflow
  3088.     xor   eax,eax
  3089.     jmp   .ok5
  3090.   @@:
  3091.     cmp   eax,255
  3092.     jle   .ok5
  3093.     or    al,255
  3094.   .ok5:
  3095.     mov   [edi+edx+edx],al         ; putpixel
  3096.  
  3097.   .next:
  3098.     inc   edi
  3099.     dec   esi
  3100.     jnz   newp_4
  3101.     ret
  3102.  
  3103.  
  3104.  
  3105. include 'fun_voxel.inc' ;ä㭪樨 ¤«ï à ¡®âë á ¢®ªá¥«ì­®© £à ä¨ª®©
  3106.  
  3107. txt_err_size_0 db 'image size < 1 pixel',13,10,0
  3108. txt_err_n8b db 'need buffer 8 bit',13,10,0
  3109. txt_err_n24b db 'need buffer 24 bit',13,10,0
  3110. txt_err_n32b db 'need buffer 32 bit',13,10,0
  3111. txt_err_n8_24b db 'need buffer 8 or 24 bit',13,10,0
  3112.  
  3113. align 16
  3114. EXPORTS:
  3115.         dd sz_lib_init, lib_init
  3116.         dd sz_buf2d_create, buf_create
  3117.         dd sz_buf2d_create_f_img, buf_create_f_img
  3118.         dd sz_buf2d_clear, buf_clear
  3119.         dd sz_buf2d_draw, buf_draw_buf
  3120.         dd sz_buf2d_delete, buf_delete
  3121.         dd sz_buf2d_resize, buf_resize
  3122.         dd sz_buf2d_rotate, buf_rotate
  3123.         dd sz_buf2d_line, buf_line_brs
  3124.         dd sz_buf2d_line_sm, buf_line_brs_sm
  3125.         dd sz_buf2d_rect_by_size, buf_rect_by_size
  3126.         dd sz_buf2d_filled_rect_by_size, buf_filled_rect_by_size
  3127.         dd sz_buf2d_circle, buf_circle
  3128.         dd sz_buf2d_img_hdiv2, buf_img_hdiv2
  3129.         dd sz_buf2d_img_wdiv2, buf_img_wdiv2
  3130.         dd sz_buf2d_conv_24_to_8, buf_conv_24_to_8
  3131.         dd sz_buf2d_conv_24_to_32, buf_conv_24_to_32
  3132.         dd sz_buf2d_bit_blt, buf_bit_blt
  3133.         dd sz_buf2d_bit_blt_transp, buf_bit_blt_transp
  3134.         dd sz_buf2d_bit_blt_alpha, buf_bit_blt_alpha
  3135.         dd sz_buf2d_curve_bezier, buf_curve_bezier
  3136.         dd sz_buf2d_convert_text_matrix, buf_convert_text_matrix
  3137.         dd sz_buf2d_draw_text, buf_draw_text
  3138.         dd sz_buf2d_crop_color, buf_crop_color
  3139.         dd sz_buf2d_offset_h, buf_offset_h
  3140.         dd sz_buf2d_flood_fill, buf_flood_fill
  3141.         dd sz_buf2d_set_pixel, buf_set_pixel
  3142.         dd sz_buf2d_get_pixel, buf_get_pixel
  3143.         dd sz_buf2d_flip_h, buf_flip_h
  3144.         dd sz_buf2d_flip_v, buf_flip_v
  3145.         dd sz_buf2d_filter_dither, buf_filter_dither
  3146.         dd sz_buf2d_vox_brush_create, vox_brush_create
  3147.         dd sz_buf2d_vox_brush_delete, vox_brush_delete
  3148.         dd sz_buf2d_vox_obj_get_img_w_3g, buf_vox_obj_get_img_w_3g
  3149.         dd sz_buf2d_vox_obj_get_img_h_3g, buf_vox_obj_get_img_h_3g
  3150.         dd sz_buf2d_vox_obj_draw_1g, buf_vox_obj_draw_1g
  3151.         dd sz_buf2d_vox_obj_draw_3g, buf_vox_obj_draw_3g
  3152.         dd sz_buf2d_vox_obj_draw_3g_scaled, buf_vox_obj_draw_3g_scaled
  3153.         dd sz_buf2d_vox_obj_draw_pl, buf_vox_obj_draw_pl
  3154.         dd sz_buf2d_vox_obj_draw_pl_scaled, buf_vox_obj_draw_pl_scaled
  3155.         dd sz_buf2d_vox_obj_draw_3g_shadows, buf_vox_obj_draw_3g_shadows
  3156.         dd 0,0
  3157.         sz_lib_init db 'lib_init',0
  3158.         sz_buf2d_create db 'buf2d_create',0
  3159.         sz_buf2d_create_f_img db 'buf2d_create_f_img',0
  3160.         sz_buf2d_clear db 'buf2d_clear',0 ;®ç¨á⪠ ¡ãä¥à  㪠§ ­­ë¬ 梥⮬
  3161.         sz_buf2d_draw db 'buf2d_draw',0
  3162.         sz_buf2d_delete db 'buf2d_delete',0
  3163.         sz_buf2d_resize db 'buf2d_resize',0
  3164.         sz_buf2d_rotate db 'buf2d_rotate',0
  3165.         sz_buf2d_line db 'buf2d_line',0 ;à¨á®¢ ­¨¥ «¨­¨¨
  3166.         sz_buf2d_line_sm db 'buf2d_line_sm',0 ;à¨á®¢ ­¨¥ ᣫ ¦¥­­®© «¨­¨¨
  3167.         sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0 ;à¨á®¢ ­¨¥ à ¬ª¨ ¯àאַ㣮«ì­¨ª , 2-ï ª®®à¤¨­ â  § ¤ ­  ¯® à §¬¥àã
  3168.         sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0 ;à¨á®¢ ­¨¥ § «¨â®£® ¯àאַ㣮«ì­¨ª , 2-ï ª®®à¤¨­ â  § ¤ ­  ¯® à §¬¥àã
  3169.         sz_buf2d_circle db 'buf2d_circle',0 ;à¨á®¢ ­¨¥ ®ªà㦭®áâ¨
  3170.         sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0 ;ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® ¢ëá®â¥ ¢ 2 à §  (à §¬¥à ¡ãä¥à  ­¥ ¬¥­ï¥âáï)
  3171.         sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0 ;ᦠ⨥ ¨§®¡à ¦¥­¨ï ¯® è¨à¨­¥ ¢ 2 à §  (à §¬¥à ¡ãä¥à  ­¥ ¬¥­ï¥âáï)
  3172.         sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
  3173.         sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0
  3174.         sz_buf2d_bit_blt db 'buf2d_bit_blt',0
  3175.         sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0
  3176.         sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0
  3177.         sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0
  3178.         sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
  3179.         sz_buf2d_draw_text db 'buf2d_draw_text',0
  3180.         sz_buf2d_crop_color db 'buf2d_crop_color',0
  3181.         sz_buf2d_offset_h db 'buf2d_offset_h',0
  3182.         sz_buf2d_flood_fill db 'buf2d_flood_fill',0
  3183.         sz_buf2d_set_pixel db 'buf2d_set_pixel',0
  3184.         sz_buf2d_get_pixel db 'buf2d_get_pixel',0
  3185.         sz_buf2d_flip_h db 'buf2d_flip_h',0
  3186.         sz_buf2d_flip_v db 'buf2d_flip_v',0
  3187.         sz_buf2d_filter_dither db 'buf2d_filter_dither',0
  3188.         sz_buf2d_vox_brush_create db 'buf2d_vox_brush_create',0
  3189.         sz_buf2d_vox_brush_delete db 'buf2d_vox_brush_delete',0
  3190.         sz_buf2d_vox_obj_get_img_w_3g db 'buf2d_vox_obj_get_img_w_3g',0
  3191.         sz_buf2d_vox_obj_get_img_h_3g db 'buf2d_vox_obj_get_img_h_3g',0
  3192.         sz_buf2d_vox_obj_draw_1g db 'buf2d_vox_obj_draw_1g',0
  3193.         sz_buf2d_vox_obj_draw_3g db 'buf2d_vox_obj_draw_3g',0
  3194.         sz_buf2d_vox_obj_draw_3g_scaled db 'buf2d_vox_obj_draw_3g_scaled',0
  3195.         sz_buf2d_vox_obj_draw_pl db 'buf2d_vox_obj_draw_pl',0
  3196.         sz_buf2d_vox_obj_draw_pl_scaled db 'buf2d_vox_obj_draw_pl_scaled',0
  3197.         sz_buf2d_vox_obj_draw_3g_shadows db 'buf2d_vox_obj_draw_3g_shadows',0
  3198.