Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
717 mikedld 1
use32
2
org 0x0
3
 
4
db 'MENUET01'
5
dd 0x01, START, I_END, 0x1000, 0x1000, @PARAMS, 0x0
6
 
7
;-----------------------------------------------------------------------------
8
 
9
FALSE = 0
10
TRUE  = 1
11
 
12
include '../../../../../proc32.inc'
13
include '../../../../../macros.inc'
14
include '../dll.inc'
15
 
16
include '../../libio/libio.inc'
783 mikedld 17
include '../../libimg/libimg.inc'
717 mikedld 18
 
19
;-----------------------------------------------------------------------------
20
 
21
START:
22
	mcall	68, 11
23
 
24
	stdcall dll.Load, @IMPORT
25
	or	eax, eax
26
	jnz	exit
27
 
28
	invoke	file.open, @PARAMS, O_READ
29
	or	eax, eax
30
	jz	exit
31
	mov	[fh], eax
32
	invoke	file.size, @PARAMS
33
	mov	[img_data_len], ebx
34
	stdcall mem.Alloc, ebx
35
	or	eax, eax
36
	jz	exit
37
	mov	[img_data], eax
38
	invoke	file.read, [fh], eax, [img_data_len]
39
	cmp	eax, -1
40
	je	exit
41
	cmp	eax, [img_data_len]
42
	jne	exit
43
	invoke	file.close, [fh]
44
	inc	eax
45
	jz	exit
46
 
47
	invoke	img.is_img, [img_data], [img_data_len]
48
	or	eax, eax
49
	jz	exit
50
	invoke	img.decode, [img_data], [img_data_len]
51
	or	eax, eax
52
	jz	exit
783 mikedld 53
	mov	[image], eax
717 mikedld 54
	invoke	img.to_rgb, eax
55
	or	eax, eax
56
	jz	exit
57
	mov	[rgb_img], eax
58
 
59
;-----------------------------------------------------------------------------
60
 
61
red:
62
	call	draw_window
63
 
64
still:
65
	mcall	10
66
	cmp	eax, 1
67
	je	red
68
	cmp	eax, 2
69
	je	key
70
	cmp	eax, 3
71
	je	button
72
	jmp	still
73
 
74
  key:
75
	mcall	2
76
	jmp	still
77
 
78
  button:
79
	mcall	17
783 mikedld 80
	shr	eax, 8
81
 
82
	; flip horizontally
83
	cmp	eax, 'flh'
84
	jne	@f
85
 
86
	invoke	img.flip, [image], FLIP_HORIZONTAL
87
	jmp	redraw_image
88
 
89
	; flip vertically
90
    @@: cmp	eax, 'flv'
91
	jne	@f
92
 
93
	invoke	img.flip, [image], FLIP_VERTICAL
94
	jmp	redraw_image
95
 
96
	; flip both horizontally and vertically
97
    @@: cmp	eax, 'flb'
98
	jne	@f
99
 
100
	invoke	img.flip, [image], FLIP_BOTH
101
	jmp	redraw_image
102
 
103
	; rotate left
104
    @@: cmp	eax, 'rtl'
105
	jne	@f
106
 
107
	invoke	img.rotate, [image], ROTATE_90_CCW
108
	jmp	redraw_image
109
 
110
	; rotate right
111
    @@: cmp	eax, 'rtr'
112
	jne	@f
113
 
114
	invoke	img.rotate, [image], ROTATE_90_CW
115
	jmp	redraw_image
116
 
117
    @@: cmp	eax, 1
717 mikedld 118
	jne	still
119
 
120
  exit:
121
	mcall	-1
122
 
783 mikedld 123
  redraw_image:
124
	stdcall mem.Free, [rgb_img]
125
	invoke	img.to_rgb, [image]
126
	or	eax, eax
127
	jz	exit
128
	mov	[rgb_img], eax
129
	jmp	red
130
 
717 mikedld 131
draw_window:
132
	invoke	gfx.open, TRUE
133
	mov	[ctx], eax
134
 
783 mikedld 135
@^
717 mikedld 136
	mov	edi, [rgb_img]
137
	mov	ebx, 200 * 65536
138
	mov	bx, [edi + 0]
139
	add	bx, 9
140
	mov	ecx, 200 * 65536
141
	mov	cx, [edi + 4]
142
	add	cx, 5 + 21
143
	mcall	0, , , 0x33FF0000, , s_header
783 mikedld 144
^@
145
	mcall	0, <100, 640>, <100, 480>, 0x33FFFFFF, , s_header
717 mikedld 146
 
783 mikedld 147
	invoke	gfx.pen.color, [ctx], 0x007F7F7F
