User avatar
Grumpy Mike
Posts: 909
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Displaying JPEGs

Thu May 22, 2014 9:40 am

Does anyone know how you can display a JPEG image from a BASIC program. The methods I used years ago seem not to work anymore.
Thanks

User avatar
Burngate
Posts: 5930
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Displaying JPEGs

Fri May 23, 2014 10:40 am

I saw your post yesterday afternoon, and ever since I've been cogitating.
And I've come to the conclusion that I don't know the answer - in part because I'm unclear (a) what you're trying to do and (b) what you did that used to work but now doesn't

Are you wanting to display it as a backdrop, or in your own window, or separately in its own window?

Just double-clicking on a JPEG opens it in !SwiftJPEG, so perhaps BASIC could call that, or !ChangeFSI.
On the other hand, that seems too easy so you want to do something other than opening a window with it in.

User avatar
Grumpy Mike
Posts: 909
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Displaying JPEGs

Fri May 23, 2014 3:09 pm

Thanks for the reply.
in part because I'm unclear (a) what you're trying to do
I am trying to read a jpeg file in a basic program and draw it on the screen in a specific position.
what you did that used to work but now doesn't
A whole heap of sprite_op calls that now totally crash RISC OS and require a hardware reset.
Are you wanting to display it as a backdrop, or in your own window, or separately in its own window?
I want to write it to the screen not in a window, in other words directly access the window. This the Raspberry port is happy to do for normal graphics operations.
Just double-clicking on a JPEG opens it in !SwiftJPEG,
Yes I can do that.
so perhaps BASIC could call that, or !ChangeFSI.
No because it would not put it where I want on the screen.

User avatar
GavinW
Posts: 89
Joined: Tue Nov 01, 2011 8:11 pm
Location: UK
Contact: Website

Re: Displaying JPEGs

Sun May 25, 2014 9:10 pm

It sounds to me that you need to use:

SYS "JPEG_PlotFileScaled", filenamebuffer%, x%, y%, scale%, flag%

See PRM5a page 152, and nearby pages for variations on this theme.
Last edited by GavinW on Sun May 25, 2014 10:20 pm, edited 3 times in total.
otium negare negotium vanum

User avatar
Grumpy Mike
Posts: 909
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Displaying JPEGs

Sun May 25, 2014 9:11 pm

Thanks I will take a look.

User avatar
GavinW
Posts: 89
Joined: Tue Nov 01, 2011 8:11 pm
Location: UK
Contact: Website

Re: Displaying JPEGs

Sun May 25, 2014 10:09 pm

I just checked that this function plots the jpeg in the file with pathname given by its argument at half size at the point one quarter the screenwidth and one quarter the screenheight. It is in RiscLua but transcription to Basic is straightforward.

Code: Select all

plot = \ (jpegfile)
local dim, sys, ! in riscos
local X, Y -- screensize
do ----------- screen variables -----------[
 local scrvar = \ (n)
   local r0, r1, r2 = sys (0x35, -1, n) -- OS_ReadModeVariable
   => r2 end -- function
  X, Y = scrvar (11) << scrvar (4), scrvar (12) << scrvar (5)
end --------------------------------------------]
local scale
do ---------------------------------------------[
 scale = dim (16)
 ![scale] = 1; ![scale + 4] = 1; ![scale + 8] = 2; ![scale + 12] = 2 -- halve
end -------------------------------------------]
sys ("JPEG_PlotFileScaled", jpegfile .. "\0", X/4, Y/4, scale, 0)
end -- function
otium negare negotium vanum

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: Displaying JPEGs

Sun Jun 08, 2014 5:22 pm

I have done what you want to do in ASM, it should be easy to convert

Code: Select all

; -----------------------------------------------------  ;
; RISC OS JPEG example by Craig Bamford                  ;
; -----------------------------------------------------  ;
format binary as ''                                      ;  format COFF
include 'FasmArmMacros\FasmArm.inc'                      ;
include 'R_PI_Address\R_PI_Address.inc'                  ;
include 'RiscOSLIB\Swi.inc'                              ;
include 'Header\Header.inc'                              ;
;======================================================= ;
; start                                                  ;
;======================================================= ;
start:                                                   ;
        IMM32 r0,message                                 ;
        swi   OS_Write0                                  ;
        swi   OS_NewLine                                 ;
        swi   OS_RemoveCursors                           ;
        IMM32 r13,StackBuffer                            ;
        swi   OS_ReadC                                   ;
;======================================================= ;
; decode jpeg                                            ;
;======================================================= ;
        IMM32 r0,MyBmpImage                              ;
        mov   r1,0                                       ; x from bottom left hand corner
        IMM16 r2,1080                                    ; y from bottom left hand corner
        mov   r3,0                                       ;
        IMM32 r4,message-MyBmpImage                      ;
        mov   r5,0                                       ;
        swi   JPEG_PlotScaled                            ;
;======================================================= ;
; Exit                                                   ;
;======================================================= ;
        mov   r0,0                                       ;
        swi   OS_Exit                                    ;
;======================================================= ;
; Graphics  include                                      ;
;======================================================= ;

;======================================================= ;
; Image                                                  ;
;======================================================= ;
align 4                                                  ;
MyBmpImage:                                              ;
file 'Images\Bg.jpg'                                     ;
align 4                                                  ;
;======================================================= ;
; String                                                 ;
;======================================================= ;
message:                                                 ;
db "Press anykey to load jpeg file and anykey to exit",0 ;
align 4                                                  ;
;======================================================= ;
; Data                                                   ;
;======================================================= ;
rb   0x1000                                              ;
StackBuffer:  dw   0                                     ;
filend:                                                                                   
Let me know if you want the full code.
Dex.
Batteries not included, Some assembly required.

Return to “RISCOS”