Rev 8789 | Rev 9396 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8789 | Rev 8821 | ||
---|---|---|---|
1 | //Asper |
1 | //Asper |
2 | #ifndef INCLUDE_LIBIMG_H |
2 | #ifndef INCLUDE_LIBIMG_H |
3 | #define INCLUDE_LIBIMG_H |
3 | #define INCLUDE_LIBIMG_H |
4 | 4 | ||
5 | #ifndef INCLUDE_KOLIBRI_H |
5 | #ifndef INCLUDE_KOLIBRI_H |
6 | #include "../lib/kolibri.h" |
6 | #include "../lib/kolibri.h" |
7 | #endif |
7 | #endif |
8 | 8 | ||
9 | #ifndef INCLUDE_MEM_H |
9 | #ifndef INCLUDE_MEM_H |
10 | #include "../lib/mem.h" |
10 | #include "../lib/mem.h" |
11 | #endif |
11 | #endif |
12 | 12 | ||
13 | #ifndef INCLUDE_DLL_H |
13 | #ifndef INCLUDE_DLL_H |
14 | #include "../lib/dll.h" |
14 | #include "../lib/dll.h" |
15 | #endif |
15 | #endif |
16 | 16 | ||
17 | //library |
17 | //library |
18 | dword libimg = #alibimg; |
18 | dword libimg = #alibimg; |
19 | char alibimg[] = "/sys/lib/libimg.obj"; |
19 | char alibimg[] = "/sys/lib/libimg.obj"; |
20 | 20 | ||
21 | dword libimg_init = #alibimg_init; |
21 | dword libimg_init = #alibimg_init; |
22 | dword img_decode = #aimg_decode; |
22 | dword img_decode = #aimg_decode; |
23 | dword img_destroy = #aimg_destroy; |
23 | dword img_destroy = #aimg_destroy; |
24 | dword img_draw = #aimg_draw; |
24 | dword img_draw = #aimg_draw; |
25 | dword img_create = #aimg_create; |
25 | dword img_create = #aimg_create; |
26 | dword img_encode = #aimg_encode; |
26 | dword img_encode = #aimg_encode; |
27 | dword img_convert = #aimg_convert; |
27 | dword img_convert = #aimg_convert; |
28 | dword img_from_file = #aimg_from_file; |
28 | dword img_from_file = #aimg_from_file; |
29 | dword img_blend = #aimg_blend; |
29 | dword img_blend = #aimg_blend; |
30 | //dword img_resize = #aimg_resize; |
30 | //dword img_resize = #aimg_resize; |
31 | //dword img_is_img = #aimg_is_img; |
31 | //dword img_is_img = #aimg_is_img; |
32 | //dword img_to_rgb2 = #aimg_to_rgb2; |
32 | //dword img_to_rgb2 = #aimg_to_rgb2; |
33 | //dword img_scale = #aimg_scale; |
33 | //dword img_scale = #aimg_scale; |
34 | //dword img_flip = #aimg_flip; |
34 | //dword img_flip = #aimg_flip; |
35 | //dword img_rotate = #aimg_rotate; |
35 | //dword img_rotate = #aimg_rotate; |
36 | 36 | ||
37 | $DD 2 dup 0 |
37 | $DD 2 dup 0 |
38 | 38 | ||
39 | //import |
39 | //import |
40 | char alibimg_init[] = "lib_init"; |
40 | char alibimg_init[] = "lib_init"; |
41 | char aimg_decode[] = "img_decode"; |
41 | char aimg_decode[] = "img_decode"; |
42 | char aimg_destroy[] = "img_destroy"; |
42 | char aimg_destroy[] = "img_destroy"; |
43 | char aimg_draw[] = "img_draw"; |
43 | char aimg_draw[] = "img_draw"; |
44 | char aimg_create[] = "img_create"; |
44 | char aimg_create[] = "img_create"; |
45 | char aimg_encode[] = "img_encode"; |
45 | char aimg_encode[] = "img_encode"; |
46 | char aimg_convert[] = "img_convert"; |
46 | char aimg_convert[] = "img_convert"; |
47 | char aimg_from_file[] = "img_from_file"; |
47 | char aimg_from_file[] = "img_from_file"; |
48 | char aimg_blend[] = "img_blend"; |
48 | char aimg_blend[] = "img_blend"; |
49 | //char aimg_resize[] = "img_resize"; |
49 | //char aimg_resize[] = "img_resize"; |
50 | //char aimg_is_img[] = "img_is_img"; |
50 | //char aimg_is_img[] = "img_is_img"; |
51 | //char aimg_to_rgb2[] = "img_to_rgb2"; |
51 | //char aimg_to_rgb2[] = "img_to_rgb2"; |
52 | //char aimg_scale[] = "img_scale"; |
52 | //char aimg_scale[] = "img_scale"; |
53 | //char aimg_flip[] = "img_flip"; |
53 | //char aimg_flip[] = "img_flip"; |
54 | //char aimg_rotate[] = "img_rotate"; |
54 | //char aimg_rotate[] = "img_rotate"; |
55 | 55 | ||
56 | #define LIBIMG_FORMAT_BMP 1 |
56 | #define LIBIMG_FORMAT_BMP 1 |
57 | #define LIBIMG_FORMAT_ICO 2 |
57 | #define LIBIMG_FORMAT_ICO 2 |
58 | #define LIBIMG_FORMAT_CUR 3 |
58 | #define LIBIMG_FORMAT_CUR 3 |
59 | #define LIBIMG_FORMAT_GIF 4 |
59 | #define LIBIMG_FORMAT_GIF 4 |
60 | #define LIBIMG_FORMAT_PNG 5 |
60 | #define LIBIMG_FORMAT_PNG 5 |
61 | #define LIBIMG_FORMAT_JPEG 6 |
61 | #define LIBIMG_FORMAT_JPEG 6 |
62 | #define LIBIMG_FORMAT_TGA 7 |
62 | #define LIBIMG_FORMAT_TGA 7 |
63 | #define LIBIMG_FORMAT_PCX 8 |
63 | #define LIBIMG_FORMAT_PCX 8 |
64 | #define LIBIMG_FORMAT_XCF 9 |
64 | #define LIBIMG_FORMAT_XCF 9 |
65 | #define LIBIMG_FORMAT_TIFF 10 |
65 | #define LIBIMG_FORMAT_TIFF 10 |
66 | #define LIBIMG_FORMAT_PNM 11 |
66 | #define LIBIMG_FORMAT_PNM 11 |
67 | #define LIBIMG_FORMAT_WBMP 12 |
67 | #define LIBIMG_FORMAT_WBMP 12 |
68 | #define LIBIMG_FORMAT_XBM 13 |
68 | #define LIBIMG_FORMAT_XBM 13 |
69 | #define LIBIMG_FORMAT_Z80 14 |
69 | #define LIBIMG_FORMAT_Z80 14 |
70 | 70 | ||
71 | // values for Image.Type |
71 | // values for Image.Type |
72 | // must be consecutive to allow fast switch on Image.Type in support functions |
72 | // must be consecutive to allow fast switch on Image.Type in support functions |
73 | #define IMAGE_BPP8i 1 // indexed |
73 | #define IMAGE_BPP8i 1 // indexed |
74 | #define IMAGE_BPP24 2 |
74 | #define IMAGE_BPP24 2 |
75 | #define IMAGE_BPP32 3 |
75 | #define IMAGE_BPP32 3 |
76 | #define IMAGE_BPP15 4 |
76 | #define IMAGE_BPP15 4 |
77 | #define IMAGE_BPP16 5 |
77 | #define IMAGE_BPP16 5 |
78 | #define IMAGE_BPP1 6 |
78 | #define IMAGE_BPP1 6 |
79 | #define IMAGE_BPP8g 7 // grayscale |
79 | #define IMAGE_BPP8g 7 // grayscale |
80 | #define IMAGE_BPP2i 8 |
80 | #define IMAGE_BPP2i 8 |
81 | #define IMAGE_BPP4i 9 |
81 | #define IMAGE_BPP4i 9 |
82 | #define IMAGE_BPP8a 10 // grayscale with alpha channel; application layer only!!! |
82 | #define IMAGE_BPP8a 10 // grayscale with alpha channel; application layer only!!! |
83 | // kernel doesn't handle this image type, |
83 | // kernel doesn't handle this image type, |
84 | // libimg can only create and destroy such images |
84 | // libimg can only create and destroy such images |
85 | 85 | ||
86 | struct libimg_image |
86 | struct libimg_image |
87 | { |
87 | { |
88 | dword checksum; // ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far |
88 | dword checksum; // ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far |
89 | dword w; |
89 | dword w; |
90 | dword h; |
90 | dword h; |
91 | dword next; |
91 | dword next; |
92 | dword previous; |
92 | dword previous; |
93 | dword type; // one of Image.bppN |
93 | dword type; // one of Image.bppN |
94 | dword imgsrc; |
94 | dword imgsrc; |
95 | dword palette; // used iff Type eq Image.bpp1, Image.bpp2, Image.bpp4 or Image.bpp8i |
95 | dword palette; // used iff Type eq Image.bpp1, Image.bpp2, Image.bpp4 or Image.bpp8i |
96 | dword extended; |
96 | dword extended; |
97 | dword flags; // bitfield |
97 | dword flags; // bitfield |
98 | dword delay; // used iff Image.IsAnimated is set in Flags |
98 | dword delay; // used iff Image.IsAnimated is set in Flags |
99 | dword image; |
99 | dword image; |
100 | void load(); |
100 | void load(); |
101 | void convert_into(); |
101 | void convert_into(); |
102 | void replace_color(); |
102 | void replace_color(); |
103 | void replace_2colors(); |
103 | void replace_2colors(); |
104 | void set_vars(); |
104 | void set_vars(); |
105 | void draw(); |
105 | void draw(); |
106 | }; |
106 | }; |
107 | 107 | ||
108 | :void libimg_image::set_vars() |
108 | :void libimg_image::set_vars() |
109 | { |
109 | { |
110 | $push edi |
110 | $push edi |
111 | EDI = image; |
111 | EDI = image; |
112 | //checksum = ESDWORD[EDI]; |
112 | //checksum = ESDWORD[EDI]; |
113 | w = ESDWORD[EDI+4]; |
113 | w = ESDWORD[EDI+4]; |
114 | h = ESDWORD[EDI+8]; |
114 | h = ESDWORD[EDI+8]; |
115 | //next = ESDWORD[EDI+12]; |
115 | //next = ESDWORD[EDI+12]; |
116 | //previous = ESDWORD[EDI+16]; |
116 | //previous = ESDWORD[EDI+16]; |
117 | imgsrc = ESDWORD[EDI+24]; |
117 | imgsrc = ESDWORD[EDI+24]; |
118 | //palette = ESDWORD[EDI+28]; |
118 | //palette = ESDWORD[EDI+28]; |
119 | //extended = ESDWORD[EDI+32]; |
119 | //extended = ESDWORD[EDI+32]; |
120 | //flags = ESDWORD[EDI+36]; |
120 | //flags = ESDWORD[EDI+36]; |
121 | //delay = ESDWORD[EDI+40]; |
121 | //delay = ESDWORD[EDI+40]; |
122 | $pop edi |
122 | $pop edi |
123 | } |
123 | } |
124 | 124 | ||
125 | :void libimg_image::load(dword file_path) |
125 | :void libimg_image::load(dword file_path) |
126 | { |
126 | { |
127 | if (image) img_destroy stdcall(image); |
127 | if (image) img_destroy stdcall(image); |
128 | img_from_file stdcall(file_path); |
128 | img_from_file stdcall(file_path); |
129 | if (!EAX) { |
129 | if (!EAX) { |
130 | notify("'Error: Image not loaded'E"); |
130 | notify("'Error: Image not loaded'E"); |
131 | } else { |
131 | } else { |
132 | image = EAX; |
132 | image = EAX; |
133 | set_vars(); |
133 | set_vars(); |
134 | } |
134 | } |
135 | } |
135 | } |
136 | 136 | ||
137 | :void libimg_image::replace_color(dword old_color, new_color) |
137 | :void libimg_image::replace_color(dword old_color, new_color) |
138 | { |
138 | { |
139 | EDX = w * h * 4 + imgsrc; |
139 | EDX = w * h * 4 + imgsrc; |
140 | ESI = old_color; |
140 | ESI = old_color; |
141 | ECX = new_color; |
141 | ECX = new_color; |
142 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
142 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
143 | } |
143 | } |
144 | 144 | ||
145 | :void libimg_image::replace_2colors(dword old_color1, new_color1, old_color2, new_color2) |
145 | :void libimg_image::replace_2colors(dword old_color1, new_color1, old_color2, new_color2) |
146 | { |
146 | { |
147 | EDX = w * h * 4 + imgsrc; |
147 | EDX = w * h * 4 + imgsrc; |
148 | ESI = old_color1; |
148 | ESI = old_color1; |
149 | ECX = new_color1; |
149 | ECX = new_color1; |
150 | EBX = old_color2; |
150 | EBX = old_color2; |
151 | EAX = new_color2; |
151 | EAX = new_color2; |
152 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) { |
152 | FOR (EDI = imgsrc; EDI < EDX; EDI += 4) { |
153 | IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
153 | IF (DSDWORD[EDI]==ESI) DSDWORD[EDI] = ECX; |
154 | ELSE IF (DSDWORD[EDI]==EBX) DSDWORD[EDI] = EAX; |
154 | ELSE IF (DSDWORD[EDI]==EBX) DSDWORD[EDI] = EAX; |
155 | } |
155 | } |
156 | } |
156 | } |
157 | 157 | ||
158 | :void libimg_image::draw(dword _x, _y, _w, _h, _xoff, _yoff) |
158 | :void libimg_image::draw(dword _x, _y, _w, _h, _xoff, _yoff) |
159 | { |
159 | { |
160 | if (image) img_draw stdcall(image, _x, _y, _w, _h, _xoff, _yoff); |
160 | if (image) img_draw stdcall(image, _x, _y, _w, _h, _xoff, _yoff); |
161 | } |
161 | } |
162 | 162 | ||
163 | :void libimg_image::convert_into(dword _to) |
163 | :void libimg_image::convert_into(dword _to) |
164 | { |
164 | { |
165 | img_convert stdcall(image, 0, _to, 0, 0); |
165 | img_convert stdcall(image, 0, _to, 0, 0); |
166 | $push eax |
166 | $push eax |
167 | img_destroy stdcall(image); |
167 | img_destroy stdcall(image); |
168 | $pop eax |
168 | $pop eax |
169 | if (!EAX) { |
169 | if (!EAX) { |
170 | notify("'LibImg convertation error!'E"); |
170 | notify("'LibImg convertation error!'E"); |
171 | } else { |
171 | } else { |
172 | image = EAX; |
172 | image = EAX; |
173 | set_vars(); |
173 | set_vars(); |
174 | } |
174 | } |
175 | } |
175 | } |
176 | 176 | ||
177 | :dword create_image(dword type, dword width, dword height) { |
177 | :dword create_image(dword type, dword width, dword height) { |
178 | img_create stdcall(width, height, type); |
178 | img_create stdcall(width, height, type); |
179 | return EAX; |
179 | return EAX; |
180 | } |
180 | } |
181 | 181 | ||
182 | // size - output parameter, error code / the size of encoded data |
182 | // size - output parameter, error code / the size of encoded data |
183 | :dword encode_image(dword image_ptr, dword options, dword specific_options, dword* size) { |
183 | :dword encode_image(dword image_ptr, dword options, dword specific_options, dword* size) { |
184 | img_encode stdcall(image_ptr, options, specific_options); |
184 | img_encode stdcall(image_ptr, options, specific_options); |
185 | ESDWORD[size] = ECX; |
185 | ESDWORD[size] = ECX; |
186 | 186 | ||
187 | return EAX; |
187 | return EAX; |
188 | } |
188 | } |
189 | 189 | ||
190 | #ifdef LANG_RUS |
190 | #ifdef LANG_RUS |
191 | #define TEXT_FILE_SAVED_AS "' ©« á®åà ¥ ª ª " |
191 | #define TEXT_FILE_SAVED_AS "' ©« á®åà ¥ ª ª " |
192 | #else |
192 | #else |
193 | #define TEXT_FILE_SAVED_AS "'File saved as " |
193 | #define TEXT_FILE_SAVED_AS "'File saved as " |
194 | #endif |
194 | #endif |
195 | :void save_image(dword _image_pointer, _w, _h, _path) |
195 | :void save_image(dword _image_pointer, _w, _h, _path) |
196 | { |
196 | { |
197 | char save_success_message[4096+200]; |
197 | char save_success_message[4096+200]; |
198 | dword encoded_data=0; |
198 | dword encoded_data=0; |
199 | dword encoded_size=0; |
199 | dword encoded_size=0; |
200 | dword image_ptr = 0; |
200 | dword image_ptr = 0; |
201 | 201 | ||
202 | image_ptr = create_image(IMAGE_BPP24, _w, _h); |
202 | image_ptr = create_image(IMAGE_BPP24, _w, _h); |
203 | 203 | ||
204 | if (image_ptr == 0) { |
204 | if (image_ptr == 0) { |
205 | notify("'Error saving file, probably not enought memory!' -E"); |
205 | notify("'Error saving file, probably not enought memory!' -E"); |
206 | } |
206 | } |
207 | else { |
207 | else { |
208 | EDI = image_ptr; |
208 | EDI = image_ptr; |
209 | memmov(EDI.libimg_image.imgsrc, _image_pointer, _w * _h * 3); |
209 | memmov(EDI.libimg_image.imgsrc, _image_pointer, _w * _h * 3); |
210 | 210 | ||
211 | encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size); |
211 | encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size); |
212 | 212 | ||
213 | img_destroy stdcall(image_ptr); |
213 | img_destroy stdcall(image_ptr); |
214 | 214 | ||
215 | if(encoded_data == 0) { |
215 | if(encoded_data == 0) { |
216 | notify("'Error saving file, incorrect data!' -E"); |
216 | notify("'Error saving file, incorrect data!' -E"); |
217 | } |
217 | } |
218 | else { |
218 | else { |
219 | if (CreateFile(encoded_size, encoded_data, _path) == 0) { |
219 | if (CreateFile(encoded_size, encoded_data, _path) == 0) { |
220 | strcpy(#save_success_message, TEXT_FILE_SAVED_AS); |
220 | strcpy(#save_success_message, TEXT_FILE_SAVED_AS); |
221 | strcat(#save_success_message, _path); |
221 | strcat(#save_success_message, _path); |
222 | strcat(#save_success_message, "' -O"); |
222 | strcat(#save_success_message, "' -O"); |
223 | notify(#save_success_message); |
223 | notify(#save_success_message); |
224 | } |
224 | } |
225 | else { |
225 | else { |
226 | notify("'Error saving image file!\nNot enough space? Path wrong?\nFile system is not writable?..' -E"); |
226 | notify("'Error saving image file!\nNot enough space? Path wrong?\nFile system is not writable?..' -E"); |
227 | } |
227 | } |
228 | } |
228 | } |
229 | } |
229 | } |
230 | } |
230 | } |
231 | 231 | ||
232 | 232 | ||
233 | 233 | ||
234 | ///////////////////////////// |
234 | ///////////////////////////// |
235 | /* |
235 | /* |
236 | // DRAW ICON PATTERN / TEMP |
236 | // DRAW ICON PATTERN / TEMP |
237 | */ |
237 | */ |
238 | ///////////////////////////// |
238 | ///////////////////////////// |
239 | 239 | ||
240 | :void DrawIcon32(dword x,y, _bg, icon_n) { |
240 | :void DrawIcon32(dword x,y, _bg, icon_n) { |
241 | static dword bg; |
241 | static dword bg; |
242 | static dword pure_img32; |
242 | static dword pure_img32; |
243 | if (!pure_img32) || (bg!=_bg) { |
243 | if (!pure_img32) || (bg!=_bg) { |
244 | bg = _bg; |
244 | bg = _bg; |
245 | if (pure_img32) img_destroy stdcall(pure_img32); |
245 | if (pure_img32) img_destroy stdcall(pure_img32); |
246 | img_from_file stdcall("/sys/icons32.png"); |
246 | img_from_file stdcall("/sys/icons32.png"); |
247 | pure_img32 = EAX; |
247 | pure_img32 = EAX; |
248 | //now fill transparent with another color |
248 | //now fill transparent with another color |
249 | EDX = ESDWORD[EAX+4] * ESDWORD[EAX+8] * 4 + ESDWORD[EAX+24]; |
249 | EDX = ESDWORD[EAX+4] * ESDWORD[EAX+8] * 4 + ESDWORD[EAX+24]; |
250 | for (ESI = ESDWORD[EAX+24]; ESI < EDX; ESI += 4) { |
250 | for (ESI = ESDWORD[EAX+24]; ESI < EDX; ESI += 4) { |
251 | if (DSDWORD[ESI]==0x00000000) DSDWORD[ESI] = bg; |
251 | if (DSDWORD[ESI]==0x00000000) DSDWORD[ESI] = bg; |
252 | } |
252 | } |
253 | } |
253 | } |
254 | img_draw stdcall(pure_img32, x, y, 32, 32, 0, icon_n*32); |
254 | img_draw stdcall(pure_img32, x, y, 32, 32, 0, icon_n*32); |
255 | } |
255 | } |
256 | 256 | ||
257 | :void DrawIcon16(dword x,y, _bg, icon_n) { |
257 | :int DrawIcon16(dword x,y, _bg, icon_n) { |
258 | static dword bg; |
258 | static dword bg; |
259 | static dword pure_img16; |
259 | static dword pure_img16; |
260 | dword bgshadow; |
260 | dword bgshadow; |
- | 261 | int size; |
|
261 | if (!pure_img16) || (bg!=_bg) { |
262 | if (!pure_img16) || (bg!=_bg) { |
262 | bg = _bg; |
263 | bg = _bg; |
263 | bgshadow = MixColors(bg, 0, 220); |
264 | bgshadow = MixColors(bg, 0, 220); |
264 | if (pure_img16) img_destroy stdcall(pure_img16); |
265 | if (pure_img16) img_destroy stdcall(pure_img16); |
265 | img_from_file stdcall("/sys/icons16.png"); |
266 | img_from_file stdcall("/sys/icons16.png"); |
266 | pure_img16 = EAX; |
267 | pure_img16 = EAX; |
267 | //now fill transparent with another color |
268 | //now fill transparent with another color |
268 | EDX = ESDWORD[EAX+4] * ESDWORD[EAX+8] * 4 + ESDWORD[EAX+24]; |
269 | EDX = ESDWORD[EAX+4] * ESDWORD[EAX+8] * 4 + ESDWORD[EAX+24]; |
269 | for (ESI = ESDWORD[EAX+24]; ESI < EDX; ESI += 4) { |
270 | for (ESI = ESDWORD[EAX+24]; ESI < EDX; ESI += 4) { |
270 | if (DSDWORD[ESI]==0xffFFFfff) DSDWORD[ESI] = bg; |
271 | if (DSDWORD[ESI]==0xffFFFfff) DSDWORD[ESI] = bg; |
271 | if (DSDWORD[ESI]==0xffCACBD6) DSDWORD[ESI] = bgshadow; |
272 | if (DSDWORD[ESI]==0xffCACBD6) DSDWORD[ESI] = bgshadow; |
272 | } |
273 | } |
273 | } |
274 | } |
- | 275 | size = ESDWORD[pure_img16+4]; //get image width |
|
274 | img_draw stdcall(pure_img16, x, y, ESDWORD[EAX+4], ESDWORD[EAX+4], 0, icon_n*ESDWORD[EAX+4]); |
276 | img_draw stdcall(pure_img16, x, y, size, size, 0, icon_n*size); |
- | 277 | return size; |
|
275 | } |
278 | } |
276 | 279 | ||
277 | #endif>>>> |
280 | #endif>>>> |