Oxygen Basic
Programming => Example Code => Topic started by: Peter on April 12, 2013, 06:50:05 AM
-
Deleted
-
Hi Peter,
where is the ImageRect definition.
-
Sorry, I forgot the new sw.dll ;D
-
thanks Peter,
but only i got a red screen.???????
BTW
i am using RTL32
-
i think the same, but what could be?
-
Sorry, I forgot the new sw.dll
Thanks for the Simple Window library update!
What is new, changed and will my existing Peter ports to SB continue to work with this new DLL?
-
great Peter,
thank you ,
did you made the toy by yourself?
-
Ok Peter,
i have made some changes to your LoadPPm to allow it to load the img from memory by using embedfile
but the program crash
here it is
$ filename "PPM_Img_Ex.exe"
#include "..\..\inc\RTL32.inc"
include "sw.inc"
indexbase 0
Window 640,480,1
sys ppmHandle[128]
sys ppmWidth [128]
sys ppmHeight[128]
Function LoadFromMemPPM(sys MemPtr) as sys
sys h,j=3,co,string sW,sH
byte ppm[16] at MemPtr
static sys id
if id <128 then inc id
if ppm[0]=0x50 and ppm[1]=0x36
while ppm[j] <> 0x20
sW += Chr ppm[j]
j +=1
wend
while ppm[j] <> 0x0A
sH += Chr ppm[j]
j +=1
wend
ppmWidth [id] = Val(sW)
ppmHeight[id] = Val(sH)
j +=1
while ppm[j] <> 0x0A
j +=1
wend
j +=1
co = ppmWidth[id]*ppmHeight[id]*3
sys mem at (MemPtr+j)
ppmHandle[id] = mem
img=NewImage ppmWidth[id],ppmHeight[id]
for y=0 to ppmHeight[id]-1
for x=0 to ppmWidth[id]-1
z=(y*ppmWidth[id]+x)*3
r=Peek mem,z+0
g=Peek mem,z+1
b=Peek mem,z+2
SetImagePixel img,x,y,RGB(r,g,b)
next
next
Endif
Return img
End Function
sys p
embedfile "toy.ppm",p
p1 = LoadFromMemPPM p
p2 = LoadBmp "stern32.bmp",32
sys z
single v
while Key(27)=0
cls 255
ImageRect p1,300,100,256,256,0,0
ImageRect p1,0,0,256,256,0,0
DrawBmp p2,50,350,100,100,z
DrawBmp p2,150,350,100,100,z
DrawBmp p2,250,350,100,100,z
DrawBmp p2,350,350,100,100,z
DrawBmp p2,450,350,100,100,z
v +=.2
if v >=1
v=0
z +=1
if z=32 then z=0
endif
Sync
wend
Quit
-
Hi Peter,
MemPtr must be pointer!
actually any pointer is just a 32bit positive value that hold the pointer to a certain location in memory.
so i can hold the pointer value in sys variable.
even , i change Sys MemPtr to Sys* MemPtr or byte* MemPtr and still crash.
-
Hi Peter ,
i have fixed it , here is a working example
$ filename "PPM_Img_Ex.exe"
#include "..\..\inc\RTL32.inc"
include "sw.inc"
indexbase 0
Window 640,480,1
sys ppmHandle[128]
sys ppmWidth [128]
sys ppmHeight[128]
Function LoadFromMemPPM(sys MemPtr) as sys
sys h,j=3,co,mem,string sW,sH
byte ppm[16] at MemPtr
static sys id
if id <128 then inc id
if ppm[0]=0x50 and ppm[1]=0x36
while ppm[j] <> 0x20
sW += Chr ppm[j]
j +=1
wend
while ppm[j] <> 0x0A
sH += Chr ppm[j]
j +=1
wend
ppmWidth [id] = Val(sW)
ppmHeight[id] = Val(sH)
j +=1
while ppm[j] <> 0x0A
j +=1
wend
j +=1
mem = MemPtr+j
img=NewImage ppmWidth[id],ppmHeight[id]
for y=0 to ppmHeight[id]-1
for x=0 to ppmWidth[id]-1
z=(y*ppmWidth[id]+x)*3
r=Peek mem,z+0
g=Peek mem,z+1
b=Peek mem,z+2
SetImagePixel img,x,y,RGB(r,g,b)
next
next
Endif
Return img
End Function
sys p
embedfile "toy.ppm",p
p1 = LoadFromMemPPM p
p2 = LoadBmp "stern32.bmp",32
sys z
single v
while Key(27)=0
cls 255
ImageRect p1,300,100,256,256,0,0
ImageRect p1,0,0,256,256,0,0
DrawBmp p2,50,350,100,100,z
DrawBmp p2,150,350,100,100,z
DrawBmp p2,250,350,100,100,z
DrawBmp p2,350,350,100,100,z
DrawBmp p2,450,350,100,100,z
v +=.2
if v >=1
v=0
z +=1
if z=32 then z=0
endif
Sync
wend
Quit