Any library or tips on how to create a compatible eInk image at runtime

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
GeIo_1586191
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

At the moment if I want to create a suitable byte array for an image to be displayed on the eInk display, I first need to convert my 264px x 176px bitmap into a "variable array" using the manufacturer's PDI Apps utility program.

This works fine for hardcoding but now I want to create an application which includes some QR code generator code (you can find various libraries on github etc.) whereby I can create a compatible eInk image at runtime. The idea for the example app is to allow someone to send a text string via Bluetooth and for a QR code to be generated and displayed on the eInk display.

The problem now is that it is not obvious how the PDI App converts the bitmap. The methodology appears to have changed compared to the old eInk displays.

So, does anyone have a conversion library that will do this or does anyone have some tips on how to do it?

I have reviewed Appendix B of the example "CE218133 - PSoC 6 MCU E-INK Display with CapSense" document but none the wiser.

Thanks

G//

.

0 Likes
1 Solution
Anonymous
Not applicable

Hi,

i did this with a python script. You can implement this in c if you have all pixel values as array.

from PIL import Image

import numpy as np

import os

import matplotlib.pyplot as plt

import binascii

img = Image.open("eink.jpg")

n_img = np.asarray(img)

n_img = n_img[:,:,0]

height, width = n_img.shape[:2]

op = "output.c"

oS = "/* Cypress custom image */" + os.linesep

oS += "cy_eink_image_t const pyimg[CY_EINK_IMAGE_SIZE]=" + os.linesep

oS += "{" + os.linesep

testImg = np.zeros((height,width))

for y in range(height): #rows

    for x in range(width/8): # columns

        intVal = 0

        for i in range(0,8): # 8 pixel in x = 1 byte

            boolVal = int(n_img[y,8*x+i] > 127 )

            intVal += boolVal << (7-i)

            testImg[y,8*x+i] = boolVal

        hexString = '0x{:02x}'.format(intVal).upper().replace("X","x")

        oS += hexString + ", "

    if y == height - 1:

        oS = oS[:-2]

    oS += " // " + str(y+1) + os.linesep

oS += "};" + os.linesep

with open(op, "w+") as outFile:

    outFile.write(oS)

plt.imshow(testImg)

plt.show()

You go row for row and for each column byte combine 8 pixel (boolean, 1 or 0) to one byte. I Think the most significant bit ist the left most pixel. Its mostly bit shifting.

View solution in original post

3 Replies
Anonymous
Not applicable

Hi,

i did this with a python script. You can implement this in c if you have all pixel values as array.

from PIL import Image

import numpy as np

import os

import matplotlib.pyplot as plt

import binascii

img = Image.open("eink.jpg")

n_img = np.asarray(img)

n_img = n_img[:,:,0]

height, width = n_img.shape[:2]

op = "output.c"

oS = "/* Cypress custom image */" + os.linesep

oS += "cy_eink_image_t const pyimg[CY_EINK_IMAGE_SIZE]=" + os.linesep

oS += "{" + os.linesep

testImg = np.zeros((height,width))

for y in range(height): #rows

    for x in range(width/8): # columns

        intVal = 0

        for i in range(0,8): # 8 pixel in x = 1 byte

            boolVal = int(n_img[y,8*x+i] > 127 )

            intVal += boolVal << (7-i)

            testImg[y,8*x+i] = boolVal

        hexString = '0x{:02x}'.format(intVal).upper().replace("X","x")

        oS += hexString + ", "

    if y == height - 1:

        oS = oS[:-2]

    oS += " // " + str(y+1) + os.linesep

oS += "};" + os.linesep

with open(op, "w+") as outFile:

    outFile.write(oS)

plt.imshow(testImg)

plt.show()

You go row for row and for each column byte combine 8 pixel (boolean, 1 or 0) to one byte. I Think the most significant bit ist the left most pixel. Its mostly bit shifting.

briancolgan
Level 1
Level 1
5 questions asked 5 sign-ins First comment on KBA

I know this is an old thread but for anyone who comes across this thread, I found this tool very useful for converting images into a C-array of hex values.

Convert picture to C code array