Subversion Repositories Kolibri OS

Rev

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