Subversion Repositories Kolibri OS

Rev

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

  1. ;*****************************************************************************
  2. ; RAW to RAW convert plugin - for zSea image viewer
  3. ; Copyright (c) 2008-2011, Marat Zakiyanov aka Mario79, aka Mario
  4. ; All rights reserved.
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions are met:
  8. ;        * Redistributions of source code must retain the above copyright
  9. ;          notice, this list of conditions and the following disclaimer.
  10. ;        * Redistributions in binary form must reproduce the above copyright
  11. ;          notice, this list of conditions and the following disclaimer in the
  12. ;          documentation and/or other materials provided with the distribution.
  13. ;        * Neither the name of the <organization> nor the
  14. ;          names of its contributors may be used to endorse or promote products
  15. ;          derived from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
  18. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ;*****************************************************************************
  28.  
  29. ; Convert:
  30. ; 16b in 8b
  31. ; 1b,2b,3b in 8b
  32.  
  33. format MS COFF
  34.  
  35. public EXPORTS
  36.  
  37. section '.flat' code readable align 16
  38.  
  39. ;include    'macros.inc'
  40. include    '../../../../macros.inc'
  41. ;---------------------------------------------------------------------
  42. START:
  43.         pushad
  44.         mov     eax,dword [esp+36]
  45.         mov     [pointer],eax
  46.         mov     eax,[eax+4]
  47.         mov     [image_file],eax
  48.         mov     esi,[eax+28]
  49.         add     esi,eax
  50.         mov     edi,esi
  51.         mov     ecx,[eax+32]
  52.        
  53.         cmp     [eax+16],word 16
  54.         je      .16b
  55.         cmp     [eax+12],dword 1
  56.         je      .1b
  57.         cmp     [eax+12],dword 2
  58.         je      .2b
  59.         cmp     [eax+12],dword 4
  60.         je      .4b
  61. ;---------------------------------------------------------------------
  62. .ret_ok:
  63.         mov     ebx,[image_file]
  64.         cmp     [ebx+18],word 2
  65.         jne     @f
  66.         mov     eax,[ebx+12]
  67.         shr     eax,1
  68.         mov     [ebx+12],eax
  69. @@:
  70.         popad
  71.         ret     4
  72. ;--------------------------------------------------------------------- 
  73. .less_8b:
  74.         mov     edx,[image_file]
  75.         mov     ecx,[area_size]
  76.         add     ecx,[edx+28]
  77.         mcall   68,20
  78.         mov     [image_file],eax
  79.  
  80.         mov     ecx,[area_size]
  81.         mov     eax,ecx
  82.         shr     ecx,2
  83.         test    eax,3
  84.         jz      @f
  85.         inc     ecx
  86. @@:
  87.         mov     esi,[raw_area]
  88.         mov     edi,[image_file]
  89.         add     edi,[edi+28]
  90.         cld  
  91.         rep     movsd
  92.  
  93.         mcall   68,13,[raw_area]
  94.         mov     eax,[image_file]
  95.         mov     ebx,[pointer]
  96.         mov     [ebx+4],eax
  97.         popad
  98.         ret     4
  99. ;--------------------------------------------------------------------- 
  100. .16b:
  101. ; eax - RAW image_file
  102.         cmp     [eax+18],word 3
  103.         je      @f
  104.         cmp     [eax+18],word 4
  105.         jne     .16b_1
  106. @@:
  107.         xor     ebx,ebx
  108.         mov     bx,[eax+18]
  109.        
  110.         xchg    eax,ecx
  111.         xor     edx,edx
  112.         div     ebx
  113.         xchg    ecx,eax
  114.        
  115.         shr     ecx,1
  116.        
  117.         mov     [eax+16],word 8
  118.         mov     ebx,[eax+12]
  119.         shr     ebx,1
  120.         mov     [eax+12],ebx
  121.  
  122.         mov     ebx,eax
  123.        
  124. .convert_16_in_8:   ; converting 16 bit sample to 8 bit
  125.         cld
  126.         lodsw
  127.         mov     al,ah
  128.         stosb
  129.        
  130.         lodsw
  131.         mov     al,ah
  132.         stosb
  133.        
  134.         lodsw
  135.         mov     al,ah
  136.         stosb
  137.        
  138.         cmp     [ebx+18],word 4
  139.         jne     @f
  140.         lodsw
  141.         mov     al,ah
  142.         stosb
  143. @@:  
  144.         dec     ecx
  145.         jnz     .convert_16_in_8
  146.        
  147.         jmp     .16b_end
  148. ;---------------------------------------------------------------------
  149. .16b_1:
  150. ; eax - RAW image_file
  151.         cmp     [eax+18],word 1
  152.         je      @f
  153.         cmp     [eax+18],word 2
  154.         jne     .16b_end
  155. @@:
  156.         shr     ecx,1
  157.        
  158.         mov     [eax+16],word 8
  159.         mov     ebx,[eax+12]
  160.         shr     ebx,1
  161.         mov     [eax+12],ebx
  162.        
  163. .convert_16_in_8_1:
  164.         cld
  165.         lodsw
  166.         stosb
  167.         dec     ecx
  168.         jnz     .convert_16_in_8_1
  169. ;---------------------------------------------------------------------
  170. .16b_end:
  171.         xor     eax,eax
  172.         mov     [raw_area],eax
  173.         jmp     .ret_ok
  174. ;--------------------------------------------------------------------- 
  175. .4b:
  176.         call    .get_memory
  177.         mov     edx,ebx
  178.         inc     ebx
  179.         shr     ebx,1
  180. .4b_1:
  181.         push    ebx edi
  182. @@:
  183.         cld
  184.         lodsb
  185.         shl     eax,8
  186.         mov     al,ah
  187.         and     ah,0xf
  188.         shr     al,4
  189.         stosw
  190.        
  191.         dec     ebx
  192.         jnz     @b
  193.         pop     edi ebx
  194.         add     edi,edx
  195.         dec     ecx
  196.         jnz     .4b_1
  197.        
  198.         jmp     .less_8b
  199. ;---------------------------------------------------------------------
  200. .2b:
  201.         call    .get_memory
  202.         mov     edx,ebx
  203.         mov     eax,ebx
  204.         shr     ebx,2
  205.         test    eax,3
  206.         jz      @f
  207.         inc     ebx
  208. @@:
  209.         mov     ebp,ebx
  210. .2b_1:
  211.         push    ebp edi
  212. @@:
  213.         cld
  214.         lodsb
  215.        
  216.         mov     bl,al
  217.        
  218.         and     al,11b
  219.         shl     ax,8
  220.        
  221.         mov     al,bl
  222.         shr     al,2
  223.         and     al,11b
  224.         shl     eax,8
  225.        
  226.         mov     al,bl
  227.         shr     al,4
  228.         and     al,11b
  229.         shl     eax,8
  230.        
  231.         mov     al,bl
  232.         shr     al,6
  233.         and     al,11b
  234.        
  235.         stosd
  236.  
  237.         dec     ebp
  238.         jnz     @b
  239.         pop     edi ebp
  240.        
  241.         add     edi,edx
  242.         dec     ecx
  243.         jnz     .2b_1
  244.        
  245.         jmp     .less_8b
  246. ;---------------------------------------------------------------------
  247. .1b:
  248.         call    .get_memory
  249.         mov     edx,ebx
  250.         mov     eax,ebx
  251.         shr     ebx,3
  252.         test    eax,7
  253.         jz      @f
  254.         inc     ebx
  255. @@:
  256.         mov     ebp,ebx
  257. .1b_1:
  258.         push    ebp edi
  259. @@:
  260.         cld
  261.         lodsb
  262.        
  263.         mov     bl,al
  264.         shr     al,4
  265.         and     al,1b
  266.         shl     ax,8
  267.        
  268.         mov     al,bl
  269.         shr     al,5
  270.         and     al,1b
  271.         shl     eax,8
  272.        
  273.         mov     al,bl
  274.         shr     al,6
  275.         and     al,1b
  276.         shl     eax,8
  277.        
  278.         mov     al,bl
  279.         shr     al,7
  280.        
  281.         stosd
  282.        
  283.         mov     al,bl
  284.         and     al,1b
  285.         shl     ax,8
  286.        
  287.         mov     al,bl
  288.         shr     al,1
  289.         and     al,1b
  290.         shl     eax,8
  291.  
  292.         mov     al,bl
  293.         shr     al,2
  294.         and     al,1b
  295.         shl     eax,8
  296.        
  297.         mov     al,bl
  298.         shr     al,3
  299.         and     al,1b
  300.        
  301.         stosd
  302.        
  303.         dec     ebp
  304.         jnz     @b
  305.         pop     edi ebp
  306.        
  307.         add     edi,edx
  308.         dec     ecx
  309.         jnz     .1b_1
  310.  
  311.         jmp     .less_8b
  312. ;---------------------------------------------------------------------
  313. .get_memory:
  314. ; eax - RAW image_file
  315.         mov     ebx,dword 8
  316.         mov     [eax+16],bx
  317.         mov     [eax+12],ebx
  318.         mov     ecx,[eax+4]
  319.         imul    ecx,[eax+8]
  320.         push    eax
  321.         mov     [area_size],ecx
  322.         mcall   68,12
  323.         mov     [raw_area],eax
  324.         mov     edi,eax
  325.         pop     eax
  326.         mov     ebx,[eax+4]
  327.         mov     ecx,[eax+8]
  328.         ret
  329. ;---------------------------------------------------------------------
  330. Convert24b:
  331.         pushad
  332.         mov     eax,dword [esp+36]
  333.         mov     [pointer],eax
  334.         mov     eax,[eax+4]
  335.         mov     [image_file],eax
  336.  
  337.         mov     esi,[eax+28]
  338.         add     esi,eax
  339.  
  340.         mov     ebp,[eax+20]
  341.         add     ebp,eax
  342.        
  343.         mov     ecx,[eax+4]
  344.         imul    ecx,[eax+8]
  345.         push    eax ecx
  346.         lea     ecx,[ecx*3]
  347.         mov     edx,ecx
  348.         add     ecx,44          ; header
  349.         mcall   68,12           ;get new RAW area
  350.         mov     [raw_area],eax
  351.         mov     edi,eax
  352.        
  353.         push    esi
  354.         mov     esi,[image_file]
  355.         mov     ecx,3
  356.         cld
  357.         rep     movsd                   ;copy the 3 first dword for the structure of RAW
  358.         pop     esi
  359.        
  360.         sub     edi,12
  361.         mov     [edi+12],dword 24       ;overall depth of the pixel
  362.         mov     [edi+16],word 8         ;channel depth of the pixel
  363.         xor     eax,eax
  364.         mov     [edi+20],eax            ;palette area pointer
  365.         mov     [edi+24],eax            ;palette area size
  366.         mov     [edi+28],dword 44       ;rgb area pointer
  367.         mov     [edi+32],edx            ;rgb area size
  368.         mov     [edi+36],eax            ;transparency area pointer
  369.         mov     [edi+40],eax            ;transparency area size
  370.         pop     ecx eax
  371.        
  372.         add     edi,44
  373.  
  374.         cmp     [eax+12],dword 32
  375.         je      .32b
  376.         cmp     [eax+12],dword 16
  377.         je      .16b
  378.         cmp     [eax+12],dword 15
  379.         je      .15b
  380.         cmp     [eax+12],dword 8
  381.         je      .8b
  382.        
  383. .ret_ok:
  384.         mov     ebx,[pointer]
  385.         mov     eax,[raw_area]
  386.         mov     [ebx+20],eax  ; store RAW pointer
  387.         popad
  388.         ret     4
  389. ;---------------------------------------------------------------------
  390. .32b:
  391.         cld
  392.         lodsd
  393.         stosw
  394.         shr     eax,16
  395.         stosb
  396.        
  397.         dec     ecx
  398.         jnz     .32b
  399.        
  400.         jmp     .ret_ok
  401. ;---------------------------------------------------------------------
  402. .16b:
  403.         cld
  404.         lodsw
  405.        
  406.         xor     ebx,ebx
  407.         ror     ax,11
  408.         mov     bl,al
  409.         and     bl,11111b
  410.         shl     bl,3
  411.         shl     ebx,8
  412.         rol     ax,6
  413.         mov     bl,al
  414.         and     bl,111111b
  415.         shl     bl,2
  416.         shl     ebx,8
  417.         rol     ax,5
  418.         mov     bl,al
  419.         and     bl,11111b
  420.         shl     bl,3
  421.         mov     eax,ebx
  422.        
  423.         cld
  424.         stosw
  425.         shr     eax,16
  426.         stosb
  427.        
  428.         dec     ecx
  429.         jnz     .16b
  430.        
  431.         jmp     .ret_ok
  432. ;---------------------------------------------------------------------
  433. .15b:
  434.         cld
  435.         lodsw
  436.        
  437.         xor     ebx,ebx
  438.         ror     ax,10
  439.         mov     bl,al
  440.         and     bl,11111b
  441.         shl     bl,3
  442.         shl     ebx,8
  443.         rol     ax,5
  444.         mov     bl,al
  445.         and     bl,11111b
  446.         shl     bl,3
  447.         shl     ebx,8
  448.         rol     ax,5
  449.         mov     bl,al
  450.         and     bl,11111b
  451.         shl     bl,3
  452.         mov     eax,ebx
  453.        
  454.         cld
  455.         stosw
  456.         shr     eax,16
  457.         stosb
  458.        
  459.         dec     ecx
  460.         jnz     .15b
  461.        
  462.         jmp     .ret_ok
  463. ;---------------------------------------------------------------------
  464. .8b:
  465.         xor     eax,eax
  466.         cld
  467.         lodsb
  468.         shl     eax,2
  469.         mov     eax,[eax+ebp]
  470.        
  471.         cld
  472.         stosw
  473.         shr     eax,16
  474.         stosb
  475.        
  476.         dec     ecx
  477.         jnz     .8b
  478.        
  479.         jmp     .ret_ok
  480. ;---------------------------------------------------------------------
  481. align 16
  482. EXPORTS:
  483.         dd szStart,     START
  484.         dd szVersion,   0x00010003
  485.         dd szConv_24b,  Convert24b
  486.         dd 0
  487.  
  488. szStart         db 'START',0
  489. szVersion       db 'version',0
  490. szConv_24b      db 'Convert24b',0
  491. pointer         dd 0
  492. image_file      dd 0
  493. ;delta          dd 0
  494. ;resolution     dd 0
  495. ;compression    dd 0
  496. raw_area        dd 0
  497. area_size       dd 0