summaryrefslogtreecommitdiff
path: root/NxWidgets/tools
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-11-09 14:54:29 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-11-09 14:54:29 +0000
commit42a56e78dda5561d301ec2e61a0bac17e7342525 (patch)
tree5dec10051ddb12ddf1d6d7f02c69d09ad2a27895 /NxWidgets/tools
parent2b35c03044dc6acfe720522f943ee07df1b65897 (diff)
downloadnuttx-42a56e78dda5561d301ec2e61a0bac17e7342525.tar.gz
nuttx-42a56e78dda5561d301ec2e61a0bac17e7342525.tar.bz2
nuttx-42a56e78dda5561d301ec2e61a0bac17e7342525.zip
Several patches from Petteri Aimonen (mostly NxWidgets)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5324 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/tools')
-rwxr-xr-xNxWidgets/tools/README.txt51
-rwxr-xr-xNxWidgets/tools/bitmap_converter.py148
-rwxr-xr-xNxWidgets/tools/install.sh2
3 files changed, 201 insertions, 0 deletions
diff --git a/NxWidgets/tools/README.txt b/NxWidgets/tools/README.txt
new file mode 100755
index 000000000..22b2bf2a9
--- /dev/null
+++ b/NxWidgets/tools/README.txt
@@ -0,0 +1,51 @@
+NxWidgets/tools README File
+===========================
+
+addobjs.sh
+----------
+
+ $0 will add all object (.o) files in directory to an archive.
+
+ Usage: tools/addobjs.sh [OPTIONS] <lib-path> <obj-dir>
+
+ Where:
+ <lib-path> is the full, absolute path to the library to use
+ <obj-dir> is full path to the directory containing the object files to be added
+ OPTIONS include:
+ -p Prefix to use. For example, to use arm-elf-ar, add '-p arm-elf-'
+ -w Use Windows style paths insted of POSIX paths
+ -d Enable script debug
+ -h Show this usage information
+
+bitmap_converter.py
+-------------------
+
+ This script converts from any image type supported by Python imaging library to
+ the RLE-encoded format used by NxWidgets.
+
+indent.sh
+---------
+
+ This script uses the Linux 'indent' utility to re-format C source files
+ to match the coding style that I use. It differs from my coding style in that
+
+ - I normally put the traiing */ of a multi-line comment on a separate line,
+ - I usually align things vertically (like '='in assignments.
+
+install.sh
+----------
+
+ Install a unit test in the NuttX source tree"
+
+ USAGE: tools/install.sh <apps-directory-path> <test-sub-directory>
+
+ Where:
+ <apps-directory-path> is the full, absolute path to the NuttX apps/ directory
+ <test-sub-directory> is the name of a sub-directory in the UnitTests directory
+
+zipme.sh
+--------
+
+ Pack up the NxWidgets tarball for release.
+
+ USAGE: tools/zipme.sh <version>
diff --git a/NxWidgets/tools/bitmap_converter.py b/NxWidgets/tools/bitmap_converter.py
new file mode 100755
index 000000000..2cb7e8869
--- /dev/null
+++ b/NxWidgets/tools/bitmap_converter.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env python
+
+'''This script converts from any image type supported by
+Python imaging library to the RLE-encoded format used by
+NxWidgets.
+'''
+
+from PIL import Image
+
+def get_palette(img, maxcolors = 255):
+ '''Returns a list of colors. If there are too many colors in the image,
+ the least used are removed.
+ '''
+ img = img.convert("RGB")
+ colors = img.getcolors(65536)
+ colors.sort(key = lambda c: -c[0])
+ return [c[1] for c in colors[:maxcolors]]
+
+def write_palette(outfile, palette):
+ '''Write the palette (normal and hilight) to the output file.'''
+
+ outfile.write('static const NXWidgets::nxwidget_pixel_t palette[BITMAP_PALETTESIZE] =\n');
+ outfile.write('{\n')
+
+ for i in range(0, len(palette), 4):
+ outfile.write(' ');
+ for r, g, b in palette[i:i+4]:
+ outfile.write('MKRGB(%3d,%3d,%3d), ' % (r, g, b))
+ outfile.write('\n');
+
+ outfile.write('};\n\n')
+
+ outfile.write('static const NXWidgets::nxwidget_pixel_t hilight_palette[BITMAP_PALETTESIZE] =\n');
+ outfile.write('{\n')
+
+ for i in range(0, len(palette), 4):
+ outfile.write(' ');
+ for r, g, b in palette[i:i+4]:
+ r = min(255, r + 50)
+ g = min(255, g + 50)
+ b = min(255, b + 50)
+ outfile.write('MKRGB(%3d,%3d,%3d), ' % (r, g, b))
+ outfile.write('\n');
+
+ outfile.write('};\n\n')
+
+
+def quantize(color, palette):
+ '''Return the color index to closest match in the palette.'''
+ try:
+ return palette.index(color)
+ except ValueError:
+ # No exact match, search for the closest
+ def distance(color2):
+ return sum([(a - b)**2 for a, b in zip(color, color2)])
+
+ return palette.index(min(palette, key = distance));
+
+def encode_row(img, palette, y):
+ '''RLE-encode one row of image data.'''
+ entries = []
+ color = None
+ repeats = 0
+
+ for x in range(0, img.size[0]):
+ c = quantize(img.getpixel((x, y)), palette)
+ if c == color:
+ repeats += 1
+ else:
+ if color is not None:
+ entries.append((repeats, color))
+
+ repeats = 1
+ color = c
+
+ if color is not None:
+ entries.append((repeats, color))
+
+ return entries
+
+def write_image(outfile, img, palette):
+ '''Write the image contents to the output file.'''
+
+ outfile.write('static const NXWidgets::SRlePaletteBitmapEntry bitmap[] =\n');
+ outfile.write('{\n');
+
+ for y in range(0, img.size[1]):
+ entries = encode_row(img, palette, y)
+ row = ""
+ for r, c in entries:
+ if len(row) > 60:
+ outfile.write(' ' + row + '\n')
+ row = ""
+
+ row += '{%3d, %3d}, ' % (r, c)
+
+ row += ' ' * (73 - len(row))
+ outfile.write(' ' + row + '/* Row %d */\n' % y)
+
+ outfile.write('};\n\n');
+
+def write_descriptor(outfile, name):
+ '''Write the public descriptor structure for the image.'''
+
+ outfile.write('extern const struct NXWidgets::SRlePaletteBitmap g_%s =\n' % name)
+ outfile.write('{\n')
+ outfile.write(' CONFIG_NXWIDGETS_BPP,\n')
+ outfile.write(' CONFIG_NXWIDGETS_FMT,\n')
+ outfile.write(' BITMAP_PALETTESIZE,\n')
+ outfile.write(' BITMAP_WIDTH,\n')
+ outfile.write(' BITMAP_HEIGHT,\n')
+ outfile.write(' {palette, hilight_palette},\n')
+ outfile.write(' bitmap\n')
+ outfile.write('};\n')
+
+if __name__ == '__main__':
+ import sys
+ import os.path
+
+ if len(sys.argv) != 3:
+ print "Usage: bitmap_converter.py source.png output.cxx"
+ sys.exit(1)
+
+ img = Image.open(sys.argv[1])
+ outfile = open(sys.argv[2], 'w')
+ palette = get_palette(img)
+
+ outfile.write(
+'''
+/* Automatically NuttX bitmap file. */
+/* Generated from %(src)s by bitmap_converter.py. */
+
+#include <nxconfig.hxx>
+#include <crlepalettebitmap.hxx>
+
+#define BITMAP_WIDTH %(width)s
+#define BITMAP_HEIGHT %(height)s
+#define BITMAP_PALETTESIZE %(palettesize)s
+
+''' % {'src': sys.argv[1], 'width': img.size[0], 'height': img.size[1],
+ 'palettesize': len(palette)}
+ )
+
+ name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
+
+ write_palette(outfile, palette)
+ write_image(outfile, img, palette)
+ write_descriptor(outfile, name)
diff --git a/NxWidgets/tools/install.sh b/NxWidgets/tools/install.sh
index 6917b4b03..dd212b5a6 100755
--- a/NxWidgets/tools/install.sh
+++ b/NxWidgets/tools/install.sh
@@ -40,6 +40,8 @@
function ShowUsage()
{
echo ""
+ echo "Install a unit test in the NuttX source tree"
+ echo ""
echo "USAGE: $0 <apps-directory-path> <test-sub-directory>"
echo ""
echo "Where:"