Skip to content

Commit

Permalink
version 1.2, keep image colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp committed Apr 26, 2021
1 parent 8db4d45 commit 3f68614
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
2021-04-10 Decca (Philipp)
* Version 1.0
* Initial release

2021-04-17 Decca (Philipp)
* Version 1.1
* Choose any supported scripting language

2021-04-26 Decca (Philipp)
* Version 1.2
* Keep colors of image instead of default palette
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ And 2 colors will result in **four pages** of the same size for each type. You c
See this [animation](https://user-images.githubusercontent.com/1101448/92115601-5b25ce80-edfb-11ea-8153-3abc187153ac.gif) for a better explaination/usage of the [sprite editor](https://user-images.githubusercontent.com/1101448/92114828-2a916500-edfa-11ea-9905-0650335f5860.png).

But there is currently no easy way to use these extended capabilities with images made outside the [TIC-80](https://tic80.com/). The *import*-[command](https://github.com/nesbox/TIC-80/wiki/Console#available-commands) used with the [sprite editor](https://user-images.githubusercontent.com/1101448/92114828-2a916500-edfa-11ea-9905-0650335f5860.png) will always fall back to **one** page (128 x 128 pixels) with 16 colors each.
But **TicMcTile** comes to the rescue. It will convert your images (no matter if 16, 4 or 2 colors) into a .lua-file with the correct _encoding_ of the data. This file can then directly be used by the [TIC-80](https://tic80.com/) and its [sprite editor](https://user-images.githubusercontent.com/1101448/92114358-5d872900-edf9-11ea-8252-35b9c5c27083.png).
But **TicMcTile** comes to the rescue. It will convert your images (no matter if 16, 4 or 2 colors) into a script-file with the correct _encoding_ of the data. This file can then directly be used by the [TIC-80](https://tic80.com/) and its [sprite editor](https://user-images.githubusercontent.com/1101448/92114358-5d872900-edf9-11ea-8252-35b9c5c27083.png).

You can convert a **singlepage**-image (128x128 or smaller) and assign it to one of the avaliable pages, or you can use **multipage**-images. When using 4 colors, a **multipage** can be
**max. 256 pixels** wide & 128 pixels high. In case of 2 colors, a **multipage** can be **max. 512 pixels** wide & 128 pixels high. You can select whether the image(s) should be converted to tiles (default) or sprites.
You can convert a **singlepage**-image (128x128 or smaller) and assign it to one of the avaliable pages, or you can use **multipage**-images. When using **4** colors, a **multipage** can be
**max. 256 pixels** wide & 128 pixels high. In case of **2** colors, a **multipage** can be **max. 512 pixels** wide & 128 pixels high. You can select whether the image(s) should be converted to tiles (default) or sprites.

Only images with **16 colors or less** are supported, for obvious reasons. These images should consist of [indexed colors](https://en.wikipedia.org/wiki/Indexed_color) or have a [color-palette](https://en.wikipedia.org/wiki/Palette_(computing)). Truecolor-images will be converted, but results may vary. Also make sure, that images match the [color-palette](https://github.com/nesbox/TIC-80/wiki/palette) [(SWEETIE-16)](https://lospec.com/palette-list/sweetie-16) of the **TIC-80**. Custom palettes are not yet supported.
Only images with **16 colors or less** are supported, for obvious reasons. These images should consist of [indexed colors](https://en.wikipedia.org/wiki/Indexed_color) or have a [color-palette](https://en.wikipedia.org/wiki/Palette_(computing)). Truecolor-images will be converted, but results may vary. Make sure, that images match the [color-palette](https://github.com/nesbox/TIC-80/wiki/palette) [(SWEETIE-16)](https://lospec.com/palette-list/sweetie-16) of the **TIC-80**. Or tell **TicMcTile** to keep the colors of your image by replacing the default ones.


Requirements
Expand Down Expand Up @@ -97,7 +97,13 @@ Save the tiles or sprites to a different memory bank, there is only 1 by default

In the PRO Version of TIC-80 there are 8 memory banks instead of only 1.

Keep the colors of the image file instead of using the default ones:

$ ticmctile.py ownpalette-16colors.png -o mynicepalette.lua -k

16 colors will replace the whole palette, 4 or 2 colors will only replace the first palette entries.


Commandline options
===================

Expand All @@ -116,6 +122,7 @@ Commandline options
-s, --sprites export as sprites (FG) instead of tiles (BG)
-p, --page start page (1-3) for tiles/sprites, default is 0
-b, --bank memory bank (1-7) for TIC-80 PRO version, default is 1
-k, --keep keep colors of imagefile to adjust the TIC-80 palette
-v, --version show version info
-h, --help show this help
Expand All @@ -127,7 +134,8 @@ Commandline options
The data can be saved as sprites (-s / --sprites) instead of tiles.
Tiles/sprites can start on a different page (-p / --page) instead of 0.
In the PRO version of TIC-80 there are up to 8 memory banks (-b / --bank)
to store the tiles/sprites, instead of only one.
to store the tiles/sprites, instead of only one. The colors of the image can
be kept (-k / --keep), replacing the default colors (Sweetie-16) of the TIC-80.

examples:
ticmctile imagefile.png
Expand All @@ -137,6 +145,7 @@ Commandline options
ticmctile goblins.gif -o sprites.txt -s
ticmctile font.png -o lettering.lua -p 2
ticmctile tilesgalore.gif -o membank3.lua -b 3
ticmctile nicecolors.png -o mypalette.lua -k


Files
Expand All @@ -148,13 +157,14 @@ Files
* **singlepage-16colors.png** (example image with 16 colors, [original](https://demozoo.org/graphics/3719/) by Decca/Lego)
* **multipage-2colors.png** (3 pages with 2 colors, [originals](https://demozoo.org/graphics/3719/) [both](https://demozoo.org/graphics/115000/) by Decca/Lego, font from [Chartist](https://github.com/PhilSwiss/chartist))
* **multipage-4colors.png** (2 pages with 4 colors, [originals](https://demozoo.org/graphics/3719/) [both](https://demozoo.org/graphics/115000/) by Decca/Lego)
* **ownpalette-16colors.png** (example image with an own palette, [original](https://demozoo.org/graphics/3719/) by Decca/Lego)


Future ideas
============

* Output of other languages than Lua, e.g. JavaScript - **Done**, implemented in version [1.1](https://github.com/PhilSwiss/ticmctile/tree/version1.1)
* keeping the color-palette of the image, instead of using the default palette
* keeping the color-palette of the image, instead of using the default palette - **Done**, implemented in version [1.2](https://github.com/PhilSwiss/ticmctile/tree/version1.2)
* Real compression of the values incl. a small decompressor for [Lua](https://www.lua.org/)


Expand Down
32 changes: 27 additions & 5 deletions ticmctile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Hint: python -m pip install pillow (install PIL on Windows)
#
# last updated by Decca / RiFT on 17.04.2021 23:20
# last updated by Decca / RiFT on 26.04.2021 14:00
#

# import modules
Expand All @@ -30,6 +30,7 @@ def error(self, message):
" -s, --sprites export as sprites (FG) instead of tiles (BG)\n"
" -p, --page start page (1-3) for tiles/sprites, default is 0\n"
" -b, --bank memory bank (1-7) for TIC-80 PRO version, default is 1\n"
" -k, --keep keep colors of imagefile to adjust the TIC-80 palette\n"
" -v, --version show version info\n"
" -h, --help show this help\n"
"\n"
Expand All @@ -41,7 +42,8 @@ def error(self, message):
"The data can be saved as sprites instead of tiles (-s / --sprites).\n"
"Tiles/sprites can start on a different page (-p / --page) instead of 0.\n"
"In the PRO version of TIC-80 there are up to 8 memory banks (-b / --bank)\n"
"to store the tiles/sprites, instead of only one.\n"
"to store the tiles/sprites, instead of only one. The colors of the image can\n"
"be kept (-k / --keep), replacing the default colors (Sweetie-16) of the TIC-80.\n"
"\n"
"examples:\n"
" ticmctile imagefile.png \n"
Expand All @@ -50,7 +52,8 @@ def error(self, message):
" ticmctile logo.png -o tempvalues.lua -f\n"
" ticmctile goblins.gif -o sprites.txt -s\n"
" ticmctile font.png -o lettering.lua -p 2\n"
" ticmctile tilesgalore.gif -o membank3.lua -b 3\n", file=sys.stderr)
" ticmctile tilesgalore.gif -o membank3.lua -b 3\n"
" ticmctile nicecolors.png -o mypalette.lua -k \n", file=sys.stderr)
self.exit(1, '%s: ERROR: %s\n' % (self.prog, message))


Expand Down Expand Up @@ -97,9 +100,12 @@ def error(self, message):
nargs='?',
action='store',
help='memory bank (1-7) for TIC-80 PRO version, default is 1')
parser.add_argument('-k', '--keep',
action='store_true',
help='keep original image colors')
parser.add_argument('-v', '--version',
action='version',
version='%(prog)s 1.1')
version='%(prog)s 1.2')
args = parser.parse_args()


Expand All @@ -108,6 +114,7 @@ def error(self, message):
outputFile = args.output
outputLang = args.language
outputForce = args.force
outputKeep = args.keep
outputPage = args.page
outputSprites = args.sprites
outputBank = args.bank
Expand Down Expand Up @@ -175,6 +182,21 @@ def error(self, message):
exit(1)


# set palette for output file
Palette = "1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57" # SWEETIE-16 palette
if not outputKeep:
outputPalette = "000:" + Palette
else:
srcPalette = srcImg.getpalette() # get original palette from image
rgbEntries = (2 ** digits) * 3
rgbPalette = srcPalette[:rgbEntries]
outputPalette = ""
for entry in rgbPalette:
hexVal = '%0*x' % (2, entry)
outputPalette = outputPalette + hexVal
outputPalette = "000:" + outputPalette + Palette[len(outputPalette):] # fill up with default palette


# set string for output file
if not outputSprites:
outputString = "TILES"
Expand Down Expand Up @@ -287,7 +309,7 @@ def check_file(outputName):
file.write(outputCmnt + "script: " + outputLang + "\n\n")
file.write(outputCode + "\n\n")
file.write(outputCmnt + "<PALETTE>\n")
file.write(outputCmnt + "000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57\n") # SWEETIE-16 palette
file.write(outputCmnt + outputPalette + "\n") # write palette
file.write(outputCmnt + "</PALETTE>\n\n")
file.write(outputCmnt + "<" + outputString + ">\n")
for tile in tiles:
Expand Down

0 comments on commit 3f68614

Please sign in to comment.