Subversion Repositories Kolibri OS

Rev

Rev 1921 | Rev 2397 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;================================================================================================;;
  2. ;;//// pcx.asm //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;;
  3. ;;================================================================================================;;
  4. ;;                                                                                                ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).                                  ;;
  6. ;;                                                                                                ;;
  7. ;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
  8. ;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
  9. ;; of the License, or (at your option) any later version.                                         ;;
  10. ;;                                                                                                ;;
  11. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
  12. ;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
  13. ;; Lesser General Public License for more details.                                                ;;
  14. ;;                                                                                                ;;
  15. ;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
  16. ;; If not, see <http://www.gnu.org/licenses/>.                                                    ;;
  17. ;;                                                                                                ;;
  18. ;;================================================================================================;;
  19.  
  20. include 'pcx.inc'
  21. ;include '../../../../system/board/trunk/debug.inc'
  22.  
  23. ;;================================================================================================;;
  24. proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
  25. ;;------------------------------------------------------------------------------------------------;;
  26. ;? Determine if raw data could be decoded (is in pcx format)                                      ;;
  27. ;;------------------------------------------------------------------------------------------------;;
  28. ;> _data = raw data as read from file/stream                                                      ;;
  29. ;> _length = data length                                                                          ;;
  30. ;;------------------------------------------------------------------------------------------------;;
  31. ;< eax = false / true                                                                             ;;
  32. ;;================================================================================================;;
  33.  
  34.         push    ecx edi
  35.         xor     eax, eax
  36.  
  37.         mov     edi, [_data]
  38.  
  39.         cmp     [edi + pcx_header.magic_number], 10
  40.         jne     .is_not_pcx
  41.         cmp     [edi + pcx_header.version], 5
  42.         jne     .is_not_pcx
  43.         cmp     [edi + pcx_header.encoding], 1
  44.         jne     .is_not_pcx
  45.         cmp     [edi + pcx_header.reserved], 0
  46.         jne     .is_not_pcx
  47.  
  48.         add     edi, pcx_header.filler
  49.         xor     al, al
  50.         mov     ecx, 58
  51.         cld
  52.         repe    scasb
  53.         test    ecx, ecx
  54.         jnz     .is_not_pcx
  55.  
  56.   .is_pcx:
  57.         inc     eax
  58.  
  59.   .is_not_pcx:
  60.         pop     edi ecx
  61.         ret
  62. endp
  63.  
  64.  
  65. ;;================================================================================================;;
  66. proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
  67. ;;------------------------------------------------------------------------------------------------;;
  68. ;? Decode data into image if it contains correctly formed raw data in pcx format                  ;;
  69. ;;------------------------------------------------------------------------------------------------;;
  70. ;> _data = raw data as read from file/stream                                                      ;;
  71. ;> _length = data length                                                                          ;;
  72. ;;------------------------------------------------------------------------------------------------;;
  73. ;< eax = 0 (error) or pointer to image                                                            ;;
  74. ;;================================================================================================;;
  75. locals
  76.         nplanes                 rd      1
  77.         xsize                   rw      1
  78.         ysize                   rw      1
  79.         bpl                     rw      1
  80.         total_bpl               rd      1
  81.         line_begin              rd      1
  82.         retvalue                rd      1               ; 0 (error) or pointer to image
  83. endl
  84.  
  85.         pusha
  86.  
  87.         mov     esi, [_data]
  88.         movzx   eax, byte[esi + pcx_header.nplanes]
  89.         mov     [nplanes], eax
  90.         mov     bx, word[esi + pcx_header.bpl]
  91.         mov     [bpl], bx
  92.         mul     bx
  93.         shl     eax, 16
  94.         mov     ax, dx
  95.         ror     eax, 16
  96.         mov     [total_bpl], eax
  97.  
  98.         movzx   eax, word[esi + pcx_header.xmax]
  99.         inc     ax
  100.         sub     ax, word[esi + pcx_header.xmin]
  101.         mov     [xsize], ax
  102.  
  103.         movzx   ebx, word[esi + pcx_header.ymax]
  104.         inc     bx
  105.         sub     bx, word[esi + pcx_header.ymin]
  106.         mov     [ysize], bx
  107.  
  108.  
  109.         cmp     [esi + pcx_header.bpp], 1
  110.         jz      .monochrome
  111.         cmp     byte[esi + pcx_header.nplanes], 3
  112.         jnz     .indexed
  113.  
  114.  
  115.   ._24bit:
  116.  
  117.         stdcall img.create, eax, ebx, Image.bpp24
  118.         mov     [retvalue], eax
  119.         test    eax, eax
  120.         jz      .quit
  121.  
  122.         movzx   ebx, [xsize]
  123.         movzx   ecx, [ysize]
  124.         mov     edx, [eax+Image.Data]
  125.  
  126.         rol     ebx, 16
  127.         or      ebx, ecx
  128.         xor     ebx, [edx]
  129.         mov     [eax + Image.Checksum], ebx
  130.  
  131.  
  132.         mov     esi, [_data]
  133.         add     esi, 128
  134. ;       mov     edi, [retvalue]
  135.         mov     edi, [eax + Image.Data]
  136.         add     edi, 2
  137.         mov     [line_begin], edi
  138.         mov     ebx, [total_bpl]
  139.  
  140.   ._24bit.begin:
  141.         mov     ax, word[bpl]
  142.   ._24bit.decode:
  143.         call    pcx._.get_byte
  144.   ._24bit.write_sequence:
  145.         mov     [edi], dl
  146.         dec     ax
  147.         add     edi, [nplanes]
  148.         dec     dh
  149.         jnz     ._24bit.write_sequence
  150.  
  151.         test    ax, ax
  152.         jz      ._24bit.end_color_line
  153.         jmp     ._24bit.decode
  154.  
  155.   ._24bit.end_color_line:
  156.         test    ebx, ebx
  157.         jz      ._24bit.end_full_line
  158.         dec     [line_begin]
  159.         mov     edi, [line_begin]
  160.         jmp     ._24bit.begin
  161.  
  162.   ._24bit.end_full_line:
  163.         dec     word[ysize]
  164.         jz      .quit
  165.         mov     ebx, [total_bpl]
  166.         add     edi, 2
  167.         mov     [line_begin], edi
  168.         jmp     ._24bit.begin
  169.  
  170.  
  171.   .indexed:
  172.  
  173.         stdcall img.create, eax, ebx, Image.bpp8
  174.         mov     [retvalue], eax
  175.         test    eax, eax
  176.         jz      .quit
  177.  
  178.         movzx   ebx, [xsize]
  179.         movzx   ecx, [ysize]
  180.         mov     edx, [eax + Image.Data]
  181.  
  182.         rol     ebx, 16
  183.         or      ebx, ecx
  184.         xor     ebx, [edx]
  185.         mov     [eax + Image.Checksum], ebx
  186.  
  187.         mov     esi, [_data]
  188.         add     esi, [_length]
  189.         sub     esi, 768
  190.         mov     edi, [eax + Image.Palette]
  191.         mov     cx, 256
  192.     @@:
  193.         mov     ebx, [esi]
  194.         bswap   ebx
  195.         shr     ebx, 8
  196.         mov     [edi], ebx
  197.         add     edi, 4
  198.         add     esi, 3
  199.         dec     cx
  200.         jnz     @b
  201.  
  202.         mov     esi, [_data]
  203.         add     esi, 128
  204. ;       mov     edi, [retvalue]
  205.         mov     edi, [eax + Image.Data]
  206.  
  207.   .indexed.begin:
  208.         mov     ax, word[bpl]
  209.   .indexed.decode:
  210.         call    pcx._.get_byte
  211.   .indexed.write_sequence:
  212.         mov     [edi], dl
  213.         inc     edi
  214.         dec     ax
  215.         dec     dh
  216.         jnz     .indexed.write_sequence
  217.  
  218.         test    ax, ax
  219.         jz      .indexed.end_line
  220.         jmp     .indexed.decode
  221.  
  222.   .indexed.end_line:
  223.         dec     word[ysize]
  224.         jz      .quit
  225.         jmp     .indexed.begin
  226.  
  227.  
  228.   .monochrome:
  229.  
  230.         stdcall img.create, eax, ebx, Image.bpp1
  231.         mov     [retvalue], eax
  232.         test    eax, eax
  233.         jz      .quit
  234.  
  235.         movzx   ebx, [xsize]
  236.         movzx   ecx, [ysize]
  237.         mov     edx, [eax + Image.Data]
  238.  
  239.         rol     ebx, 16
  240.         or      ebx, ecx
  241.         xor     ebx, [edx]
  242.         mov     [eax + Image.Checksum], ebx
  243.  
  244.         mov     edi, [eax + Image.Palette]
  245.         mov     [edi], dword 0x00000000
  246.         mov     [edi + 4], dword 0x00ffffff
  247.  
  248.         mov     esi, [_data]
  249.         add     esi, 128
  250. ;       mov     edi, [retvalue]
  251.         mov     edi, [eax + Image.Data]
  252.  
  253.  
  254.   .monochrome.begin:
  255.         mov     ebx, [total_bpl]
  256.         mov     ax, [xsize]
  257.  
  258.   .monochrome.decode:
  259.         call    pcx._.get_byte
  260.   .monochrome.write_sequence:
  261.         mov     [edi], dl
  262.         inc     edi
  263.         cmp     ax, 8
  264.         jng     .monochrome.is_last_byte_in_line
  265.         sub     ax, 8
  266.         dec     dh
  267.         jnz     .monochrome.write_sequence
  268.         jmp     .monochrome.decode
  269.  
  270.   .monochrome.is_last_byte_in_line:
  271.         test    ebx, ebx
  272.         jng     @f
  273.         call    pcx._.get_byte
  274.         jmp     .monochrome.is_last_byte_in_line
  275.     @@:
  276.         dec     word[ysize]
  277.         jnz     .monochrome.begin
  278.         jmp     .quit
  279.  
  280.  
  281.   .quit:
  282.         popa
  283.         mov     eax, [retvalue]
  284.         ret
  285. endp
  286.  
  287.  
  288. ;;================================================================================================;;
  289. proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
  290. ;;------------------------------------------------------------------------------------------------;;
  291. ;? Encode image into raw data in pcx format                                                     ;;
  292. ;;------------------------------------------------------------------------------------------------;;
  293. ;> _img = pointer to image                                                                        ;;
  294. ;;------------------------------------------------------------------------------------------------;;
  295. ;< eax = 0 (error) or pointer to encoded data                                                     ;;
  296. ;< _p_length = encoded data length                                                                ;;
  297. ;;================================================================================================;;
  298.         xor     eax, eax
  299.         ret
  300. endp
  301.  
  302.  
  303. ;;================================================================================================;;
  304. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  305. ;;================================================================================================;;
  306. ;! Below are private procs you should never call directly from your code                          ;;
  307. ;;================================================================================================;;
  308. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  309. ;;================================================================================================;;
  310. proc    pcx._.get_byte
  311.  
  312.         mov     dh, byte[esi]
  313.         inc     esi
  314.         cmp     dh, 0xC0
  315.         jnb     .cycle1
  316.         mov     dl, dh
  317.         mov     dh, 1
  318.         jmp     .exit1
  319.   .cycle1:
  320.         and     dh, 0x3F
  321.         mov     dl, byte[esi]
  322.         inc     esi
  323.   .exit1:
  324.         movzx   ecx, dh
  325.         sub     ebx, ecx
  326.         ret
  327. endp
  328.  
  329.  
  330. ;;================================================================================================;;
  331. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  332. ;;================================================================================================;;
  333. ;! Below is private data you should never use directly from your code                             ;;
  334. ;;================================================================================================;;
  335. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  336. ;;================================================================================================;;
  337.