Subversion Repositories Kolibri OS

Rev

Rev 135 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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