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:
  29.    push eax ecx edx
  30.    mov  ebp,[line_filter_type]
  31.    cmp  ebp,0
  32.    je   .end
  33.    cmp  ebp,1
  34.    je   .Sub
  35.    cmp  ebp,2
  36.    je   .Up
  37.    cmp  ebp,3
  38.    je   .Averag
  39.    cmp  ebp,4
  40.    je   .Paeth
  41.    jmp  .end
  42. ;---------------------------------------------------------------------
  43. .Sub:
  44.    cmp  [IHDR_data.Bit_depth],byte 16
  45.    jne  @f
  46.    mov  eax,ebx
  47.    shr  eax,16
  48.    add  bl,al
  49.    add  bh,ah
  50.    jmp  .end
  51. @@:
  52.    add  bl,bh
  53.    jmp  .end
  54. ;---------------------------------------------------------------------
  55. .Up:
  56.    cmp  [first_line],byte 0
  57.    jne  .end
  58.    mov  eax,[IHDR_data.Width]
  59.    cmp [IHDR_data.Color_type],byte 0
  60.    je  .Up_Color_type_0_and_3
  61.    cmp [IHDR_data.Color_type],byte 3
  62.    je  .Up_Color_type_0_and_3
  63.    cmp [IHDR_data.Color_type],byte 4
  64.    je  @f
  65.    lea  eax,[eax*3]
  66. @@:
  67.    cmp [IHDR_data.Color_type],byte 4
  68.    je  .Up_Alpfa
  69.    cmp [IHDR_data.Color_type],byte 6
  70.    jne @f
  71. .Up_Alpfa:
  72.    add  eax,[IHDR_data.Width]
  73.    
  74. @@:
  75. .Up_8:
  76.    cmp  [IHDR_data.Bit_depth],byte 16
  77.    je   .Up_16
  78.    mov  ebp,edi
  79.    sub  ebp,eax
  80.    mov  bh,[ebp]
  81.    add  bl,bh
  82.    jmp  .end
  83.  
  84. .Up_Color_type_0_and_3:
  85.    cmp  [IHDR_data.Bit_depth],byte 16
  86.    je   .Up_16
  87.    call  .Bit_depth_less_8
  88.    jmp  .Up_8
  89.  
  90. .Bit_depth_less_8:  
  91. ;   imul eax,[resolution]
  92.    cmp [resolution],8
  93.    jne @f
  94.    ret
  95. @@:
  96.    cmp [resolution],4
  97.    jne @f
  98.    shl eax,2
  99.    jmp  .continue_Bit_depth_less_8
  100. @@:
  101.    cmp [resolution],2
  102.    jne .continue_Bit_depth_less_8
  103.    shl eax,1
  104. .continue_Bit_depth_less_8:
  105.    push ebx
  106.    mov  ebx,eax
  107.    shr  eax,3
  108.    test ebx,7
  109.    jz  @f
  110.    inc  eax
  111. @@:
  112.    pop  ebx
  113.    ret
  114.  
  115. .Up_16:
  116.    shl  eax,1
  117.    mov  ebp,edi
  118.    sub  ebp,eax
  119.    mov  ax,[ebp]
  120.    add  bl,al
  121.    add  bh,ah
  122.    jmp  .end
  123. ;---------------------------------------------------------------------
  124. .Averag:
  125.    cmp [first_line],byte 0
  126.    je  @f
  127.    xor eax,eax
  128.    cmp  [IHDR_data.Bit_depth],byte 16
  129.    je  .Averag_2
  130.    jmp .Averag_1
  131. @@:
  132.    mov eax,[IHDR_data.Width]
  133.    cmp [IHDR_data.Color_type],byte 0
  134.    je  .Averag_Color_type_0_and_3  ;@f
  135.    cmp [IHDR_data.Color_type],byte 3
  136.    je  .Averag_Color_type_0_and_3  ;@f
  137.    cmp [IHDR_data.Color_type],byte 4
  138.    je  @f
  139.    lea eax,[eax*3]
  140. @@:
  141.    cmp [IHDR_data.Color_type],byte 4
  142.    je  .Averag_Alpfa
  143.    cmp [IHDR_data.Color_type],byte 6
  144.    jne @f
  145. .Averag_Alpfa:
  146.    add eax,[IHDR_data.Width]
  147.  
  148. @@:
  149. .Averag_8:
  150.    cmp  [IHDR_data.Bit_depth],byte 16
  151.    je  .Averag_16
  152.    mov ebp,edi
  153.    sub ebp,eax
  154.    xor eax,eax
  155.    mov al,[ebp]
  156. .Averag_1:
  157.    movzx ebp,bh
  158.    add eax,ebp
  159.    shr eax,1
  160.    add bl,al
  161.    jmp  .end
  162.  
  163. .Averag_Color_type_0_and_3:
  164.    cmp  [IHDR_data.Bit_depth],byte 16
  165.    je   .Averag_16
  166.    call  .Bit_depth_less_8
  167.    jmp  .Averag_8
  168.      
  169. .Averag_16:
  170.    shl eax,1
  171.    mov ebp,edi
  172.    sub ebp,eax
  173.    xor eax,eax
  174.    mov ax,[ebp]
  175. .Averag_2:
  176.    mov ebp,ebx
  177.    shr ebp,16
  178.    mov ecx,ebp
  179.    and ecx,0xff
  180.    mov edx,eax
  181.    and edx,0xff  
  182.    add ecx,edx
  183.    shr ecx,1
  184.    add bl,cl
  185.    shr ebp,8
  186.    shr eax,8
  187.    add eax,ebp
  188.    shr eax,1
  189.    add bh,al  
  190.    jmp  .end
  191. ;---------------------------------------------------------------------
  192. .Paeth:
  193.    cmp [first_line],byte 0
  194.    je  @f
  195.    xor eax,eax
  196.    cmp  [IHDR_data.Bit_depth],byte 16
  197.    je  .Paeth_16_1
  198.    jmp .Paeth_1
  199. @@:
  200.    mov eax,[IHDR_data.Width]
  201.    cmp [IHDR_data.Color_type],byte 0
  202.    je  .Paeth_Color_type_0_and_3  ;@f
  203.    cmp [IHDR_data.Color_type],byte 3
  204.    je  .Paeth_Color_type_0_and_3  ;@f
  205.    cmp [IHDR_data.Color_type],byte 4
  206.    je  @f
  207.    lea eax,[eax*3]
  208. @@:
  209.    cmp [IHDR_data.Color_type],byte 4
  210.    je  .Paeth_Alpfa
  211.    cmp [IHDR_data.Color_type],byte 6
  212.    jne @f
  213. .Paeth_Alpfa:
  214.    add eax,[IHDR_data.Width]
  215.  
  216. @@:
  217.    cmp  [IHDR_data.Bit_depth],byte 16
  218.    je  .Paeth_16
  219. .Paeth_8:
  220.    mov ebp,edi
  221.    sub ebp,eax
  222.    xor eax,eax
  223.    mov al,[ebp]
  224. .Paeth_1:
  225.    mov [Paeth_filter.b],al
  226.    
  227.    cmp [first_line],byte 0
  228.    jne  @f
  229.    cmp [first_pixel],0
  230.    jne  @f
  231.    mov ah,[ebp-1]
  232.    cmp [IHDR_data.Color_type],byte 0
  233.    je  @f
  234.    cmp [IHDR_data.Color_type],byte 3
  235.    je  @f
  236.    mov ah,[ebp-2]
  237.    cmp [IHDR_data.Color_type],byte 4
  238.    je  @f
  239.    mov ah,[ebp-3]
  240.    cmp [IHDR_data.Color_type],byte 2
  241.    je @f
  242.    mov ah,[ebp-4]
  243. @@:
  244.    mov [Paeth_filter.c],ah
  245.    mov [Paeth_filter.a],bh
  246.    
  247.    xor eax,eax
  248.    mov al,[Paeth_filter.a]
  249.    mov ebp,eax
  250.    mov al,[Paeth_filter.b]
  251.    add ebp,eax
  252.    mov al,[Paeth_filter.c]
  253.    sub ebp,eax
  254.    mov [Paeth_filter.p],ebp
  255. ;----------------------------------------
  256.    mov al,[Paeth_filter.a]
  257.    sub ebp,eax
  258.    test ebp,0x80000000
  259.    jz  @f
  260.    neg ebp
  261. @@:
  262.    mov [Paeth_filter.pa],ebp
  263.    
  264.    mov ebp,[Paeth_filter.p]
  265.    mov al,[Paeth_filter.b]
  266.    sub ebp,eax
  267.    test ebp,0x80000000
  268.    jz  @f
  269.    neg ebp
  270. @@:
  271.    mov [Paeth_filter.pb],ebp  
  272.    
  273.    mov ebp,[Paeth_filter.p]
  274.    mov al,[Paeth_filter.c]
  275.    sub ebp,eax
  276.    test ebp,0x80000000
  277.    jz  @f
  278.    neg ebp
  279. @@:
  280.    mov [Paeth_filter.pc],ebp
  281.    
  282.    mov eax,[Paeth_filter.pa]
  283.    mov ebp,[Paeth_filter.pb]
  284.    cmp eax,ebp
  285.    ja .no_return_a
  286.    cmp eax,[Paeth_filter.pc]
  287.    ja .no_return_a
  288.    add bl,[Paeth_filter.a]
  289.    jmp .end
  290. .no_return_a:
  291.    cmp ebp,[Paeth_filter.pc]
  292.    ja .no_return_b
  293.    add bl,[Paeth_filter.b]
  294.    jmp .end
  295. .no_return_b:
  296.    add bl,[Paeth_filter.c]
  297. .end:
  298.    pop  edx ecx eax
  299.    ret
  300. ;----------------------------------------  
  301. .Paeth_Color_type_0_and_3:
  302.    cmp  [IHDR_data.Bit_depth],byte 16
  303.    je   .Paeth_16
  304.    call  .Bit_depth_less_8
  305.    jmp  .Paeth_8
  306. ;----------------------------------------
  307. .Paeth_16:
  308.    shl eax,1
  309.    mov ebp,edi
  310.    sub ebp,eax
  311.    xor eax,eax
  312.    mov ax,[ebp]
  313. .Paeth_16_1:
  314.    mov [Paeth_filter.b],ax
  315.    xor eax,eax
  316.    cmp [first_line],byte 0
  317.    jne  @f
  318.    cmp [first_pixel],0
  319.    jne  @f
  320.    mov ax,[ebp-2]
  321.    cmp [IHDR_data.Color_type],byte 0
  322.    je  @f
  323.    mov ax,[ebp-4]
  324.    cmp [IHDR_data.Color_type],byte 4
  325.    je  @f
  326.    mov ax,[ebp-6]
  327.    cmp [IHDR_data.Color_type],byte 2
  328.    je  @f
  329.    mov ax,[ebp-8]
  330. @@:
  331.    mov [Paeth_filter.c],ax
  332.    mov eax,ebx
  333.    shr eax,16
  334.    mov [Paeth_filter.a],ax
  335. ;----------------------------------------
  336.    xor eax,eax
  337.    mov ax,[Paeth_filter.a]
  338.    shr ax,8
  339.    mov bp,ax
  340.    mov ax,[Paeth_filter.b]
  341.    shr ax,8
  342.    add bp,ax
  343.    mov ax,[Paeth_filter.c]
  344.    shr ax,8
  345.    sub bp,ax
  346.    shl ebp,16
  347.    
  348.    xor eax,eax
  349.    mov al,[Paeth_filter.a]
  350.    mov bp,ax
  351.    mov al,[Paeth_filter.b]
  352.    add bp,ax
  353.    mov al,[Paeth_filter.c]
  354.    sub bp,ax  
  355.    
  356.    mov [Paeth_filter.p],ebp
  357. ;----------------------------------------
  358.    xor eax,eax
  359.    mov ax,[Paeth_filter.a]
  360.    mov ecx,ebp
  361.    mov dx,ax
  362.    shr ecx,16
  363.    shr dx,8
  364.    sub cx,dx
  365.    test cx,0x8000
  366.    jz  @f
  367.    neg cx
  368. @@:
  369.    shl ecx,16
  370.  
  371.    and ebp,0xffff
  372.    and eax,0xff
  373.    sub bp,ax
  374.    test bp,0x8000
  375.    jz  @f
  376.    neg bp
  377. @@:
  378.    add ebp,ecx
  379.    mov [Paeth_filter.pa],ebp
  380. ;----------------------------------------
  381.    xor eax,eax
  382.    mov ebp,[Paeth_filter.p]
  383.    mov ax,[Paeth_filter.b]
  384.    mov ecx,ebp
  385.    mov dx,ax
  386.    shr ecx,16
  387.    shr dx,8
  388.    sub cx,dx
  389.    test cx,0x8000
  390.    jz  @f
  391.    neg cx
  392. @@:
  393.    shl ecx,16
  394.  
  395.    and ebp,0xffff
  396.    and eax,0xff
  397.    sub bp,ax
  398.    test bp,0x8000
  399.    jz  @f
  400.    neg bp
  401. @@:
  402.    add ebp,ecx
  403.    mov [Paeth_filter.pb],ebp
  404. ;----------------------------------------
  405.    xor eax,eax
  406.    mov ebp,[Paeth_filter.p]
  407.    mov ax,[Paeth_filter.c]
  408.    mov ecx,ebp
  409.    mov dx,ax
  410.    shr ecx,16
  411.    shr dx,8
  412.    sub cx,dx
  413.    test cx,0x8000
  414.    jz  @f
  415.    neg cx
  416. @@:
  417.    shl ecx,16
  418.  
  419.    and ebp,0xffff
  420.    and eax,0xff
  421.    sub bp,ax
  422.    test bp,0x8000
  423.    jz  @f
  424.    neg bp
  425. @@:
  426.    add ebp,ecx
  427.    mov [Paeth_filter.pc],ebp
  428. ;----------------------------------------
  429.    mov eax,[Paeth_filter.pa]
  430.    mov ebp,[Paeth_filter.pb]
  431.    mov ecx,[Paeth_filter.pc]
  432.    shr eax,16
  433.    shr ebp,16
  434.    shr ecx,16
  435.    cmp ax,bp
  436.    ja .no_return_a_1
  437.    cmp ax,cx
  438.    ja .no_return_a_1
  439.    mov ax,[Paeth_filter.a]
  440.    add bh,ah
  441.    jmp .end_1
  442. .no_return_a_1:
  443.    cmp bp,cx
  444.    ja .no_return_b_1
  445.    mov ax,[Paeth_filter.b]
  446.    add bh,ah
  447.    jmp .end_1
  448. .no_return_b_1:
  449.    mov ax,[Paeth_filter.c]
  450.    add bh,ah
  451. .end_1:
  452. ;----------------------------------------
  453.    mov eax,[Paeth_filter.pa]
  454.    mov ebp,[Paeth_filter.pb]
  455.    mov ecx,[Paeth_filter.pc]
  456.    cmp ax,bp
  457.    ja .no_return_a_2
  458.    cmp ax,cx
  459.    ja .no_return_a_2
  460.    add bl,[Paeth_filter.a]
  461.    jmp .end_2
  462. .no_return_a_2:
  463.    cmp bp,cx
  464.    ja .no_return_b_2
  465.    add bl,[Paeth_filter.b]
  466.    jmp .end_2
  467. .no_return_b_2:
  468.    add bl,[Paeth_filter.c]
  469. .end_2:
  470.    pop  edx ecx eax
  471.    ret
  472. ;---------------------------------------------------------------------