News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Images in Memory (memblocks)

Started by Scraggle, March 06, 2006, 09:07:19 AM

Previous topic - Next topic

Scraggle

I have a 2D project in DarkBASIC that makes heavy use of memblocks to manipulate images.  Unfortunately DarkBASIC isn't too hot with 2D stuff and so I was considering converting to PlayBasic.  However, because of the memblock stuff I am unsure how easy it would be to convert.
I have the PlayBasic demo and have looked through the help file and see that there are BANK commands.  Is this what I am looking for?
There isn't an obvious command for putting an image into memory like there is with DarkBASIC (Make Memblock From Image).  But do I even need to?  I hear that PlayBasic is much faster at 2D than DarkBASIC so is PlayBasic fast enough to manipulate images directly without use BANKs or is there a method of putting images into them?

If I can manipulate images with PlayBasic in a similar (or superior) manor to DarkBASIC then I will conced that PlayBasic is a necessary purchase!

Thanks
Scraggle

kevin

Banks in PB = Mem Blocks from DB

What effect are your trying to do ?   as I wouldn't to surprised if it's unnecessary in PB.  Post an example perhaps ?

Scraggle

What I have at the moment is a function that takes a PNG image and strips the edges from it by finding the nearest non-alpha pixels on each edge.  Then using this new image I can apply drop shadows, outlines, bevels etc.
All this is done with DarkBASICs memblocks because I can easily calculate the RGBA of each pixel.

So, I suppose really my question is:
Is there a fast method of calculating the Red, Green, Blue and Alpha components of each pixel within an image and then changing them?

kevin

Normally in PB you'd just create whats called an FX image.  Which is just an image stored in system memory.  From there you can just point/dot (or fastpoint, fastdot).  Since the buffer is not in video memory, you can read much faster.

But since you want to use alpha channel you can't do that with FX images as alpha is screened out.

I could add some  IMageToBank and BankToIMage commands. But there's probably a better way

Scraggle

It is essential that I use the Alpha channel.  So, it seems I am forced to stay with DB for now.  A shame because for 2D it seems that PB way outshines DB.
I will keep checking back here for any future developments though.

Thanks for your help
Scraggle

kevin

#5
If your going to apply a shadow say on the alpha channel, you can do that with Alpha add/sub and just a standard image.

I.e

RendertoIMage 1
InkMode 1+64 ; set alpha pen draw mode
Boxc 10,10,WidthOfIMage,HeigthOfImage,$11000000


It's a little hard trying to guess whether that's a viable alternative without actually seeing it though.

Scraggle

Alpha Pens!

Now that sounds interesting!

I will have a play with these and see what they can do.  The lack of Alpha in the point command is probably what will be the stalling point.  I am guessing (because I haven't played yet) that Alpha Pen will allow me to draw with alpha.  If I could read back the alpha value of what had been drawn I would be happy.

I just read the help commands before posting and it seems that the ink mode doesn't draw with alpha but instead makes a new colour to draw with based on the ink colour, background colour and blend mode ... am I right?

Scraggle

To make things a little clearer on my intentions:
I want the user to be able to load in a png file and then choose to apply a drop shadow, outline, glow etc ... before saving it back as a png. So you see the alpha has to be true alpha because the user will expect to be able to load in his png to his own project and still have transparent shadows.
I know that I can do this is DB but some of the things I am soing are proving to be rather slow and cumbersome.  If PB can handle it then I would convert.

kevin

#8
Quotebefore saving it back as a png.

There's no built in save image command that can do that at this point.


Also,

If your running 32bit mode, then Point + Dot both read and write ARGB pixels.  In  other words it's reading and writing longs to video memory without any masking.

Scraggle

QuoteThere's no built in save image command that can do that at this point.

Ahh ... that would be a snag.

You say 'at this point' are you suggesting that you are planning to include it?

Also your comment about POINT and DOT.  Are you saying that you can read and write alpha ... you have me a little confused, earlier you said alpha was 'screened out'.

Scraggle

I realize that it can't be easy to answer my questions when you don't know what it is I am trying to do.  So here is a screen shot of my project.

It is a Bitmap Font Editor that I am writing in DB using a custom GUI and it is very nearly complete.
On my system there is no problem but on lower spec machines, re-drawing the large pixels (blocks) is very slow. Porbably because of DB's slow 2d commands and that is where I was hoping PB could help.

Without a save image command though I suppose it is a hopeless endevour :(


kevin

#11
Confused, that makes two of us...    :)

in 32bit point+dot read/write 32bit ARGB pixels.  

Above, I'm talking about a different PB image format.  Called an FXIMage.  The problem being that when you load your normal image and convert it to the FX format, this conversion process removes the A channel.      But normal video images keep it. (if it's present to being with)  

The beauty of an FX images, in DB terms,  would be that pixel access is fast as reading a pixel from a mem block. Only you can do it directy to the image.  No second state is required. (ie. Make mem block from image, change pixels, make image from mem block.. )

2014 MOD EDIT: The advice in this thread is pretty much all obsolette.  Alpha support (the AFX  image format) was added around 2007/2008.   If you want Alpha Channel, use that.  - You can draw or read.write directly to/from those buffers.


kevin

Looks great.  So your writing this in DB or DBpro ?

Scraggle

Ok,  Ithink I understand now.

If I want speed I need to convert to an FXimage but the I lose Alpha.
If I want to keep alpha I use DOT & POINT but it's slower.

Bit of a no-winner really especially as I can't save the image.

QuoteLooks great. So your writing this in DB or DBpro ?

Thanks ... it's DBpro :)

Tracy

#14
Not to hijack a conversation I've not been part of, but Kevin, _are_ you planning on implementing a SaveImage command in future versions, or maybe PBFX? Just curious.


Mod Edit:   Just use the FREEIMAGE library, then you can save any format you want.