I have a raw binary file containing color (RGB, 1byte per channel) with band interleaved by pixel (BIP) layout that I'd like to translate to a PNG. I could probably use some other non-GIS specific tool for this (recommendations welcome), but I'd prefer to use gdal_translate since it's already in my pipeline and has done a good job of translating other formats for me.
Is it possible to use raw files as input to gdal_translate?
Best Answer
You have an 8 bit 3 band binary file, interleaved by pixel. Assuming you don't already have a header file that GDAL understands and you know the number of columns and rows, you can create (in code or by hand) a VRT file that describes the layout of the binary file so that GDAL can read it. Write something like the following to a file (can be called anything you like)
From the GDAL VRT tutorial:
So the only things you'll need to change in the example are rasterXSize, rasterYSize, SourceFilename and LineOffset. LineOffset will be 3 x rasterXSize.
You can then use
gdal_translate
to convert the VRT to PNG:gdal_translate {appropriate options if required} /path/to/file.vrt /path/to/file.png