Subversion Repositories Kolibri OS

Rev

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