800x600x24 bitmap fun...

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Mysoft
Posts: 836
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

800x600x24 bitmap fun...

Post by Mysoft »

ok... first you need to get the bitmap

http://www.sendspace.com/file/xsnw7r
its a 800x600x24 bitmap = 1.3mb

you can check it wherever you want... or maybe in freebasic with

Code: Select all

screenres 800,600,32
bload "image.bmp"
sleep
so... now try this! :)

Code: Select all

#include "fbgfx.bi"

declare sub Blur(WHERE as any ptr)

#define Cvt(WHAT) ((WHAT and &h00030303) shl 6)

screenres 800,600,32,,fb.gfx_high_priority

dim as any ptr IMG = ImageCreate(800,600)
dim PIX as integer ptr,BT as double

' bload the bitmap and clear alpha
bload "image.bmp",IMG:PIX = IMG+sizeof(fb.image)
for D as integer=1 to 800*600:*PIX or= &hFF202020: PIX += 1:next D
screenlock:put(0,0),IMG,pset:Blur(screenptr):screenunlock

' do the magic
PIX = IMG+sizeof(fb.image)
for D as integer = 1 to 800*600
  if (*PIX and &HFF000000) then *PIX = Cvt(*PIX)
  PIX += 1
next D
Blur(IMG+sizeof(fb.image))

' wait key
do
  BT xor= 1:sleep 300,1
  if BT then WindowTitle ("PRESS A KEY TO CONTINUE!") else WindowTitle ("")
  if BT then if inkey$ <> "" then exit do
loop

' alpha effect
BT = timer
for D as integer = 0 to 39
  put(0,0),IMG,alpha,1.15^D
  while (timer-BT) < 1/15
    sleep 1
  wend
  BT += 1/15
next D
WindowTitle ("Press any key to finish")
sleep

' blur to raise image quality
sub Blur(WHERE as any ptr)
  dim as ubyte ptr PIX
  dim as integer TMP
  PIX = WHERE  
  for D as integer = 1 to 800*598*4
    TMP = *PIX+PIX[4]+PIX[3200]+PIX[3204]
    TMP += PIX[8]+PIX[3208]+PIX[6400]+PIX[6404]
    *PIX = (TMP shr 3)
    PIX += 1
  next D
end sub
funny isnt it?
no? oh then... try changing the #define there (line 5) for...

Code: Select all

#define Cvt(WHAT) ((WHAT and &h000C0C0C) shl 4)
and then run it again!
haaa! there it goes again...

want another one??
well maybe then let's try something different
try this one:

Code: Select all

#include "fbgfx.bi"

screenres 800,600,32,,fb.gfx_high_priority or fb.gfx_alpha_primitives

declare sub Blur(WHERE as any ptr)

dim as uinteger ptr PIX
dim as ubyte TST,BITS
dim as uinteger PTX,PTZ
dim as string NNM = chr$(118,105,100,101,111,46,119,109,118)
dim as double BT
dim as string TT

' bload the image
bload "image.bmp"

' *** extract magic ***
open NNM for binary as #1
open cons for output as #99
PIX = screenptr: BITS = 0: TST = 0
for Y as integer = 1 to 600  
  screenlock
  for X as integer = 1 to 800
    PTX = (*PIX and &h303030)    
    *PIX and= (not &h303030)
    TST shr= 2: TST or= ((PTX shr 14) and &hC0)
    PTX shl= 8
    BITS = (BITS+1) and 3
    if BITS = 0 then put #1,,TST
    TST shr= 2: TST or= ((PTX shr 14) and &hC0)
    PTX shl= 8
    BITS = (BITS+1) and 3
    if BITS = 0 then put #1,,TST
    TST shr= 2: TST or= ((PTX shr 14) and &hC0)
    BITS = (BITS+1) and 3
    if BITS = 0 then put #1,,TST
    PIX += 1    
  next X
  screenunlock  
  sleep 1
next Y
close

' blur fade!
BT = timer
var BUF = imagecreate(800,600)
BITS = 0:TST = 0
for C as integer = 0 to 128
  screenlock  
  line(0,596)-(799,599),rgb(0,0,0),bf:line(796,0)-(799,599),rgb(0,0,0),bf
  line(0,0)-(799,4),rgb(0,0,0),bf:line(0,0)-(4,599),rgb(0,0,0),bf
  Blur(screenptr)
  line(0,0)-(799,599),rgba(0,0,0,TST/8),bf
  BITS xor= 1: TST += 1
  if BITS then
    get(0,0)-(799,599),BUF  
    put(1,1),BUF,pset
  end if
  screenunlock
  while (timer-BT) < 1/10
    sleep 1
  wend
  BT += 1/10
next C

shell NNM

' blur to raise image quality
sub Blur(WHERE as any ptr)
  dim as ubyte ptr PIX
  dim as integer TMP
  PIX = WHERE  
  for D as integer = 1 to 800*598*4
    TMP = *PIX+PIX[4]+PIX[3200]+PIX[3204]
    *PIX = TMP/3.94
    PIX += 1
  next D
end sub
and that's all folks...
ps: if you're a linux user... than you probabily need to execute the file manually after executing the last one... but enjoy the fade/blur effect too :P

subliminar .bmp ftw! xD
duke4e
Posts: 717
Joined: Dec 04, 2005 0:16
Location: Varazdin, Croatia, Europe
Contact:

Post by duke4e »

3 images + titus the fox video all in one tiny bmp file. awesome!
Hezad
Posts: 469
Joined: Dec 17, 2006 23:37
Contact:

Post by Hezad »

yey ! dude, that's awesome oO

*clap*
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Cool stuff mysoft!

really amazing, at least to me who knows very little of image handling beyond "bload" and "put".

cheers,
Michael
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Post by Deleter »

cool. "and you thought that was the main menu file :P"
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19

Post by stylin »

Out of This World, yeah !
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Post by phishguy »

That's wild! I kinda freaked out when the last one started playing a video. I had thoughts of viruses attacking my PC. Oh, the nasty stuff you could do if you were an evil genius instead of just a plain genius.
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

That is insane. I haven't seen something as impressive as this in... a long time.
BastetFurry
Posts: 255
Joined: Jan 05, 2006 0:56

Post by BastetFurry »

This is scene gold!
Ever thought about attending the Breakpoint with stuff like that in a tiny, as in size, demo and kick some Farbrausch butt with it?
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Post by angros47 »

I've heard about steganography, but you brought it to the next level.

Have you ever heard about notpron and others online riddles, where you have to find an hidden message inside a page? Maybe you could solve them.

One last comment... if you could fit three images and a video in the same space wich is normally used to store only one image... what a waste of memory are normally BMP!
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Post by Deleter »

angros47 wrote:... what a waste of memory are normally BMP!
idd...
Mysoft
Posts: 836
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Post by Mysoft »

yeah its sure that it's a waste... but also the images there are 2 bits per component instead of 8... (so instead of one image with 8 bits per component is 3 images with 2 bits the 2 remaining bits are used for form 6/8 of a byte (per pixel)...

i like those sites... i sometimes try some challenge when my soul is calm enough for that... its fun =)
Post Reply