How to pack BMP files in the .exe or into a single external file?
#1 Members - Reputation: 105
Posted 11 June 2012 - 03:45 PM
Instead of having them into the same folder i would like them embeded into the exe or into a single files (eg .dat)
Seens they are 20+ flooding the folder accessible by anyone and eligible to lose therefore
In the past I have been proposed the resource system of windows.
But i think its olny for icons cursors and UI tools in general.
Can it be used for large files destined for any manipulation?
If you could have some example code would be greate. WOX book on VC 6.0 does not has something
#2 Members - Reputation: 1594
Posted 11 June 2012 - 03:50 PM
An alternative is to do custom data files, which you can structure in any way you want.
#3 Members - Reputation: 105
Posted 11 June 2012 - 03:56 PM
Right in the bitmap filename in the parameter? Or do i nott both.
(Since we re talking of DirectX API windows its the only way)
#5 Crossbones+ - Reputation: 3555
Posted 11 June 2012 - 09:22 PM
Incorrect assumption. Under Windows you can store anything you want in resources as binary data, via the RCDATA/RT_RCDATA type (and you retrieve them in much the same way as you would other resources, as a bitstream).In the past I have been proposed the resource system of windows.
But i think its olny for icons cursors and UI tools in general.
But doing that usually isn't the best way to go, because it makes updating your executable difficult. A good compromise is to store your stuff in a single big file (or multiple, medium-sized files, sensibly) and read them like that. But unless you really need that, it's often best to just stick with one file per asset, scan for their existence when you start your program and come up with an error if one is missing.
#6 Members - Reputation: 530
Posted 12 June 2012 - 12:58 AM
LPCVOID LoadRes(CONST INT pResID, DWORD & pLen)
{
HINSTANCE hInst = GetModuleHandle(NULL);
HRSRC hRsrc = FindResource(
hInst,
MAKEINTRESOURCE(pResID),
RT_RCDATA);
if(NULL == hRsrc)
return NULL;
DWORD len = SizeofResource(hInst, hRsrc);
if(len == 0)
return NULL;
LPVOID lpLoad = LoadResource(hInst, hRsrc);
if(NULL == lpLoad)
return NULL;
pLen = len;
return LockResource(lpLoad);
}
#7 Crossbones+ - Reputation: 1172
Posted 12 June 2012 - 06:31 AM
You need to make a HEX dump of the BMP file and thin in code you define this:
class image_error
{
public:
static const unsigned char m_imageData[] = {
0x42, 0x4D, 0x38, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x40,
0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x1, 0x0, 0x18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x30, 0x0, 0x0, 0xE6,
0x1C, 0x0, 0x0, 0xE6, 0x1C, 0x0, ... ,0x0
};
static const unsigned int m_dataSize = 12344;
};
This is not ideal however as it will make the executable very big and you have to have facilities in place to be able to load image data from memory (which usually shouldn't be a problem).
Edited by NightCreature83, 12 June 2012 - 06:35 AM.
#8 Members - Reputation: 125
Posted 12 June 2012 - 09:40 AM
As another option you could compile them into the binary as well.
You need to make a HEX dump of the BMP file and thin in code you define this:class image_error { public: static const unsigned char m_imageData[] = { 0x42, 0x4D, 0x38, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x1, 0x0, 0x18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x30, 0x0, 0x0, 0xE6, 0x1C, 0x0, 0x0, 0xE6, 0x1C, 0x0, ... ,0x0 }; static const unsigned int m_dataSize = 12344; };
This is not ideal however as it will make the executable very big and you have to have facilities in place to be able to load image data from memory (which usually shouldn't be a problem).
I would REALLY avoid this.
#10 Members - Reputation: 426
Posted 12 June 2012 - 03:59 PM
As for having a large EXE, well the whole package is going to be large whether the EXE is big, or the EXE+ external files is big. It really does not matter if the EXE is big. I don't personally plan on storing any textures in my projects in my EXEs other than the font texture (adds < 10kb for my purposes) just because I have other approaches that work fine (procedural).
http://www.van-noland.com/downloads.php look for 'fontpack.zip' for source to the project I'm talking about.
#11 Moderators - Reputation: 2484
Posted 12 June 2012 - 04:40 PM
http://icculus.org/physfs/
You can use it to pack everything into a single ZIP file, and read them transparently at runtime.
Edited by Promit, 12 June 2012 - 04:40 PM.
#12 Members - Reputation: 530
Posted 12 June 2012 - 11:55 PM
It would have a good compression ratio for bitmaps, but it is the slow method.Instead of all the things people suggested, which strike me as bad ideas:
http://icculus.org/physfs/
You can use it to pack everything into a single ZIP file, and read them transparently at runtime.
It depends on project requirements.
#14 Members - Reputation: 210
Posted 13 June 2012 - 06:54 AM
#15 Members - Reputation: 1575
Posted 13 June 2012 - 04:45 PM
You can see a slighty old version of my code here: http://www.gamedev.net/index.php?app=core&module=attach§ion=attach&attach_id=8980
The resource packager has been changed slightly since then, but only in order to accommodate more resource types.
The relevant code is the 'RPAK' project within the solution and the 'RscStore' namespace in the main solution ('Bricks').
It's probably not something that you could just use for your own project, but if you look over it you should get the main thrust of it. The RPAK code is a little messy. Sorry.
There are ten kinds of people in this world: those who understand binary and those who don't.







