Include binary use as a normal file / 256 colors indexed bmp

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
PB_Rainer
User
User
Posts: 80
Joined: Fri Jun 07, 2019 1:56 pm

Include binary use as a normal file / 256 colors indexed bmp

Post by PB_Rainer »

Hello,

maybe I'm the onlyone who asks for this, sorry, but it came from the development of my last program.

I would like to have two things:

Using 2bit, 4bit, 8bit-256 colors indexed BMP's in a normal way, not to be converted into 24/32bit BMP's.

Using an included BMP (IncludeBinary) like a file opened from any disk.

Short explanation why:

I'm a carpet-designer, all programs are developed for my work. Im working in the section aof weaving, not printing. In the weaving section all BMP's are indexed with max 256 colors.

So the BMP has just one byte (0-255) for each pixel of the BMP. This is necessary, because any pixelss value is used for multiple weaving-informations too. It is not only the pointer to an RGB-value in the palette-section of the BMP-file, but for much more waeving-technical informations.

In my last program I transform a carpet-design-BMP into weaving instructions, using the original-design-BMP and 3 more binding-BMP-files with technical informations. These 4 BMP-files will be read and combined into a new 5th BMP-file for the loom.

The 3 binding-BMP-files are always the same, therefore they are included binary into the exe-file. This is done, that no "stupid user can delete these files from any disk, by accident" with the result the program is unusable.
  • To work with these included BMP'S, I want to have the possibility to open a binary included file with a fileNumber, like a file on disk OpenIncludedBianry(file#) ,

    and to have the possibility to set a pointer f.e. to the beginning of the color-palette-section (byte 54) to read the palette RGB'S, or to the section with the bitmap-data (byte 1078) to read the pixlevalue 0-255. Therefore a command like IncludedBinarySeek(file#, bytepos) is needed,

    and to read the data the command ReadIncludedBinary(file#, [ .a, .b, .c, .i, .w, .d, .l, .s], bytes)

    at least CloseIncludedBinary(file#)
The Restore only points to the start of the datasection.

I hope I could explain it understandable.

Regards and a nice sunday with #stayathome
Rainer
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Include binary use as a normal file / 256 colors indexed

Post by Kurzer »

Hi PB_Rainer,

a suggestion for "IncludeBinary as file":

You could save the included images into a temporary directory at every program start (if they are not already there) and then access them with the normal file commands.
Otherwise Fred would have to maintain the new library you suggested in addition to the file library and keep it up to date. So double work.

Greetings
Kurzer
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
STARGÅTE
Addict
Addict
Posts: 2085
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Include binary use as a normal file / 256 colors indexed

Post by STARGÅTE »

Hi PB_Rainer.

I think my not yet published module is exactly what you want:
https://www.unionbytes.de/downloads/Package.pbi
You can catch your IncludeBinary memory with CatchPackage(#Package, *Memory, Length) and then use typical commands like:
PackagePosition() to change the position, ReadPackageByte(), ReadPackageData(), ...
Try it out.

Edit: You can also use WritePackageByte() to change the content and later CatchImage(#Image, PackageBuffer(#Package)) to import the changed data.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
PB_Rainer
User
User
Posts: 80
Joined: Fri Jun 07, 2019 1:56 pm

Re: Include binary use as a normal file / 256 colors indexed

Post by PB_Rainer »

STARGÅTE wrote:Hi PB_Rainer.

I think my not yet published module is exactly what you want:
https://www.unionbytes.de/downloads/Package.pbi
You can catch your IncludeBinary memory with CatchPackage(#Package, *Memory, Length) and then use typical commands like:
PackagePosition() to change the position, ReadPackageByte(), ReadPackageData(), ...
Try it out.

Edit: You can also use WritePackageByte() to change the content and later CatchImage(#Image, PackageBuffer(#Package)) to import the changed data.
Hi,

thanks, I will download an test next week. edited (DONE!)

regards
Rainer

Some questions:

if I use catchPackage() 2np Param ist the Startpoint of the incudedBinary?

Code: Select all

DataSection
	Memory_Test_BMP_Start:
	IncludeBinary "C:\Program Files\PureBasic\MySources\BMP_Memory_Test\Memory_Test.bmp" ; 1142 bytes
	Memory_Test_BMP_End:
EndDataSection

CatchImage(#Memory_Test_BMP, ?Memory_Test_BMP_Start, ?Memory_Test_BMP_End - ?Memory_Test_BMP_Start)

;like

CatchPackage(1, ?Memory_Test_BMP_Start, ?Memory_Test_BMP_End - ?Memory_Test_BMP_Start, PB_Ignore)

When setting the pointer, are the points exactely as in the bitmap, or are there some header-data in the beginning? How long?
F.e. the palette start is the 54th byte the bitmapdata start is byte 1078!

Is it the same when the includedbinary ist caught with CatchPackage()

thanks for your help
Rainer

Edit:
Found the answers by try without error.
User avatar
STARGÅTE
Addict
Addict
Posts: 2085
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Include binary use as a normal file / 256 colors indexed

Post by STARGÅTE »

CatchPackage(1, ?Memory_Test_BMP_Start, ?Memory_Test_BMP_End - ?Memory_Test_BMP_Start) is sufficient.
The 4th parameter is only for string format.

> if I use catchPackage() 2np Param ist the Startpoint of the incudedBinary?
Right.

>When setting the pointer, are the points exactely as in the bitmap, or are there some header-data in the beginning? How long?
The position of PackagePosition() is the position in the package (the memory or image).

>Is it the same when the includedbinary ist caught with CatchPackage()
Yes.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
PB_Rainer
User
User
Posts: 80
Joined: Fri Jun 07, 2019 1:56 pm

Re: Include binary use as a normal file / 256 colors indexed

Post by PB_Rainer »

STARGÅTE wrote:CatchPackage(1, ?Memory_Test_BMP_Start, ?Memory_Test_BMP_End - ?Memory_Test_BMP_Start) is sufficient.
The 4th parameter is only for string format.

> if I use catchPackage() 2np Param ist the Startpoint of the incudedBinary?
Right.

>When setting the pointer, are the points exactely as in the bitmap, or are there some header-data in the beginning? How long?
The position of PackagePosition() is the position in the package (the memory or image).

>Is it the same when the includedbinary ist caught with CatchPackage()
Yes.
Hi Martin,

I wrote a small testcode. Everything works well.
Now I can rewrite my main-procedure using the included binary BMP's instead of loading them from disc.
Thanks a lot.

B.t.w. I have a question about your module.

When I use modules from Thorsten 1867 f.e. ListEx or StatusBarEx every procedure or Flag needs the prefix of the module like ListEx::Procedurename() or ListEx::#Normal, and when typed in a procedurename you have a helping hint in the editors statusbar with parameters and types, which I like very much, unfortunately not with your module. What is different between module and module?

Regards and #styathome and use PureBasic
Rainer
User avatar
STARGÅTE
Addict
Addict
Posts: 2085
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Include binary use as a normal file / 256 colors indexed

Post by STARGÅTE »

You can use either "Package::ReadPackageByte()" or "UseModule Package" and then only "ReadPackageByte()"

Regarding the status bar help. This functionality works only if you use a project or if the source code is also opened.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
PB_Rainer
User
User
Posts: 80
Joined: Fri Jun 07, 2019 1:56 pm

Re: Include binary use as a normal file / 256 colors indexed

Post by PB_Rainer »

STARGÅTE wrote:You can use either "Package::ReadPackageByte()" or "UseModule Package" and then only "ReadPackageByte()"

Regarding the status bar help. This functionality works only if you use a project or if the source code is also opened.

Thanks.

Edit:

I have edited the procedure and changed all file-operations into memory-operations, using your module.

Works perfect and is about 50% faster.

Thanks again
Post Reply