Subversion Repositories Kolibri OS

Rev

Rev 1016 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1004 diamond 1
use32
2
org 0x0
3
 
4
db 'MENUET01'
5
dd 0x01, START, I_END, 0x4000, 0x4000, @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 '../../../develop/libraries/libs-dev/libio/libio.inc'
17
include '../../../develop/libraries/libs-dev/libimg/libimg.inc'
18
 
19
;-----------------------------------------------------------------------------
20
 
21
START:
22
	mcall	68, 11
23
 
24
	stdcall dll.Load, @IMPORT
25
	or	eax, eax
26
	jnz	exit
27
 
28
	mov	ecx, 1	; for 15.4: 1 = tile
29
	cmp	word [@PARAMS], '\T'
30
	jz	set_bgr
31
	inc	ecx	; for 15.4: 2 = stretch
32
	cmp	word [@PARAMS], '\S'
33
	jz	set_bgr
34
 
35
	cmp	byte [@PARAMS], 0
36
	jnz	params_given
37
 
38
	call	opendialog
39
	jc	exit
40
	mov	esi, path
41
	mov	edi, @PARAMS
42
	mov	ecx, 512/4
43
	rep	movsd
44
	mov	byte [edi-1], 0
45
	jmp	params_given
46
 
47
set_bgr:
48
	mcall	15, 4
49
	mov	eax, @PARAMS + 4
50
	call	load_image
51
	jc	exit_bgr
52
 
53
	mov	esi, [image]
54
	mov	ecx, [esi + Image.Width]
55
	mov	edx, [esi + Image.Height]
56
	mcall	15, 1
57
 
58
	mcall	15, 6
59
	test	eax, eax
60
	jz	exit_bgr
61
 
62
	push	eax
63
	invoke	img.to_rgb2, esi, eax
64
	pop	ecx
65
	mcall	15, 7
66
 
67
exit_bgr:
68
	mcall	15, 3
69
	jmp	exit
70
 
71
params_given:
72
 
73
	mov	eax, @PARAMS
74
	call	load_image
75
	jc	exit
76
 
77
;-----------------------------------------------------------------------------
78
 
79
red:
80
	call	draw_window
81
 
82
still:
83
	mcall	10
84
	dec	eax
85
	jz	red
86
	dec	eax
87
	jnz	button
88
 
89
  key:
90
	mcall	2
91
	jmp	still
92
 
93
  button:
94
	mcall	17
95
	shr	eax, 8
96
 
97
	; flip horizontally
98
	cmp	eax, 'flh'
99
	jne	@f
100
 
101
	invoke	img.flip, [image], FLIP_HORIZONTAL
102
	jmp	redraw_image
103
 
104
	; flip vertically
105
    @@: cmp	eax, 'flv'
106
	jne	@f
107
 
108
	invoke	img.flip, [image], FLIP_VERTICAL
109
	jmp	redraw_image
110
 
111
	; flip both horizontally and vertically
112
    @@: cmp	eax, 'flb'
113
	jne	@f
114
 
115
	invoke	img.flip, [image], FLIP_BOTH
116
	jmp	redraw_image
117
 
118
	; rotate left
119
    @@: cmp	eax, 'rtl'
120
	jne	@f
121
 
122
	push	ROTATE_90_CCW
123
.rotate_common:
124
	invoke	img.rotate, [image]
125
	mov	eax, [image]
126
	test	eax, eax	; clear ZF flag
127
	call	update_image_sizes
128
	jmp	redraw_image
129
 
130
	; rotate right
131
    @@: cmp	eax, 'rtr'
132
	jne	@f
133
 
134
	push	ROTATE_90_CW
135
	jmp	.rotate_common
136
 
137
	; open new file
138
    @@: cmp	eax, 'opn'
139
	jne	@f
140
 
141
	call	opendialog
142
	jc	still
143
	push	[image]
144
	mov	eax, path
145
	call	load_image
146
	jc	.restore_old
147
	mov	esi, path
148
	mov	edi, @PARAMS
149
	mov	ecx, 512/4
150
	rep	movsd
151
	invoke	img.destroy
152
	mov	byte [edi-1], 0
153
	jmp	red
154
    .restore_old:
155
	pop	[image]
156
	jmp	still
157
 
158
    @@: cmp	eax, 1
159
	jne	still
160
 
161
  exit:
162
	mcall	-1
163
 
164
  redraw_image = red
165
 
166
load_image:
167
	and	[img_data], 0
168
	push	eax
169
	invoke	file.open, eax, O_READ
170
	or	eax, eax
171
	jz	.error_pop
172
	mov	[fh], eax
173
	invoke	file.size
174
	mov	[img_data_len], ebx
175
	stdcall mem.Alloc, ebx
176
	test	eax, eax
177
	jz	.error_close
178
	mov	[img_data], eax
179
	invoke	file.read, [fh], eax, [img_data_len]
180
	cmp	eax, -1
181
	jz	.error_close
182
	cmp	eax, [img_data_len]
183
	jnz	.error_close
184
	invoke	file.close, [fh]
185
	inc	eax
186
	jz	.error
187
 
188
; img.decode checks for img.is_img
189
;	invoke	img.is_img, [img_data], [img_data_len]
190
;	or	eax, eax
191
;	jz	exit
192
	invoke	img.decode, [img_data], [img_data_len]
193
	or	eax, eax
194
	jz	.error
195
	cmp	[image], 0
196
	mov	[image], eax
197
	call	update_image_sizes
198
	call	free_img_data
199
	clc
200
	ret
201
 
202
.error_free:
203
	invoke	img.destroy, [image]
204
	jmp	.error
205
 
206
.error_pop:
207
	pop	eax
208
	jmp	.error
209
.error_close:
210
	invoke	file.close, [fh]
211
.error:
212
	call	free_img_data
213
	stc
214
	ret
215
 
216
free_img_data:
217
	mov	eax, [img_data]
218
	test	eax, eax
219
	jz	@f
220
	stdcall	mem.Free, eax
221
@@:
222
	ret
223
 
224
update_image_sizes:
225
	pushf
226
	mov	edx, [eax + Image.Width]
227
	add	edx, 19
228
	cmp	edx, 50 + 25*5
229
	jae	@f
230
	mov	edx, 50 + 25*5
231
@@:
232
	mov	[wnd_width], edx
233
	mov	esi, [eax + Image.Height]
234
	add	esi, 44
235
	mov	[wnd_height], esi
236
	popf
237
	jz	.no_resize
238
	mcall	48, 4
239
	add	esi, eax
240
	mcall	67,-1,-1
241
.no_resize:
242
	ret
243
 
244
draw_window:
245
	invoke	gfx.open, TRUE
246
	mov	[ctx], eax
247
 
248
	mcall	48, 4
249
	mov	ebp, eax	; save skin height
250
	add	eax, [wnd_height]
251
	__mov	ebx, 100, 0
252
	add	ebx, [wnd_width]
253
	lea	ecx, [100*65536 + eax]
254
	mcall	0, , , 0x73FFFFFF, , s_header
255
 
256
	mcall	9, procinfo, -1
257
 
258
	mov	ebx, [procinfo + 42]
259
	sub	ebx, 9
260
	mcall	13, , <0, 35>, 0xFFFFFF
261
	mov	ecx, [procinfo + 46]
262
	sub	ecx, ebp
263
	sub	ecx, 9
264
	shl	ecx, 16
265
	mov	cl, 5
266
	mcall
267
	mov	cl, 35
268
	ror	ecx, 16
269
	sub	cx, 35
270
	mov	ebx, 5
271
	mcall
272
; 5 pixels for indentation, [image.Width] pixels for image
273
; client_width - 5 - [image.Width] pixels must be white
274
	mov	ebx, [image]
275
	mov	esi, [procinfo + 62]
276
	inc	esi
277
	push	esi
278
	mov	ebx, [ebx + Image.Width]
279
	sub	esi, 5
280
	sub	esi, ebx
281
	pop	ebx
282
	sub	ebx, esi
283
	shl	ebx, 16
284
	add	ebx, esi
285
	mcall
286
 
287
	invoke	gfx.pen.color, [ctx], 0x007F7F7F
288
	mov	eax, [procinfo + 42]
289
	sub	eax, 10
290
	invoke	gfx.line, [ctx], 0, 30, eax, 30
291
 
292
	xor	ebp, ebp
293
 
294
	mcall	8, <5 + 25 * 0, 20>, <5, 20>, 'opn'+40000000h
295
	mcall	65, openbtn, <20, 20>, <5 + 25 * 0, 5>, 4, palette
296
 
297
	invoke	gfx.line, [ctx], 5 + 25 * 1, 0, 5 + 25 * 1, 30
298
 
299
	mcall	8, <10 + 25 * 1, 20>, <5, 20>, 'flh'+40000000h
300
	mcall	65, fliphorzbtn, <20, 20>, <10 + 25 * 1, 5>, 4, palette
301
	mcall	8, <10 + 25 * 2, 20>, <5, 20>, 'flv'+40000000h
302
	mcall	65, flipvertbtn, <20, 20>, <10 + 25 * 2, 5>, 4, palette
303
 
304
	invoke	gfx.line, [ctx], 10 + 25 * 3, 0, 10 + 25 * 3, 30
305
 
306
	mcall	8, <15 + 25 * 3, 20>, <5, 20>, 'rtr'+40000000h
307
	mcall	65, rotcwbtn, <20, 20>, <15 + 25 * 3, 5>, 4, palette
308
	mcall	8, <15 + 25 * 4, 20>, <5, 20>, 'rtl'+40000000h
309
	mcall	65, rotccwbtn, <20, 20>, <15 + 25 * 4, 5>, 4, palette
310
	mcall	8, <15 + 25 * 5, 20>, <5, 20>, 'flb'+40000000h
311
	mcall	65, rot180btn, <20, 20>, <15 + 25 * 5, 5>, 4, palette
312
 
313
	mov	ebx, [image]
314
	mov	ecx, [ebx + Image.Width]
315
	shl	ecx, 16
316
	add	ecx, [ebx + Image.Height]
317
	__mov	edx, 5, 35
318
	mov	esi, 8
319
	cmp	[ebx + Image.Type], Image.bpp8
320
	jz	@f
321
	mov	esi, 24
322
	cmp	[ebx + Image.Type], Image.bpp24
323
	jz	@f
324
	mov	esi, 32
325
@@:
326
	mov	edi, [ebx + Image.Palette]
327
	mov	ebx, [ebx + Image.Data]
328
	xor	ebp, ebp
329
	mcall	65
330
 
331
	invoke	gfx.close, [ctx]
332
	ret
333
 
334
; void* __stdcall mem.Alloc(unsigned size);
335
mem.Alloc:
336
	push	ebx ecx
337
	mov	ecx, [esp+12]
338
	mcall	68, 12
339
	pop	ecx ebx
340
	ret	4
341
 
342
; void* __stdcall mem.ReAlloc(void* mptr, unsigned size);
343
mem.ReAlloc:
344
	push	ebx ecx edx
345
	mov	edx, [esp+16]
346
	mov	ecx, [esp+20]
347
	mcall	68, 20
348
	pop	edx ecx ebx
349
	ret	8
350
 
351
; void __stdcall mem.Free(void* mptr);
352
mem.Free:
353
	push	ebx ecx
354
	mov	ecx, [esp+12]
355
	mcall	68, 13
356
	pop	ecx ebx
357
	ret	4
358
 
359
;-----------------------------------------------------------------------------
360
 
361
s_header db 'Kolibri Image Viewer', 0
362
 
363
;-----------------------------------------------------------------------------
364
 
365
opendialog:
366
;
367
; STEP 1 Run SYSXTREE with parametrs MYPID 4 bytes in dec,
368
; 1 byte space, 1 byte type of dialog (O - Open ,S - Save)
369
;
370
 
371
;;    mov esi,path
372
    mov edi,path
373
    xor eax,eax
374
    mov ecx,(1024+16)/4
375
    rep stosd
376
 
377
;mov [get_loops],0
378
mov [dlg_pid_get],0
379
 
380
; Get my PID in dec format 4 bytes
381
    mov eax,9
382
    mov ebx,procinfo
383
    or  ecx,-1
384
    mcall
385
 
386
; convert eax bin to param dec
387
    mov eax,dword [procinfo+30]  ;offset of myPID
388
    mov edi,param+4-1		 ;offset to 4 bytes
389
    mov ecx,4
390
    mov ebx,10
391
new_d:
392
    xor edx,edx
393
    div ebx
394
    add dl,'0'
395
    mov [edi],dl
396
    dec edi
397
    loop new_d
398
 
399
; wirite 1 byte space to param
400
    mov [param+4],byte 32    ;Space for next parametr
401
; and 1 byte type of dialog to param
402
    mov [param+5],byte 'O'   ;Get Open dialog (Use 'S' for Save dialog)
403
 
404
;
405
; STEP2 prepare IPC area for get messages
406
;
407
 
408
; prepare IPC area
409
    mov [path],dword 0
410
    mov [path+4],dword 8
411
 
412
; define IPC memory
413
    mov eax,60
414
    mov ebx,1	     ; define IPC
415
    mov ecx,path     ; offset of area
416
    mov edx,1024+16  ; size
417
    mcall
418
 
419
; change wanted events list 7-bit IPC event
420
    mov eax,40
421
    mov ebx,01000111b
422
	cmp	[image], 0
423
	jnz	@f
424
	mov	bl, 01000110b
425
@@:
426
    mcall
427
 
428
;
429
; STEP 3 run SYSTEM XTREE with parameters
430
;
431
 
432
    mov eax,70
433
    mov ebx,run_fileinfo
434
    mcall
435
 
436
    mov [get_loops],0
437
getmesloop:
438
    mov eax,23
439
    mov ebx,50	   ;0.5 sec
440
    mcall
441
        dec     eax
442
        jz      mred
443
        dec     eax
444
        jz      mkey
445
        dec     eax
446
        jz      mbutton
447
        cmp     al, 7-3
448
        jz      mgetmes
449
 
450
; Get number of procces
451
    mov ebx,procinfo
452
    mov ecx,-1
453
    mov eax,9
454
    mcall
455
    mov ebp,eax
456
 
457
loox:
458
    mov eax,9
459
    mov ebx,procinfo
460
    mov ecx,ebp
461
    mcall
462
    mov eax,[DLGPID]
463
    cmp [procinfo+30],eax    ;IF Dialog find
464
    je	dlg_is_work	     ;jmp to dlg_is_work
465
    dec ebp
466
    jnz loox
467
 
468
    jmp erroff
469
 
470
dlg_is_work:
471
    cmp [procinfo+50],word 9 ;If slot state 9 - dialog is terminated
472
    je	erroff		       ;TESTODP2 terminated too
473
 
474
    cmp [dlg_pid_get],dword 1
475
    je	getmesloop
476
    inc [get_loops]
477
    cmp [get_loops],4  ;2 sec if DLG_PID not get, TESTOP2  terminated
478
    jae erroff
479
    jmp getmesloop
480
 
481
mred:
482
	cmp	[image], 0
483
	jz	getmesloop
484
    call draw_window
485
    jmp  getmesloop
486
mkey:
487
    mov  eax,2
488
    mcall			; read (eax=2)
489
    jmp  getmesloop
490
mbutton:
491
    mov  eax,17 		; get id
492
    mcall
493
    cmp  ah,1			; button id=1 ?
494
    jne  getmesloop
495
    mov  eax,-1 		; close this program
496
    mcall
497
mgetmes:
498
 
499
; If dlg_pid_get then second message get jmp to still
500
    cmp  [dlg_pid_get],dword 1
501
    je	 ready
502
 
503
; First message is number of PID SYSXTREE dialog
504
 
505
; convert PID dec to PID bin
506
    movzx eax,byte [path+16]
507
    sub eax,48
508
    imul eax,10
509
    movzx ebx,byte [path+16+1]
510
    add eax,ebx
511
    sub eax,48
512
    imul eax,10
513
    movzx ebx,byte [path+16+2]
514
    add eax,ebx
515
    sub eax,48
516
    imul eax,10
517
    movzx ebx,byte [path+16+3]
518
    add eax,ebx
519
    sub eax,48
520
    mov [DLGPID],eax
521
 
522
; Claear and prepare IPC area for next message
523
    mov [path],dword 0
524
    mov [path+4],dword 8
525
    mov [path+8],dword 0
526
    mov [path+12],dword 0
527
    mov [path+16],dword 0
528
 
529
; Set dlg_pid_get for get next message
530
    mov [dlg_pid_get],dword 1
531
	cmp	[image], 0
532
	jz	getmesloop
533
    call draw_window
534
    jmp  getmesloop
535
 
536
ready:
537
;
538
; The second message get
539
; Second message is 100 bytes path to SAVE/OPEN file
540
; shl path string on 16 bytes
541
;
542
    mov esi,path+16
543
    mov edi,path
544
    mov ecx,1024/4
545
    rep movsd
546
    mov [edi],byte 0
547
 
548
openoff:
549
	mcall	40, 7
550
	clc
551
	ret
552
 
553
erroff:
554
	mcall	40, 7
555
	stc
556
	ret
557
 
558
;-----------------------------------------------------------------------------
559
 
560
align 4
561
@IMPORT:
562
 
563
library 			\
564
	libio  , 'libio.obj'  , \
565
	libgfx , 'libgfx.obj' , \
566
	libimg , 'libimg.obj'
567
 
568
import	libio			  , \
569
	libio.init , 'lib_init'   , \
570
	file.size  , 'file.size'  , \
571
	file.open  , 'file.open'  , \
572
	file.read  , 'file.read'  , \
573
	file.close , 'file.close'
574
 
575
import	libgfx				, \
576
	libgfx.init   , 'lib_init'	, \
577
	gfx.open      , 'gfx.open'	, \
578
	gfx.close     , 'gfx.close'	, \
579
	gfx.pen.color , 'gfx.pen.color' , \
580
	gfx.line      , 'gfx.line'
581
 
582
import	libimg			   , \
583
	libimg.init , 'lib_init'   , \
584
	img.is_img  , 'img.is_img' , \
585
	img.to_rgb2 , 'img.to_rgb2', \
586
	img.decode  , 'img.decode' , \
587
	img.flip    , 'img.flip'   , \
588
	img.rotate  , 'img.rotate' , \
589
	img.destroy , 'img.destroy'
590
 
591
;-----------------------------------------------------------------------------
592
 
593
palette:
594
	dd	0x000000, 0x800000, 0x008000, 0x808000
595
	dd	0x000080, 0x800080, 0x008080, 0x808080
596
	dd	0xC0C0C0, 0xFF0000, 0x00FF00, 0xFFFF00
597
	dd	0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFF
598
 
599
macro loadbtn filename
600
{
601
repeat 20
602
file filename:76h+(%-1)*12,10
603
end repeat
604
repeat 10
605
y = % - 1
606
z = 20 - %
607
repeat 10
608
load a byte from $ - 20*10 + y*10 + (%-1)
609
load b byte from $ - 20*10 + z*10 + (%-1)
610
store byte a at $ - 20*10 + z*10 + (%-1)
611
store byte b at $ - 20*10 + y*10 + (%-1)
612
end repeat
613
end repeat
614
}
615
 
616
openbtn:
617
	loadbtn 'open.bmp'
618
fliphorzbtn:
619
	loadbtn 'fliphorz.bmp'
620
flipvertbtn:
621
	loadbtn 'flipvert.bmp'
622
rotcwbtn:
623
	loadbtn 'rotcw.bmp'
624
rotccwbtn:
625
	loadbtn 'rotccw.bmp'
626
rot180btn:
627
	loadbtn 'rot180.bmp'
628
 
629
; DATA AREA
630
get_loops   dd 0
631
dlg_pid_get dd 0
632
DLGPID	    dd 0
633
 
634
param:
635
   dd 0    ; My dec PID
636
   dd 0,0  ; Type of dialog
637
 
638
run_fileinfo:
639
 dd 7
640
 dd 0
641
 dd param
642
 dd 0
643
 dd 0
644
;run_filepath
645
 db '/sys/SYSXTREE',0
646
 
647
;-----------------------------------------------------------------------------
648
 
649
I_END:
650
 
651
img_data     dd ?
652
img_data_len dd ?
653
fh	     dd ?
654
image	     dd ?
655
wnd_width	dd	?
656
wnd_height	dd	?
657
 
658
ctx dd ?
659
 
660
procinfo:	rb	1024
661
path:		rb	1024+16
662
 
663
@PARAMS rb 512