BBC BASIC
« Creating Bitmap »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 11:11pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Creating Bitmap  (Read 288 times)
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: 157
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: 803
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: 803
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

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Creating Bitmap
« Reply #10 on: Feb 18th, 2018, 08:55am »

One possible explanation might be if the computer in question is a laptop and turns the hard drive off after every access - I had one that did that. You had to wait for the drive to come up to speed before any read or write. Most frustrating!
User IP Logged

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

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls