December 04, 2020, 11:54:02 AM

Author Topic: [bb] EXTREMELY FAST FADER... by Kostik [ 1+ years ago ]  (Read 506 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] EXTREMELY FAST FADER... by Kostik [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : EXTREMELY FAST FADER...
Author : Kostik
Posted : 1+ years ago

Description : This is a extremely fast bitmap-fader!!!

Works only with 16 color images!!!

You can fade in/out automaticale a full screen bitmap...


Code :
Code: BlitzBasic
  1. Graphics 640,480,32,1
  2. Global fader_tmp=CreateImage(300,100)
  3. Global fader_max=1
  4. Dim    fader_bmp(fader_max)
  5. Dim    fader_col(fader_max)
  6. Dim    fader_r  (fader_max,15)
  7. Dim    fader_g  (fader_max,15)
  8. Dim    fader_b  (fader_max,15)
  9.  
  10.  
  11.  
  12. Delay 1000 ;example
  13. loadfader 0,"bitmap.bmp"
  14. animfader 0,170,190,0,2000
  15. animfader 0,170,190,1,2000
  16. freefader 0
  17. FreeImage fader_tmp
  18. WaitKey()
  19. End
  20.  
  21.  
  22.  
  23. Function animfader(nr,x,y,mode,time)
  24.   source=ImageBuffer(fader_tmp)
  25.   dest  =BackBuffer()
  26.   sizex =ImageWidth(fader_bmp(nr))
  27.   sizey =ImageHeight(fader_bmp(nr))
  28.   time2 =MilliSecs()
  29.   Repeat
  30.     time3=MilliSecs()-time2
  31.     pro=(1000*time3)/time
  32.     If pro>1000 Then pro=1000
  33.     If mode=1 Then pro=1000-pro
  34.     SetBuffer source
  35.     DrawBlock fader_bmp(nr),0,0
  36.     SetBuffer dest
  37.     For i=0 To fader_col(nr)-1
  38.       MaskImage fader_tmp,fader_r(nr,i),fader_g(nr,i),fader_b(nr,i)
  39.       Color (fader_r(nr,i)*pro)/1000,(fader_g(nr,i)*pro)/1000,(fader_b(nr,i)*pro)/1000
  40.       Rect x,y,sizex,sizey,1
  41.       DrawImageRect fader_tmp,x,y,0,0,sizex,sizey
  42.       CopyRect x,y,sizex,sizey,0,0,dest,source
  43.     Next
  44.     Flip
  45.   Until time3>time
  46.   If mode=0 Then DrawBlock fader_bmp(nr),x,y
  47.   If mode=1 Then Color 0,0,0: Rect x,y,sizex,sizey,1
  48.   Flip
  49. End Function
  50.  
  51.  
  52.  
  53. Function freefader(nr)
  54.   If nr<0 Then Return
  55.   If nr>fader_max Then Return
  56.   If fader_bmp(nr)=0 Then Return
  57.   FreeImage fader_bmp(nr)
  58.   fader_bmp(nr)=0
  59. End Function
  60.  
  61.  
  62.  
  63. Function loadfader(nr,file$)
  64.   If nr<0 Then Return
  65.   If nr>fader_max Then Return
  66.   If fader_bmp(nr)<>0 Then Return
  67.   fader_bmp(nr)=LoadImage(file$)
  68.   If fader_bmp(nr)=0 Then Return
  69.   open=ReadFile(file$)
  70.   SeekFile open,28
  71.   depth=ReadShort(open)
  72.   If depth<>4 Then
  73.     CloseFile open
  74.     freefader nr
  75.     Return
  76.   End If
  77.   SeekFile open,54
  78.   For i=0 To 15
  79.     colb =ReadByte(open)
  80.     colg =ReadByte(open)
  81.     colr =ReadByte(open)
  82.     dummy=ReadByte(open)
  83.     If fader_col(nr)>0 Then
  84.       For ii=0 To fader_col(nr)-1
  85.         If fader_r(nr,ii)=colr And fader_g(nr,ii)=colg And fader_b(nr,ii)=colb Then
  86.           colr=0
  87.           colg=0
  88.           colb=0
  89.         End If
  90.       Next
  91.     End If
  92.     If colr+colg+colb>0 Then
  93.       fader_col(nr)=fader_col(nr)+1
  94.       fader_r(nr,fader_col(nr)-1)=colr
  95.       fader_g(nr,fader_col(nr)-1)=colg
  96.       fader_b(nr,fader_col(nr)-1)=colb
  97.     End If
  98.   Next
  99.   CloseFile open
  100.   For i=0 To fader_col(nr)-2
  101.     For ii=i+1 To fader_col(nr)-1
  102.       If fader_r(nr,i)+fader_g(nr,i)+fader_b(nr,i)>fader_r(nr,ii)+fader_g(nr,ii)+fader_b(nr,ii) Then
  103.         fader_r_tmp=fader_r(nr,i)
  104.         fader_g_tmp=fader_g(nr,i)
  105.         fader_b_tmp=fader_b(nr,i)
  106.         fader_r(nr,i)=fader_r(nr,ii)
  107.         fader_g(nr,i)=fader_g(nr,ii)
  108.         fader_b(nr,i)=fader_b(nr,ii)
  109.         fader_r(nr,ii)=fader_r_tmp
  110.         fader_g(nr,ii)=fader_g_tmp
  111.         fader_b(nr,ii)=fader_b_tmp
  112.       End If
  113.     Next
  114.   Next
  115. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal