Subversion Repositories Kolibri OS

Rev

Rev 1956 | Go to most recent revision | 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. ;       xor  ebx,ebx
  53. ;       mov  [raw_area],ebx
  54.  
  55. ;       mov  ebx,[pointer]
  56. ;       movzx  eax,word [eax+18]
  57. ;       mov  [ebx+24],eax
  58. ;       jmp  .ret_ok
  59.        
  60.         cmp [eax+16],word 16
  61.         je  .16b
  62.         cmp [eax+12],dword 1
  63.         je  .1b
  64.         cmp [eax+12],dword 2
  65.         je  .2b
  66.         cmp [eax+12],dword 4
  67.         je  .4b
  68. ;---------------------------------------------------------------------
  69. .ret_ok:
  70. ;       mov ebx,[pointer]      
  71. ;       mov  eax,[raw_area]
  72. ;       mov  [ebx+20],eax  ; store RAW pointer
  73. ;       mov  [ebx+24],ecx
  74.  
  75.         mov  ebx,[image_file]
  76.         cmp  [ebx+18],word 2
  77.         jne  @f
  78.         mov  eax,[ebx+12]
  79.         shr  eax,1
  80.         mov  [ebx+12],eax
  81. @@:
  82.        
  83.         popad
  84.         ret     4
  85. ;--------------------------------------------------------------------- 
  86. .less_8b:
  87.         mov edx,[image_file]
  88.         mov ecx,[area_size]
  89.         add ecx,[edx+28]
  90.         mcall 68,20
  91.         mov  [image_file],eax
  92.  
  93.        
  94.         mov ecx,[area_size]
  95.         mov  eax,ecx
  96.         shr  ecx,2
  97.         test eax,3
  98.         jz  @f
  99.         inc  ecx
  100. @@:
  101.         mov  esi,[raw_area]
  102.         mov  edi,[image_file]
  103.         add  edi,[edi+28]
  104.         cld  
  105.         rep movsd
  106.                
  107.         mov  ecx,[raw_area]
  108.         mcall 68,13
  109.         mov eax,[image_file]
  110.         mov ebx,[pointer]
  111.         mov [ebx+4],eax
  112.         popad
  113.         ret     4
  114. ;--------------------------------------------------------------------- 
  115. .16b:
  116.         cmp  [eax+18],word 3
  117.         je   @f   ;.convert_16_in_8
  118.         cmp  [eax+18],word 4
  119.         jne  .16b_1
  120. @@:
  121.         xor  ebx,ebx
  122.         mov  bx,[eax+18]
  123.        
  124.         xchg  eax,ecx
  125.         xor  edx,edx
  126.         div  ebx
  127.         xchg  ecx,eax
  128.        
  129.         shr  ecx,1
  130.        
  131.         mov  [eax+16],word 8
  132.         mov  ebx,[eax+12]
  133.         shr  ebx,1
  134.         mov  [eax+12],ebx
  135.  
  136.         mov  ebx,eax
  137. ;       jmp  .ret_ok
  138.        
  139. .convert_16_in_8:   ; converting 16 bit sample to 8 bit
  140.         cld
  141.         lodsw
  142.         mov al,ah
  143.         stosb
  144.        
  145.         lodsw
  146.         mov al,ah
  147.         stosb
  148.        
  149.         lodsw
  150.         mov al,ah
  151.         stosb
  152.        
  153.         cmp [ebx+18],word 4
  154.         jne @f
  155.         lodsw
  156.         mov al,ah
  157.         stosb
  158. @@:  
  159.         dec ecx
  160.         jnz .convert_16_in_8
  161.         jmp .16b_end
  162. ;---------------------------------------------------------------------
  163. .16b_1:
  164.         cmp  [eax+18],word 1
  165.         je   @f  ;.convert_16_in_8_1
  166.         cmp  [eax+18],word 2
  167.         jne  .16b_end
  168. @@:
  169.         shr  ecx,1
  170.        
  171.         mov  [eax+16],word 8
  172.         mov  ebx,[eax+12]
  173.         shr  ebx,1
  174.         mov  [eax+12],ebx
  175.        
  176. .convert_16_in_8_1:
  177.         cld
  178.         lodsw
  179. ;       shr ax,8
  180. ;       mov al,ah
  181.         stosb
  182.         dec ecx
  183.         jnz .convert_16_in_8_1
  184. ;---------------------------------------------------------------------
  185. .16b_end:
  186.         xor  eax,eax
  187.         mov  [raw_area],eax
  188.         jmp .ret_ok
  189. ;--------------------------------------------------------------------- 
  190. .4b:
  191.         call .get_memory
  192.         mov  edx,ebx
  193.         inc  ebx
  194.         shr  ebx,1
  195. .4b_1:
  196.         push ebx edi
  197. @@:
  198.         cld
  199.         lodsb
  200.         shl  eax,8
  201.         mov  al,ah
  202.         and  ah,0xf
  203.         shr  al,4
  204.         stosw
  205.        
  206.         dec  ebx
  207.         jnz  @b
  208.         pop  edi ebx
  209.         add  edi,edx
  210.         dec  ecx
  211.         jnz  .4b_1
  212.        
  213.         jmp .less_8b  ;.ret_ok
  214. ;---------------------------------------------------------------------
  215. .2b:
  216.         call .get_memory
  217. ;       jmp .ret_ok
  218. ;       shr  ecx,1
  219.         mov  edx,ebx
  220.         mov  eax,ebx
  221.         shr  ebx,2
  222.         test eax,3
  223.         jz  @f
  224.         inc  ebx
  225. @@:
  226.         mov  ebp,ebx
  227. .2b_1:
  228.         push ebp edi
  229. @@:
  230.         cld
  231.         lodsb
  232.        
  233.         mov  bl,al
  234.        
  235.         and  al,11b
  236.         shl  ax,8
  237.        
  238.         mov  al,bl
  239.         shr  al,2
  240.         and  al,11b
  241.         shl  eax,8
  242.        
  243.         mov  al,bl
  244.         shr  al,4
  245.         and  al,11b
  246.         shl  eax,8
  247.        
  248.         mov  al,bl
  249.         shr  al,6
  250.         and  al,11b
  251.        
  252.         stosd
  253.  
  254.         dec  ebp
  255.         jnz  @b
  256.         pop  edi ebp
  257.        
  258.         add  edi,edx
  259.         dec  ecx
  260.         jnz  .2b_1
  261.        
  262.         jmp .less_8b  ;.ret_ok
  263. ;---------------------------------------------------------------------
  264. .1b:
  265.         call .get_memory
  266.         mov  edx,ebx
  267.         mov  eax,ebx
  268.         shr  ebx,3
  269.         test eax,7
  270.         jz  @f
  271.         inc  ebx
  272. @@:
  273.         mov  ebp,ebx
  274. .1b_1:
  275.         push ebp edi
  276. @@:
  277.         cld
  278.         lodsb
  279.        
  280.         mov  bl,al
  281.         shr  al,4
  282.         and  al,1b
  283.         shl  ax,8
  284.        
  285.         mov  al,bl
  286.         shr  al,5
  287.         and  al,1b
  288.         shl  eax,8
  289.        
  290.         mov  al,bl
  291.         shr  al,6
  292.         and  al,1b
  293.         shl  eax,8
  294.        
  295.         mov  al,bl
  296.         shr  al,7
  297. ;       and  al,1b
  298. ;       shl  eax,8
  299.        
  300.         stosd
  301.        
  302.         mov  al,bl
  303.         and  al,1b
  304.         shl  ax,8
  305.        
  306.         mov  al,bl
  307.         shr  al,1
  308.         and  al,1b
  309.         shl  eax,8
  310.  
  311.         mov  al,bl
  312.         shr  al,2
  313.         and  al,1b
  314.         shl  eax,8
  315.        
  316.         mov  al,bl
  317.         shr  al,3
  318.         and  al,1b
  319.        
  320.         stosd
  321.        
  322.         dec  ebp
  323.         jnz  @b
  324.         pop  edi ebp
  325.        
  326.         add  edi,edx
  327.         dec  ecx
  328.         jnz  .1b_1
  329.         jmp .less_8b  ;.ret_ok 
  330. ;---------------------------------------------------------------------
  331. .get_memory:
  332.         mov  ebx,dword 8
  333.         mov  [eax+16],bx
  334.         mov  [eax+12],ebx
  335. ;       mov  esi,[eax+28]
  336. ;       add  esi,eax
  337. ;       push ecx
  338.         mov  ecx,[eax+4]
  339.         imul ecx,[eax+8]
  340.         push eax
  341.         mov  [area_size],ecx
  342.         mcall 68,12
  343. ;       pop  ecx
  344.         mov  [raw_area],eax
  345.         mov  edi,eax
  346.         pop  eax
  347.         mov  ebx,[eax+4]
  348.         mov  ecx,[eax+8]
  349.         ret
  350. ;---------------------------------------------------------------------
  351. Convert24b:
  352.         pushad
  353.         mov     eax,dword [esp+36]
  354.         mov [pointer],eax
  355.         mov eax,[eax+4]
  356.         mov [image_file],eax
  357.  
  358.         mov  esi,[eax+28]
  359.         add  esi,eax
  360.  
  361.         mov  ebp,[eax+20]
  362.         add  ebp,eax
  363.        
  364.         mov  ecx,[eax+4]
  365.         imul ecx,[eax+8]
  366.         push eax ecx
  367.         lea  ecx,[ecx*3]
  368.         mcall 68,12
  369.         mov  [raw_area],eax
  370.         mov  edi,eax
  371.         pop  ecx eax
  372.  
  373.         cmp [eax+12],dword 32
  374.         je  .32b
  375.         cmp [eax+12],dword 16
  376.         je  .16b
  377.         cmp [eax+12],dword 15
  378.         je  .15b
  379.         cmp [eax+12],dword 8
  380.         je  .8b
  381.        
  382. .ret_ok:
  383.         mov ebx,[pointer]
  384.         mov  eax,[raw_area]
  385.         mov  [ebx+20],eax  ; store RAW pointer
  386.         popad
  387.         ret     4
  388.  
  389. ;---------------------------------------------------------------------
  390. .32b:
  391.         cld
  392.         lodsd
  393.        
  394.         stosw
  395.         shr eax,16
  396.         stosb
  397.        
  398.         dec  ecx
  399.         jnz  .32b
  400.        
  401.         jmp  .ret_ok
  402. ;---------------------------------------------------------------------
  403. .16b:
  404.         cld
  405.         lodsw
  406.        
  407.         xor ebx,ebx
  408.         ror ax,11
  409.         mov bl,al
  410.         and bl,11111b
  411.         shl bl,3
  412.         shl ebx,8
  413.         rol ax,6
  414.         mov bl,al
  415.         and bl,111111b
  416.         shl bl,2
  417.         shl ebx,8
  418.         rol ax,5
  419.         mov bl,al
  420.         and bl,11111b
  421.         shl bl,3
  422.         mov eax,ebx
  423.        
  424.         cld
  425.         stosw
  426.         shr eax,16
  427.         stosb
  428.        
  429.         dec  ecx
  430.         jnz  .16b
  431.        
  432.         jmp  .ret_ok
  433. ;---------------------------------------------------------------------
  434. .15b:
  435.         cld
  436.         lodsw
  437.        
  438.         xor ebx,ebx
  439.         ror ax,10
  440.         mov bl,al
  441.         and bl,11111b
  442.         shl bl,3
  443.         shl ebx,8
  444.         rol ax,5
  445.         mov bl,al
  446.         and bl,11111b
  447.         shl bl,3
  448.         shl ebx,8
  449.         rol ax,5
  450.         mov bl,al
  451.         and bl,11111b
  452.         shl bl,3
  453.         mov eax,ebx
  454.        
  455.         cld
  456.         stosw
  457.         shr eax,16
  458.         stosb
  459.        
  460.         dec  ecx
  461.         jnz  .15b
  462.        
  463.         jmp  .ret_ok
  464. ;---------------------------------------------------------------------
  465. .8b:
  466.         xor  eax,eax
  467.         cld
  468.         lodsb
  469.         shl  eax,2
  470.         mov  eax,[eax+ebp]
  471.        
  472.         cld
  473.         stosw
  474.         shr eax,16
  475.         stosb
  476.        
  477.         dec  ecx
  478.         jnz  .8b
  479.        
  480.         jmp  .ret_ok
  481. ;---------------------------------------------------------------------
  482. align 16
  483. EXPORTS:
  484.         dd      szStart,        START
  485.         dd      szVersion,      0x00010002
  486.         dd      szConv_24b,     Convert24b
  487.         dd      0
  488.  
  489. szStart         db 'START',0
  490. szVersion       db 'version',0
  491. szConv_24b      db 'Convert24b',0
  492. pointer         dd 0
  493. image_file      dd 0
  494. ;delta          dd 0
  495. ;resolution     dd 0
  496. ;compression    dd 0
  497. raw_area        dd 0
  498. area_size       dd 0