Convert images to .raw programs

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder:

You can then copy/paste the listing and post it in "code" tags.
Post Reply
User avatar
Posts: 13
Joined: Tue Feb 05, 2019 1:08 pm
Location: FR/CH/ES

Convert images to .raw programs

Post by nibheis » Wed Jun 12, 2019 3:26 pm

Hi all,

To follow up on this thread, here is a python3 script that turns any 400x240 image into a .raw program for the DM42 (and free42).

It is basically one single class (Img2Hex) - you only need PIL or pillow Python package to use it.
Here's how to use it:

Code: Select all

from img2hex import Img2Hex

hexcode = Img2Hex(filename = 'matterhorn.bmp', label = 'MATT', negative = False)
Assuming that 'matterhorn.bmp' is in the same directory, you will get a 'MATT.raw' program for your DM42, with LBL MATT.

You can also add payload into the program, like this:

Code: Select all

    # Prepare payload
    pl = {
        "V1": 1234,
        "V2": -3.1415,
        "VA": "Hello"
    hx = Img2Hex(filename = 'matterhorn.bmp', label = 'MATT', negative = False, verbose = False, payload = pl)
When you execute the program on the DM42, the "V1", "V2" and "VA" variables are set to the corresponding values.
(I use payloads while creating charts for the DM42: the payload contains the scale, center coordinates and name of the displayed chart - more on this chart plotting app in another thread soon.)

Enjoy !
(2.72 KiB) Downloaded 43 times

Post Reply