Subversion Repositories Kolibri OS

Rev

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

  1. ;;================================================================================================;;
  2. ;;//// pcx.asm //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
  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 Targa 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     [esi+pcx_header.reserved],  1
  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. ;pusha
  58. ;dps 'is_pcx'
  59. ;newline
  60. ;popa
  61.     inc     eax
  62.     pop     edi ecx
  63.     ret
  64.  
  65. .is_not_pcx:
  66. ;pusha
  67. ;dps 'is_not_pcx'
  68. ;newline
  69. ;popa
  70.     pop     edi ecx
  71.     ret
  72.  
  73. endp
  74.  
  75. ;;================================================================================================;;
  76. proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
  77. ;;------------------------------------------------------------------------------------------------;;
  78. ;? Decode data into image if it contains correctly formed raw data in Targa format                ;;
  79. ;;------------------------------------------------------------------------------------------------;;
  80. ;> _data = raw data as read from file/stream                                                      ;;
  81. ;> _length = data length                                                                          ;;
  82. ;;------------------------------------------------------------------------------------------------;;
  83. ;< eax = 0 (error) or pointer to image                                                            ;;
  84. ;;================================================================================================;;
  85. locals
  86. ;  IMGwidth      dd ?
  87. ;  IMGheight     dd ?
  88. ;  IMGbpp        dd ?
  89. buf                 rb      1
  90. nplanes             rd      1
  91. xsize               rw      1
  92. ysize               rw      1
  93. stxsize             rw      1
  94. stysize             rw      1
  95. total_bpl           rd      1
  96. line_begin          rd      1
  97. retvalue            rd      1
  98.  
  99. endl
  100.  
  101.     pusha
  102.  
  103.     mov     esi,    [_data]
  104.  
  105.     xor     eax,   eax
  106.     mov     al,    byte[esi+pcx_header.nplanes]
  107.     mov     [nplanes],  eax
  108.     mul     word[esi+pcx_header.bpl]
  109.     mov     [total_bpl],    eax
  110.  
  111.     movzx   eax,    word[esi+pcx_header.xmax]
  112.     inc     ax
  113.     sub     ax,     word[esi+pcx_header.xmin]
  114.     mov     [xsize],    ax
  115.  
  116.     movzx   ebx,    word[esi+pcx_header.ymax]
  117.     inc     bx
  118.     sub     bx,     word[esi+pcx_header.ymin]
  119.     mov     [ysize],    bx
  120.  
  121.       stdcall   img.create, eax, ebx, Image.bpp24
  122.     mov     [retvalue], eax
  123.     test    eax,    eax
  124.      jz     .quit
  125.  
  126.     movzx   ebx,    [xsize]
  127.     movzx   ecx,    [ysize]
  128.     mov     edx,    [eax+Image.Data]
  129.  
  130.     rol     ebx,    16
  131.     or      ebx,    ecx
  132.     xor     ebx,    [edx]
  133.     mov     [eax+Image.Checksum],   ebx
  134.  
  135.  
  136.     mov     esi,    [_data]
  137.     add     esi,    128
  138.     mov     edi,    [retvalue]
  139.     mov     edi,    [edi+Image.Data]
  140.     add     edi,    2
  141.     mov     [line_begin],   edi
  142.     mov     ebx,    [total_bpl]
  143.  
  144.   .begin:
  145.     mov     eax,    [_data]
  146.     mov     ax,     word[eax+pcx_header.bpl]
  147.   .decode:
  148.     mov     dl,     byte[esi]
  149.     inc     esi
  150.     mov     [buf],  dl
  151.     and     dl,     0xC0
  152.     cmp     dl,     0xC0
  153.      jne    @f
  154.     mov     dl,     byte[buf]
  155.     and     dl,     0x3F
  156.     mov     dh,     [esi]
  157.     inc     esi
  158.  
  159.   .write_sequence:
  160.     mov     [edi], dh
  161.     dec     ax
  162.     dec     ebx
  163.     add     edi,    [nplanes]
  164.     dec     dl
  165.     test    dl,     dl
  166.      jnz    .write_sequence
  167.  
  168.     test    ax,     ax
  169.      jz     .end_color_line
  170.      jmp    .decode
  171.   @@:
  172.     mov     dl,     byte[buf]
  173.     mov     [edi],  dl
  174.     add     edi, [nplanes]
  175.     dec     ebx
  176.     dec     ax
  177.      jz     .end_color_line
  178.      jmp    .decode
  179.  
  180.  .end_color_line:
  181.     test    ebx,    ebx
  182.      jz     .end_full_line
  183.     dec     [line_begin]
  184.     mov     edi,    [line_begin]
  185.      jmp    .begin
  186.  
  187.   .end_full_line:
  188.     dec     word[ysize]
  189.      jz     .quit
  190.     mov     ebx,    [total_bpl]
  191.     add     edi,    2
  192.     mov     [line_begin],   edi
  193.      jmp    .begin
  194.  
  195.   .quit:
  196.     popa
  197.     mov     eax,    [retvalue]
  198.     ret
  199. endp
  200.  
  201. ;;================================================================================================;;
  202. proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
  203. ;;------------------------------------------------------------------------------------------------;;
  204. ;? Encode image into raw data in Targa format                                                     ;;
  205. ;;------------------------------------------------------------------------------------------------;;
  206. ;> _img = pointer to image                                                                        ;;
  207. ;;------------------------------------------------------------------------------------------------;;
  208. ;< eax = 0 (error) or pointer to encoded data                                                     ;;
  209. ;< _p_length = encoded data length                                                                ;;
  210. ;;================================================================================================;;
  211.     xor eax, eax
  212.     ret
  213. endp
  214.  
  215.  
  216. ;;================================================================================================;;
  217. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  218. ;;================================================================================================;;
  219. ;! Below are private procs you should never call directly from your code                          ;;
  220. ;;================================================================================================;;
  221. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  222. ;;================================================================================================;;
  223.  
  224. ;;================================================================================================;;
  225. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  226. ;;================================================================================================;;
  227. ;! Below is private data you should never use directly from your code                             ;;
  228. ;;================================================================================================;;
  229. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  230. ;;================================================================================================;;
  231.  
  232. ;