Subversion Repositories Kolibri OS

Rev

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

  1. ;*****************************************************************************
  2. ; Scaling RAW image plugin - for zSea image viewer
  3. ; Copyright (c) 2009 - 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. ; Scaling 32b, 24b, 16b, 8b
  29.  
  30. format MS COFF
  31.  
  32. public EXPORTS
  33.  
  34. section '.flat' code readable align 16
  35.  
  36. ;include        'macros.inc'
  37. include '../../../../macros.inc'
  38. ;---------------------------------------------------------------------
  39. START:
  40.         pushad
  41.         mov     eax,dword [esp+60]      ; eax - crop size
  42.         mov     ebx,eax
  43.         and     eax,0xffff
  44.         shr     ebx,16
  45.         mov     [crop_x],ebx
  46.         mov     [crop_y],eax
  47.         mov     edi,dword [esp+56]      ; edi - background color
  48.         mov     esi,dword [esp+52]      ; esi - filtering
  49.         mov     edx,dword [esp+48]      ; edx - scaling mode
  50.         mov     ecx,dword [esp+44]      ; ecx - start_coordinates
  51.         mov     ebx,dword [esp+40]      ; ebx - new_size
  52.         mov     eax,dword [esp+36]      ; eax -  convert data table    
  53.         mov     [pointer],eax
  54.         test    bx,bx
  55.         jnz     @f
  56.        
  57.         inc     bx
  58. @@:
  59.         ror     ebx,16
  60.         test    bx,bx
  61.         jnz     @f
  62.        
  63.         inc     bx
  64. @@:
  65.         rol     ebx,16
  66.         mov     [new_size],ebx
  67.         mov     [start_coordinates],ecx
  68.         mov     [scaling_mode],edx
  69.         mov     [filtering],esi
  70.         mov     [background_color],edi
  71.         mov     eax,[eax+4]
  72.         mov     [image_file],eax
  73.  
  74.         mov     esi,[eax+28]
  75.         add     esi,eax
  76.        
  77.         mov     ebx,[eax+20]
  78.         add     ebx,eax
  79.         mov     [palette],ebx
  80.        
  81.         mov     ebx,[eax+12]
  82.         mov     [resolution],ebx
  83.         cmp     ebx,32
  84.         jne     @f
  85.         mov     ebp,dword START.32
  86.         jmp     .1
  87. @@:
  88.         cmp     ebx,24
  89.         jne     @f
  90.         mov     ebp,dword START.24
  91.         jmp     .1
  92. @@:
  93.         cmp     ebx,16
  94.         jne     @f
  95.         mov     ebp,dword START.16
  96.         jmp     .1
  97. @@:
  98.         cmp     ebx,15
  99.         jne     @f
  100.         inc     ebx
  101.         mov     ebp,dword START.16
  102.         jmp     .1
  103. @@:
  104.         cmp     ebx,8
  105.         jne     @f
  106.         mov     ebp,dword START.8
  107. @@:
  108. .1:
  109.         shr     ebx,3
  110.         mov     [bytes_to_pixel],ebx
  111.        
  112.         mov     ebx,[eax+8]
  113.         mov     [y],ebx
  114.         mov     ebx,[eax+4]
  115.         mov     [x],ebx
  116.         imul    ebx,[bytes_to_pixel]
  117.         mov     [size_x],ebx
  118.        
  119.         mov     eax,[crop_y]
  120.         test    eax,eax
  121.         jz      @f
  122.         mov     [y],eax
  123. @@:
  124.         mov     eax,[crop_x]
  125.         test    eax,eax
  126.         jz      @f
  127.         mov     [x],eax
  128. @@:
  129.         mov     eax,100
  130.         shl     eax,12
  131.         mov     ebx,[scaling_mode]
  132.         test    ebx,ebx
  133.         jnz     @f
  134.         inc     ebx
  135. @@:
  136.         xor     edx,edx
  137.         div     ebx
  138.         mov     [scaling_delta],eax
  139.        
  140.         call    .get_memory
  141.         call    .scaling       
  142. ;---------------------------------------------------------------------
  143. .ret_ok:
  144.         mcall   68,13,[area_for_x]
  145.         mov     ebx,[pointer]
  146.         mov     eax,[raw_area]
  147.         mov     [ebx+20],eax  ; store RAW pointer
  148. ;       movzx   eax,word [new_size.x1]
  149. ;       mov     [ebx+24],esi  ;eax
  150. ;       movzx   eax,word [new_size.y1]
  151. ;       mov     [ebx+28],eax
  152. ;       mov     eax,[size_x]
  153. ;       mov     [ebx+32],eax
  154. ;       mov     eax,[bytes_to_pixel]
  155. ;       mov     [ebx+36],eax
  156. ;       mov     eax,[x]
  157. ;       mov     [ebx+40],eax
  158. ;       mov     eax,[y]
  159. ;       mov     [ebx+44],eax
  160. .exit:
  161.         popad
  162.         ret     28
  163. ;---------------------------------------------------------------------
  164. align 4
  165. .scaling:
  166.         xor     eax,eax
  167.         mov     ax,[start_coordinates.y]
  168.         imul    eax,[size_x]
  169.         add     esi,eax
  170.         xor     eax,eax
  171.         mov     ax,[start_coordinates.x]
  172.         imul    eax,[bytes_to_pixel]
  173.         add     esi,eax
  174.        
  175.         xor     eax,eax
  176.         dec     eax
  177.         mov     [temp_y],eax
  178.        
  179.         xor     ecx,ecx
  180. align 4
  181. .y_2:
  182.         xor     ebx,ebx
  183. ;-------------------------
  184. align 4
  185. .x_2:
  186.         call    ebp
  187.         inc     ebx
  188.         cmp     bx,[new_size.x1]
  189.         jb      .x_2
  190. ;-------------------------
  191.         inc     ecx
  192.         cmp     cx,[new_size.y1]
  193.         jb      .y_2
  194.         ret
  195. ;---------------------------------------------------------------------
  196. align 4
  197. .32:
  198.         push    ecx ebx
  199.         call    .calculate_pixel
  200.         mov     eax,[ecx]
  201.         call    .check_filtering_32
  202.         pop     ebx ecx
  203.         cld
  204.         stosd
  205.         ret
  206. ;---------------------------------------------------------------------
  207. align 4
  208. .24:
  209.         push    ecx ebx
  210.         call    .calculate_pixel
  211.         mov     eax,[ecx]      
  212.         call    .check_filtering_24
  213.         cld
  214.         stosw
  215.         shr     eax,16 
  216.         pop     ebx ecx
  217.         cld
  218.         stosb
  219.         ret
  220. ;---------------------------------------------------------------------
  221. align 4
  222. .16:
  223.         push    ecx ebx
  224.         call    .calculate_pixel
  225.         xor     eax,eax
  226.         mov     ax,[ecx]
  227.         call    .check_filtering_16
  228.         pop     ebx ecx
  229.         cld
  230.         stosw
  231.         ret
  232. ;---------------------------------------------------------------------
  233. align 4
  234. .8:
  235.         push    ecx ebx
  236.         call    .calculate_pixel
  237.         cmp     [filtering],0
  238.         jne     @f
  239.         mov     al,[ecx]
  240.         pop     ebx ecx
  241.         cld
  242.         stosb
  243.         ret
  244. @@:
  245.         call    .check_filtering_8
  246.         cld
  247.         stosw
  248.         shr     eax,16 
  249.         pop     ebx ecx
  250.         cld
  251.         stosb
  252.         ret    
  253.        
  254. ;---------------------------------------------------------------------
  255. align 4
  256. .calculate_pixel:
  257.         test    ecx,ecx
  258.         jz      .offset_x
  259. ;.offset_y:
  260.         mov     eax,ecx
  261.        
  262.         mov     ecx,[temp_y]
  263.         cmp     eax,ecx
  264.         jne     .new_y
  265.         mov     eax,[temp_y_offset]
  266.         mov     ecx,eax
  267.         jmp     .offset_x
  268. ;--------------------------------
  269. align 4
  270. .new_y:
  271.         mov     [temp_y],eax
  272.         mov     ebx,[scaling_mode]
  273.         test    ebx,ebx
  274.         jz      @f
  275.        
  276.         imul    eax,[scaling_delta]
  277. ;--------------------------------
  278.         push    ebx
  279.         mov     ebx,eax
  280.         shr     eax,12
  281.         and     ebx,0xFFF
  282.         shl     ebx,7           ;multiply 128
  283.         shr     ebx,12
  284.         mov     [next_pixel_y],ebx
  285.         pop     ebx
  286. ;--------------------------------
  287.         jmp     .ex_1
  288. ;--------------------------------
  289. align 4
  290. @@:
  291.         imul    eax,dword [y]
  292. ;--------------------------------
  293. align 4
  294. @@:
  295.         mov     bx,word [new_size.y1]
  296. ;--------------------------------
  297. align 4
  298. .y_div:
  299.         test    ebx,ebx
  300.         jnz     @f
  301.         inc     ebx
  302. ;--------------------------------
  303. align 4
  304. @@:
  305.         xor     edx,edx
  306.         div     ebx
  307. ;--------------------------------
  308.         push    eax
  309.         mov     eax,edx
  310.         shl     eax,7           ;multiply 128
  311.         xor     edx,edx
  312.         div     ebx
  313.         mov     [next_pixel_y],eax
  314.         pop     eax
  315. ;--------------------------------
  316. align 4
  317. .ex_1:
  318.         mov     [temp_y1],eax
  319.         imul    eax,[size_x]
  320.  
  321.         mov     [temp_y_offset],eax
  322.         mov     ecx,eax
  323. align 4
  324. .offset_x:
  325.         test    ebx,ebx
  326.         jz      .finish
  327.         mov     eax,[esp+4]   ;ebx
  328.        
  329.         mov     edx,[esp+8]
  330.         test    edx,edx
  331.         jz      .continue
  332.         shl     eax,3
  333.         add     eax,[area_for_x]
  334.         mov     edx,[eax+4]
  335.         mov     [next_pixel_x],edx
  336.         mov     eax,[eax]
  337.         jmp     .ex_3
  338. ;--------------------------------
  339. align 4
  340. .continue:
  341.         mov     ebx,[scaling_mode]
  342.         test    ebx,ebx
  343.         jz      @f
  344.         imul    eax,[scaling_delta]
  345. ;--------------------------------
  346.         mov     ebx,eax
  347.         shr     eax,12
  348.         and     ebx,0xFFF
  349.         shl     ebx,7  ;multiply 128
  350.         shr     ebx,12
  351.         mov     [next_pixel_x],ebx
  352. ;--------------------------------
  353.         jmp     .ex_2
  354. ;--------------------------------
  355. align 4
  356. @@:
  357.         imul    eax,dword [x]
  358. ;--------------------------------
  359. align 4
  360. @@:    
  361.         mov     bx,word [new_size.x1]
  362. ;--------------------------------
  363. align 4
  364. .x_div:
  365.         test    ebx,ebx
  366.         jnz     @f
  367.         inc     ebx
  368. align 4
  369. @@:
  370.         xor     edx,edx
  371.         div     ebx
  372. ;--------------------------------
  373.         push    eax
  374.         mov     eax,edx
  375.         shl     eax,7  ;multiply 128
  376.         xor     edx,edx
  377.         div     ebx
  378.         mov     [next_pixel_x],eax
  379.         pop     eax
  380. ;--------------------------------
  381. align 4
  382. .ex_2:
  383.         mov     edx,[bytes_to_pixel]
  384.         mov     ebx,eax
  385.         xor     eax,eax
  386. align 4
  387. @@:
  388.         add     eax,ebx
  389.         dec     edx
  390.         jnz     @r
  391.        
  392.         mov     ebx,[esp+4]
  393.         shl     ebx,3
  394.         add     ebx,[area_for_x]
  395.         mov     [ebx],eax
  396.         mov     edx,[next_pixel_x]
  397.         mov     [ebx+4],edx
  398. align 4
  399. .ex_3:
  400.         mov     [temp_x1],eax
  401.         add     ecx,eax
  402. align 4
  403. .finish:
  404.         add     ecx,esi
  405.         ret
  406. ;---------------------------------------------------------------------
  407. align 4
  408. .get_memory:
  409.         xor     ecx,ecx
  410.         mov     cx,[new_size.x1]
  411.         shl     ecx,3
  412.         mcall   68,12
  413.         mov     [area_for_x],eax
  414.        
  415.         xor     ecx,ecx
  416.         mov     ebx,[new_size]
  417.         mov     cx,bx
  418.         shr     ebx,16
  419.         imul    ecx,ebx  ;[eax+8]
  420.         mov     eax,[bytes_to_pixel]
  421.         cmp     eax,1
  422.         jne     @f
  423.         mov     eax,3
  424. @@:
  425.         imul    ecx,eax
  426.         mov     edx,ecx
  427.         add     ecx,44
  428.         mov     eax,[image_file]
  429.         add     ecx,[eax+24]    ;palette area size
  430.         mcall   68,12
  431.         mov     [raw_area],eax
  432.         mov     edi,eax
  433.        
  434. ; create RAW header
  435.         push    esi
  436.         mov     esi,[image_file]
  437.         mov     ecx,44/4
  438.         cld
  439.         rep     movsd                   ;copy the 3 first dword for the structure of RAW
  440.         mov     edi,[raw_area]
  441.         movzx   eax,word [new_size.x1]
  442.         mov     [edi+4],eax
  443.         movzx   eax,word [new_size.y1]
  444.         mov     [edi+8],eax
  445.         mov     [edi+32],edx            ;rgb area size
  446.         xor     eax,eax
  447.         mov     [edi+36],eax            ;transparency area pointer
  448.         mov     [edi+40],eax            ;transparency area size
  449.        
  450.         cmp     [filtering],eax         ;0 or 1
  451.         je      @f
  452.  
  453.         mov     [edi+20],eax            ;palette area pointer
  454.         mov     [edi+24],eax            ;palette area size
  455.         mov     [edi+28],dword 44       ;rgb area pointer
  456.         cmp     [edi+12],dword 8        ;overall depth of the pixel
  457.         ja      .not_overall_depth_8
  458.        
  459.         mov     [edi+12],dword 24       ;overall depth of the pixel
  460.         mov     [edi+16],word 8         ;channel depth of the pixel
  461. .not_overall_depth_8:
  462.         add     edi,44
  463.         jmp     .end
  464. @@:
  465.         mov     eax,[edi+24]
  466.         add     edi,44
  467.         test    eax,eax         ;palette area is present?
  468.         jz      @f
  469.        
  470.         sub     esi,44
  471.        
  472.         mov     ecx,[esi+24]
  473.         shr     ecx,2
  474.         add     esi,[esi+20]
  475.         cld
  476.         rep     movsd           ;copy palette area
  477. @@:
  478.  
  479. .end:
  480.         pop     esi
  481.        
  482.         ret
  483. ;---------------------------------------------------------------------
  484. include 'b_filter.inc'
  485. ;---------------------------------------------------------------------
  486. align 4
  487. EXPORTS:
  488.         dd szStart,     START
  489.         dd szVersion,   0x00010003
  490.         dd 0
  491.  
  492. szStart         db 'START',0
  493. szVersion       db 'version',0
  494.  
  495. align 4
  496. pointer         dd 0
  497. image_file      dd 0
  498. new_size:
  499. .y1:            dw 0
  500. .x1:            dw 0
  501.  
  502. x:      dd 0
  503. y:      dd 0
  504.  
  505. crop_x  dd 0
  506. crop_y  dd 0
  507.  
  508. size_x          dd 0
  509. bytes_to_pixel  dd 0
  510.  
  511. start_coordinates:
  512. .y      dw 0
  513. .x      dw 0
  514.  
  515. scaling_mode    dd 0
  516. raw_area        dd 0
  517. scaling_delta   dd 0
  518.  
  519. area_for_x      dd 0
  520.  
  521. temp_y          dd 0
  522. temp_y_offset   dd 0
  523.  
  524. resolution      dd 0
  525.  
  526. filtering       dd 0
  527.  
  528. next_pixel_y    dd 0
  529. next_pixel_x    dd 0
  530.  
  531. temp_y1         dd 0
  532. temp_x1         dd 0
  533.  
  534. B_sample        dd 0
  535. G_sample        dd 0
  536. R_sample        dd 0
  537.  
  538. B_sample_1      dd 0
  539. G_sample_1      dd 0
  540. R_sample_1      dd 0
  541.  
  542. palette dd 0
  543.  
  544. background_color        dd 0