Oxygen Basic

Programming => Example Code => Topic started by: Peter on April 12, 2013, 06:50:05 AM

Title: Portable Pixel Map
Post by: Peter on April 12, 2013, 06:50:05 AM
Deleted
Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 07:11:07 AM

Hi Peter,

where is the ImageRect definition.
Title: Re: Portable Pixel Map
Post by: Peter on April 12, 2013, 08:43:59 AM
Sorry, I forgot the new sw.dll  ;D
Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 09:00:02 AM
thanks Peter,

but only i got a red screen.???????

BTW

 i am using RTL32
Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 09:23:33 AM

i think the same, but what could be?
Title: Re: Portable Pixel Map
Post by: JRS on April 12, 2013, 09:24:53 AM
Quote
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?

Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 09:43:12 AM

great Peter,

thank you ,

did you made the toy by yourself?
Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 10:03:44 AM
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
Code: [Select]
$ 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

Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 10:36:30 AM
Hi Peter,

Quote
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.
Title: Re: Portable Pixel Map
Post by: Emil_halim on April 12, 2013, 11:45:42 AM
Hi Peter ,

i have fixed it , here is a working example
Code: [Select]

$ 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