Subversion Repositories Kolibri OS

Rev

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

  1. ;;============================================================================;;
  2. ;;//// convert.asm //// (c) dunkaist, 2012,2016,2017,2020,2022 ///////////////;;
  3. ;;============================================================================;;
  4. ;;                                                                            ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).              ;;
  6. ;;                                                                            ;;
  7. ;; SPDX-License-Identifier: LGPL-2.1-or-later                                 ;;
  8. ;;                                                                            ;;
  9. ;; Libs-Dev is free software: you can redistribute it and/or modify it under  ;;
  10. ;; the terms of the GNU Lesser General Public License as published by the     ;;
  11. ;; Free Software Foundation, either version 2.1 of the License, or (at your   ;;
  12. ;; option) any later version.                                                 ;;
  13. ;;                                                                            ;;
  14. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT    ;;
  15. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      ;;
  16. ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public        ;;
  17. ;; License for more details.                                                  ;;
  18. ;;                                                                            ;;
  19. ;; You should have received a copy of the GNU Lesser General Public License   ;;
  20. ;; along with Libs-Dev. If not, see <http://www.gnu.org/licenses/>.           ;;
  21. ;;                                                                            ;;
  22. ;;============================================================================;;
  23.  
  24.  
  25. ;;============================================================================;;
  26. proc img.convert _src, _dst, _dst_type, _flags, _param                        ;;
  27. ;;----------------------------------------------------------------------------;;
  28. ;? convert _image                                                             ;;
  29. ;;----------------------------------------------------------------------------;;
  30. ;> [_src]      = pointer to source image                                      ;;
  31. ;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
  32. ;> [_dst_type] = Image.Type of resulting image                                ;;
  33. ;> [_flags]    = see libimg.inc                                               ;;
  34. ;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
  35. ;;----------------------------------------------------------------------------;;
  36. ;< eax = 0 / pointer to converted image                                       ;;
  37. ;< ecx = error code / undefined                                               ;;
  38. ;;============================================================================;;
  39. locals
  40.         img     dd ?
  41.         prev    dd ?
  42. endl
  43.         push    ebx esi edi
  44.         mov     [img], 0
  45.         mov     [prev], 0
  46.         mov     ebx, [_src]
  47. @@:
  48.         mov     eax, [ebx + Image.Previous]
  49.         test    eax, eax
  50.         jz      .loop
  51.         mov     ebx, eax
  52.         jmp     @b
  53. .loop:
  54.         stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
  55.         test    eax, eax
  56.         jz      .error
  57.         cmp     [img], 0
  58.         jnz     @f
  59.         mov     [img], eax
  60. @@:
  61.         mov     ecx, [prev]
  62.         jecxz   @f
  63.         mov     [ecx + Image.Next], eax
  64.         mov     [eax + Image.Previous], ecx
  65. @@:
  66.         mov     [prev], eax
  67.         push    [ebx + Image.Flags]
  68.         pop     [eax + Image.Flags]
  69.         push    [ebx + Image.Delay]
  70.         pop     [eax + Image.Delay]
  71.         mov     ebx, [ebx + Image.Next]
  72.         test    ebx, ebx
  73.         jnz     .loop
  74.         mov     eax, [img]
  75. .error:
  76.         pop     edi esi ebx
  77.         ret
  78. endp
  79.  
  80.  
  81. ;;============================================================================;;
  82. proc img.convert.layer _src, _dst, _dst_type, _flags, _param                  ;;
  83. ;;----------------------------------------------------------------------------;;
  84. ;? convert _image layer                                                       ;;
  85. ;;----------------------------------------------------------------------------;;
  86. ;> [_src]      = pointer to source image                                      ;;
  87. ;> [_dst]      = pointer to destination image, or 0 to create a new one       ;;
  88. ;> [_dst_type] = Image.Type of resulting image                                ;;
  89. ;> [_flags]    = see libimg.inc                                               ;;
  90. ;> [_param]    = depends on _flags fields, see libimg.inc                     ;;
  91. ;;----------------------------------------------------------------------------;;
  92. ;< eax = 0 / pointer to converted image                                       ;;
  93. ;< ecx = error code / undefined                                               ;;
  94. ;;============================================================================;;
  95. locals
  96.         fun     rd 1
  97. endl
  98.         push    ebx esi edi
  99.  
  100.         mov     ebx, [_src]
  101.         mov     eax, [ebx + Image.Type]
  102.         mov     esi, [img.convert.table + 4*eax]
  103.         mov     ecx, LIBIMG_ERROR_BIT_DEPTH
  104. .next:
  105.         lodsd
  106.         test    eax, eax
  107.         jz      .exit
  108.         cmp     eax, [_dst_type]
  109.         lodsd
  110.         jnz     .next
  111.         mov     [fun], eax
  112.  
  113.         mov     eax, [_dst]
  114.         test    eax, eax
  115.         jnz     @f
  116.         stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], \
  117.                 [_dst_type]
  118.         test    eax, eax
  119.         jz      .exit
  120.         mov     [_dst], eax
  121. @@:
  122.         mov     edi, [eax + Image.Data]
  123.         mov     esi, [ebx + Image.Data]
  124.         mov     eax, [ebx + Image.Type]
  125.         stdcall [fun], [_src], [_dst]
  126.         mov     eax, [_dst]
  127. .exit:
  128.         pop     edi esi ebx
  129.         ret
  130. endp
  131.  
  132. proc img._.convert.bpp8i_to_bpp24 _src, _dst
  133.         mov     ecx, [ebx + Image.Width]
  134.         imul    ecx, [ebx + Image.Height]
  135.  
  136.         mov     ebx, [ebx + Image.Palette]
  137.         sub     ecx, 1
  138.         jz      .bpp8i.last
  139. @@:
  140.         movzx   eax, byte[esi]
  141.         add     esi, 1
  142.         mov     eax, [ebx + eax*4]
  143.         mov     [edi], eax
  144.         add     edi, 3
  145.         sub     ecx, 1
  146.         jnz     @b
  147. .bpp8i.last:
  148.         movzx   eax, byte[esi]
  149.         mov     eax, [ebx + eax*4]
  150.         mov     [edi], ax
  151.         shr     eax, 16
  152.         mov     [edi + 2], al
  153.         ret
  154. endp
  155.  
  156. proc img._.convert.bpp8i_to_bpp32 _src, _dst
  157.         mov     ecx, [ebx + Image.Width]
  158.         imul    ecx, [ebx + Image.Height]
  159.  
  160.         mov     ebx, [ebx + Image.Palette]
  161. @@:
  162.         movzx   eax, byte[esi]
  163.         add     esi, 1
  164.         mov     eax, [ebx + eax*4]
  165.         mov     [edi], eax
  166.         add     edi, 4
  167.         dec     ecx
  168.         jnz     @b
  169.         ret
  170. endp
  171.  
  172. proc img._.convert.bpp8g_to_bpp1 _src, _dst
  173.         mov     eax, [_dst]
  174.         mov     eax, [eax + Image.Palette]
  175.         mov     dword[eax], 0x00000000
  176.         mov     dword[eax + 4], 0xffffffff
  177.         mov     edx, [ebx + Image.Height]
  178. .bpp8g_to_bpp1.line:
  179.         mov     ax, 0x0800
  180.         mov     ecx, [ebx + Image.Width]
  181. .bpp8g_to_bpp1.pixel:
  182.         shl     al, 1
  183.         cmp     byte[esi], 0x7f
  184.         cmc
  185.         adc     eax, 0
  186.         add     esi, 1
  187.         dec     ah
  188.         jnz     @f
  189.         mov     byte[edi], al
  190.         add     edi, 1
  191.         mov     ax, 0x0800
  192. @@:
  193.         dec     ecx
  194.         jnz     .bpp8g_to_bpp1.pixel
  195.         cmp     ah, 8
  196.         je      @f
  197.         mov     cl, ah
  198.         shl     al, cl
  199.         mov     byte[edi], al
  200.         add     edi, 1
  201. @@:
  202.         dec     edx
  203.         jnz     .bpp8g_to_bpp1.line
  204.         ret
  205. endp
  206.  
  207. proc img._.convert.bpp8g_to_bpp24 _src, _dst
  208.         mov     ecx, [ebx + Image.Width]
  209.         imul    ecx, [ebx + Image.Height]
  210. @@:
  211.         mov     al, byte[esi]
  212.         mov     byte[edi + 0], al
  213.         mov     byte[edi + 1], al
  214.         mov     byte[edi + 2], al
  215.         add     esi, 1
  216.         add     edi, 3
  217.         sub     ecx, 1
  218.         jnz     @b
  219.         ret
  220. endp
  221.  
  222. proc img._.convert.bpp8g_to_bpp32 _src, _dst
  223.         mov     ecx, [ebx + Image.Width]
  224.         imul    ecx, [ebx + Image.Height]
  225. @@:
  226.         mov     al, byte[esi]
  227.         mov     byte[edi + 0], al
  228.         mov     byte[edi + 1], al
  229.         mov     byte[edi + 2], al
  230.         mov     byte[edi + 3], -1
  231.         add     esi, 1
  232.         add     edi, 4
  233.         dec     ecx
  234.         jnz     @b
  235.         ret
  236. endp
  237.  
  238. proc img._.convert.bpp24_to_bpp24 _src, _dst
  239.         mov     ecx, [ebx + Image.Width]
  240.         imul    ecx, [ebx + Image.Height]
  241.         lea     ecx, [ecx*3]
  242.         mov     edx, ecx
  243.         shr     ecx, 2
  244.         rep     movsd
  245.         mov     ecx, edx
  246.         and     ecx, 3
  247.         rep     movsb
  248.         ret
  249. endp
  250.  
  251. proc img._.convert.bpp24_to_bpp8g _src, _dst
  252.         mov     ecx, [ebx + Image.Width]
  253.         imul    ecx, [ebx + Image.Height]
  254. @@:
  255.         movzx   ebx, byte[esi + 0]
  256.         movzx   eax, byte[esi + 1]
  257.         add     ebx, eax
  258.         movzx   eax, byte[esi + 2]
  259.         add     eax, ebx
  260.         mov     ebx, 3
  261.         add     esi, 3
  262.         div     bl
  263.         mov     byte[edi], al
  264.         add     edi, 1
  265.         sub     ecx, 1
  266.         jnz     @b
  267.         ret
  268. endp
  269.  
  270. proc img._.convert.bpp24_to_bpp32 _src, _dst
  271.         mov     ecx, [ebx + Image.Width]
  272.         imul    ecx, [ebx + Image.Height]
  273. @@:
  274.         lodsw
  275.         ror     eax, 16
  276.         lodsb
  277.         mov     ah, 0xff        ; opaque
  278.         rol     eax, 16
  279.         stosd
  280.         dec     ecx
  281.         jnz     @b
  282.         ret
  283. endp
  284.  
  285. proc img._.convert.bpp24_to_bpp1 _src, _dst
  286.         stdcall img.convert.layer, [_src], 0, Image.bpp8g, 0, 0
  287.         test    eax, eax
  288.         jz      .exit
  289.         push    eax
  290.         mov     ecx, [_dst]
  291.         stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
  292.         stdcall img.destroy     ; arg pushed
  293. .exit:
  294.         ret
  295. endp
  296.  
  297. proc img._.convert.bpp32_to_bpp24 _src, _dst
  298.         mov     ecx, [ebx + Image.Width]
  299.         imul    ecx, [ebx + Image.Height]
  300. @@:
  301.         mov     eax, [esi]
  302.         mov     [edi], ax
  303.         shr     eax, 16
  304.         mov     [edi + 2], al
  305.         add     esi, 4
  306.         add     edi, 3
  307.         sub     ecx, 1
  308.         jnz     @b
  309.         ret
  310. endp
  311.  
  312. proc img._.convert.bpp32_to_bpp32 _src, _dst
  313.         mov     ecx, [ebx + Image.Width]
  314.         imul    ecx, [ebx + Image.Height]
  315.         rep     movsd
  316.         ret
  317. endp
  318.  
  319. proc img._.convert.bpp32_to_bpp1 _src, _dst
  320.         push    esi
  321.         stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
  322.         test    eax, eax
  323.         jz      .exit
  324.         push    eax
  325.         stdcall img.convert.layer, eax, 0, Image.bpp8g, 0, 0
  326.         mov     esi, eax
  327.         stdcall img.destroy     ; arg pushed
  328.         test    esi, esi
  329.         jz      .exit
  330.         push    esi
  331.         mov     ecx, [_dst]
  332.         stdcall img.convert.layer, esi, ecx, [ecx+Image.Type], 0, 0
  333.         stdcall img.destroy     ; arg pushed
  334. .exit:
  335.         pop     esi
  336.         ret
  337. endp
  338.  
  339. proc img._.convert.bpp32_to_bpp8g _src, _dst
  340.         stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
  341.         test    eax, eax
  342.         jz      .exit
  343.         push    eax
  344.         mov     ecx, [_dst]
  345.         stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
  346.         stdcall img.destroy     ; arg pushed
  347. .exit:
  348.         ret
  349. endp
  350.  
  351. proc img._.convert.bpp15_to_bpp24 _src, _dst
  352.         mov     ecx, [ebx + Image.Width]
  353.         imul    ecx, [ebx + Image.Height]
  354.  
  355. .bpp15.intel: ; copypasted from do_rgb
  356.         push    ebx ebp
  357.         sub     ecx, 4
  358.         jb      .bpp15.tail
  359. align 16
  360. .bpp15.intel.loop:
  361. repeat 2
  362.         mov     ebx, [esi]
  363.         mov     al, [esi]
  364.         mov     ah, [esi + 1]
  365.         add     esi, 4
  366.         and     al, 0x1F
  367.         and     ah, 0x1F shl 2
  368.         mov     ebp, ebx
  369.         mov     dl, al
  370.         mov     dh, ah
  371.         shr     al, 2
  372.         shr     ah, 4
  373.         shl     dl, 3
  374.         shl     dh, 1
  375.         and     ebp, 0x1F shl 5
  376.         add     al, dl
  377.         add     ah, dh
  378.         shr     ebp, 2
  379.         mov     [edi], al
  380.         mov     [edi + 2], ah
  381.         mov     eax, ebx
  382.         mov     ebx, ebp
  383.         shr     eax, 16
  384.         shr     ebx, 5
  385.         add     ebx, ebp
  386.         mov     ebp, eax
  387.         mov     [edi + 1], bl
  388.         and     eax, (0x1F) or (0x1F shl 10)
  389.         and     ebp, 0x1F shl 5
  390.         lea     edx, [eax + eax]
  391.         shr     al, 2
  392.         mov     ebx, ebp
  393.         shr     ah, 4
  394.         shl     dl, 2
  395.         shr     ebx, 2
  396.         shr     ebp, 7
  397.         add     al, dl
  398.         add     ah, dh
  399.         mov     [edi + 3], al
  400.         add     ebx, ebp
  401.         mov     [edi + 5], ah
  402.         mov     [edi + 4], bl
  403.         add     edi, 6
  404. end repeat
  405.         sub     ecx, 4
  406.         jnb     .bpp15.intel.loop
  407. .bpp15.tail:
  408.         add     ecx, 4
  409.         jz      .bpp15.done
  410.     @@:
  411.         movzx   eax, word [esi]
  412.         mov     ebx, eax
  413.         add     esi, 2
  414.         and     eax, (0x1F) or (0x1F shl 10)
  415.         and     ebx, 0x1F shl 5
  416.         lea     edx, [eax + eax]
  417.         shr     al, 2
  418.         mov     ebp, ebx
  419.         shr     ebx, 2
  420.         shr     ah, 4
  421.         shl     dl, 2
  422.         shr     ebp, 7
  423.         add     eax, edx
  424.         add     ebx, ebp
  425.         mov     [edi], al
  426.         mov     [edi + 1], bl
  427.         mov     [edi + 2], ah
  428.         add     edi, 3
  429.         sub     ecx, 1
  430.         jnz     @b
  431. .bpp15.done:
  432.         pop     ebp ebx
  433.         mov     eax, [_dst]
  434.         jmp     .quit
  435.  
  436. .bpp15.amd:
  437.         push    ebx ebp
  438.         sub     ecx, 4
  439.         jb      .bpp15.tail
  440. align 16
  441. .bpp15.amd.loop:
  442. repeat 4
  443. if (% mod 2) = 1
  444.         mov     eax, dword[esi]
  445.         mov     ebx, dword[esi]
  446. else
  447.         movzx   eax, word[esi]
  448.         mov     ebx, eax
  449. end if
  450.         add     esi, 2
  451.         and     eax, (0x1F) or (0x1F shl 10)
  452.         and     ebx, 0x1F shl 5
  453.         lea     edx, [eax + eax]
  454.         shr     al, 2
  455.         mov     ebp, ebx
  456.         shr     ebx, 2
  457.         shr     ah, 4
  458.         shl     dl, 2
  459.         shr     ebp, 7
  460.         add     eax, edx
  461.         add     ebx, ebp
  462.         mov     [edi], al
  463.         mov     [edi + 1], bl
  464.         mov     [edi + 2], ah
  465.         add     edi, 3
  466. end repeat
  467.         sub     ecx, 4
  468.         jnb     .bpp15.amd.loop
  469.         jmp     .bpp15.tail
  470.  
  471. .quit:
  472.         ret
  473. endp
  474.  
  475.  
  476. proc img._.convert.bpp16_to_bpp24 _src, _dst
  477.         mov     ecx, [ebx + Image.Width]
  478.         imul    ecx, [ebx + Image.Height]
  479. .bpp16.intel:
  480.         push    ebx ebp
  481.         sub     ecx, 4
  482.         jb      .bpp16.tail
  483. align 16
  484. .bpp16.intel.loop:
  485. repeat 2
  486.         mov     ebx, [esi]
  487.         mov     al, [esi]
  488.         mov     ah, [esi + 1]
  489.         add     esi, 4
  490.         and     al, 0x1F
  491.         and     ah, 0x1F shl 3
  492.         mov     ebp, ebx
  493.         mov     dl, al
  494.         mov     dh, ah
  495.         shr     al, 2
  496.         shr     ah, 5
  497.         shl     dl, 3
  498.         and     ebp, 0x3F shl 5
  499.         add     al, dl
  500.         add     ah, dh
  501.         shr     ebp, 3
  502.         mov     [edi], al
  503.         mov     [edi + 2], ah
  504.         mov     eax, ebx
  505.         mov     ebx, ebp
  506.         shr     eax, 16
  507.         shr     ebx, 6
  508.         add     ebx, ebp
  509.         mov     ebp, eax
  510.         mov     [edi + 1], bl
  511.         and     eax, (0x1F) or (0x1F shl 11)
  512.         and     ebp, 0x3F shl 5
  513.         mov     edx, eax
  514.         shr     al, 2
  515.         mov     ebx, ebp
  516.         shr     ah, 5
  517.         shl     dl, 3
  518.         shr     ebx, 3
  519.         shr     ebp, 9
  520.         add     al, dl
  521.         add     ah, dh
  522.         mov     [edi + 3], al
  523.         add     ebx, ebp
  524.         mov     [edi + 5], ah
  525.         mov     [edi + 4], bl
  526.         add     edi, 6
  527. end repeat
  528.         sub     ecx, 4
  529.         jnb     .bpp16.intel.loop
  530. .bpp16.tail:
  531.         add     ecx, 4
  532.         jz      .bpp16.done
  533.     @@:
  534.         movzx   eax, word[esi]
  535.         mov     ebx, eax
  536.         add     esi, 2
  537.         and     eax, (0x1F) or (0x1F shl 11)
  538.         and     ebx, 0x3F shl 5
  539.         mov     edx, eax
  540.         shr     al, 2
  541.         mov     ebp, ebx
  542.         shr     ebx, 3
  543.         shr     ah, 5
  544.         shl     dl, 3
  545.         shr     ebp, 9
  546.         add     eax, edx
  547.         add     ebx, ebp
  548.         mov     [edi], al
  549.         mov     [edi + 1], bl
  550.         mov     [edi + 2], ah
  551.         add     edi, 3
  552.         sub     ecx, 1
  553.         jnz     @b
  554. .bpp16.done:
  555.         pop     ebp ebx
  556.         mov     eax, [_dst]
  557.         jmp     .quit
  558.  
  559. .bpp16.amd:
  560.         push    ebx ebp
  561.         sub     ecx, 4
  562.         jb      .bpp16.tail
  563. align 16
  564. .bpp16.amd.loop:
  565. repeat 4
  566. if (% mod 2) = 1
  567.         mov     eax, dword[esi]
  568.         mov     ebx, dword[esi]
  569. else
  570.         movzx   eax, word[esi]
  571.         mov     ebx, eax
  572. end if
  573.         add     esi, 2
  574.         and     eax, (0x1F) or (0x1F shl 11)
  575.         and     ebx, 0x3F shl 5
  576.         mov     edx, eax
  577.         shr     al, 2
  578.         mov     ebp, ebx
  579.         shr     ebx, 3
  580.         shr     ah, 5
  581.         shl     dl, 3
  582.         shr     ebp, 9
  583.         add     eax, edx
  584.         add     ebx, ebp
  585.         mov     [edi], al
  586.         mov     [edi + 1], bl
  587.         mov     [edi + 2], ah
  588.         add     edi, 3
  589. end repeat
  590.         sub     ecx, 4
  591.         jnb     .bpp16.amd.loop
  592.         jmp     .bpp16.tail
  593.  
  594. .quit:
  595.         ret
  596. endp
  597.  
  598.  
  599. proc img._.convert.bpp1_to_bpp24 uses ebx, _src, _dst
  600. locals
  601.         width   rd 1
  602.         height  rd 1
  603. endl
  604.         push    [ebx + Image.Width]
  605.         pop     [width]
  606.         push    [ebx + Image.Height]
  607.         pop     [height]
  608.         mov     edx, [ebx + Image.Palette]
  609. .bpp1_to_bpp24.line:
  610.         mov     ebx, [width]
  611. .bpp1_to_bpp24.byte:
  612.         mov     ah, 8
  613.         mov     al, byte[esi]
  614.         add     esi, 1
  615. .bpp1_to_bpp24.bit:
  616.         xor     ecx, ecx
  617.         shl     al, 1
  618.         adc     ecx, 0
  619.         mov     ecx, [edx + 4*ecx]
  620.         mov     word[edi], cx
  621.         shr     ecx, 8
  622.         mov     byte[edi + 2], ch
  623.         add     edi, 3
  624.         sub     ebx, 1
  625.         jnz     @f
  626.         sub     [height], 1
  627.         jnz     .bpp1_to_bpp24.line
  628.         jmp     .bpp1.done
  629. @@:
  630.         sub     ah, 1
  631.         jnz     .bpp1_to_bpp24.bit
  632.         jmp     .bpp1_to_bpp24.byte
  633. .bpp1.done:
  634.         ret
  635. endp
  636.  
  637. proc img._.convert.bpp1_to_bpp32 _src, _dst
  638.         stdcall img.convert.layer, [_src], 0, Image.bpp24, 0, 0
  639.         test    eax, eax
  640.         jz      .exit
  641.         push    eax
  642.         mov     ecx, [_dst]
  643.         stdcall img.convert.layer, eax, ecx, [ecx+Image.Type], 0, 0
  644.         stdcall img.destroy     ; arg pushed
  645. .exit:
  646.         ret
  647. endp
  648.  
  649. proc img._.convert.bpp1_to_bpp8g _src, _dst
  650. locals
  651.         width   rd 1
  652.         height  rd 1
  653. endl
  654.         push    [ebx + Image.Width]
  655.         pop     [width]
  656.         push    [ebx + Image.Height]
  657.         pop     [height]
  658. .line:
  659.         mov     edx, [width]
  660. .byte:
  661.         mov     ah, 8
  662.         mov     al, byte[esi]
  663.         inc     esi
  664. .bit:
  665.         xor     ecx, ecx
  666.         shl     al, 1
  667.         sbb     ecx, 0
  668.         mov     byte[edi], cl
  669.         inc     edi
  670.         dec     edx
  671.         jnz     @f
  672.         dec     [height]
  673.         jnz     .line
  674.         jmp     .done
  675. @@:
  676.         dec     ah
  677.         jnz     .bit
  678.         jmp     .byte
  679. .done:
  680.         ret
  681. endp
  682.  
  683. proc img._.convert.bpp8a_to_bpp1 _src, _dst
  684.         mov     eax, [_dst]
  685.         mov     eax, [eax + Image.Palette]
  686.         mov     dword[eax], 0x00000000
  687.         mov     dword[eax + 4], 0xffffffff
  688.         mov     edx, [ebx + Image.Height]
  689. .bpp8a_to_bpp1.line:
  690.         mov     ax, 0x0800
  691.         mov     ecx, [ebx + Image.Width]
  692. .bpp8a_to_bpp1.pixel:
  693.         shl     al, 1
  694.         cmp     byte[esi], 0x7f
  695.         cmc
  696.         adc     eax, 0
  697.         add     esi, 2
  698.         dec     ah
  699.         jnz     @f
  700.         mov     byte[edi], al
  701.         add     edi, 1
  702.         mov     ax, 0x0800
  703. @@:
  704.         dec     ecx
  705.         jnz     .bpp8a_to_bpp1.pixel
  706.         cmp     ah, 8
  707.         je      @f
  708.         mov     cl, ah
  709.         shl     al, cl
  710.         mov     byte[edi], al
  711.         add     edi, 1
  712. @@:
  713.         dec     edx
  714.         jnz     .bpp8a_to_bpp1.line
  715.         ret
  716. endp
  717.  
  718.  
  719. proc img._.convert.bpp8a_to_bpp24 _src, _dst
  720.         mov     ecx, [ebx + Image.Width]
  721.         imul    ecx, [ebx + Image.Height]
  722. @@:
  723.         mov     al, byte[esi]
  724.         mov     byte[edi + 0], al
  725.         mov     byte[edi + 1], al
  726.         mov     byte[edi + 2], al
  727.         add     esi, 2
  728.         add     edi, 3
  729.         sub     ecx, 1
  730.         jnz     @b
  731.         ret
  732. endp
  733.  
  734.  
  735. proc img._.convert.bpp8a_to_bpp32 _src, _dst
  736.         mov     ecx, [ebx + Image.Width]
  737.         imul    ecx, [ebx + Image.Height]
  738. @@:
  739.         lodsw
  740.         shl     eax, 8
  741.         mov     al, ah
  742.         shl     eax, 8
  743.         mov     al, ah
  744.         stosd
  745.         dec     ecx
  746.         jnz     @b
  747.         ret
  748. endp
  749.  
  750.  
  751. img.convert.bpp8i.table:
  752.         dd Image.bpp24, img._.convert.bpp8i_to_bpp24
  753.         dd Image.bpp32, img._.convert.bpp8i_to_bpp32
  754.         dd 0
  755. img.convert.bpp24.table:
  756.         dd Image.bpp24, img._.convert.bpp24_to_bpp24
  757.         dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
  758.         dd Image.bpp32, img._.convert.bpp24_to_bpp32
  759.         dd Image.bpp1,  img._.convert.bpp24_to_bpp1
  760.         dd 0
  761. img.convert.bpp32.table:
  762.         dd Image.bpp24, img._.convert.bpp32_to_bpp24
  763.         dd Image.bpp32, img._.convert.bpp32_to_bpp32
  764.         dd Image.bpp1,  img._.convert.bpp32_to_bpp1
  765.         dd Image.bpp8g, img._.convert.bpp32_to_bpp8g
  766.         dd 0
  767. img.convert.bpp15.table:
  768.         dd Image.bpp24, img._.convert.bpp15_to_bpp24
  769.         dd 0
  770. img.convert.bpp16.table:
  771.         dd Image.bpp24, img._.convert.bpp16_to_bpp24
  772.         dd 0
  773. img.convert.bpp1.table:
  774.         dd Image.bpp24, img._.convert.bpp1_to_bpp24
  775.         dd Image.bpp32, img._.convert.bpp1_to_bpp32
  776.         dd Image.bpp8g, img._.convert.bpp1_to_bpp8g
  777.         dd 0
  778. img.convert.bpp8g.table:
  779.         dd Image.bpp24, img._.convert.bpp8g_to_bpp24
  780.         dd Image.bpp32, img._.convert.bpp8g_to_bpp32
  781.         dd Image.bpp1,  img._.convert.bpp8g_to_bpp1
  782.         dd 0
  783. img.convert.bpp2i.table:
  784.         dd 0
  785. img.convert.bpp4i.table:
  786.         dd 0
  787. img.convert.bpp8a.table:
  788.         dd Image.bpp24, img._.convert.bpp8a_to_bpp24
  789.         dd Image.bpp32, img._.convert.bpp8a_to_bpp32
  790.         dd 0
  791.  
  792. img.convert.table:
  793.         dd 0    ; no image type zero
  794.         dd img.convert.bpp8i.table
  795.         dd img.convert.bpp24.table
  796.         dd img.convert.bpp32.table
  797.         dd img.convert.bpp15.table
  798.         dd img.convert.bpp16.table
  799.         dd img.convert.bpp1.table
  800.         dd img.convert.bpp8g.table
  801.         dd img.convert.bpp2i.table
  802.         dd img.convert.bpp4i.table
  803.         dd img.convert.bpp8a.table
  804.