Subversion Repositories Kolibri OS

Rev

Rev 180 | 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,2  ; offset for boarder
  102.     add     ebx,2 ; 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,48
  239.     mov  ebx,3
  240.     mov  ecx,sc
  241.     mov  edx,sizeof.system_colors
  242.     int  0x40
  243.  
  244.     mov  eax,12
  245.     mov  ebx,1
  246.     int  0x40
  247.  
  248.     ; Draw the window to the appropriate size - it may have
  249.     ; been resized by the user
  250.     cmp     [winxs], 0
  251.     jne     dw_001
  252.  
  253.     ; Give the screen some inital defaults
  254.     mov     [winxs], 400
  255.     mov     [winys], 300
  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     ebx, dword [winxo-2]
  277.         mov     bx, [winxs]
  278.         mov     ecx, dword [winyo-2]
  279.         mov     cx, [winys]
  280.  
  281.     xor  eax,eax                   ; DRAW WINDOW
  282.     mov  edx,[sc.work]
  283.     or   edx,0x33000000
  284.     mov  edi,header                ; WINDOW LABEL
  285.     int  0x40
  286.  
  287.  
  288.     mov  eax,8                     ; BUTTON 2: slideshow
  289.     mov  ebx,57
  290.     mov  cx, [winys]
  291.     sub  cx, 39
  292.     shl  ecx, 16
  293.     add  ecx, 12
  294.     mov  esi, [sc.work_button]
  295.     mov  edx,2
  296.     int  0x40
  297.  
  298.     mov  eax,4                     ; Button text
  299.     movzx ebx, word [winys]
  300.     add   ebx, 3 shl 16 - 36
  301.     mov  ecx,[sc.work_button_text]
  302.     mov  edx,setname
  303.     mov  esi,setnamelen-setname
  304.     int  0x40
  305.  
  306.  
  307.     mov  eax,8                     ; BUTTON 3: set as background
  308.     mov  bx, [winxs]
  309.     sub  bx, 65
  310.     shl  ebx, 16
  311.     mov  bx,55
  312.     mov  cx, [winys]
  313.     sub  cx, 39
  314.     shl  ecx, 16
  315.     add  ecx, 12
  316.     mov  esi, [sc.work_button]
  317.     mov  edx,3
  318.     int  0x40
  319.  
  320.     mov  eax,4                     ; Button text
  321.     movzx ebx, word [winxs]
  322.     sub   ebx, 63
  323.     shl   ebx,16
  324.     mov   bx, word [winys]
  325.     sub   bx,36
  326.     mov  ecx,[sc.work_button_text]
  327.     mov  edx,setbgr
  328.     mov  esi,setbgrlen-setbgr
  329.     int  0x40
  330.     call    print_strings
  331.     call    load_image
  332.     mov     eax,12                    ; function 12:tell os about windowdraw
  333.     mov     ebx,2                     ; 2, end of draw
  334.     int     0x40
  335.  
  336.     ret
  337.  
  338.  
  339.  
  340.     ; Read in the image file name.
  341. read_string:
  342.     movzx edi,byte[name_string.cursor]
  343.     add     edi,name_string
  344.     mov     eax,2
  345.     int     0x40                        ; Get the key value
  346.     shr     eax,8
  347.     cmp     eax,13                      ; Return key ends input
  348.     je      .rs_done
  349.     cmp     eax,8
  350.     jnz     .nobsl
  351.     cmp     edi,name_string
  352.     je      .exit
  353.     dec     edi
  354.     mov     [edi],byte 0;'_'
  355.     dec     byte[name_string.cursor]
  356.     jmp     print_strings
  357. .exit:   ret
  358. .nobsl:
  359.     cmp     eax,31
  360.     jbe     .exit
  361.     cmp     eax,97
  362.     jb      .keyok
  363.     sub     eax,32
  364. .keyok:
  365.     mov ah,0
  366.     stosw
  367.     cmp edi,name_string.end
  368.     jnc print_strings
  369.     inc byte[name_string.cursor]
  370.     jmp    print_strings
  371. .rs_done:
  372.     call   print_strings
  373.     mov     esi,name_string
  374.     call    open
  375.     test    eax,eax
  376.     jz      .exit
  377.     call    jpeg_info
  378.     test    ebp,ebp
  379.     jz      close
  380.     xchg    [jpeg_st],ebp
  381.     call jpeg_close
  382.  
  383. load_image:
  384.  
  385.     mov     eax,13              ; clear picture area
  386.     movzx    ebx, word [winxs]
  387.     add     ebx, 1  shl 16 -10
  388.     movzx    ecx, word [winys]
  389.     sub     ecx, 40
  390.     add     ecx, 1  shl 16
  391.  
  392.     mov     edx,[sc.work]
  393.     int     0x40
  394.     mov    ebp,[jpeg_st]
  395.     test    ebp,ebp
  396.     jz      .exit
  397.     mov     dword [ebp+draw_ptr],put_image
  398.     jmp    jpeg_display
  399.  .exit: ret
  400.  
  401. print_strings:
  402.     pusha
  403.     mov     eax,13              ; clear text area
  404.     movzx   ebx, word [winxs]
  405.     add     ebx, 59 shl 16 -125
  406.     mov     cx, [winys]
  407.     sub     cx, 39
  408.     shl     ecx, 16
  409.     add     ecx, 12
  410.     mov     edx,0xffffff
  411.     int     0x40
  412.  
  413.     mov     eax,4               ;
  414.     movzx   ebx, word [winys]
  415.     add     ebx, 61 shl 16 - 37
  416.     mov     ecx,0x000000
  417.     mov     edx,name_string
  418.     mov     esi,60
  419.     int     0x40
  420.     popa
  421.     ret
  422.  
  423. slideshow:
  424.         cmp     [file_dir], 0
  425.         jnz     .exit
  426.         cmp     [jpeg_st], 0
  427.         jz      .exit
  428.         mov     esi, name_string
  429.         movzx   ecx, byte [name_string.cursor]
  430. .l1:
  431.         cmp     byte [esi+ecx], '/'
  432.         jz      .l2
  433.         loop    .l1
  434. .exit:
  435.         ret
  436. .l2:
  437.         mov     byte [esi+ecx], 0
  438.         call    open
  439.         mov     byte [esi+ecx], '/'
  440.         test    eax, eax
  441.         jz      .exit
  442.         test    byte [fileattr], 0x10
  443.         jz      .exit
  444.         mov     [file_dir], eax
  445.         inc     ecx
  446.         mov     [name_string.cursor], cl
  447. display_next:
  448.         mov     ebx, [file_dir]
  449.         test    ebx, ebx
  450.         jnz     @f
  451.         ret
  452. @@:
  453.         mov     byte [ebx], 1
  454.         mov     byte [ebx+12], 1
  455.         mov     dword [ebx+16], dirinfo
  456.         mov     eax, 70
  457.         int     0x40
  458.         mov     eax, [file_dir]
  459.         inc     dword [eax+4]
  460.         cmp     ebx, 1
  461.         jz      @f
  462.         mov     eax, [file_dir]
  463.         and     [file_dir], 0
  464.         jmp     close
  465. @@:
  466.         movzx   edi, byte [name_string.cursor]
  467.         add     edi, name_string
  468.         lea     esi, [dirinfo+32+40]
  469. @@:
  470.         lodsb
  471.         stosb
  472.         test    al, al
  473.         jnz     @b
  474.         mov     ecx, name_string.end
  475.         sub     ecx, edi
  476.         rep     stosb
  477.     call   print_strings
  478.     mov     esi,name_string
  479.     call    open
  480.     test    eax,eax
  481.     jz      display_next
  482.     call    jpeg_info
  483.     test    ebp,ebp
  484.     jnz     .l6
  485.     call close
  486.     jmp display_next
  487.    .l6:
  488.     mov dword[ebp+draw_ptr],put_image
  489.     push ebp
  490.     xchg [jpeg_st],ebp
  491.     call jpeg_close
  492.     pop ebp
  493.     jmp jpeg_display
  494.  
  495.  
  496. include 'filelib.asm'
  497. include 'memlib.asm'
  498. include 'jpeglib.asm'
  499.  
  500.  
  501. ; DATA AREA
  502.  
  503. wcolor          dd  0x000000
  504. header          db  appname,version,0
  505. setname          db  'SLIDESHOW'
  506. setnamelen:
  507.  
  508. setbgr           db  '   BGR  '
  509. setbgrlen:
  510.  
  511. x_pointer       dd  0
  512. x_offset        dd  0
  513. x_numofbytes    dd  0
  514. x_numofb2       dd  0
  515. x_counter       dd  0
  516. winxo           dw  0
  517. winyo           dw  0
  518. winxs           dw  0
  519. winys           dw  0
  520. jpeg_st         dd  0
  521. file_dir        dd  0
  522. name_string:    db '/rd/1/jpegview.jpg',0
  523. rb 256
  524.     .end:
  525.     .cursor: db 19
  526.     .cursor2: db 0
  527.  
  528. align 4
  529.  
  530. rgb16:          db 0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63
  531. rgb4:           db 0,21,42,63
  532.  
  533. include 'jpegdat.asm'
  534.  
  535. align 4
  536.  
  537. iniciomemoria:
  538.               dd -(iniciomemoria+4),-(iniciomemoria+4),(iniciomemoria+4),.l1,0
  539. .l1           dd 0
  540.  
  541. fin:
  542. I_END:
  543. sc     system_colors
  544. fileattr: rb 40
  545. dirinfo: rb 32+304
  546.