Rev 5305 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5305 | codemaster | 1 | ; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$ |
2 | ; *************** STAR^2 SOFTWARE **************** |
||
3 | ; ;;;;;;;;;;;;;;;;;;; IMAGE ;;;;;;;;;;;;;;;;;;;;;; |
||
4 | |||
5 | ; image class/object/structure |
||
6 | |||
7 | macro IMAGE a { |
||
8 | a: |
||
9 | void a#.p |
||
10 | integer a#.x, a#.y, a#.w, a#.h |
||
11 | integer a#.bpp=32, a#.key, a#.alpha |
||
12 | } |
||
13 | |||
14 | virtual at 0 |
||
15 | ?image.p dd 0 |
||
16 | ?image.x dd 0 |
||
17 | ?image.y dd 0 |
||
18 | ?image.w dd 0 |
||
19 | ?image.h dd 0 |
||
20 | ?image.bpp dd 32 |
||
21 | ?image.key dd 0 |
||
22 | ?image.alpha dd 0 |
||
23 | END virtual |
||
24 | |||
25 | ?image.box fix ?image.x |
||
26 | |||
27 | ; create image file/s with header: |
||
28 | ; 8 bytes: |
||
29 | |||
30 | ; byte s='I' ; signature |
||
31 | ; byte v=0 ; version: AABBCC.VV |
||
32 | ; int16 w, h ; size: w:h |
||
33 | ; byte bpp ; bpp: 32/24/16/15/8 |
||
34 | ; byte n ; # colors or 0=256+ |
||
35 | |||
36 | ; byte pixels[w*h*(bpp/8)] ; or *2 if 15 |
||
37 | |||
38 | macro IMAGE [p] { |
||
39 | forward |
||
40 | local w, h |
||
41 | w=0 |
||
42 | h=0 |
||
43 | define ?s 0 |
||
44 | match a==b, p \{ |
||
45 | \local ..q |
||
46 | ..q: inject.image b, 32 |
||
47 | load w word from ..q+2 |
||
48 | load h word from ..q+4 |
||
49 | a: |
||
50 | void a\#.p=..q+8 |
||
51 | integer a\#.x, a\#.y, a\#.w=w, a\#.h=h |
||
52 | integer a\#.bpp, a\#.key, a\#.alpha |
||
53 | define ?s 1 |
||
54 | \} |
||
55 | IF ?s eq 0 |
||
56 | IMAGE p |
||
57 | END IF |
||
58 | } |
||
59 | |||
60 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
61 | |||
62 | ; load 24PP .BMP, store as .IMAGE 15/16/24/32. |
||
63 | ; for OSs, ROMs. warning: causes slow compile |
||
64 | ; with 1+ MB worth of images. to compile fast |
||
65 | ; without images, comment "; IMAGE name='abc'" |
||
66 | |||
67 | macro inject.image name, bpp { |
||
68 | local i, p, a, r, g, b,\ |
||
69 | x, y, w, h, wb |
||
70 | virtual at 0 |
||
5309 | yogev_ezra | 71 | p:: file CD#'/media/'#name#'.bmp' |
5305 | codemaster | 72 | END virtual |
73 | IF ~bpp in <15,16,24,32> |
||
74 | 'Invalid BPP' name |
||
75 | END IF |
||
76 | load a word from p:0 |
||
77 | IF a<>'BM' |
||
78 | 'Invalid signature' name |
||
79 | END IF |
||
80 | load a byte from p:1Ch |
||
81 | IF a<>24 |
||
82 | 'Must be 24BPP' name |
||
83 | END IF |
||
84 | load w dword from p:12h |
||
85 | load h dword from p:16h |
||
86 | db 'I', 0 |
||
87 | dw w, h |
||
88 | db bpp, 0 |
||
89 | a=((3-((w*3)+3)) and 3) |
||
90 | wb=(w*3)+a |
||
91 | y=h |
||
92 | WHILE y>0 |
||
93 | o=36h+((y-1)*wb) |
||
94 | x=0 |
||
95 | WHILE x |
||
96 | i=o+(x*3) |
||
97 | load b byte from p:i |
||
98 | load g byte from p:i+1 |
||
99 | load r byte from p:i+2 |
||
100 | IF bpp=32 |
||
101 | dd (r shl 16) or (g shl 8) or b |
||
102 | ELSE IF bpp=24 |
||
103 | db r, g, b ; or b, g, r |
||
104 | ELSE IF bpp=16 |
||
105 | r=((r and 11111b)/8) shl 11 |
||
106 | g=((g and 111111b)/4) shl 5 |
||
107 | b=((b and 11111b)/8) |
||
108 | dw r or g or b |
||
109 | ELSE IF bpp=15 |
||
110 | r=((r and 11111b)/8) shl 10 |
||
111 | g=((g and 11111b)/8) shl 5 |
||
112 | b=((b and 11111b)/8) |
||
113 | dw r or g or b |
||
114 | END IF |
||
115 | x=x+1 |
||
116 | END WHILE |
||
117 | y=y-1 |
||
118 | END WHILE |
||
119 | } |
||
120 | |||
121 | ; insert 8BPP .BMP as .IMAGE with palette. |
||
122 | ; note: must use special .8 drawing |
||
123 | |||
124 | macro inject.image.8 name { |
||
125 | local i, p, a, c,\ |
||
126 | x, y, w, h, wb |
||
127 | virtual at 0 |
||
5309 | yogev_ezra | 128 | p:: file CD#'/media/'#name#'.bmp' |
5305 | codemaster | 129 | END virtual |
130 | load a word from p:0 |
||
131 | IF a<>'BM' |
||
132 | 'Invalid signature' name |
||
133 | END IF |
||
134 | load a byte from p:1Ch |
||
135 | IF a<>8 |
||
136 | 'Must be 8BPP' name |
||
137 | END IF |
||
138 | load w dword from p:12h |
||
139 | load h dword from p:16h |
||
140 | db 'I', 0 |
||
141 | dw w, h |
||
142 | db 8, 0 |
||
143 | i=0 |
||
144 | WHILE i<256 |
||
145 | o=36h+(i*4) |
||
146 | load b byte from p:o |
||
147 | load g byte from p:o+1 |
||
148 | load r byte from p:o+2 |
||
149 | db b, g, r, 0 |
||
150 | i=i+1 |
||
151 | END WHILE |
||
152 | a=((3-(w+3)) and 3) |
||
153 | wb=w+a |
||
154 | y=h |
||
155 | WHILE y>0 |
||
156 | o=436h+((y-1)*wb) |
||
157 | x=0 |
||
158 | WHILE x |
||
159 | load c byte from p:o+x |
||
160 | db c |
||
161 | x=x+1 |
||
162 | END WHILE |
||
163 | y=y-1 |
||
164 | END WHILE |
||
165 | } |
||
166 | |||
167 | macro IMAGE8 [p] { |
||
168 | forward |
||
169 | local w, h |
||
170 | w=0 |
||
171 | h=0 |
||
172 | define ?s 0 |
||
173 | match a==b, p \{ |
||
174 | \local ..q |
||
175 | ..q: inject.image.8 b |
||
176 | load w word from ..q+2 |
||
177 | load h word from ..q+4 |
||
178 | a: |
||
179 | void a\#.p=..q+408h |
||
180 | integer a\#.x, a\#.y, a\#.w=w, a\#.h=h |
||
181 | integer a\#.bpp, a\#.key, a\#.alpha |
||
182 | ; ... |
||
183 | void a\#.palette=..q+8 |
||
184 | define ?s 1 |
||
185 | \} |
||
186 | IF ?s eq 0 |
||
187 | 'Error: 8BPP must specify file' |
||
188 | END IF |
||
189 | } |
||
190 | |||
191 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
192 | |||
193 | ; unfinished, unorganized... |
||
194 | |||
195 | ; 2-DO: convert to functions. create one |
||
196 | ; good draw.scanline.x with bpp and type |
||
197 | ; BIT flags: |
||
198 | |||
199 | ; draw.scanline.x p, x, y, w, 32,\ |
||
200 | ; G.KEY or G.ALPHA or G.GRAY or G.INVERT.X |
||
201 | |||
202 | macro move.image i, x, y { . i#.x=x, i#.y=y } |
||
203 | |||
204 | macro draw.image i, x, y { |
||
205 | IF ~x eq |
||
206 | move.image i, x, y |
||
207 | END IF |
||
208 | draw.bitmap i#.p, i#.x, i#.y, i#.w, i#.h |
||
209 | } |
||
210 | |||
211 | macro draw.image.t i, x, y { |
||
212 | IF ~x eq |
||
213 | move.image i, x, y |
||
214 | END IF |
||
215 | draw.bitmap.t i#.p, i#.x, i#.y, i#.w, i#.h |
||
216 | } |
||
217 | |||
218 | ; draw with inverted x/y |
||
219 | |||
220 | macro draw.image.ix i, x, y { |
||
221 | IF ~x eq |
||
222 | move.image i, x, y |
||
223 | END IF |
||
224 | draw.bitmap.ix i#.p,\ |
||
225 | i#.x, i#.y, i#.w, i#.h |
||
226 | } |
||
227 | |||
228 | macro draw.image.iy i, x, y { |
||
229 | IF ~x eq |
||
230 | move.image i, x, y |
||
231 | END IF |
||
232 | draw.bitmap.iy i#.p, i#.x, i#.y, i#.w, i#.h |
||
233 | } |
||
234 | |||
235 | macro draw.image.ixy i, x, y, ix, iy { |
||
236 | IF ~x eq |
||
237 | move.image i, x, y |
||
238 | END IF |
||
239 | draw.bitmap.ixy i#.p, i#.x, i#.y, i#.w, i#.h |
||
240 | } |
||
241 | |||
242 | macro draw.image.v i, x, y, c { |
||
243 | IF ~x eq |
||
244 | move.image i, x, y |
||
245 | END IF |
||
246 | draw.bitmap.v i#.p, i#.x, i#.y, i#.w, i#.h, c |
||
247 | } |
||
248 | |||
249 | ; draw rotated. warning: no clipping |
||
250 | |||
251 | function draw.scanline.rl, pixels, x, y, w |
||
252 | alias p=r0, s=r1, n=r2 |
||
253 | vga.xy x, y |
||
254 | . s=w, s--, s*4, s+pixels, n=screen.pitch |
||
255 | loop w, (u32) *p=*s--, p+n, endl |
||
256 | endf 1 |
||
257 | |||
258 | function draw.scanline.rr, pixels, x, y, w |
||
259 | alias p=r0, s=r1, n=r2 |
||
260 | vga.xy x, y |
||
261 | . s=pixels, n=screen.pitch |
||
262 | loop w, (u32) *p=*s++, p+n, endl |
||
263 | endf 1 |
||
264 | |||
265 | function draw.bitmap.rl, pixels, x, y, w, h |
||
266 | locals i, p |
||
267 | try visible x, y, w, h |
||
268 | . p=pixels |
||
269 | loop h |
||
270 | draw.scanline.rl p, x, y, w |
||
271 | . r0=w, r0*4, p+r0, x++ |
||
272 | endl |
||
273 | endf 1 |
||
274 | |||
275 | function draw.bitmap.rr, pixels, x, y, w, h |
||
276 | locals i, p |
||
277 | try visible x, y, w, h |
||
278 | . r0=w, r0--, x+r0, p=pixels |
||
279 | loop h |
||
280 | draw.scanline.rr p, x, y, w |
||
281 | . r0=w, r0*4, p+r0, x-- |
||
282 | endl |
||
283 | endf 1 |
||
284 | |||
285 | macro draw.image.rl i, x, y { |
||
286 | IF ~x eq |
||
287 | move.image i, x, y |
||
288 | END IF |
||
289 | draw.bitmap.rl i#.p, i#.x, i#.y, i#.w, i#.h |
||
290 | } |
||
291 | |||
292 | macro draw.image.rr i, x, y { |
||
293 | IF ~x eq |
||
294 | move.image i, x, y |
||
295 | END IF |
||
296 | draw.bitmap.rr i#.p, i#.x, i#.y, i#.w, i#.h |
||
297 | } |
||
298 | |||
299 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
300 | |||
301 | ; 8BPP with palette... |
||
302 | |||
303 | macro draw.image.8 i, x, y { |
||
304 | IF ~x eq |
||
305 | move.image i, x, y |
||
306 | END IF |
||
307 | . palette.p=i#.palette |
||
308 | draw.bitmap.8 i#.p, i#.x, i#.y, i#.w, i#.h |
||
309 | } |
||
310 | |||
311 | macro draw.image.v.8 i, x, y, c { |
||
312 | IF ~x eq |
||
313 | move.image i, x, y |
||
314 | END IF |
||
315 | . palette.p=i#.palette |
||
316 | draw.bitmap.v.8 i#.p, i#.x, i#.y, i#.w, i#.h, c |
||
317 | } |
||
318 | |||
319 | function draw.image.v8, im, x, y, co |
||
320 | locals p, w, h |
||
321 | . r0=im |
||
322 | . (u32) r1=*(r0+?image.p), p=r1 |
||
323 | . (u32) r1=*(r0+?image.w), w=r1 |
||
324 | . (u32) r1=*(r0+?image.h), h=r1 |
||
325 | draw.bitmap.v.8 p, x, y, w, h, co |
||
326 | endf |
||
327 | |||
328 | function draw.bitmap.viy.8, pixels,\ |
||
329 | x, y, w, h, c |
||
330 | locals i, p |
||
331 | try visible x, y, w, h |
||
332 | . r0=h, y+r0, p=pixels |
||
333 | loop h |
||
334 | draw.scanline.v.8 p, x, y, w, c |
||
335 | . r0=w, p+r0, y-- |
||
336 | endl |
||
337 | endf 1 |
||
338 | |||
339 | function draw.image.viy.8, im, x, y, co |
||
340 | locals p, w, h |
||
341 | . r0=im |
||
342 | . (u32) r1=*(r0+?image.p), p=r1 |
||
343 | . (u32) r1=*(r0+?image.w), w=r1 |
||
344 | . (u32) r1=*(r0+?image.h), h=r1 |
||
345 | draw.bitmap.viy.8 p, x, y, w, h, co |
||
346 | endf |
||
347 | |||
348 | |||
349 | ;;;;;;;;;;;;;;;;;;; LOAD .BMP ;;;;;;;;;;;;;;;;;;;; |
||
350 | |||
351 | ; load 8BPP .BMP as 32BIT pixel array. |
||
352 | ; if success, return allocated pixels address |
||
353 | ; in r0 and w/h in r1/r2. return 0 if error |
||
354 | |||
355 | function load.bmp, file |
||
356 | locals image, palette,\ |
||
357 | p, s, x, y, w, h, a |
||
358 | catch .error |
||
359 | |||
360 | ; load file, get size then allocate |
||
361 | ; 32BPP image... |
||
362 | |||
363 | try file=load.file file |
||
364 | . r1=[r0+18], r2=[r0+22] |
||
365 | . w=r1, h=r2, r1*r2, r1*4 |
||
366 | try image=allocate r1 |
||
367 | |||
368 | ; create and load palette... |
||
369 | |||
370 | try palette=allocate 1024 |
||
371 | . r0=file, r0+54 |
||
372 | memory.copy palette, r0, 1024 |
||
373 | |||
374 | align.n w, 4 ; get alignment value |
||
375 | . a=r1 ; 0-3 bytes |
||
376 | |||
377 | ; advance to p/ixels data, point |
||
378 | ; s/ource at first pixel in last |
||
379 | ; line then read image upside down |
||
380 | |||
381 | . p=image, r0=file, r0+54, r0+1024 |
||
382 | . r1=w, r1+a, r2=h, r2--, r1*r2 |
||
383 | . r0+r1, s=r0, y=h |
||
384 | loop y, x=w |
||
385 | loop x, r2=s, r1=*r2, r1*4 |
||
386 | . r1+palette, r0=p, (u32) *r0=*r1 |
||
387 | . p+4, s++ |
||
388 | endl |
||
389 | . r0=w, r0*2, r0+a, s-r0 |
||
390 | endl |
||
391 | |||
392 | destroy file, palette |
||
393 | . r0=image, r1=w, r2=h |
||
394 | return |
||
395 | .error: |
||
396 | destroy image, file, palette |
||
397 | endf 0 |