148
	invoke	gfx.line, [ctx], 0, 30, 630, 30
149
 
150
	mcall	8, <5 + 25 * 0, 20>, <5, 20>, 'flh', 0x007F7F7F
151
	mcall	8, <5 + 25 * 1, 20>, <5, 20>, 'flv', 0x007F7F7F
152
	mcall	8, <5 + 25 * 2, 20>, <5, 20>, 'flb', 0x007F7F7F
153
 
154
	invoke	gfx.line, [ctx], 5 + 25 * 3, 0, 5 + 25 * 3, 30
155
 
156
	mcall	8, <10 + 25 * 3, 20>, <5, 20>, 'rtl', 0x007F7F7F
157
	mcall	8, <10 + 25 * 4, 20>, <5, 20>, 'rtr', 0x007F7F7F
158
 
717 mikedld 159
	mov	ebx, [rgb_img]
160
	mov	ecx, [ebx + 0]
161
	shl	ecx, 16
162
	mov	cx, [ebx + 4]
163
	add	ebx, 4 * 2
783 mikedld 164
	mcall	7, , , <5, 35>
717 mikedld 165
 
166
	invoke	gfx.close, [ctx]
167
	ret
168
 
169
;-----------------------------------------------------------------------------
170
proc mem.Alloc, size ;////////////////////////////////////////////////////////
171
;-----------------------------------------------------------------------------
172
	push	ebx ecx
173
	mov	ecx, [size]
174
	add	ecx, 4
175
	mcall	68, 12
176
	add	ecx, -4
177
	mov	[eax], ecx
178
	add	eax, 4
179
	pop	ecx ebx
180
	ret
181
endp
182
 
183
;-----------------------------------------------------------------------------
184
proc mem.ReAlloc, mptr, size ;////////////////////////////////////////////////
185
;-----------------------------------------------------------------------------
186
	push	ebx ecx edx
187
	mov	ecx, [size]
188
	or	ecx, ecx
189
	jz	@f
190
	add	ecx, 4
191
    @@: mov	edx, [mptr]
192
	or	edx, edx
193
	jz	@f
194
	add	edx, -4
195
    @@: mcall	68, 20
196
	or	eax, eax
197
	jz	@f
198
	add	ecx, -4
199
	mov	[eax], ecx
200
	add	eax, 4
201
    @@: pop	edx ecx ebx
202
	ret
203
endp
204
 
205
;-----------------------------------------------------------------------------
206
proc mem.Free, mptr ;/////////////////////////////////////////////////////////
207
;-----------------------------------------------------------------------------
208
	push	ebx ecx
209
	mov	ecx, [mptr]
210
	or	ecx, ecx
211
	jz	@f
212
	add	ecx, -4
213
    @@: mcall	68, 13
214
	pop	ecx ebx
215
	ret
216
endp
217
 
218
;-----------------------------------------------------------------------------
219
 
220
s_header db 'Image Viewer (test app)', 0
221
 
222
;-----------------------------------------------------------------------------
223
 
224
align 16
225
@IMPORT:
226
 
227
library 			\
228
	libio  , 'libio.obj'  , \
229
	libgfx , 'libgfx.obj' , \
230
	libimg , 'libimg.obj'
231
 
232
import	libio			  , \
783 mikedld 233
	libio.init , 'lib_init'   , \
717 mikedld 234
	file.size  , 'file.size'  , \
235
	file.open  , 'file.open'  , \
236
	file.read  , 'file.read'  , \
237
	file.close , 'file.close'
238
 
783 mikedld 239
import	libgfx				, \
240
	libgfx.init   , 'lib_init'	, \
241
	gfx.open      , 'gfx.open'	, \
242
	gfx.close     , 'gfx.close'	, \
243
	gfx.pen.color , 'gfx.pen.color' , \
244
	gfx.line      , 'gfx.line'
717 mikedld 245
 
783 mikedld 246
import	libimg			   , \
247
	libimg.init , 'lib_init'   , \
248
	img.is_img  , 'img.is_img' , \
249
	img.to_rgb  , 'img.to_rgb' , \
250
	img.decode  , 'img.decode' , \
251
	img.flip    , 'img.flip'   , \
252
	img.rotate  , 'img.rotate'
717 mikedld 253
 
254
;-----------------------------------------------------------------------------
255
 
256
I_END:
257
 
258
img_data     dd ?
259
img_data_len dd ?
260
fh	     dd ?
261
rgb_img      dd ?
783 mikedld 262
image	     dd ?
717 mikedld 263
 
264
ctx dd ?
265
 
266
@PARAMS rb 512