Round bmp image [SOLVED]

General FreeBASIC programming questions.
Dinosaur
Posts: 1358
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Round bmp image [SOLVED]

Postby Dinosaur » Apr 29, 2011 7:28

Hi all

To represent an Led on some of my screens, I have drawn a square in AutoCad and filled it with the right colour. Then saved it in a bmp that is 15 x 15 pixels and about 775 bytes.
Then when an Led needs to be turned On or Off I use the Allegro Blit statement.

However, it doesnt look as good as a round Led. The problem is that if I draw a round Led, it saves as a square bitmap, and the background colour becomes a problem.

Is there any way that I can put a round bitmap on the screen, regardless of background colour.?
I only use Red , Green, Yellow and white.

Any pointers appreciated.

Regards
Last edited by Dinosaur on Apr 30, 2011 3:54, edited 1 time in total.
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Apr 29, 2011 7:37

You mean, put with the trans option and background color &HFFFF00FF? 32-bit BMPs exist, but you could also do some manual adjustments in code to set the pixel alpha value to 0 for pixels of the background color.
Does Allegro not support opacity? Did I misread the question?
Dinosaur
Posts: 1358
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Postby Dinosaur » Apr 29, 2011 7:55

Hi all

I have never created a bmp with FB, and thus dont know how to create a round bitmap filled with colour. Then when I place this bmp on any background, it should only cover a round area of the background. If Allegro supports opacity, then I still need to create and save the bitmaps.

KristopherWindsor, your reply assumes that I know how to create and "set the pixel alpha value to 0". Other than loading and blitting I have no knowledge of bitmaps.
Regards
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Postby MichaelW » Apr 29, 2011 8:20

Why can’t you just create two bitmaps, one for on and one for off, each with the proper background color?

To make such round images look reasonable I have had to create them (in Paint) pixel by pixel and apply manual anti-aliasing. This code generates one such image:

Code: Select all

'==========================================================
'' This code generates a manually anti-aliased green dot
'' centered on a 14x14-pixel black background, and stores
'' it as a 24-bit BMP.
'==========================================================

'----------------------------------------
'' Green components for quadrant II ony:
'----------------------------------------

dim as integer greens(0 to 48) = { _
  000,000,000,000,000,000,000, _
  000,000,000,000,150,200,255, _
  000,000,000,200,255,255,255, _
  000,000,200,255,255,255,255, _
  000,150,255,255,255,255,255, _
  000,200,255,255,255,255,255, _
  000,255,255,255,255,255,255  }

dim as any ptr pimage

screenres 320, 200, 32

pimage = imagecreate( 14, 14, 0 )

for x as integer = 0 to 6
  for y as integer = 0 to 6
    pset pimage, (x,y), RGB(0,greens(x+y*7),0)
  next
next
for x as integer = 6 to 0 step - 1
  for y as integer = 0 to 6
    pset pimage, (13-x,y), RGB(0,greens(x+y*7),0)
  next
next
for x as integer = 0 to 6
  for y as integer = 6 to 0 step - 1
    pset pimage, (x,13-y), RGB(0,greens(x+y*7),0)
  next
next
for x as integer = 6 to 0 step - 1
  for y as integer = 6 to 0 step - 1
    pset pimage, (13-x,13-y), RGB(0,greens(x+y*7),0)
  next
next

print bsave( "dot.bmp", pimage )

imagedestroy( pimage )

sleep

bfuller
Posts: 339
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Postby bfuller » Apr 29, 2011 9:05

You might find your answer here, with the alpha attribute (RGBA):

http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgRgba
Dinosaur
Posts: 1358
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Postby Dinosaur » Apr 29, 2011 9:21

Hi all

MichaelW, the image created with the code you suggested is what I was worried about.
Yes it created a round dot of green colour, but it was in a black square. So, I guess you have answered one question, and that is that the image saved is in fact a square image.
I was hoping that we could save the round dot as a round image.Then I wouldnt have to worry about whatever background I put it on. And the problem is, that I may put it onto all different colour backgrounds, and hopefully without having to remember what the background colour is, and adjusting the square background colour to suit.

Regards

EDIT:bfuller, I have the same problem with the link you posted. BY saving the image created with the circle command,it still creates a square with a circle in it.
I think what's wrong is that I don't understand the mechanics involved in putting an image over the top of another. Most of you guys are involved in games where I am sure you are doing this all the time without having to worry about the background colour when putting your fire breathing dragons on the screen.
bfuller
Posts: 339
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Postby bfuller » Apr 29, 2011 9:54

I have only a very simple understanding of programming, but what's wrong with just drawing a circle?

Code: Select all

 '' set screen mode
   SCREEN 15, 32

Dim As Integer x, y

   'draw a background (diagonal white lines)
For x = -240 To 319 Step 10
  Line (x, 0)-Step(240, 240), RGB(255, 255, 255)
Next

   CIRCLE (100, 100), 10,&HFF0000,,,,F
   CIRCLE (140, 140), 10,&H00FF00,,,,F
   
   Sleep


Unless I suppose if you want to make the LED disappear, to show the background underneath again. But in my (electronic) world, the LED is either RED or GREEN, so the background would never show anyway. If you want it to, then just clear screen and redraw.

Code: Select all

 '' set screen mode
   SCREEN 15, 32

Dim As Integer x, y
for y = 1 to 10
   'draw a background (diagonal white lines)
For x = -240 To 319 Step 5
  Line (x, 0)-Step(240, 240), RGB(255, 255, 255)
Next

   CIRCLE (100, 100), 10,&HFF0000,,,,F
   CIRCLE (140, 140), 10,&H00FF00,,,,F
   
   Sleep 500

