Skip to content

Commit

Permalink
mkpack: add image resources (#130)
Browse files Browse the repository at this point in the history
* mkpack: add image resources

these are crushed with a function imported from the SDK

* Remove expand_user function

* Move crush_png in global scope
  • Loading branch information
Helco authored and jwise committed Oct 23, 2018
1 parent ded87b9 commit 8e7ae6a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions Utilities/mkpack.py
Expand Up @@ -38,10 +38,43 @@
from stm32_crc import crc32
import struct
import json
import os
import sys

crush_png = None # To be imported

TAB_OFS = 0x0C
RES_OFS = 0x200C

def find_pebble_sdk():
"""
Returns a valid path to the currently installed pebble sdk or
nothing if none was found.
"""

for path in [
"~/Library/Application Support/Pebble SDK/SDKs/current",
"~/.pebble-sdk/SDKs/current"
]:
if os.path.isdir(os.path.expanduser(path)):
return os.path.expanduser(path)

return None

def import_crush_png(sdk_path):
"""
Activates the sdks virtual environment and dynamically imports
the png2pblpng functionality
"""

activate_this = os.path.join(sdk_path, ".env/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))

sys.path.append(os.path.join(sdk_path, "sdk-core/pebble/common/tools/"))
from png2pblpng import convert_png_to_pebble_png_bytes
return convert_png_to_pebble_png_bytes


def load_resource_from_pbpack(fname, resid):
"""
Returns resource number |resid| from the pbpack file specified by
Expand Down Expand Up @@ -157,6 +190,22 @@ def data(self):
def sourcedesc(self):
return self.file

class ResourceImage(Resource):
def __init__(self, coll, j, palette):
super(self.__class__, self).__init__(coll, j)

self.file = "{}/{}".format(self.coll.root, j["input"]["file"])
self.palette = palette

def deps(self):
return [self.file]

def data(self):
return crush_png(self.file, self.palette)

def sourcedesc(self):
return "imported image " + self.file

class ResourceCollection:
"""
A collection of resources, as defined by a dictionary loaded from a JSON
Expand Down Expand Up @@ -199,13 +248,18 @@ def __init__(self, fname, root = "."):
self.references = {k: "{}/{}".format(self.root, v) for k, v in jdb["references"].items()}
else:
self.references = {}

if "palette" not in jdb:
raise ValueError("palette is not set")

self.resources = []
for res in jdb["resources"]:
if res["input"]["type"] == "file":
self.resources.append(ResourceFile(self, res))
elif res["input"]["type"] == "resource":
self.resources.append(ResourceRef(self, res))
elif res["input"]["type"] == "image":
self.resources.append(ResourceImage(self, res, jdb["palette"]))
else:
raise ValueError("unknown resource type {}".format(res["type"]))

Expand Down Expand Up @@ -284,9 +338,18 @@ def main():
parser.add_argument("-M", "--make-dep", action="store_true", default = False, help = "produce a .d file to be included by 'make'")
parser.add_argument("-H", "--header", action = "store_true", default = False, help = "produce a .h file to be included in C source")
parser.add_argument("-P", "--pbpack", action = "store_true", default = False, help = "produce a .pbpack file")
parser.add_argument("-s", "--sdk", nargs=1, default = [None], help = "pathname to pebble sdk")
parser.add_argument("json", help = "input JSON configuration file")
parser.add_argument("basename", help = "base output name ('.d', '.h', and '.pbpack' are appended automatically)")
args = parser.parse_args()

sdk_path = find_pebble_sdk()
if args.sdk[0] is not None:
sdk_path = os.path.expanduser(args.sdk[0])
if not os.path.isdir(sdk_path):
raise ValueError("could not find pebble sdk, please provide one with --sdk")
global crush_png
crush_png = import_crush_png(sdk_path)

rc = ResourceCollection(args.json, root = args.root[0])

Expand Down
2 changes: 1 addition & 1 deletion lib/neographics
Submodule neographics updated 88 files
+155 −0 CMakeLists.txt
+15 −0 contrib/pebble_env/pebble.c
+72 −0 contrib/pebble_env/pebble.h
+322 −0 contrib/testrunner_pc/resources.c
+21 −0 contrib/testrunner_pc/stb_impl.c
+228 −0 contrib/testrunner_pc/testrunner.c
+56 −0 contrib/testrunner_pc/testrunner.h
+32 −0 contrib/testrunner_pc/tests.c
+99 −0 contrib/testrunner_pc/utils.c
+5 −4 src/context.c
+15 −1 src/context.h
+64 −0 src/gbitmap/blit.h
+80 −0 src/gbitmap/blit_bw.c
+120 −0 src/gbitmap/blit_color.c
+249 −0 src/gbitmap/gbitmap.c
+120 −0 src/gbitmap/gbitmap.h
+6 −4 src/macros.h
+1 −1 src/primitives/rect.c
+13 −2 src/types/color.h
+6 −0 src/types/point.h
+81 −2 src/types/rect.c
+32 −6 src/types/rect.h
+6 −0 src/types/size.h
+ test/resources/blit_bigsmiley.png
+ test/resources/blit_blending.png
+ test/resources/blit_smiley.png
+ test/resources/rect/blit_assign1bit.png
+ test/resources/rect/blit_assign1bitpalette.png
+ test/resources/rect/blit_assign2bitpalette.png
+ test/resources/rect/blit_assign4bitpalette.png
+ test/resources/rect/blit_assign8bit.png
+ test/resources/rect/blit_biggerthanscreen.png
+ test/resources/rect/blit_blending4bitpalette.png
+ test/resources/rect/blit_blending8bit.png
+ test/resources/rect/blit_compopand.png
+ test/resources/rect/blit_compopclear.png
+ test/resources/rect/blit_compopinverted.png
+ test/resources/rect/blit_compopor.png
+ test/resources/rect/blit_compopset.png
+ test/resources/rect/blit_fullyclipped.png
+ test/resources/rect/blit_partiallyclipped.png
+ test/resources/rect/blit_tiling1bit.png
+ test/resources/rect/blit_tiling4bitpalette.png
+ test/resources/rect/blit_tiling8bit.png
+ test/resources/rect/test_checker_full.png
+ test/resources/rect_bw/blit_assign1bit.png
+ test/resources/rect_bw/blit_assign1bitpalette.png
+ test/resources/rect_bw/blit_assign2bitpalette.png
+ test/resources/rect_bw/blit_assign4bitpalette.png
+ test/resources/rect_bw/blit_biggerthanscreen.png
+ test/resources/rect_bw/blit_blending4bitpalette.png
+ test/resources/rect_bw/blit_compopand.png
+ test/resources/rect_bw/blit_compopclear.png
+ test/resources/rect_bw/blit_compopinverted.png
+ test/resources/rect_bw/blit_compopor.png
+ test/resources/rect_bw/blit_compopset.png
+ test/resources/rect_bw/blit_fullyclipped.png
+ test/resources/rect_bw/blit_partiallyclipped.png
+ test/resources/rect_bw/blit_tiling1bit.png
+ test/resources/rect_bw/blit_tiling4bitpalette.png
+ test/resources/rect_bw/test_checker_full.png
+ test/resources/round/blit_assign1bit.png
+ test/resources/round/blit_assign1bitpalette.png
+ test/resources/round/blit_assign2bitpalette.png
+ test/resources/round/blit_assign4bitpalette.png
+ test/resources/round/blit_assign8bit.png
+ test/resources/round/blit_biggerthanscreen.png
+ test/resources/round/blit_blending4bitpalette.png
+ test/resources/round/blit_blending8bit.png
+ test/resources/round/blit_compopand.png
+ test/resources/round/blit_compopclear.png
+ test/resources/round/blit_compopinverted.png
+ test/resources/round/blit_compopor.png
+ test/resources/round/blit_compopset.png
+ test/resources/round/blit_fullyclipped.png
+ test/resources/round/blit_partiallyclipped.png
+ test/resources/round/blit_tiling1bit.png
+ test/resources/round/blit_tiling4bitpalette.png
+ test/resources/round/blit_tiling8bit.png
+ test/resources/round/test_checker_full.png
+ test/resources/test_checker.png
+1 −0 test/resources/test_helloworld.txt
+224 −0 test/test.h
+340 −0 test/test_blit.h
+179 −0 test/test_gbitmap.h
+204 −0 test/test_test.h
+45 −0 test/test_types.h
+4 −0 test/tests.h

0 comments on commit 8e7ae6a

Please sign in to comment.