Author Topic: Tool for converting image to binary form for storing in FPGA  (Read 3469 times)

0 Members and 1 Guest are viewing this topic.

Offline davorinTopic starter

  • Supporter
  • ****
  • Posts: 922
  • Country: ch
Tool for converting image to binary form for storing in FPGA
« on: April 28, 2018, 03:02:08 pm »
EHLO (o;

Does someone know of a tool or script which can take a PNG/TIFF/whatever RGB image and convert it to a raw binary data representation for converting then to Intel HEX format which Altera Quartus accepts?

This is for testing my Verilog RGB panel driver design....
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8168
  • Country: fi
Re: Tool for converting image to binary form for storing in FPGA
« Reply #1 on: April 28, 2018, 04:15:08 pm »
GIMP can save a headerless RAW, just type in extension .data when saving. RGBRGB... and RRRBBBGGG formats are supported. Then, you only need to convert it to Intel HEX.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Tool for converting image to binary form for storing in FPGA
« Reply #2 on: April 28, 2018, 04:20:58 pm »
ImageMagick
https://www.imagemagick.org/script/index.php

Easier to script/integrate into a build system.
 

Offline davorinTopic starter

  • Supporter
  • ****
  • Posts: 922
  • Country: ch
Re: Tool for converting image to binary form for storing in FPGA
« Reply #3 on: April 28, 2018, 04:24:56 pm »
Tried ImageMagick with

convert icon.png icon.rgb

but output file seemed rubbish....thought convert recognizes input/output formats automatically.
The filesize was exact though for a 64x64 rgb image..
 

Offline Wiljan

  • Regular Contributor
  • *
  • Posts: 225
  • Country: dk
Re: Tool for converting image to binary form for storing in FPGA
« Reply #4 on: April 28, 2018, 05:17:00 pm »
Irfanview does save as RAW with different options
 

Offline chris_leyson

  • Super Contributor
  • ***
  • Posts: 1541
  • Country: wales
Re: Tool for converting image to binary form for storing in FPGA
« Reply #5 on: April 28, 2018, 05:32:33 pm »
Matlab or GNU Octave will do it.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Tool for converting image to binary form for storing in FPGA
« Reply #6 on: April 28, 2018, 06:05:58 pm »
Tried ImageMagick with

convert icon.png icon.rgb

but output file seemed rubbish....thought convert recognizes input/output formats automatically.
The filesize was exact though for a 64x64 rgb image..

Use the .raw extension instead and the "stream" tool:

stream input.png output.raw
« Last Edit: April 28, 2018, 06:10:56 pm by janoc »
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: Tool for converting image to binary form for storing in FPGA
« Reply #7 on: April 28, 2018, 08:00:13 pm »
Being old-school I save in PMN format, then use a short program, that can use the attributes in the human readable ASCII  header.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Tool for converting image to binary form for storing in FPGA
« Reply #8 on: April 29, 2018, 06:59:14 am »
Singe it’s an RGB panel, is there a reason not to use MSPaint to open the file, save as 24 bit MS bitmap, and then manually strip the header with a hex editor?
 

Offline davorinTopic starter

  • Supporter
  • ****
  • Posts: 922
  • Country: ch
Re: Tool for converting image to binary form for storing in FPGA
« Reply #9 on: April 29, 2018, 07:04:52 am »
Ah I see what the problem is...nothing to do with rgb conversion (o;

Did a small 64x64 rgb png with just a red dot on black backrground...
The generated hex file is correct and shows that the first occurrence of rad is at address 0x07CE (28):

Code: [Select]
:2007C00000000000000000000000000000002800005F00008F0000B90000DA0000F100007F

The used memory is organized as 24x4096...and when looking with the in-system memory controller....the same pattern appears at 24-bit word address:
So seems quartus messes up with the hex file when the memory is not organized as 8-bit wide..

 

Offline davorinTopic starter

  • Supporter
  • ****
  • Posts: 922
  • Country: ch
Re: Tool for converting image to binary form for storing in FPGA
« Reply #10 on: April 29, 2018, 07:50:11 am »
Seems there are no tools which can generate a 24-bit wide memory initialization file....

srec_cat supports mif files, but only with widths being a multiple of 8 like:

Code: [Select]
srec_cat icon.rgb -binary -output icon.mif -mif 1
srec_cat icon.rgb -binary -output icon.mif -mif 2
srec_cat icon.rgb -binary -output icon.mif -mif 4

Seems I have to split the rgb channels in 3 8-bit wide memories.

This are the commands used for generating 3 memory initialization files for Quartus:

Code: [Select]
convert image.png -separate image_%d.gray
srec_cat image_0.gray -binary -output image_0.mif -mif
srec_cat image_1.gray -binary -output image_1.mif -mif
srec_cat image_2.gray -binary -output image_2.mif -mif
« Last Edit: April 29, 2018, 08:39:40 am by davorin »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf