Author Topic: software library  (Read 2495 times)

0 Members and 1 Guest are viewing this topic.

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
software library
« on: April 23, 2007 »
Hi all

Here is my first attempt to make my software library , it looks like My OgerMagic Library , it has not optimized yet.

If you have any idea ,let me know , and feel free to modify it or add any function that you want.

Here is the code

Code: [Select]
'============================================================
'
'   SoftWare ImageProcessing Library
'            By Emil Halim
'              23/4/2007
'
'============================================================

        OPTION STATIC
        OPTION EXPLICIT

        #DEFINE PTC_WIN
        #INCLUDE "TINYPTC.BI"
        #INCLUDE "windows.BI"
        
        CONST   XRES = 640  'WIDTH
        CONST   YRES = 480  'HEIGHT
        DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )  
        
        
        type IMAGE
             Ibuf    as UINTEGER ptr
             IbufLen as UINTEGER
             Iwidth  as UINTEGER
             Iheight as UINTEGER
        end type  
        
        declare Function LoadBMPImage(file as string) as IMAGE ptr  
        declare sub SetColorKey(img as IMAGE ptr,clr as uinteger)
        declare sub DrawSolidImage( img as IMAGE ptr,x as integer, y as integer)
        declare sub DrawTransparentImage( img as IMAGE ptr,x as integer, y as integer)
        ''To Do Functions List
        declare sub DrawAlphaImage( img as IMAGE ptr,x as integer, y as integer,a as Dword)  
          
  
        If( PTC_OPEN( "SoftWare Library By Emil Halim", XRES, YRES ) = 0 ) Then
        End -1
        End If
        
        dim as IMAGE ptr Image_1,Image_2
        
        Image_1 =  LoadBMPImage("planet.bmp")
        Image_2 =  LoadBMPImage("crashtitle.bmp")
        
        
        while(1)
          
            DrawSolidImage(Image_2,0,240)
          ' DrawAlphaImage(Image_1,0,0,1.0)
            PTC_UPDATE @BUFFER(0)
              
        wend
        
        
    Function LoadBMPImage(file as string) as IMAGE ptr
           dim pic AS HBITMAP , iDC as HDC
               dim bm  as BITMAP
               dim bi24BitInfo As BITMAPINFO
               dim buf as uInteger ptr
    
               pic =  LoadImage(0,file,IMAGE_BITMAP,0,0,LR_LOADFROMFILE or LR_CREATEDIBSECTION)
               GetObject(pic, SIZEOF(BITMAP), @bm)
      
               With  bi24BitInfo.bmiHeader
                    .biBitCount = 32
                    .biCompression = BI_RGB
                    .biPlanes = 1
                    .biSize = SIZEOF(BITMAPINFO)
                    .biWidth = bm.bmWidth
                    .biHeight = bm.bmHeight
               End With
              
               buf = allocate(bm.bmWidth*bm.bmHeight*4)    
               iDC = CreateCompatibleDC(0)
               SelectObject(iDC, pic)
               GetDIBits(iDC, pic, 0, bm.bmHeight, buf, @bi24BitInfo, DIB_RGB_COLORS)
               DeleteObject(pic)
               DeleteDC(iDC)
              
               dim as IMAGE ptr img = allocate(Len(IMAGE))
               img->Iwidth  = bm.bmWidth
               img->Iheight = bm.bmHeight  
               img->Ibuf    = allocate(bm.bmWidth*bm.bmHeight*4)    
               img->IbufLen = bm.bmWidth*bm.bmHeight*4
              
              
               dim as integer x,y
               for x = 0 to bm.bmWidth-1
                for y = 0 to  bm.bmHeight -1
                    img->Ibuf[x+y*bm.bmWidth]=buf[x+(bm.bmHeight-y-1)*bm.bmWidth]    
                next
               next      
               Deallocate(buf)      
         return img
        end function
        
        sub SetColorKey(img as IMAGE ptr,clr as uinteger)
               dim as integer x,y
               for x = 0 to img->Iwidth-1
                for y = 0 to  img->Iheight-1
                    dim as uinteger ndx
                    ndx = x+y*img->Iwidth
                    if(img->Ibuf[ndx]=clr) then  img->Ibuf[ndx] = 0  
                next
               next    
        end sub
        sub DrawSolidImage( img as IMAGE ptr,x as integer, y as integer)
              dim as integer xx,yy
              dim as integer sx,sy,sw,sh
              if(x<0)then sx = img->Iwidth+x else sx = 0
              if(y<0)then sy = img->Iheight+y else sy = 0
              if(x+img->Iwidth > XRES) then sw = XRES - x else sw = img->Iwidth-1
              if(y+img->Iheight > YRES) then sh = YRES - y else sh = img->Iheight-1
              for yy=sy to sh
                dim as integer ds = x+(y+yy)*XRES
                dim as integer sr = yy*img->Iwidth
                for xx=sx to sw
                     BUFFER(xx+ds) =  img->Ibuf[xx+sr]
                next
              next  
        end sub
        sub DrawTransparentImage( img as IMAGE ptr,x as integer, y as integer)
              dim as integer xx,yy
              dim as integer sx,sy,sw,sh
              if(x<0)then sx = img->Iwidth+x else sx = 0
              if(y<0)then sy = img->Iheight+y else sy = 0
              if(x+img->Iwidth > XRES) then sw = XRES - x else sw = img->Iwidth-1
              if(y+img->Iheight > YRES) then sh = YRES - y else sh = img->Iheight-1
              for yy=sy to sh
                dim as integer ds = x+(y+yy)*XRES
                dim as integer sr = yy*img->Iwidth
                for xx=sx to sw
                    if(BUFFER(xx+ds) > 0 ) then BUFFER(xx+ds) =  img->Ibuf[xx+sr]
                next
              next  
        end sub

        ' TO DO
        sub DrawAlphaImage( img as IMAGE ptr,x as integer, y as integer,a as Dword)
      
        end sub

   end

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: software library
« Reply #1 on: April 23, 2007 »
Just some suggestions:

You should use the CVS version of FB since the stable .17 will not support the option statements. You can also use the OOPish extended type syntax in the CVS version which will make it easier to add classes when that is implemented. I have written a couple of tuts on this in the tut section here on the extended types.

I would also use the tinyptc_ext library since the current ptc does not compile under the CVS version.


Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: software library
« Reply #2 on: April 23, 2007 »

thanks for your suggestion rdc.

i think that  , shocky still use that version and he did not move to CVS or OOP, so i saw that made it like it was for any one want to use it.

BTW i am a big Fan of OOP , my first version of OgreMagic was done by singlton Class.