Subversion Repositories Kolibri OS

Rev

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