Commit 7803a2cc authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Checkout bitmap iles

parent 46fb09f2
#include <bitmaps.h>
static const uint8_t example_icon_data[] = {
0x2e,
0x81,
0x05,
0x81,
0x04,
0x81,
0x05,
0x82,
0x16,
0x80,
0x0d,
0x80,
0x0d,
0x80,
0x08,
0x80,
0x09,
0x80,
0x02,
0x80,
0x08,
0x81,
0x02,
0x81,
0x06,
0x81,
0x04,
0x83,
0x01,
0x82,
0x08,
0x83,
0x14};
const struct rle_bitmap example_icon = { 15, 15, example_icon_data };
static const uint8_t gps_receiving_data[] = {
0x06,
0x83,
0x0e,
0x80,
0x0a,
0x81,
0x01,
0x80,
0x04,
0x82,
0x03,
0x80,
0x01,
0x80,
0x02,
0x81,
0x06,
0x80,
0x00,
0x80,
0x01,
0x81,
0x03,
0x81,
0x01,
0x80,
0x00,
0x80,
0x01,
0x82,
0x00,
0x83,
0x03,
0x80,
0x01,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
const struct rle_bitmap gps_receiving = { 15, 15, gps_receiving_data };
static const uint8_t battery_data[] = {
0x8d,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x82,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x8d,
0x00};
const struct rle_bitmap battery = { 15, 12, battery_data };
static const uint8_t gps_disconnected_data[] = {
0x0a,
0x80,
0x0d,
0x80,
0x0b,
0x84,
0x03,
0x82,
0x04,
0x80,
0x04,
0x81,
0x06,
0x80,
0x03,
0x81,
0x03,
0x81,
0x06,
0x82,
0x00,
0x83,
0x06,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
const struct rle_bitmap gps_disconnected = { 15, 15, gps_disconnected_data };
static const uint8_t battery_charging_data[] = {
0x8d,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x80,
0x05,
0x81,
0x03,
0x82,
0x04,
0x84,
0x01,
0x82,
0x00,
0x86,
0x03,
0x82,
0x00,
0x86,
0x03,
0x82,
0x04,
0x84,
0x01,
0x82,
0x05,
0x81,
0x03,
0x82,
0x0b,
0x80,
0x00,
0x80,
0x0b,
0x80,
0x00,
0x8d,
0x00};
const struct rle_bitmap battery_charging = { 15, 12, battery_charging_data };
static const uint8_t gps_searching_data[] = {
0x0c,
0x80,
0x0c,
0x80,
0x13,
0x82,
0x03,
0x80,
0x05,
0x81,
0x04,
0x80,
0x05,
0x81,
0x03,
0x81,
0x06,
0x82,
0x00,
0x83,
0x06,
0x82,
0x02,
0x80,
0x07,
0x83,
0x01,
0x80,
0x01,
0x80,
0x05,
0x83,
0x03,
0x80,
0x06,
0x84,
0x00,
0x81,
0x07,
0x85,
0x0a,
0x81,
0x09,
0x84,
0x08,
0x86,
0x05};
const struct rle_bitmap gps_searching = { 15, 15, gps_searching_data };
#ifndef BITMAPS_H
#define BITMAPS_H
#include <stdint.h>
struct rle_bitmap
{
uint8_t w;
uint8_t h;
uint8_t *data;
};
extern const struct rle_bitmap example_icon;
extern const struct rle_bitmap gps_receiving;
extern const struct rle_bitmap battery;
extern const struct rle_bitmap gps_disconnected;
extern const struct rle_bitmap battery_charging;
extern const struct rle_bitmap gps_searching;
#endif /* BITMAPS_H */
#!/usr/bin/python
import sys
import math
import numpy
import os
import os.path
from PIL import Image
def pixel_to_bit(pixel,threshold=128):
"""Convert the pixel value to a bit."""
if pixel[0] > threshold:
return 1
else:
return 0
def convert(im, name):
name = name.split('.')[0]
f = open("bitmaps.c",'a')
pix = im.load()
f.write("static const uint8_t %s_data[] = {\n"%name);
for y in range(0, im.size[1]):
for x in range(0, im.size[0]):
if(x==0 and y==0):
prev = pix[0, 0][0]
l=0
else:
cur = pix[x, y][0]
if(cur!=prev or l == 127):
if(prev):
f.write(" 0x%02x,\n" % (l))
else:
f.write(" 0x%02x,\n" % (l | 0x80))
l = 0
else:
l=l+1
prev=cur
if(prev):
f.write(" 0x%02x" % (l))
else:
f.write(" 0x%02x" % (l | 0x80))
f.write("};\n");
f.write("const struct rle_bitmap %s = { %d, %d, %s_data };\n\n" % (name, im.size[0], im.size[1], name));
f.close()
f = open("bitmaps.h",'a')
f.write("extern const struct rle_bitmap %s;\n" % name);
f.close()
#
# Main script begins here.
#
# Clean the previous output
if os.path.isfile("bitmaps.c"):
os.remove("bitmaps.h")
if os.path.isfile("bitmaps.c"):
os.remove("bitmaps.c")
# Write headers
f = open("bitmaps.h", 'a')
f.write("""#ifndef BITMAPS_H
#define BITMAPS_H
#include <stdint.h>
struct rle_bitmap
{
uint8_t w;
uint8_t h;
uint8_t *data;
};
""")
f.close()
f = open("bitmaps.c", 'a')
f.write("#include <bitmaps.h>\n\n")
f.close()
#
# Process .bmp files in the current directory
#
for file in os.listdir("."):
if file.endswith(".bmp"):
try:
print("Processing: " + file)
im = Image.open(file)
width,height = im.size
print("format : %s" % im.format)
print("mode : %s" % im.mode)
print("palette : %s" % im.palette)
print("size : %dx%d" % (width, height))
convert(im, file)
except:
# Eventually this should give more useful information (e.g. file does not
# exist, or not an image file, or ...
print("Unable to open " + file)
f = open("bitmaps.h", 'a')
f.write("\n#endif /* BITMAPS_H */\n")
f.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment