Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
31 halyavin 1
;    IMGVIEW.ASM
2
;
3
;    This program displays jpeg images. The window can be resized.
4
;
5
;    Version 0.0    END OF 2003
6
;                   Octavio Vega
7
;    Version 0.1    7th March 2004
8
;                   Mike Hibbett ( very small part! )
9
;    Version 0.11   7th April 2004
10
;                   Ville Turjanmaa ( 'set_as_bgr' function )
11
;    Version 0.12   29th May 2004
12
;                   Ivan Poddubny (correct "set_as_bgr"+parameters+boot+...)
13
;    Version 0.12   30 de mayo 2004
14
;                   Octavio Vega
15
;                   bugs correction and slideshow
16
;    version 0.13   3 de junio 2004
17
;                   Octavio Vega
18
;                   unos retoques
19
;    version 0.14   10th August 2004
20
;                   Mike Hibbett Added setting default colours
21
;
22
               memsize=20000h
23
               org 0
24
 PARAMS     =    memsize - 1024
25
 
26
use32
27
 
28
               db     'MENUET01'              ; 8 byte id
29
               dd     0x01                    ; header version
30
               dd     START                   ; start of code
31
               dd     I_END                   ; size of image
32
               dd     memsize                 ; memory for app
33
               dd     memsize - 1024           ; esp
34
               dd     PARAMS , 0x0               ; I_Param , I_Icon
35
 
36
include 'lang.inc'
37
stack_size=4096 + 1024
38
 
132 diamond 39
include 'macros.inc'
31 halyavin 40
 
41
START:                          ; start of execution
42
 
43
    cmp     [PARAMS], byte 0
44
    jne     check_parameters
45
 
46
    ; Calculate the 'free' memory available
47
    ; to the application, and create the malloc block from it
48
  .l1:
49
    mov     ecx,memsize-fin-stack_size
50
    mov     edi,fin
51
    call    add_mem
52
 
53
    ; Get some memory
54
    mov     ecx,16384
55
    call    malloc
56
    mov     [work_area],edi
57
    call    colorprecalc ;inicializa tablas usadas para pasar de ybr a bgr
58
    call    draw_window
59
    call    read_string.rs_done
60
 
61
still:
62
    push still
63
    mov ebx,100                ;1 second
64
    mov  eax,23                 ; wait here for event
65
    int  0x40
66
    cmp  eax,1                  ; redraw request ?
67
    je   draw_window
68
    cmp  eax,2                  ; key in buffer ?
69
    je   read_string
70
    cmp  eax,3                  ; button in buffer ?
71
    je   button
72
    jmp display_next
73
 
74
button:                       ; BUTTON
75
    mov  eax,17
76
    int  0x40
77
    cmp ah,3
78
    je set_as_bgr2
79
    cmp ah,2
80
    je slideshow
81
    cmp  ah,1                   ; CLOSE PROGRAM
82
    jne  close_program.exit
83
close_program:
84
    mov  eax,-1
85
    int  0x40
86
  .exit:
87
    ret
88
 
89
   ; Put a 'chunk' of the image on the window
90
put_image:
91
    pushad
92
 
93
    lea ebp,[edx+eax+7]
94
    cmp  [winxs],bp
95
    jc     .l1
96
    lea ebp,[ecx+ebx+20+2+17]
97
    cmp [winys],bp
98
    jc     .l1
99
 
100
    add     eax,5  ; offset for boarder
101
    add     ebx,20 ; offset for title bar
102
    push    ax ; pox
103
    push    bx ; pos
104
    push    cx ; size
105
    push    dx ; size
106
    pop     ecx
107
    pop     edx
108
    mov     ebx,edi
109
    mov     eax,7
110
 
111
    int     40h                         ; Put image function
112
.l1:
113
    popad
114
    ret
115
 
116
 
117
 
118
;******************************************************************************
119
 
