Subversion Repositories Kolibri OS

Rev

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

  1. //Asper
  2. #ifndef INCLUDE_LIBIMG_H
  3. #define INCLUDE_LIBIMG_H
  4.  
  5. #ifndef INCLUDE_KOLIBRI_H
  6. #include "../lib/kolibri.h"
  7. #endif
  8.  
  9. #ifndef INCLUDE_MEM_H
  10. #include "../lib/mem.h"
  11. #endif
  12.  
  13. #ifndef INCLUDE_DLL_H
  14. #include "../lib/dll.h"
  15. #endif
  16.  
  17. #ifndef INCLUDE_LIBIO_H
  18. #include "../lib/obj/libio_lib.h"
  19. #endif
  20.  
  21. :byte init_imglib_check;
  22.  
  23. //library
  24. dword libimg = #alibimg;
  25. char alibimg[21] = "/sys/lib/libimg.obj\0";
  26. ?define LIB_IMG_LOAD_ERR "Error while loading library /rd/1/lib/libimg.obj"
  27.  
  28. dword libimg_init = #alibimg_init;
  29. dword img_is_img  = #aimg_is_img;
  30. dword img_to_rgb2 = #aimg_to_rgb2;
  31. dword img_decode  = #aimg_decode;
  32. dword img_destroy = #aimg_destroy;
  33. dword img_draw    = #aimg_draw;
  34. //dword img_flip    = #aimg_flip;
  35. //dword img_rotate  = #aimg_rotate;
  36. $DD 2 dup 0
  37.  
  38. //import  libimg                     , \
  39. char alibimg_init[9] = "lib_init\0";
  40. char aimg_is_img[11]  = "img_is_img\0";
  41. char aimg_to_rgb2[12] = "img_to_rgb2\0";
  42. char aimg_decode[11]  = "img_decode\0";
  43. char aimg_destroy[12] = "img_destroy\0";
  44. char aimg_draw[9]    = "img_draw\0";
  45. //char aimg_flip[9]    = "img_flip\0";
  46. //char aimg_rotate[11]  = "img_rotate\0 ";
  47.  
  48.  
  49.  
  50. dword load_image(dword filename)
  51. {
  52.         //align 4
  53.         dword img_data=0;
  54.         dword img_data_len=0;
  55.         dword fh=0;
  56.         dword image=0;
  57.  
  58.         byte tmp_buf[40];
  59.         $and     img_data, 0
  60.         //$mov     eax, filename
  61.         //$push    eax        
  62.         //invoke  file.open, eax, O_READ
  63.         file_open stdcall (filename, O_READ);
  64.         $or      eax, eax
  65.         $jnz      loc05  
  66.         $stc
  67.         return 0;
  68.     @loc05:    
  69.         $mov     fh, eax
  70.         //invoke  file.size
  71.         file_size stdcall (filename);
  72.         $mov     img_data_len, ebx
  73.         //stdcall mem.Alloc, ebx
  74.         mem_Alloc(EBX);
  75.        
  76.         $test    eax, eax
  77.         $jz      error_close
  78.         $mov     img_data, eax
  79.         //invoke  file.read, [fh], eax, [img_data_len]
  80.         file_read stdcall (fh, EAX, img_data_len);
  81.         $cmp     eax, -1
  82.         $jz      error_close
  83.         $cmp     eax, img_data_len
  84.         $jnz     error_close
  85.         //invoke  file.close, [fh]
  86.         file_close stdcall (fh);
  87.         $inc     eax
  88.         $jz      error_
  89. //; img.decode checks for img.is_img
  90. //;       //invoke  img.is_img, [img_data], [img_data_len]
  91. //;       $or      eax, eax
  92. //;       $jz      exit
  93.         //invoke  img.decode, [img_data], [img_data_len], 0
  94.         EAX=img_data;
  95.         img_decode stdcall (EAX, img_data_len,0);
  96.         $or      eax, eax
  97.         $jz      error_
  98.         $cmp     image, 0
  99.         $pushf
  100.         $mov     image, eax
  101.         //call    init_frame
  102.         $popf
  103.         //call    update_image_sizes
  104.         mem_Free(img_data);//free_img_data(img_data);
  105.         $clc
  106.         return image;
  107.  
  108. @error_free:
  109.         //invoke  img.destroy, [image]
  110.         img_destroy stdcall (image);
  111.         $jmp     error_
  112.  
  113. @error_pop:
  114.         $pop     eax
  115.         $jmp     error_
  116. @error_close:
  117.         //invoke  file.close, [fh]
  118.         file_close stdcall (fh);
  119. @error_:
  120.         mem_Free(img_data);
  121.         $stc
  122.         return 0;
  123. }
  124.  
  125. #endif