Author |
Topic: Creating Bitmap (Read 288 times) |
|
MarsFS
New Member
member is offline


Gender: 
Posts: 16
|
 |
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.
|
|
Logged
|
|
|
|
michael
Full Member
member is offline


Posts: 157
|
 |
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 » |
Logged
|
I like reinventing the wheel, but for now I will work on tools for D3D
|
|
|
MarsFS
New Member
member is offline


Gender: 
Posts: 16
|
 |
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 
Hmmm I wonder if an asm routine will be faster than what I am doing currently...
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
MarsFS
New Member
member is offline


Gender: 
Posts: 16
|
 |
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
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!
|
|
Logged
|
|
|
|
|