120
check_parameters:
121
    cmp     [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
122
    je      boot_set_background
123
 
124
    mov     edi, name_string       ; clear string with file name
125
    mov     al,  0
126
    mov     ecx, 100
127
    rep     stosb
128
 
129
    mov     ecx, 100               ; calculate length of parameter string
130
    mov     edi, PARAMS
131
    repne   scasb
132
    sub     edi, PARAMS
133
    mov     ecx, edi
134
 
135
    mov     esi, PARAMS            ; copy parameters to file name
136
    mov     edi, name_string
137
    cld
138
    rep     movsb
139
 
140
    jmp     START.l1       ; return to beggining of the progra
141
 
142
;******************************************************************************
143
 
144
 
145
 
146
boot_set_background:
147
 
148
    mov     ecx,memsize-fin-stack_size  ; size
149
    mov     edi,fin                     ; pointer
150
    call    add_mem             ; mark memory from fin to 0x100000-1024 as free
151
    ; Get some memory
152
    mov     ecx,16384           ; get 16 Kb of memory
153
    call    malloc              ; returns pointer in edi
154
    mov     [work_area],edi     ; save it
155
    call    colorprecalc        ; calculate colors
156
    mov     esi,name_string
157
    call    open
158
    test    eax,eax
159
    jz      close_program
160
    call    jpeg_info
161
    mov dword [jpeg_st],ebp
162
    call    set_as_bgr2         ; set wallpaper
163
    jmp     close_program       ; close the program right now
164
 
165
;******************************************************************************
166
;******************************************************************************
167
 
168
set_as_bgr2:
169
    mov ebp,dword[jpeg_st]
170
    test    ebp,ebp
171
    jz      .end
172
 
173
    mov     dword [ebp+draw_ptr],put_chunk_to_bgr
174
    call    jpeg_display
175
    mov     eax, 15
176
    mov     ebx, 1
177
    mov     ecx, [ebp + x_size]
178
    mov     edx, [ebp + y_size]
179
    int     0x40
180
 
181
    ; Stretch the image to fit
182
    mov     eax, 15
183
    mov     ebx, 4
184
    mov     ecx, 2
185
    int     0x40
186
 
187
    mov     eax, 15
188
    mov     ebx, 3
189
    int     0x40
190
 
191
 
192
 .end:
193
    ret
194
 
195
;******************************************************************************
196
 
197
put_chunk_to_bgr:
198
    pushad
199
 
200
    mov     [x_pointer], edi
201
    mov     esi, ecx
202
    imul    esi, 3
203
    mov     [x_numofbytes], esi
204
    mov     ecx, [ebp + x_size]
205
    imul    ecx, ebx
206
    add     ecx, eax
207
    imul    ecx, 3
208
    mov     [x_offset], ecx
209
    mov     [x_counter], edx
210
    mov     eax, [ebp + x_size]
211
    imul    eax, 3
212
    mov     [x_numofb2], eax
213
 .new_string:
214
    mov     eax, 15
215
    mov     ebx, 5
216
    mov     ecx, [x_pointer]
217
    mov     edx, [x_offset]
218
    mov     esi, [x_numofbytes]
219
    int     0x40
220
    mov     eax, [x_numofbytes]
221
    add     [x_pointer], eax
222
    mov     eax, [x_numofb2]
223
    add     [x_offset], eax
224
    dec     [x_counter]
225
    jnz     .new_string
226
 
227
    popad
228
    ret
229
 
230
;******************************************************************************
231
 
232
 
233
 
234
;   *********************************************
235
;   *******  WINDOW DEFINITIONS AND DRAW ********
236
;   *********************************************
237
 
238
 
239
draw_window:
240
 
241
    mov  eax,12
242
    mov  ebx,1
243
    int  0x40
244
 
245
    ; Draw the window to the appropriate size - it may have
246
    ; been resized by the user
247
    mov     eax, 0
248
    cmp     [winxs], ax
249
    jne     dw_001
250
 
251
    ; Give the screen some inital defaults
252
    mov     ax, 400
253
    mov     [winxs], ax
254
    mov     ax, 300
255
    mov     [winys], ax
256
    mov     ax, 100
257
    mov     [winxo], ax
258
    mov     [winyo], ax
259
    jmp     dw_002
260
 
261
dw_001:
262
    mov     eax, 9
263
    mov ebx, memsize - 1024
264
    mov ecx, -1
265
    int     0x40
266
    mov     eax, [ebx + 34]
267
    mov     [winxo], ax
268
    mov     eax, [ebx + 38]
269
    mov     [winyo], ax
270
    mov     eax, [ebx + 42]
271
    mov     [winxs], ax
272
    mov     eax, [ebx + 46]
273
    mov     [winys], ax
274
 
275
dw_002:
276
    mov     bx, [winxo]
277
    shl     ebx, 16
278
    mov     bx, [winxs]
279
 
280
    mov     cx, [winyo]
281
    shl     ecx, 16
282
    mov     cx, [winys]
283
 
284
 
285
    mov  eax,0                     ; DRAW WINDOW
286
    mov  edx,[wcolor]
287
    add  edx,0x02000000
288
    mov  esi,0x80557799
289
    mov  edi,0x00557799
290
    int  0x40
291
 
292
    mov  eax,4                     ; WINDOW LABEL
293
    mov  ebx,8*65536+8
294
    mov  ecx,0x00ffffff
295
    mov  edx,labelt
296
    mov  esi,labellen-labelt
297
    int  0x40
298
 
299
 
300
    mov  eax,8                     ; CLOSE BUTTON
301
 
302
    mov  bx, [winxs]
303
    sub  bx, 19
304
    shl  ebx, 16
305
    add  ebx, 12
306
 
307
    mov  ecx,5*65536+12
308
    mov  edx,1
309
    mov  esi,0x557799
310
    int  0x40
311
 
312
    ; draw status bar
313
    mov     eax, 13
314
    movzx     ebx, word [winxs]
315
    sub     ebx, 5
316
    add     ebx, 4*65536
317
    mov     cx, [winys]
318
    sub     ecx, 19
319
    shl     ecx, 16
320
    add     ecx, 3
321
    mov     edx, 0x00557799
322
    int     0x40
323
 
324
    mov  eax,8                     ; BUTTON 2: filename
325
    mov  ebx,4*65536+55
326
    mov  cx, [winys]
327
    sub  cx, 16
328
    shl  ecx, 16
329
    add  ecx, 12
330
    mov  esi, 0x00557799
331
    mov  edx,2
332
    int  0x40
333
 
334
    mov  eax,4                     ; Button text
335
    movzx ebx, word [winys]
336
    sub   ebx, 13
337
    add   ebx, 6*65536
338
    mov  ecx,0x00ffffff
339
    mov  edx,setname
340
    mov  esi,setnamelen-setname
341
    int  0x40
342
 
343
 
344
    mov  eax,8                     ; BUTTON 3: set as background
345
    mov  bx, [winxs]
346
    sub  bx, 60
347
    shl  ebx, 16
348
    mov  bx,55
349
    mov  cx, [winys]
350
    sub  cx, 16
351
    shl  ecx, 16
352
    add  ecx, 12
353
    mov  esi, 0x00557799
354
    mov  edx,3
355
    int  0x40
356
 
357
    mov  eax,4                     ; Button text
358
    movzx ebx, word [winxs]
359
    sub   ebx, 60
360
    shl   ebx,16
361
    mov   bx, word [winys]
362
    sub   bx,13
363
    mov  ecx,0x00ffffff
364
    mov  edx,setbgr
365
    mov  esi,setbgrlen-setbgr
366
    int  0x40
367
    call    print_strings
368
    call    load_image
369
    mov     eax,12                    ; function 12:tell os about windowdraw
370
    mov     ebx,2                     ; 2, end of draw
371
    int     0x40
372
 
373
    ret
374
 
375
 
376
 
377
    ; Read in the image file name.
378
read_string:
379
    movzx edi,byte[name_string.cursor]
380
    add     edi,name_string
381
    mov     eax,2
382
    int     0x40                        ; Get the key value
383
    shr     eax,8
384
    cmp     eax,13                      ; Return key ends input
385
    je      .rs_done
386
    cmp     eax,8
387
    jnz     .nobsl
388
    cmp     edi,name_string
389
    je      .exit
390
    dec     edi
391
    mov     [edi],byte 0;'_'
392
    dec     byte[name_string.cursor]
393
    jmp     print_strings
394
.exit:   ret
395
.nobsl:
396
    cmp     eax,31
397
    jbe     .exit
398
    cmp     eax,97
399
    jb      .keyok
400
    sub     eax,32
401
.keyok:
402
    mov ah,0
403
    stosw
404
    cmp edi,name_string.end
405
    jnc print_strings
406
    inc byte[name_string.cursor]
407
    jmp    print_strings
408
.rs_done:
409
    call   print_strings
410
    mov     esi,name_string
411
    call    open
412
    test    eax,eax
413
    jz      .exit
414
    call    jpeg_info
415
    test    ebp,ebp
416
    jz      close
417
    xchg    [jpeg_st],ebp
418
    call jpeg_close
419
 
420
load_image:
421
 
422
    mov     eax,13              ; clear picture area
423
    movzx    ebx, word [winxs]
424
    sub     ebx, 7
425
    add     ebx, 4 * 65536
426
    movzx    ecx, word [winys]
427
    sub     ecx, 39
428
    add     ecx, 20 * 65536
429
 
430
    mov     edx,0
431
    int     0x40
432
    mov    ebp,[jpeg_st]
433
    test    ebp,ebp
434
    jz      .exit
435
    mov     dword [ebp+draw_ptr],put_image
436
    jmp    jpeg_display
437
 .exit: ret
438
 
439
print_strings:
440
    pusha
441
    mov     eax,13              ; clear text area
442
    movzx   ebx, word [winxs]
443
    sub     ebx, 64+58
444
    add     ebx, 60*65536
445
    mov     cx, [winys]
446
    sub     cx, 16
447
    shl     ecx, 16
448
    add     ecx, 12
449
    mov     edx,0xffffff
450
    int     0x40
451
 
452
    mov     eax,4               ;
453
    movzx   ebx, word [winys]
454
    sub     ebx, 14
455
    add     ebx, 60*65536
456
    mov     ecx,0x000000
457
    mov     edx,name_string
458
    mov     esi,60
459
    int     0x40
460
    popa
461
    ret
462
 
463
slideshow:
464
    test dword[file_dir],-1
465
    jnz .exit
466
    test dword[jpeg_st],-1
467
    jz .exit
468
    mov esi,name_string
469
    movzx ecx,byte[name_string.cursor]
470
   .l1:
471
    cmp byte[esi+ecx],'/'
472
    je .l2
473
    loop .l1
474
  .exit:
475
    ret
476
  .l2:
477
    mov byte[esi+ecx],0
478
    call open
479
    mov byte[esi+ecx],'/'
480
    test eax,eax
481
    jz .exit
482
 
483
    mov dword[eax+file_handler.size],-1 ;directory size is always 0
484
    mov [file_dir],eax
485
    inc cl
486
    mov [name_string.cursor],cl
487
 
488
display_next:
489
    mov eax,[file_dir]
490
    test eax,eax
491
    jnz .l1
492
    ret
493
   .l1:
494
    mov ecx,32
495
    sub esp,ecx
496
    mov edi,esp
497
    call read
498
    cmp ecx,32
499
    jnc .l11
500
   .l10:
501
    add esp,32
502
    mov eax,dword[file_dir]
503
    mov dword[file_dir],0
504
    jmp close
505
   .l11:
506
    mov esi,esp
507
    movzx edi,byte[name_string.cursor]
508
    add edi,name_string
509
    lodsb
510
    cmp al,0
511
    je .l10
512
    cmp al,229
513
    jne .l0
514
    add esp,32
515
    jmp display_next
516
   .l0:
517
    stosb
518
    mov cl,7
519
   .l2:
520
    lodsb
521
    cmp al,32
522
    jna .l3
523
    stosb
524
    loop .l2
525
   .l3:
526
    lea esi,[esp+8]
527
    mov al,'.'
528
    stosb
529
    mov cl,3
530
   .l4:
531
    lodsb
532
    cmp al,32
533
    jna .l5
534
    stosb
535
    loop .l4
536
   .l5:
537
    mov al,0
538
    stosb
539
    cmp edi,name_string.end
540
    jc .l5
541
    add esp,32
542
    call   print_strings
543
    mov     esi,name_string
544
    call    open
545
    test    eax,eax
546
    jz      display_next
547
    call    jpeg_info
548
    test    ebp,ebp
549
    jnz     .l6
550
    call close
551
    jmp display_next
552
   .l6:
553
    mov dword[ebp+draw_ptr],put_image
554
    push ebp
555
    xchg [jpeg_st],ebp
556
    call jpeg_close
557
    pop ebp
558
    jmp jpeg_display
559
 
560
 
561
 
562
include 'filelib.asm'
563
include 'memlib.asm'
564
include 'jpeglib.asm'
565
 
566
 
567
; DATA AREA
568
 
569
wcolor          dd  0x000000
570
labelt          db  'Jpegview v0.14'
571
labellen:
572
setname          db  'SLIDESHOW'
573
setnamelen:
574
 
575
setbgr           db  '   BGR  '
576
setbgrlen:
577
 
578
x_pointer       dd  0
579
x_offset        dd  0
580
x_numofbytes    dd  0
581
x_numofb2       dd  0
582
x_counter       dd  0
583
winxo:          dw  0
584
winyo:          dw  0
585
winxs:          dw  0
586
winys:          dw  0
587
jpeg_st:        dd  0
588
file_dir:       dd  0
589
work_area:      dd  0
590
tcolor          dd  0x000000
591
btcolor         dd  0x224466+0x808080
592
name_string:    db '/rd/1/jpegview.jpg',0
593
 
594
rb 100
595
    .end:
596
    .cursor: db 19
597
    .cursor2: db 0
598
 
599
align 4
600
 
601
rgb16:          db 0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63
602
rgb4:           db 0,21,42,63
603
 
604
include 'jpegdat.asm'
605
 
606
align 4
607
 
608
iniciomemoria:
609
              dd -(iniciomemoria+4),-(iniciomemoria+4),(iniciomemoria+4),.l1,0
610
.l1           dd 0
611
 
612
fin:
613
I_END:
614