Bitmap-as-const-and-write-to-file-thingy

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Bitmap-as-const-and-write-to-file-thingy

Marc Santhoff-2
Hi,

a program im fiddling with uses exactly 2 small .gif pictures that are to be
stored in the code and written out to the file system.

For several reasons - no gif writer, complicates ressouce file handling,
linking fpimage or similar - I want to handle those files directly in code,
having an array of hex bytes and some code writing those consts to file.

What I need:

- A program taking a binary file and spitting out pascal code for the const
array. I know I have seen such program in the past, but do not know where.

- Some hints on using this constant for making files out of them. Currently
I'm plannig to use a TFileStreaam writing out Bytes, should do.

Any pointers or hints, please?

TIA,
Marc

--
Marc Santhoff <[hidden email]>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bitmap-as-const-and-write-to-file-thingy

Tomas Hajny-2
On Wed, September 19, 2018 23:58, Marc Santhoff wrote:


Hi,

 .
 .
> What I need:
>
> - A program taking a binary file and spitting out pascal code for the
> const array. I know I have seen such program in the past, but do not know
> where.

data2inc is included with FPC.


> - Some hints on using this constant for making files out of them.
> Currently I'm plannig to use a TFileStreaam writing out Bytes, should do.

Indeed, should do; simple file of byte and BlockWrite should do as well.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bitmap-as-const-and-write-to-file-thingy

Bo Berglund
In reply to this post by Marc Santhoff-2
On Wed, 19 Sep 2018 23:58:36 +0200, Marc Santhoff
<[hidden email]> wrote:

>Any pointers or hints, please?

You can convert any file you like to an inc file with pascal syntax:

data2inc -A -B laz/images/ide_icon48x48.png datatest.inc icon48x48

This will produce a datatest.inc file ready to be included in your
project and with content looking like this:

const icon48x48 : array[0..4236] of byte=(
  $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,
....
 $45,$4E,$44,$AE,$42,$60,$82);

data2inc is installed with fpc/lazarus ready for use.
I used a png file shipped with lazarus as the example above.


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bitmap-as-const-and-write-to-file-thingy

Marc Santhoff-2
In reply to this post by Tomas Hajny-2
On Thu, 2018-09-20 at 00:47 +0200, Tomas Hajny wrote:

> On Wed, September 19, 2018 23:58, Marc Santhoff wrote:
>
>
> Hi,
>
>  .
>  .
> > What I need:
> >
> > - A program taking a binary file and spitting out pascal code for the
> > const array. I know I have seen such program in the past, but do not know
> > where.
>
> data2inc is included with FPC.

FPC is amazing! Batteries included. :)

> > - Some hints on using this constant for making files out of them.
> > Currently I'm plannig to use a TFileStreaam writing out Bytes, should do.
>
> Indeed, should do; simple file of byte and BlockWrite should do as well.

I'll try soon,

Thank you very much.

--
Marc Santhoff <[hidden email]>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Bitmap-as-const-and-write-to-file-thingy

Marc Santhoff-2
In reply to this post by Bo Berglund
Oncemore using the correct from address...
Sorry moderation.

On Thu, 2018-09-20 at 23:45 +0200, Bo Berglund wrote:

> On Wed, 19 Sep 2018 23:58:36 +0200, Marc Santhoff
> <[hidden email]> wrote:
>
> > Any pointers or hints, please?
>
> You can convert any file you like to an inc file with pascal syntax:
>
> data2inc -A -B laz/images/ide_icon48x48.png datatest.inc icon48x48
>
> This will produce a datatest.inc file ready to be included in your
> project and with content looking like this:
>
> const icon48x48 : array[0..4236] of byte=(
>   $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,
> ....
>  $45,$4E,$44,$AE,$42,$60,$82);
>
> data2inc is installed with fpc/lazarus ready for use.
> I used a png file shipped with lazarus as the example above.

Done. Cool stuff. :)

Thanks.

--
Marc Santhoff <[hidden email]>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal