Rev 9632 | Rev 9644 | 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 | |||
3107 | leency | 17 | //library |
18 | dword libimg = #alibimg; |
||
7252 | leency | 19 | char alibimg[] = "/sys/lib/libimg.obj"; |
9396 | leency | 20 | |
8381 | leency | 21 | dword libimg_init = #alibimg_init; |
22 | dword img_decode = #aimg_decode; |
||
23 | dword img_destroy = #aimg_destroy; |
||
24 | dword img_draw = #aimg_draw; |
||
25 | dword img_create = #aimg_create; |
||
26 | dword img_encode = #aimg_encode; |
||
27 | dword img_convert = #aimg_convert; |
||
28 | dword img_from_file = #aimg_from_file; |
||
8396 | leency | 29 | dword img_blend = #aimg_blend; |
30 | //dword img_is_img = #aimg_is_img; |
||
31 | //dword img_to_rgb2 = #aimg_to_rgb2; |
||
32 | //dword img_scale = #aimg_scale; |
||
9396 | leency | 33 | dword img_flip = #aimg_flip; |
34 | dword img_rotate = #aimg_rotate; |
||
35 | dword img_to_rgb = #aimg_to_rgb; |
||
9632 | leency | 36 | dword resize = #aresize; |
7190 | leency | 37 | |
3839 | Asper | 38 | $DD 2 dup 0 |
3107 | leency | 39 | |
8396 | leency | 40 | //import |
8381 | leency | 41 | char alibimg_init[] = "lib_init"; |
42 | char aimg_decode[] = "img_decode"; |
||
43 | char aimg_destroy[] = "img_destroy"; |
||
44 | char aimg_draw[] = "img_draw"; |
||
45 | char aimg_create[] = "img_create"; |
||
46 | char aimg_encode[] = "img_encode"; |
||
47 | char aimg_convert[] = "img_convert"; |
||
48 | char aimg_from_file[] = "img_from_file"; |
||
8396 | leency | 49 | char aimg_blend[] = "img_blend"; |
50 | //char aimg_is_img[] = "img_is_img"; |
||
51 | //char aimg_to_rgb2[] = "img_to_rgb2"; |
||
52 | //char aimg_scale[] = "img_scale"; |
||
9396 | leency | 53 | char aimg_flip[] = "img_flip"; |
54 | char aimg_rotate[] = "img_rotate"; |
||
55 | char aimg_to_rgb[] = "img_to_rgb"; |
||
9632 | leency | 56 | char aresize[] = "img_resize_data"; |
3107 | leency | 57 | |
7190 | leency | 58 | #define LIBIMG_FORMAT_BMP 1 |
59 | #define LIBIMG_FORMAT_ICO 2 |
||
60 | #define LIBIMG_FORMAT_CUR 3 |
||
61 | #define LIBIMG_FORMAT_GIF 4 |
||
62 | #define LIBIMG_FORMAT_PNG 5 |
||
63 | #define LIBIMG_FORMAT_JPEG 6 |
||
64 | #define LIBIMG_FORMAT_TGA 7 |
||
65 | #define LIBIMG_FORMAT_PCX 8 |
||
66 | #define LIBIMG_FORMAT_XCF 9 |
||
67 | #define LIBIMG_FORMAT_TIFF 10 |
||
68 | #define LIBIMG_FORMAT_PNM 11 |
||
69 | #define LIBIMG_FORMAT_WBMP 12 |
||
70 | #define LIBIMG_FORMAT_XBM 13 |
||
71 | #define LIBIMG_FORMAT_Z80 14 |
||
3107 | leency | 72 | |
7190 | leency | 73 | // values for Image.Type |
74 | // must be consecutive to allow fast switch on Image.Type in support functions |
||
7995 | leency | 75 | #define IMAGE_BPP8i 1 // indexed |
76 | #define IMAGE_BPP24 2 |
||
77 | #define IMAGE_BPP32 3 |
||
78 | #define IMAGE_BPP15 4 |
||
79 | #define IMAGE_BPP16 5 |
||
80 | #define IMAGE_BPP1 6 |
||
81 | #define IMAGE_BPP8g 7 // grayscale |
||
82 | #define IMAGE_BPP2i 8 |
||
83 | #define IMAGE_BPP4i 9 |
||
9396 | leency | 84 | #define IMAGE_BPP8a 10 // grayscale with alpha channel; application layer only!!! |
85 | // kernel doesn't handle this image type, |
||
7254 | leency | 86 | // libimg can only create and destroy such images |
7190 | leency | 87 | |
9396 | leency | 88 | #define FLIP_VERTICAL 0x01 |
89 | #define FLIP_HORIZONTAL 0x02 |
||
90 | |||
91 | #define ROTATE_90_CW 0x01 |
||
92 | #define ROTATE_180 0x02 |
||
93 | #define ROTATE_270_CW 0x03 |
||
94 | #define ROTATE_90_CCW ROTATE_270_CW |
||
95 | #define ROTATE_270_CCW ROTATE_90_CW |
||
96 | |||
7995 | leency | 97 | struct libimg_image |
98 | { |
||
99 | dword checksum; // ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far |
||
100 | dword w; |
||
101 | dword h; |
||
102 | dword next; |
||
103 | dword previous; |
||
104 | dword type; // one of Image.bppN |
||
105 | dword imgsrc; |
||
106 | dword palette; // used iff Type eq Image.bpp1, Image.bpp2, Image.bpp4 or Image.bpp8i |
||
107 | dword extended; |
||
108 | dword flags; // bitfield |
||
109 | dword delay; // used iff Image.IsAnimated is set in Flags |
||
110 | dword image; |
||
111 | void load(); |
||
112 | void convert_into(); |
||
113 | void replace_color(); |
||
8780 | leency | 114 | void replace_2colors(); |
7995 | leency | 115 | void set_vars(); |
116 | void draw(); |
||
117 | }; |
||
7190 | leency | 118 | |
7995 | leency | 119 | :void libimg_image::set_vars() |
120 | { |
||
121 | $push edi |
||
122 | EDI = image; |
||
8396 | leency | 123 | //checksum = ESDWORD[EDI]; |
7995 | leency | 124 | w = ESDWORD[EDI+4]; |
125 | h = ESDWORD[EDI+8]; |
||
8396 | leency | 126 | //next = ESDWORD[EDI+12]; |
127 | //previous = ESDWORD[EDI+16]; |
||
9396 | leency | 128 | type = ESDWORD[EDI+20]; |
129 | imgsrc = ESDWORD[EDI+24]; |
||
130 | //palette = ESDWORD[EDI+28]; |
||
131 | //extended = ESDWORD[EDI+32]; |
||
132 | //flags = ESDWORD[EDI+36]; |
||
133 | //delay = ESDWORD[EDI+40]; |
||
7995 | leency | 134 | $pop edi |
135 | } |
||
136 | |||
137 | :void libimg_image::load(dword file_path) |
||
138 | { |
||
8389 | leency | 139 | if (image) img_destroy stdcall(image); |
140 | img_from_file stdcall(file_path); |
||
7995 | leency | 141 | if (!EAX) { |
142 | notify("'Error: Image not loaded'E"); |
||
143 | } else { |
||
144 | image = EAX; |
||
145 | set_vars(); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | :void libimg_image::replace_color(dword old_color, new_color) |
||
150 | { |
||
151 | EDX = w * h * 4 + imgsrc; |
||
8780 | leency | 152 | ESI = old_color; |
153 | ECX = new_color; |
||
154 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
||
7995 | leency | 155 | } |
156 | |||
8780 | leency | 157 | :void libimg_image::replace_2colors(dword old_color1, new_color1, old_color2, new_color2) |
158 | { |
||
159 | EDX = w * h * 4 + imgsrc; |
||
160 | ESI = old_color1; |
||
161 | ECX = new_color1; |
||
162 | EBX = old_color2; |
||
163 | EAX = new_color2; |
||
164 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) { |
||
165 | IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
||
166 | ELSE IF (DSDWORD[EDI]==EBX) DSDWORD[EDI] = EAX; |
||
167 | } |
||
168 | } |
||
169 | |||
7995 | leency | 170 | :void libimg_image::draw(dword _x, _y, _w, _h, _xoff, _yoff) |
171 | { |
||
172 | if (image) img_draw stdcall(image, _x, _y, _w, _h, _xoff, _yoff); |
||
173 | } |
||
174 | |||
175 | :void libimg_image::convert_into(dword _to) |
||
176 | { |
||
177 | img_convert stdcall(image, 0, _to, 0, 0); |
||
178 | if (!EAX) { |
||
179 | notify("'LibImg convertation error!'E"); |
||
180 | } else { |
||
9454 | leency | 181 | $push eax |
182 | img_destroy stdcall(image); |
||
183 | $pop eax |
||
7995 | leency | 184 | image = EAX; |
185 | set_vars(); |
||
186 | } |
||
187 | } |
||
188 | |||
9016 | leency | 189 | :dword save_image(dword _image_pointer, _w, _h, _path) |
7224 | leency | 190 | { |
191 | dword encoded_data=0; |
||
192 | dword encoded_size=0; |
||
193 | dword image_ptr = 0; |
||
9396 | leency | 194 | |
9594 | leency | 195 | img_create stdcall(_w, _h, IMAGE_BPP24); |
196 | image_ptr = EAX; |
||
7190 | leency | 197 | |
9016 | leency | 198 | if (!image_ptr) { |
199 | return "Error creating image!"; |
||
7224 | leency | 200 | } |
201 | else { |
||
202 | EDI = image_ptr; |
||
7995 | leency | 203 | memmov(EDI.libimg_image.imgsrc, _image_pointer, _w * _h * 3); |
7224 | leency | 204 | |
9643 | leency | 205 | img_encode stdcall(image_ptr, LIBIMG_FORMAT_PNG, 0); |
206 | encoded_data = EAX; |
||
207 | encoded_size = ECX; |
||
7224 | leency | 208 | |
209 | img_destroy stdcall(image_ptr); |
||
210 | |||
9016 | leency | 211 | if(!encoded_data) { |
212 | return "Error encoding image!"; |
||
7224 | leency | 213 | } |
214 | else { |
||
9016 | leency | 215 | if (!CreateFile(encoded_size, encoded_data, _path)) { |
216 | return 0; |
||
7224 | leency | 217 | } |
218 | else { |
||
9016 | leency | 219 | return "'Error saving image file!\nNot enough space? Path wrong?\nFile system is not writable?..' -E"; |
7224 | leency | 220 | } |
221 | } |
||
222 | } |
||
7190 | leency | 223 | } |
224 | |||
5598 | pavelyakov | 225 | #endif>> |