Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3107 leency 1
//Asper
5598 pavelyakov 2
#ifndef INCLUDE_LIBIMG_H
3
#define INCLUDE_LIBIMG_H
3107 leency 4
 
5598 pavelyakov 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
7049 leency 18
#include "../lib/obj/libio.h"
5598 pavelyakov 19
#endif
20
 
21
:byte init_imglib_check;
22
 
3107 leency 23
//library
24
dword libimg = #alibimg;
25
char alibimg[21] = "/sys/lib/libimg.obj\0";
5626 leency 26
 
3107 leency 27
dword libimg_init = #alibimg_init;
28
dword img_is_img  = #aimg_is_img;
29
dword img_to_rgb2 = #aimg_to_rgb2;
30
dword img_decode  = #aimg_decode;
31
dword img_destroy = #aimg_destroy;
32
dword img_draw    = #aimg_draw;
33
//dword img_flip    = #aimg_flip;
34
//dword img_rotate  = #aimg_rotate;
3839 Asper 35
$DD 2 dup 0
3107 leency 36
 
37
//import  libimg                     , \
38
char alibimg_init[9] = "lib_init\0";
39
char aimg_is_img[11]  = "img_is_img\0";
40
char aimg_to_rgb2[12] = "img_to_rgb2\0";
41
char aimg_decode[11]  = "img_decode\0";
42
char aimg_destroy[12] = "img_destroy\0";
43
char aimg_draw[9]    = "img_draw\0";
44
//char aimg_flip[9]    = "img_flip\0";
45
//char aimg_rotate[11]  = "img_rotate\0 ";
46
 
47
 
48
 
49
dword load_image(dword filename)
50
{
51
        //align 4
52
        dword img_data=0;
53
        dword img_data_len=0;
54
        dword fh=0;
55
        dword image=0;
56
 
57
        byte tmp_buf[40];
58
        $and     img_data, 0
59
        //$mov     eax, filename
60
        //$push    eax
61
        //invoke  file.open, eax, O_READ
62
        file_open stdcall (filename, O_READ);
63
        $or      eax, eax
64
        $jnz      loc05
65
        $stc
66
        return 0;
67
    @loc05:
68
        $mov     fh, eax
69
        //invoke  file.size
70
        file_size stdcall (filename);
71
        $mov     img_data_len, ebx
72
        //stdcall mem.Alloc, ebx
73
        mem_Alloc(EBX);
74
 
75
        $test    eax, eax
76
        $jz      error_close
77
        $mov     img_data, eax
78
        //invoke  file.read, [fh], eax, [img_data_len]
79
        file_read stdcall (fh, EAX, img_data_len);
80
        $cmp     eax, -1
81
        $jz      error_close
82
        $cmp     eax, img_data_len
83
        $jnz     error_close
84
        //invoke  file.close, [fh]
85
        file_close stdcall (fh);
86
        $inc     eax
87
        $jz      error_
88
//; img.decode checks for img.is_img
89
//;       //invoke  img.is_img, [img_data], [img_data_len]
90
//;       $or      eax, eax
91
//;       $jz      exit
92
        //invoke  img.decode, [img_data], [img_data_len], 0
93
        EAX=img_data;
94
        img_decode stdcall (EAX, img_data_len,0);
95
        $or      eax, eax
96
        $jz      error_
97
        $cmp     image, 0
98
        $pushf
99
        $mov     image, eax
100
        //call    init_frame
101
        $popf
102
        //call    update_image_sizes
103
        mem_Free(img_data);//free_img_data(img_data);
104
        $clc
105
        return image;
106
 
107
@error_free:
108
        //invoke  img.destroy, [image]
109
        img_destroy stdcall (image);
110
        $jmp     error_
111
 
112
@error_pop:
113
        $pop     eax
114
        $jmp     error_
115
@error_close:
116
        //invoke  file.close, [fh]
117
        file_close stdcall (fh);
118
@error_:
119
        mem_Free(img_data);
120
        $stc
121
        return 0;
122
}
5598 pavelyakov 123
 
6978 leency 124
void DrawLibImage(dword image_pointer,x,y,w,h,offx,offy) {
125
    img_draw stdcall (
126
        image_pointer,
127
        x,
128
        y,
129
        w,
130
        h,
131
        offx,
132
        offy
133
    );
134
}
135
 
5598 pavelyakov 136
#endif