BBC BASIC
« Creating Bitmap »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:18pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Creating Bitmap  (Read 186 times)
MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Creating Bitmap
« Thread started on: Oct 19th, 2017, 08:08am »

Apologies for posting a windows specific topic and double apologies if this is covered in help as I can't seem to find a simple example...

I want to be able to create a bitmap handle and assign to it a region of the application window.

Once I have the bitmap handle there are various actions I wish to perform like save as PNG and keeping a buffer of undo screens.

I have already implemented saving a PNG and undo but it involves saving a temporary bitmap file, then loading it into a bitmap handle... I would really like to skip the saving bitmap step if possible.

If anyone can provide an example or link that would be great.

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Creating Bitmap
« Reply #1 on: Oct 19th, 2017, 10:53am »

on Oct 19th, 2017, 08:08am, MarsFS wrote:
I want to be able to create a bitmap handle and assign to it a region of the application window.

AFAIK there is no way of assigning a bitmap handle to a region (you can create a region handle, but that's something different). That being the case you will unavoidably have to copy the region of interest into another bitmap first.

You can achieve that using (for example) the Windows BitBlt API function, but personally I think the file approach is easier to understand and code. All modern PCs cache files in memory so creating a temporary bitmap file and reading it back isn't necessarily any slower than the API method.

In SDLIDE.BBC (my IDE for BBCSDL, written in BASIC) I use temporary files for saving and restoring regions of the screen, undo/redo buffers etc. It achieves platform independence and the performance is more than acceptable.

I appreciate that saving as a PNG is not something that you can currently achieve in a platform-agnostic way (although that might change in the future if I link BBCSDL with SDL_image) but I naturally lean towards non-API solutions these days.

Richard.
« Last Edit: Oct 19th, 2017, 11:04am by Richard Russell » User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx Re: Creating Bitmap
« Reply #2 on: Oct 20th, 2017, 01:13am »

This is a snippet from RETROLIB 10. Have you considered just updating regions with premade creations and then place them quickly where you choose to on your display?


Code:
          WHEN"savebmp" :
            name$=FNword(cmd$)+".bmp":x$=FNword(cmd$):x%=VAL(x$):y$=FNword(cmd$):y%=VAL(y$):h$=FNword(cmd$):h%=VAL(h$):v$=FNword(cmd$):v%=VAL(v$)
            OSCLI "SCREENSAVE """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(h%)+","+STR$(v%)
          WHEN"loadbmp" :
            name$=FNword(cmd$)+".bmp":x$=FNword(cmd$):x%=VAL(x$):y$=FNword(cmd$):y%=VAL(y$):h$=FNword(cmd$):h%=VAL(h$):v$=FNword(cmd$):v%=VAL(v$)
            OSCLI "DISPLAY """+name$+""" "+STR$(x%)+","+STR$(y%)+","+STR$(h%)+","+STR$(v%)
 


This is quite effective. Although, there is also storing the image data in an array.


I believe there would be a way to hold the image data

There is also the recent idea of using the 3D renderer to display multiple screens and perhaps modify each texture directly.

There is ways of doing this, by modifying the texture externally and updating it in the renderer.

Technically you could overlay and shrink multiple displays in the renderer.. ( in theory)

I am exploring that idea to create a new world of graphics. (3D and 2D and interfacing all in one screen)

IMAGINE: if draw commands could be sent to a texture that is being displayed live without needing to clear the existing texture image and reload the modified one. !!!

Wouldn't that be cool ? :)

You could have multiple screens stacked and only modify the closest texture on the closest 3D construct. (6 verticies)

AND also I had the idea of using the 3D tools to create sprites of sort.. (oooh yeah !!)


« Last Edit: Oct 20th, 2017, 01:32am by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: Creating Bitmap
« Reply #3 on: Oct 20th, 2017, 07:23am »

Thanks guys, I could hold the image data in memory but I was thinking when redrawing the entire screen it might have a performance impact.

The direct 3d approach sounds interesting but I'm trying to keep the code as close to BBC basic as possible purely from a readability point of view.

Have started to implement the temp file approach and will see how it goes for now.
User IP Logged

MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: Creating Bitmap
« Reply #4 on: Oct 30th, 2017, 11:43pm »

Have been playing around with this some more, I'd really like to be able to grab a region of the screen and store it as a BMP or DIB so as to be able to use it later say for saving or rendering back to the screen.

I have played around with directly access the screen memory with some success but I don't want to have to rewrite large sections of my application to use this method.

Would anyone be able to provide an example of storing a rectangle of the main canvas in a memory as a BMP or DIB and then rendering that BMP back to the main canvas?

My application is 1024x768 using a modified standard 16 colour palette. The area I want take a snapshot of to store in memory is 640x512.

Any assistance would be great, I am having a bit of trouble wrapping my head around the bitblit method but I really think it will suit my task better than storing to disk.
User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx Re: Creating Bitmap
« Reply #5 on: Oct 31st, 2017, 12:00am »

Hello MarsFS,

Here is a link to a perfect example with good descriptions with REMs:

http://bb4w.conforums.com/index.cgi?board=addins&action=display&num=1474243389

Ric and DDRM were so kind as to make a few examples for me and I put it in tools.

You will find a huge assortment of tools in the TOOLS section as it is now a popular area.

Best wishes,
Michael
« Last Edit: Oct 31st, 2017, 12:06am by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: Creating Bitmap
« Reply #6 on: Oct 31st, 2017, 01:33am »

Cheers Michael! I now have the direct memory part working and apart from being a bit slow it does appear to be working the way I need it too so thanks for the link cheesy

Hmmm I wonder if an asm routine will be faster than what I am doing currently...
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Creating Bitmap
« Reply #7 on: Oct 31st, 2017, 09:42am »

on Oct 30th, 2017, 11:43pm, MarsFS wrote:
I really think it will suit my task better than storing to disk.

Can you explain why, please? Have you benchmarked it and discovered a significant performance hit from "storing to disk" that you want to avoid? Or is it more a 'psychological' objection?

You need to understand that an OSCLI "gsave" followed shortly afterwards by an OSCLI "display" may well not involve any data being transferred to or from disk. The 'gsave' initially moves the data into a RAM buffer (disk cache) which will be lazily written to the physical disk at a future point, and the 'display' will almost certainly take its data from that RAM buffer.

So my original recommendation stands. Using OSCLI "gsave" and OSCLI "display" is simple, it's fast and it's platform-independent. I would not consider doing it any other way. If you have a genuine reason for not wanting to use that method, what is it?

Incidentally you refer to "storing a rectangle of the main canvas in a memory as a BMP or DIB". If it's a BMP it's a file, if it's in memory it's a DIB. A BMP is a DIB stored in a file (the only difference between them from a data structure viewpoint is that the former has a BITMAPFILEHEADER whereas the latter doesn't).

Richard.
User IP Logged

MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
xx Re: Creating Bitmap
« Reply #8 on: Nov 1st, 2017, 12:42am »

Thanks Richard.

Up to now I have been using temp files and it has been working fine.

The person I am writing the application for was trying it out on various (old) hardware and had an issue with a certain low spec machine that was taking 1-2 seconds to save the temp file which made the program unusable.

I was just exploring an alternative approach to see if it made any difference, which it did in this case so now the person can continue to use the program on his preferred device.

I guess if I was really motivated I would just rewrite the whole thing in C and be done with it but part of fun was having a BBC Basic version of the program as that is where this whole project started.

It's been interesting to see how far we could take a basic program but really it's becoming more and more departed from what it was when it started a while back.

Thanks for the advice... if anyone interested feel free to have a look at the current code and offer any further tips.

https://github.com/marsFS/ART-4-Windows
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Creating Bitmap
« Reply #9 on: Nov 1st, 2017, 09:51am »

on Nov 1st, 2017, 12:42am, MarsFS wrote:
a certain low spec machine that was taking 1-2 seconds to save the temp file

Taking 'seconds' is almost unbelievable. I've measured the time it takes to save a 640x512 window on my two slowest machines, an ancient Windows 95 (yes, really!) PC and the Raspberry Pi: they were 230 ms and 100 ms respectively. On the modern laptop I'm using to write this, it was 6 ms!

Quote:
I guess if I was really motivated I would just rewrite the whole thing in C and be done with it

Graphics operations are almost invariably dominated by the OS and the GPU, not by the programming language used. Writing it in C would probably make no discernable difference to the speed.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls