Subversion Repositories Kolibri OS

Rev

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

  1. use32
  2. org 0x0
  3.         db 'MENUET01'
  4.         dd 0x01, START, I_END, E_END, E_END, 0, 0
  5.  
  6. ;-----------------------------------------------------------------------------
  7.  
  8. include '../../../../../proc32.inc'
  9. include '../../../../../macros.inc'
  10. include '../../../../../dll.inc'
  11. ;include '../../../../../debug.inc'
  12.  
  13. include '../../libio/libio.inc'
  14. include '../../libimg/libimg.inc'
  15.  
  16. ;-----------------------------------------------------------------------------
  17.  
  18. START:
  19.         mcall   68, 11
  20.  
  21.         stdcall dll.Load, @IMPORT
  22.         or      eax, eax
  23.         jnz     exit
  24.  
  25.         invoke  file.open, input_file, O_READ
  26.         or      eax, eax
  27.         jz      exit
  28.         mov     [fh], eax
  29.  
  30.         invoke  file.size, input_file
  31.         mov     [img_data_len], ebx
  32.  
  33.         stdcall mem.Alloc, ebx
  34.         or      eax, eax
  35.         jz      exit
  36.         mov     [img_data], eax
  37.  
  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.  
  44.         invoke  file.close, [fh]
  45.         inc     eax
  46.         jz      exit
  47.        
  48.         invoke  img.decode, [img_data], [img_data_len], 0
  49.         or      eax, eax
  50.         jz      exit
  51.         mov     [image_initial], eax
  52.  
  53.         stdcall mem.Free, [img_data]
  54.         test    eax, eax
  55.         jz      exit
  56. ;-----------------------------------------------------------------------------
  57.  
  58. still:
  59.         mcall   10
  60.         cmp     eax, 1
  61.         je      .draw_window
  62.         cmp     eax, 2
  63.         je      .key
  64.         cmp     eax, 3
  65.         je      .button
  66.         jmp     still
  67.  
  68.  
  69.   .draw_window:
  70.         mcall   12, 1
  71.         mcall   0, <200, 150>, <200, 150>, 0x73FFFFFF, 0x00000000, window_title
  72.         call    draw_image
  73.         mcall   12, 2
  74.         jmp     still
  75.  
  76.   .key:
  77.         mcall   2
  78.         jmp     still
  79.  
  80.   .button:
  81.         mcall   17
  82.         shr     eax, 8
  83.         cmp     eax, 1
  84.         jne     still
  85.  
  86. exit:
  87.         cmp     [image_initial], 0
  88.         je      @f
  89.         invoke  img.destroy, [image_initial]
  90.     @@:
  91.         cmp     [image_scaled], 0
  92.         je      @f
  93.         invoke  img.destroy, [image_scaled]
  94.     @@:
  95.         mcall   -1
  96.  
  97.  
  98. proc    draw_image
  99.  
  100.         cmp     [image_scaled], 0
  101.         je      @f
  102.         invoke  img.destroy, [image_scaled]
  103.     @@:
  104.  
  105.         mcall   9, proc_info, -1
  106.  
  107.         mov     ecx, [proc_info.client_box.height]
  108.         inc     ecx
  109.         mov     edx, [proc_info.client_box.width]
  110.         inc     edx
  111.  
  112.         mov     ebx, [image_initial]
  113. ;       invoke  img.scale, ebx, 1, 2, 5, 5, 0, LIBIMG_SCALE_TYPE_STRETCH, LIBIMG_SCALE_ALG_BILINEAR, edx, ecx
  114. ;       invoke  img.scale, ebx, 1, 2, 5, 5, 0, LIBIMG_SCALE_TYPE_STRETCH, LIBIMG_SCALE_ALG_INTEGER, 3, 3
  115.         invoke  img.scale, ebx, 0, 0, [ebx + Image.Width], [ebx + Image.Height], 0, LIBIMG_SCALE_TYPE_STRETCH, LIBIMG_SCALE_ALG_BILINEAR, edx, ecx
  116.  
  117. ; proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale_type, _scale_alg, _param1, _param2
  118. ; see libimg.inc for available scale types and algorithms
  119. ; LIBIMG_SCALE_ALG_BILINEAR: _param1, _param2 -- width and height of rectangle to fit _src image to
  120. ; LIBIMG_SCALE_ALG_INTEGER:  _param1 -- scale factor (i.e. 3 means scaling 7x7 to 21x21); _param2 ignored
  121. ; LIBIMG_SCALE_TYPE_*: just try and see, they are common STRETCH, FIT_BY_WIDTH etc.
  122. ; returns pointer to a scaled image
  123.  
  124. ;       invoke  img.scale, ebx, 0, 0, [ebx + Image.Width], [ebx + Image.Height], 0, LIBIMG_SCALE_TYPE_STRETCH, LIBIMG_SCALE_ALG_INTEGER, 3, 3
  125.         test    eax, eax
  126.         jz      exit
  127.         mov     [image_scaled], eax
  128.  
  129.         invoke  img.draw, eax, 0, 0, [eax + Image.Width], [eax + Image.Height], 0, 0
  130.  
  131.         ret
  132. endp
  133.  
  134. ;-----------------------------------------------------------------------------
  135.  
  136. window_title    db 'img.scale example',0
  137.  
  138. input_file      db '/hd0/1/gray_5x7.tiff',0
  139. ;input_file     db '/hd0/1/grayscale_123x123.tiff',0
  140. ;input_file     db '/hd0/1/grayscale_357x357.tiff',0
  141. ;input_file     db '/hd0/1/grayscale_620x620.tiff',0
  142. ;input_file     db '/hd0/1/rgb_220.jpg',0
  143. ;input_file     db '/hd0/1/rgba_217.tiff',0
  144. ;input_file     db '/hd0/1/rgb_7x9.tiff',0
  145. ;input_file     db '/hd0/1/rgba_7x9.tiff',0
  146. ;input_file     db '/hd0/1/gray_7x9.tiff',0
  147. ;input_file     db '/hd0/1/rgb_70x90.png',0
  148. ;-----------------------------------------------------------------------------
  149.  
  150. align 4
  151. @IMPORT:
  152.  
  153. library                           \
  154.         libio   , 'libio.obj'   , \
  155.         libimg  , 'libimg.obj'
  156.  
  157. import  libio                           , \
  158.         libio.init      , 'lib_init'    , \
  159.         file.size       , 'file_size'   , \
  160.         file.open       , 'file_open'   , \
  161.         file.read       , 'file_read'   , \
  162.         file.close      , 'file_close'
  163.  
  164. import  libimg                          , \
  165.         libimg.init     , 'lib_init'    , \
  166.         img.decode      , 'img_decode'  , \
  167.         img.destroy     , 'img_destroy' , \
  168.         img.draw        , 'img_draw'    , \
  169.         img.scale       , 'img_scale'   , \
  170.         img.formats_table,'img_formats_table'
  171.  
  172. ;-----------------------------------------------------------------------------
  173.  
  174. I_END:
  175.  
  176. fh              dd ?
  177. img_data_len    dd ?
  178. img_data        dd ?
  179.  
  180. image_initial   dd ?
  181. image_scaled    dd ?
  182.  
  183. proc_info       process_information
  184.  
  185. rd 0x1000       ; stack
  186. E_END:
  187.