Page 1 of 1

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

Posted: Sun Apr 05, 2020 10:54 am
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

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

Posted: Sun Apr 05, 2020 11:42 am
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

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

Posted: Sun Apr 05, 2020 12:04 pm
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.

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

Posted: Sun Apr 05, 2020 1:43 pm
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.

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

Posted: Sun Apr 05, 2020 4:52 pm
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.

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

Posted: Mon Apr 06, 2020 10:53 am
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

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

Posted: Mon Apr 06, 2020 11:45 am
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.

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

Posted: Mon Apr 06, 2020 3:41 pm
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