Subversion Repositories Kolibri OS

Rev

Rev 3107 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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