Commit 332d1e05 authored by Projects's avatar Projects

bmp2rle: Processes all files in a directory and outputs a single pair of .c & .h files.

parent 9e16582c
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};
static const struct rle_bitmap battery = { 15, 12, battery_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};
static const struct rle_bitmap battery_charging = { 15, 12, battery_charging_data };
#include <bitmaps.h>
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 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
......@@ -3,6 +3,8 @@
import sys
import math
import numpy
import os
import os.path
from PIL import Image
def pixel_to_bit(pixel,threshold=128):
......@@ -13,17 +15,13 @@ def pixel_to_bit(pixel,threshold=128):
return 0
def convert(im, name):
name = name.split('.')[0]
f = open(name+".h",'w')
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]):
for x in range(0, im.size[0]):
if(x==0 and y==0):
prev = pix[0, 0][0]
l=0
......@@ -40,48 +38,72 @@ def convert(im, name):
prev=cur
if(prev):
f.write(" 0x%02x" % (l))
f.write(" 0x%02x" % (l))
else:
f.write(" 0x%02x" % (l | 0x80))
f.write(" 0x%02x" % (l | 0x80))
f.write("};\n");
f.write("static const struct rle_bitmap %s = { %d, %d, %s_data };\n" % (name, im.size[0], im.size[1], name));
f.close()
print "RLE encoded image written to: %s.h\n"%name
f.write("const struct rle_bitmap %s = { %d, %d, %s_data };\n\n" % (name, im.size[0], im.size[1], name));
f.close()
def use():
print "Use: bmp2array.py imagefile"
f = open("bitmaps.h",'a')
f.write("extern const struct rle_bitmap %s;\n" % name);
f.close()
#
# Main script begins here.
#
# First check for keyword arguments on the command line.
#
if len(sys.argv) > 2:
print "Too many arghuments."
use()
exit(-1)
# Clean the previous output
if os.path.isfile("bitmaps.c"):
os.remove("bitmaps.h")
if os.path.isfile("bitmaps.c"):
os.remove("bitmaps.c")
#
# Open the image file and get the basic information about it.
#
try:
im = Image.open(sys.argv[1])
except:
# Eventually this should give more useful information (e.g. file does not
# exist, or not an image file, or ...
print "Unable to open %s" % sys.argv[1]
exit(-1)
# Write headers
f = open("bitmaps.h", 'a')
f.write("""#ifndef BITMAPS_H
#define BITMAPS_H
width,height = im.size
print "\nfile : %s\nformat : %s\nmode : %s\npalette : %s\nsize : %dx%d\n" % (sys.argv[1], im.format, im.mode, im.palette, width, height)
#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()
#
# Do it!
# Process .bmp files in the current directory
#
convert(im, sys.argv[1])
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()
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};
static const struct rle_bitmap gps_disconnected = { 15, 15, gps_disconnected_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};
static const struct rle_bitmap gps_receiving = { 15, 15, gps_receiving_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};
static const struct rle_bitmap gps_searching = { 15, 15, gps_searching_data };
......@@ -112,6 +112,7 @@ LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
INCLUDEPATHS += \
-Isrc \
-IFreeRTOS/Source/include \
-I../bitmaps \
-I../common/CMSIS/Include \
-I../common/Device/EnergyMicro/EFM32GG/Include \
-I../common \
......@@ -123,6 +124,7 @@ INCLUDEPATHS += \
####################################################################
C_SRC += \
../bitmaps/bitmaps.c \
../common/Device/EnergyMicro/EFM32GG/Source/system_efm32gg.c \
../common/emlib/src/em_assert.c \
../common/emlib/src/em_burtc.c \
......
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