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. deflate_callback:
  29.    cmp  [deflate_start_offset],1
  30.    je   @f
  31.    mov  [deflate_start_offset],1
  32.    jmp  .1
  33. @@:
  34.    mov  eax,[IDAT.pointer]
  35.    add  eax,[IDAT.size]
  36.    mov  ebx,[image_file]
  37.    add  ebx,[file_size]
  38.    sub  ebx,32
  39.    cmp  ebx,eax
  40.    jbe   @f
  41.    mov  [next_Chunk],eax
  42.    call search_IDAT
  43.    jmp  .1
  44. @@:
  45.    xor  eax,eax
  46.    mov  [IDAT.size],eax
  47.    mov  [IDAT.pointer],eax
  48. .1:
  49.         mov     ecx, [esp+8]
  50.         mov eax,[IDAT.size]
  51.         mov     [ecx], eax   ;length
  52.         mov     eax,[IDAT.pointer]   ; buffer
  53.         ret     8
  54. ;---------------------------------------------------------------------
  55. search_IHDR:
  56.    mov  [Chunk_pointer],IHDR_name
  57.    call get_Chunk_data_pointer
  58.    mov  eax,[Chunk_pointer]
  59.    cmp  eax,0
  60.    je   .no_png_file
  61.    mov  [IHDR.pointer],eax
  62.    mov  ecx,[eax-8]
  63.    call convert_NBO_to_PC
  64.    mov  [IHDR.size],ecx
  65.    ret
  66. .no_png_file:
  67.    add  esp,4
  68.    jmp  no_png_file
  69. ;---------------------------------------------------------------------
  70. search_PLTE:
  71.    push eax ecx
  72.    mov  [Chunk_pointer],PLTE_name
  73.    call get_Chunk_data_pointer
  74.    mov  eax,[Chunk_pointer]
  75.    cmp  eax,0
  76.    je   .no_png_file
  77.    mov  [PLTE.pointer],eax
  78.    mov  ecx,[eax-8]
  79.    call convert_NBO_to_PC
  80.    mov  [PLTE.size],ecx
  81.    pop  ecx eax
  82.    ret
  83. .no_png_file:
  84.    add  esp,12
  85.    jmp  no_png_file
  86. ;---------------------------------------------------------------------
  87. search_IDAT:
  88.    mov  [Chunk_pointer],IDAT_name  
  89.    call get_Chunk_data_pointer
  90.    mov  eax,[Chunk_pointer]
  91.    cmp  eax,0
  92.    je   .no_IDAT_next
  93.    mov  [IDAT.pointer],eax
  94.    mov  ecx,[eax-8]
  95.    call convert_NBO_to_PC
  96.    mov  [IDAT.size],ecx
  97.    xor  eax,eax
  98.    ret
  99. .no_IDAT_next:
  100. ;   add  esp,4
  101. ;   jmp  no_png_file
  102.    mov  eax,1
  103.    ret
  104. ;---------------------------------------------------------------------
  105. search_IEND:
  106.    mov  [Chunk_pointer],IEND_name
  107.    call get_Chunk_data_pointer
  108.    mov  eax,[Chunk_pointer]
  109.    cmp  eax,0
  110.    je   .no_png_file
  111.    mov  [IEND.pointer],eax
  112.    mov  ecx,[eax-8]
  113.    call convert_NBO_to_PC
  114.    mov  [IEND.size],ecx
  115.    ret
  116. .no_png_file:
  117.    add  esp,4
  118.    jmp  no_png_file
  119. ;---------------------------------------------------------------------
  120. convert_NBO_to_PC:   ;network byte order value to PC value
  121.    push eax
  122.    mov  al,ch
  123.    mov  ah,cl
  124.    shl  eax,16
  125.    shr  ecx,16
  126.    mov  al,ch
  127.    mov  ah,cl
  128.    mov  ecx,eax
  129.    pop  eax
  130.    ret
  131. ;---------------------------------------------------------------------
  132. get_Chunk_data_pointer:
  133.    pushad
  134.    mov   ebp,4
  135. ;   mov   edi,[image_file]
  136.    mov   edi,[next_Chunk]  
  137.    mov   edx,[image_file]  ;edi
  138.    add   edx,[file_size]
  139.    dec   edi
  140. .search_Chunk:
  141.    cmp   edx,edi
  142.    jbe   .end
  143.    mov   esi,[Chunk_pointer]
  144.    mov   ecx,ebp
  145.    inc   edi
  146.    mov   ebx,edi
  147.    cld
  148.    rep   cmpsb
  149.    mov   edi,ebx
  150.    jne   .search_Chunk
  151.    add   edi,ebp
  152.    mov   [Chunk_pointer],edi
  153.    popad
  154.    ret
  155. .end:
  156.    mov   [Chunk_pointer],0
  157.    popad
  158.    ret
  159. ;---------------------------------------------------------------------