Jump to content
43oh

Generating image bitmaps for Nokia 7110 LCD


Recommended Posts

In oPossum's Time and Temperature project, there is an embedded TI logo that rolls across the screen when the program starts. Here is how you can generate bitmaps from your own images. You will need ImageMagick and python.

 

1) Resize your image to fit on the LCD. The maximum height is 96 pixels. The height should be a multiple of 8. Also, you will want to stretch your image horizontally a little bit, as pixels on 7110 aren't square.

 

I did something along the lines of

 

convert -resize 43x48! logo.jpg logo2.png

 

The exclamation point here tells ImageMagick to go ahead and change the aspect ratio of the image; otherwise it will set width (or height) automatically to maintain the original aspect ratio.

 

2) Convert the image to 1-bit black and white and save it in RGB format

 

convert -monochrome -depth 1 -type Bilevel +dither logo2.png logo3.rgb

 

The resulting file contains 3 bits for each pixel (red, green, and blue channels). The 3 bits are the same. 0 corresponds to black and 1 to white.

 

I wrote a short python script to convert RGB files to the format expected by nokia7110tl.h's bitmap() function:

 

import sys
import string
x = int(sys.argv[2])
y = int(sys.argv[3])
img = open(sys.argv[1]).read()
b = string.join([str(int(ord(img[i*3/8]) & (1<<(7-(i*3%8))) == 0))
                   for i in xrange(x*y)], '')
# b is a string that contains a 0 or 1 for each pixel of the image. If you now set
# the screen size to 'width' and print b, you should see your image in ascii.
# The next step is to rearrange the bits in b to match the
# addressing expected by 7110's controller.
b2 = ''
for i in reversed(xrange(y/8)):
 for j in xrange(x):
   b2 += string.join([b[(y-1-i*8-k)*x+j] for k in xrange(8)], '')
print string.join(['0x%02x' % eval('0b'+b2[i*8:i*8+8])
                 for i in xrange(x*y/8)], ',')

 

You run it like this:

 

python convert_7110.py logo3.rgb 43 48

 

where 43 is the width and 48 is the height of the image. The script spits out an array of ascii bytes that you can copy and paste directly into your C program and pass to the bitmap() function.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...