Subversion Repositories Kolibri OS

Rev

Rev 783 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. use32
  2. org 0x0
  3.  
  4. db 'MENUET01'
  5. dd 0x01, START, I_END, 0x1000, 0x1000, @PARAMS, 0x0
  6.  
  7. ;-----------------------------------------------------------------------------
  8.  
  9. FALSE = 0
  10. TRUE  = 1
  11.  
  12. include '../../../../../proc32.inc'
  13. include '../../../../../macros.inc'
  14. include '../dll.inc'
  15.  
  16. include '../../libio/libio.inc'
  17. include '../../libimg/libimg.inc'
  18.  
  19. ;-----------------------------------------------------------------------------
  20.  
  21. START:
  22.         mcall   68, 11
  23.  
  24.         stdcall dll.Load, @IMPORT
  25.         or      eax, eax
  26.         jnz     exit
  27.  
  28.         invoke  file.open, @PARAMS, O_READ
  29.         or      eax, eax
  30.         jz      exit
  31.         mov     [fh], eax
  32.         invoke  file.size, @PARAMS
  33.         mov     [img_data_len], ebx
  34.         stdcall mem.Alloc, ebx
  35.         or      eax, eax
  36.         jz      exit
  37.         mov     [img_data], eax
  38.         invoke  file.read, [fh], eax, [img_data_len]
  39.         cmp     eax, -1
  40.         je      exit
  41.         cmp     eax, [img_data_len]
  42.         jne     exit
  43.         invoke  file.close, [fh]
  44.         inc     eax
  45.         jz      exit
  46.        
  47.         invoke  img.decode, [img_data], [img_data_len], 0
  48.         or      eax, eax
  49.         jz      exit
  50.         mov     [image], eax
  51. ;-----------------------------------------------------------------------------
  52.  
  53. redraw:
  54.         call    draw_window
  55.  
  56. still:
  57.         mcall   10
  58.         cmp     eax, 1
  59.         je      redraw
  60.         cmp     eax, 2
  61.         je      key
  62.         cmp     eax, 3
  63.         je      button
  64.         jmp     still
  65.  
  66.   key:
  67.         mcall   2
  68.         jmp     still
  69.  
  70.   button:
  71.         mcall   17
  72.         shr     eax, 8
  73.  
  74.         ; flip horizontally
  75.         cmp     eax, 'flh'
  76.         jne     @f
  77.  
  78.         invoke  img.flip, [image], FLIP_HORIZONTAL
  79.         jmp     redraw
  80.  
  81.         ; flip vertically
  82.     @@: cmp     eax, 'flv'
  83.         jne     @f
  84.  
  85.         invoke  img.flip, [image], FLIP_VERTICAL
  86.         jmp     redraw
  87.  
  88.         ; flip both horizontally and vertically
  89.     @@: cmp     eax, 'flb'
  90.         jne     @f
  91.  
  92.         invoke  img.flip, [image], FLIP_BOTH
  93.         jmp     redraw
  94.  
  95.         ; rotate left
  96.     @@: cmp     eax, 'rtl'
  97.         jne     @f
  98.  
  99.         invoke  img.rotate, [image], ROTATE_90_CCW
  100.         jmp     redraw
  101.  
  102.         ; rotate right
  103.     @@: cmp     eax, 'rtr'
  104.         jne     @f
  105.  
  106.         invoke  img.rotate, [image], ROTATE_90_CW
  107.         jmp     redraw
  108.  
  109.     @@: cmp     eax, 1
  110.         jne     still
  111.  
  112.   exit:
  113.         mcall   -1
  114.  
  115.  
  116. draw_window:
  117.         invoke  gfx.open, TRUE
  118.         mov     [ctx], eax
  119.  
  120.         mcall   0, <100, 640>, <100, 480>, 0x33FFFFFF, , s_header
  121.  
  122.         invoke  gfx.pen.color, [ctx], 0x007F7F7F
  123.         invoke  gfx.line, [ctx], 0, 30, 630, 30
  124.  
  125.         mcall   8, <5 + 25 * 0, 20>, <5, 20>, 'flh', 0x007F7F7F
  126.         mcall   8, <5 + 25 * 1, 20>, <5, 20>, 'flv', 0x007F7F7F
  127.         mcall   8, <5 + 25 * 2, 20>, <5, 20>, 'flb', 0x007F7F7F
  128.  
  129.         invoke  gfx.line, [ctx], 5 + 25 * 3, 0, 5 + 25 * 3, 30
  130.  
  131.         mcall   8, <10 + 25 * 3, 20>, <5, 20>, 'rtl', 0x007F7F7F
  132.         mcall   8, <10 + 25 * 4, 20>, <5, 20>, 'rtr', 0x007F7F7F
  133.  
  134.         mov     eax, [image]
  135.         stdcall [img.draw], eax, 5, 35, [eax + Image.Width], [eax + Image.Height], 0, 0
  136.  
  137.         invoke  gfx.close, [ctx]
  138.         ret
  139.  
  140. ;-----------------------------------------------------------------------------
  141. proc mem.Alloc, size ;////////////////////////////////////////////////////////
  142. ;-----------------------------------------------------------------------------
  143.         push    ebx ecx
  144.         mov     ecx, [size]
  145.         add     ecx, 4
  146.         mcall   68, 12
  147.         add     ecx, -4
  148.         mov     [eax], ecx
  149.         add     eax, 4
  150.         pop     ecx ebx
  151.         ret
  152. endp
  153.  
  154. ;-----------------------------------------------------------------------------
  155. proc mem.ReAlloc, mptr, size ;////////////////////////////////////////////////
  156. ;-----------------------------------------------------------------------------
  157.         push    ebx ecx edx
  158.         mov     ecx, [size]
  159.         or      ecx, ecx
  160.         jz      @f
  161.         add     ecx, 4
  162.     @@: mov     edx, [mptr]
  163.         or      edx, edx
  164.         jz      @f
  165.         add     edx, -4
  166.     @@: mcall   68, 20
  167.         or      eax, eax
  168.         jz      @f
  169.         add     ecx, -4
  170.         mov     [eax], ecx
  171.         add     eax, 4
  172.     @@: pop     edx ecx ebx
  173.         ret
  174. endp
  175.  
  176. ;-----------------------------------------------------------------------------
  177. proc mem.Free, mptr ;/////////////////////////////////////////////////////////
  178. ;-----------------------------------------------------------------------------
  179.         push    ebx ecx
  180.         mov     ecx, [mptr]
  181.         or      ecx, ecx
  182.         jz      @f
  183.         add     ecx, -4
  184.     @@: mcall   68, 13
  185.         pop     ecx ebx
  186.         ret
  187. endp
  188.  
  189. ;-----------------------------------------------------------------------------
  190.  
  191. s_header db 'Image Viewer (test app)', 0
  192.  
  193. ;-----------------------------------------------------------------------------
  194.  
  195. align 16
  196. @IMPORT:
  197.  
  198. library                         \
  199.         libio  , 'libio.obj'  , \
  200.         libgfx , 'libgfx.obj' , \
  201.         libimg , 'libimg.obj'
  202.  
  203. import  libio                     , \
  204.         libio.init , 'lib_init'   , \
  205.         file.size  , 'file_size'  , \
  206.         file.open  , 'file_open'  , \
  207.         file.read  , 'file_read'  , \
  208.         file.close , 'file_close'
  209.  
  210. import  libgfx                          , \
  211.         libgfx.init   , 'lib_init'      , \
  212.         gfx.open      , 'gfx_open'      , \
  213.         gfx.close     , 'gfx_close'     , \
  214.         gfx.pen.color , 'gfx_pen_color' , \
  215.         gfx.line      , 'gfx_line'
  216.  
  217. import  libimg                     , \
  218.         libimg.init , 'lib_init'   , \
  219.         img.draw    , 'img_draw'   , \
  220.         img.decode  , 'img_decode' , \
  221.         img.flip    , 'img_flip'   , \
  222.         img.rotate  , 'img_rotate'
  223.  
  224. ;-----------------------------------------------------------------------------
  225.  
  226. I_END:
  227.  
  228. img_data     dd ?
  229. img_data_len dd ?
  230. fh           dd ?
  231. image        dd ?
  232.  
  233. ctx dd ?
  234.  
  235. @PARAMS rb 512
  236.