Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;*****************************************************************************
  2. ; PNG to RAW convert plugin - for zSea image viewer
  3. ; Copyright (c) 2008, 2009, 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. filtering_RGB:
  29.         mov  ecx,[IHDR_data.Height]
  30.         test ecx,ecx
  31.         jz       .filter_end
  32. .filter:
  33.         mov edx,[IHDR_data.Width]
  34.         test edx,edx
  35.         jz       .filter_end
  36.         xor eax,eax
  37.         mov [previous_pixel_value],eax
  38.         mov [first_pixel],byte 1
  39.         mov al,[esi]
  40.         mov [line_filter_type],eax
  41.         inc esi
  42.        
  43. .filter_x:
  44.  
  45.         mov bh,[previous_pixel_value]
  46.         call filtering_sample_8
  47.         mov [previous_pixel_value],bl
  48.        
  49.         mov bh,[previous_pixel_value+1]
  50.         call filtering_sample_8
  51.         mov [previous_pixel_value+1],bl
  52.  
  53.         mov bh,[previous_pixel_value+2]
  54.         call filtering_sample_8
  55.         mov [previous_pixel_value+2],bl
  56.        
  57.         cmp [IHDR_data.Color_type],byte 6
  58.         jne @f
  59.  
  60.         mov bh,[previous_pixel_value+3]
  61.         call filtering_sample_8
  62.         mov [previous_pixel_value+3],bl
  63. @@:
  64.         mov [first_pixel],byte 0
  65.         dec edx
  66.         jnz .filter_x
  67.         mov [first_line],byte 0
  68.         dec ecx
  69.         jnz .filter
  70. .filter_end:
  71.         ret
  72. ;-------------------------------
  73. filtering_sample_8:
  74.         cld
  75.         lodsb
  76.         mov bl,al
  77.         call filtering
  78.         mov al,bl
  79.         cld
  80.         stosb
  81.         ret
  82. ;---------------------------------------------------------------------
  83. filtering_RGB_16:
  84.         mov  ecx,[IHDR_data.Height]
  85.         test ecx,ecx
  86.         jz       .filter_end_16
  87. .filter_16:
  88.         mov edx,[IHDR_data.Width]
  89.         test edx,edx
  90.         jz       .filter_end_16
  91.         xor eax,eax
  92.         mov [previous_pixel_value],eax
  93.         mov [previous_pixel_value+4],eax
  94.         mov [first_pixel],byte 1
  95.         mov al,[esi]
  96.         mov [line_filter_type],eax
  97.         inc esi
  98. .filter_x_16:
  99.         mov bx,[previous_pixel_value]
  100.         call filtering_sample_16
  101.         mov [previous_pixel_value],bx
  102.                
  103.         mov bx,[previous_pixel_value+2]
  104.         call filtering_sample_16
  105.         mov [previous_pixel_value+2],bx
  106.                
  107.         mov bx,[previous_pixel_value+4]
  108.         call filtering_sample_16
  109.         mov [previous_pixel_value+4],bx
  110.                
  111.         cmp [IHDR_data.Color_type],byte 6
  112.         jne @f
  113.  
  114.         mov bx,[previous_pixel_value+6]
  115.         call filtering_sample_16
  116.         mov [previous_pixel_value+6],bx
  117. @@:
  118.         mov [first_pixel],byte 0
  119.         dec edx
  120.         jnz .filter_x_16
  121.         mov [first_line],byte 0
  122.         dec ecx
  123.         jnz .filter_16
  124. .filter_end_16:
  125.         ret
  126. ;-------------------------------
  127. filtering_sample_16:
  128.         shl ebx,16
  129.         cld
  130.         lodsw
  131.         mov  bx,ax
  132.         call filtering
  133.         mov  ax,bx
  134.         cld
  135.         stosw
  136.         ret
  137. ;---------------------------------------------------------------------
  138. filtering_grayscale:
  139.         mov  ecx,[IHDR_data.Height]
  140.         test ecx,ecx
  141.         jz       .filter_end_grayscale
  142.        
  143.         mov edx,[IHDR_data.Width]
  144.         test edx,edx
  145.         jz       .filter_end_grayscale
  146.         cmp [IHDR_data.Color_type],byte 4
  147.         je  @f
  148.         imul edx,[resolution]
  149.         mov eax,edx
  150.         shr edx,3
  151.         test eax,7
  152.         jz  @f
  153.         inc  edx
  154. @@:
  155.  
  156. .filter_grayscale:
  157.         push edx
  158.         xor eax,eax
  159.         mov [previous_pixel_value],eax
  160.         mov [first_pixel],byte 1
  161.         mov al,[esi]
  162.         mov [line_filter_type],eax
  163.         inc esi
  164.  
  165. .filter_x_grayscale:
  166.  
  167.         mov bh,[previous_pixel_value]
  168.         call filtering_sample_8
  169.         mov [previous_pixel_value],bl
  170.  
  171.         cmp [IHDR_data.Color_type],byte 4
  172.         jne @f
  173.        
  174.         mov bh,[previous_pixel_value+1]
  175.         call filtering_sample_8
  176.         mov [previous_pixel_value+1],bl
  177. @@:
  178.         mov [first_pixel],byte 0
  179.         dec edx
  180.         jnz .filter_x_grayscale
  181.         pop edx
  182.        
  183.         mov [first_line],byte 0
  184.         dec ecx
  185.         jnz .filter_grayscale
  186. .filter_end_grayscale:
  187.         ret
  188. ;---------------------------------------------------------------------
  189. filtering_grayscale_16:
  190.         mov  ecx,[IHDR_data.Height]
  191.         test ecx,ecx
  192.         jz       .filter_end_grayscale_16
  193.        
  194. .filter_grayscale_Bit_depth_16:
  195.  
  196.         mov edx,[IHDR_data.Width]
  197.         test edx,edx
  198.         jz       .filter_end_grayscale_16
  199.         xor eax,eax
  200.         mov [previous_pixel_value],eax
  201.         mov [first_pixel],byte 1
  202.         mov al,[esi]
  203.         mov [line_filter_type],eax
  204.         inc esi
  205. .filter_x_grayscale_16:
  206.         mov bx,[previous_pixel_value]
  207.         call filtering_sample_16
  208.         mov [previous_pixel_value],bx
  209.  
  210.         cmp [IHDR_data.Color_type],byte 4
  211.         jne @f
  212.         mov bx,[previous_pixel_value+2]
  213.         call filtering_sample_16
  214.         mov [previous_pixel_value+2],bx
  215.  
  216. @@:
  217.         mov [first_pixel],byte 0
  218.         dec edx
  219.         jnz .filter_x_grayscale_16
  220.         mov [first_line],byte 0
  221.         dec ecx
  222.         jnz .filter_grayscale_Bit_depth_16
  223. .filter_end_grayscale_16:
  224.         ret
  225. ;---------------------------------------------------------------------
  226.