CLS

   'draw a background (diagonal white lines)
For x = -240 To 319 Step 5
  Line (x, 0)-Step(240, 240), RGB(255, 255, 255)
Next x

sleep 500

Next y

sleep
Richard
Posts: 3038
Joined: Jan 15, 2007 20:44
Location: Australia

Postby Richard » Apr 29, 2011 10:07

You could also consider using a rectangular LED.
Dinosaur
Posts: 1358
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Postby Dinosaur » Apr 29, 2011 10:13

Hi all

bfuller, that works, except that I have hundreds of led's that need updating. Currently I do this like so.

Code: Select all

Sub UpdateStatus
Dim As Integer Xq
With Led
    For Xq = 1 To 112
        If .Button(Xq) > 0 Then             'if it is drawn
            If  .Req(Xq) <> .Show(Xq) Then   'if request is different
                If .Req(Xq) <> 0 Then      'then what is shown
                    If .Direction(Xq) > 0  Then Blit(opOn,.Bmp(Xq),0,0,0,0,15,15)
                    If .Direction(Xq) < 0 Then Blit(ipOn,.Bmp(Xq),0,0,0,0,15,15)
                EndIf
                If .Req(Xq) = 0 Then                           
                    If .Direction(Xq) > 0  Then Blit(opOff,.Bmp(Xq),0,0,0,0,15,15)
                    If .Direction(Xq) < 0 Then Blit(ipOff,.Bmp(Xq),0,0,0,0,15,15)
                EndIf
                Refresh(.Button(Xq))                     
                .Show(Xq) = .Req(Xq)      
            EndIf
        EndIf
    Next
End With
End Sub

It uses Led.Bmp(x) and decides if it is an input Led or an output Led. Then if the status is different then what is shown, then it Blit's it.
I was hoping to create a bmp that is simply a circle and not a square, that I can Blit as per above.
Richard, as I said in my first post, a square just doesn't look as good.
bfuller
Posts: 339
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Postby bfuller » Apr 29, 2011 10:25

There must be a way of creating a transparent square (using ALPHA), with a filled circle inside it. Someone more skilled in FB than me might be needed though.
Last edited by bfuller on Apr 29, 2011 11:51, edited 1 time in total.
Merick
Posts: 1038
Joined: May 28, 2007 1:52

Postby Merick » Apr 29, 2011 11:18

Make the background of your image pink - RGB(255, 0, 255) - and use allegro's masked_blit instead of the regular blit, according to the docs this will work the same way as using FB's put statement with the trans option.
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Apr 30, 2011 1:25

Here's what FBGFX can do for transparency. Allegro can probably do something similar.

Code: Select all

'By Kristopher Windsor

#include once "fbgfx.bi"

screenres 640, 480, 32

dim as fb.image ptr g = imagecreate(100, 100)

'white & blue background for the screen
line (0, 0) - (639, 80), &HFFFFFFFF, BF
line (0, 81) - (639, 479), &HFF0000FF, BF

'first create the bitmap (instead of loading from file)
circle g, (49, 49), 48, &HFF22FF22,,, 1, F 'green

'now show the bitmap on screen
'that pink color is &HFFFF00FF, and it represents transparency
put (0, 0), g, pset

'now show it with transparency
put (100, 0), g, trans

'now do some per-pixel adjustments to change the transparency of pink pixels
for i as integer = 0 to 99
  for j as integer = 0 to 99
    if (point(i, j, g) and &HFFFFFF) = &HFF00FF then
      pset g, (i, j), &H77FF00FF 'that's rgba(255, 0, 255, &H77)
    end if
  next j
next i
'and display it with per-pixel transparency that we just set
put (200, 0), g, alpha

'repeat the above, but with a different alpha value
for i as integer = 0 to 99
  for j as integer = 0 to 99
    if (point(i, j, g) and &HFFFFFF) = &HFF00FF then
      pset g, (i, j), &H22FF00FF 'that's rgba(255, 0, 255, &H22)
    end if
  next j
next i
put (300, 0), g, alpha

sleep()
Dinosaur
Posts: 1358
Joined: Jul 24, 2005 1:13
Location: Hervey Bay
Contact:

Postby Dinosaur » Apr 30, 2011 3:10

Hi all

Thank you, KristopherWindsor, I now understand the mechanics behind transparency and masking, thanks to your demo.

The object of this question was to create a round bmp image. I now know that there is no such thing. It is a round image within a square image, and the square can be made invisble.

Does that mean when you guys move a warrior across the screen, you are moving a transparent rectangle? Glad I am not a gamer.
In the end I managed to create the bitmaps of vaious colours like this.

Code: Select all

ScreenRes 320, 200, 32

'Make a 15 pixel square with Mask colour
Dim img As Any Ptr = ImageCreate( 15, 15, RGB(255, 0, 255) )
'Make a Red filled circle in image 6 pixel Radius @ centre of Square
Circle img, (7, 7), 6, RGB(255, 0, 0),,,1,f

'OR Make a Green filled circle
'Circle img, (7, 7), 6, RGB(0, 255, 0),,,1,f

'Save image as .bmp file
print bsave( "OPON.bmp", img )
' free the image memory
ImageDestroy img

Sleep
Merick, the Masked_Blit worked perfectly. So the only changes to my code was to make the Blit Masked_Blit, and using different bmp's.
Many thanks to all

Regards
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Postby KristopherWindsor » Apr 30, 2011 6:22

Dinosaur wrote:Does that mean when you guys move a warrior across the screen, you are moving a transparent rectangle? Glad I am not a gamer.

Yes. :)

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests