Tiled palette quantization tool

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.
Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
User avatar
olddb
Posts: 198
Joined: Thu Oct 26, 2017 12:29 pm

Re: Tiled palette quantization tool

Post by olddb »

lidnariq wrote: Thu Oct 16, 2025 11:48 pm
olddb wrote: Thu Oct 16, 2025 7:11 pm This is great. Haven't look at the code, but why does it need a server to run?
It doesn't - it runs entirely in javascript. You can save the HTML file and multiple js files locally and it'll work too.

https://github.com/rilden/tiledpalettequant
Well it doesn't work for me like that. Something about the web-browser unable to access files using
file:// /C:/. Cross origin security.
It doesn't matter, I will just use a light weight server.
Thanks for your help.
Last edited by olddb on Mon Oct 20, 2025 11:54 am, edited 1 time in total.
...
User avatar
Gilbert
Posts: 615
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong

Re: Tiled palette quantization tool

Post by Gilbert »

I just tried downloading everything and ran the webpage offline from my HDD.
Sorta worked, but nothing happened after clicking the 'quantize' button.
The button worked when I launched the online page from the first post, and the settings were all the same.

BTW, I'm using Chrome.
lidnariq
Site Admin
Posts: 11803
Joined: Sun Apr 13, 2008 11:12 am

Re: Tiled palette quantization tool

Post by lidnariq »

The kind of "worker" is apparently restricted to web content for path traversal reasons; as you correctly identify a lightweight static local web server will work. (So would a less light option of "using nwjs")
User avatar
segaloco
Posts: 913
Joined: Fri Aug 25, 2023 11:56 am

Re: Tiled palette quantization tool

Post by segaloco »

Is the problem that its trying to access other script files via the "file" protocol? I've had some luck with relative paths for locally accessed HTML/JS. If its about loading files, then that should be done via a file load dialog.

One suggestion is to consider using something like Webpack. This minifies and bundles JavaScript and optionally other things (HTML, CSS, also TS and SCSS handlers) using extensions. For instance I used webpack some time ago for bundling WordPress extensions, example here: https://gitlab.com/altlib/altlibrarian

That may be another way to run from a local file without a proper server.
turboxray
Posts: 390
Joined: Thu Oct 31, 2019 12:56 am

Re: Tiled palette quantization tool

Post by turboxray »

You could also just port the code to something like C++ (or even C). I ported it to python as an experiment and it worked fine (just amazingly slow hahah).
buckyohare
Posts: 6
Joined: Sat Feb 22, 2025 4:45 pm

Re: Tiled palette quantization tool

Post by buckyohare »

93143 wrote: Sat Feb 22, 2025 9:36 pm You mean for superimposing multiple layers?
To comply with Genesis specifications, which are limited to 1 palette per tile. The tool sometimes exceeds this limit, mixing palettes within the same block, what results in inaccurate conversions.
lidnariq
Site Admin
Posts: 11803
Joined: Sun Apr 13, 2008 11:12 am

Re: Tiled palette quantization tool

Post by lidnariq »

That's user error or anti-fingerprinting in the browser you're using. You should be able to get the 4 palettes, 16 colors of which one is shared global, R3G3B3 out of it just fine.
User avatar
olddb
Posts: 198
Joined: Thu Oct 26, 2017 12:29 pm

Re: Tiled palette quantization tool

Post by olddb »

turboxray wrote: Mon Oct 27, 2025 4:57 pm You could also just port the code to something like C++ (or even C). I ported it to python as an experiment and it worked fine (just amazingly slow hahah).
How complicated was the preocess?
Maybe I will try this approach.
...
turboxray
Posts: 390
Joined: Thu Oct 31, 2019 12:56 am

Re: Tiled palette quantization tool

Post by turboxray »

olddb wrote: Wed Oct 29, 2025 8:28 am
turboxray wrote: Mon Oct 27, 2025 4:57 pm You could also just port the code to something like C++ (or even C). I ported it to python as an experiment and it worked fine (just amazingly slow hahah).
How complicated was the preocess?
Maybe I will try this approach.
It's actually not that bad at all. The worker.js code isn't written like "javascript" code IMO. I think a few parts needed "objects", which is why I mentioned C++ (although you could do that in C with structs and function pointers). But the js code doesn't do anything elaborate with the language. It's pretty clean. I think it might have been more work to refactor the inputs (pics, params) than anything - which was still easy enough. I tried to keep everything lined up at much as possible. I used Beyond Compare as a visual aid.. and just went line-by-line replacing the original code with python code (in-place).
buckyohare wrote: Wed Oct 29, 2025 7:34 am To comply with Genesis specifications, which are limited to 1 palette per tile. The tool sometimes exceeds this limit, mixing palettes within the same block, what results in inaccurate conversions.
I have never seen this. I've converted tons of pics to MD format. But I also wrote my own tool/script that takes the TQ pic and palette files, and outputs binaries files for the system. If the script can't resolve it, it errors out. And I've never had it error out on MD converted assets from TQ.
buckyohare
Posts: 6
Joined: Sat Feb 22, 2025 4:45 pm

Re: Tiled palette quantization tool

Post by buckyohare »

I have never seen this. I've converted tons of pics to MD format. But I also wrote my own tool/script that takes the TQ pic and palette files, and outputs binaries files for the system. If the script can't resolve it, it errors out. And I've never had it error out on MD converted assets from TQ.

Try using two pallets in only one background, and will happen.
User avatar
Gilbert
Posts: 615
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong

Re: Tiled palette quantization tool

Post by Gilbert »

As olddb mentioned, this is not a bug of the quantisation tool. Instead it's a browser "feature", which was explained in page 3 of this thread.
turboxray
Posts: 390
Joined: Thu Oct 31, 2019 12:56 am

Re: Tiled palette quantization tool

Post by turboxray »

buckyohare wrote: Wed Oct 29, 2025 10:52 am
I have never seen this. I've converted tons of pics to MD format. But I also wrote my own tool/script that takes the TQ pic and palette files, and outputs binaries files for the system. If the script can't resolve it, it errors out. And I've never had it error out on MD converted assets from TQ.
Try using two pallets in only one background, and will happen.
Gilbert has you covered as to why, but just to let you know - I've done all 4 subpalette Genesis conversions with TQ without issue. I mean, TQ doesn't even "know" what a Genesis is - it just knows definitions that you give it. And by that, I've been converting 16 palette images for PCE for years with it without problems. The PCE/MD/SNES.. they all have the sample constraints; 4bit pixels.. only palette per tile limit (I'm not even sure there exists a system where you can assign multiple palettes to a tile.. and how that would even work).
stan423321
Posts: 127
Joined: Wed Sep 09, 2020 3:08 am

Re: Tiled palette quantization tool

Post by stan423321 »

Well, hypothetically speaking. It could work like two aligned (n-1)-bit layers. Palette A for first half of colours, palette B for the second.
User avatar
creaothceann
Posts: 863
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany

Re: Tiled palette quantization tool

Post by creaothceann »

turboxray wrote: Tue Nov 04, 2025 9:38 am The PCE/MD/SNES.. they all have the sample constraints; 4bit pixels.. only palette per tile limit (I'm not even sure there exists a system where you can assign multiple palettes to a tile.. and how that would even work).
Not sure if it counts, but SNES Mode 7 has a feature where the highest bit of a pixel's palette index determines if it belongs before or behind sprite with a certain priority. So if a tile is on BG1 it can select from 256 palette indices, and on BG2 it can only select from 128 palette indices.

DirectColor is also complicated.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
turboxray
Posts: 390
Joined: Thu Oct 31, 2019 12:56 am

Re: Tiled palette quantization tool

Post by turboxray »

creaothceann wrote: Tue Nov 04, 2025 11:32 am
turboxray wrote: Tue Nov 04, 2025 9:38 am The PCE/MD/SNES.. they all have the sample constraints; 4bit pixels.. only palette per tile limit (I'm not even sure there exists a system where you can assign multiple palettes to a tile.. and how that would even work).
Not sure if it counts, but SNES Mode 7 has a feature where the highest bit of a pixel's palette index determines if it belongs before or behind sprite with a certain priority. So if a tile is on BG1 it can select from 256 palette indices, and on BG2 it can only select from 128 palette indices.
Yeah, but it's not really two palettes. It just interprets both the highest bit as priority while still acting on the indexed color value. You have the full range of 256 colors.. just that now a certain range of colors also has priority attached to it. I feel like sites that explain EXT-BG tend to over complicate it. The CPS-1 has a similar system (IIRC).. lower 0-7 colors of a 4bit indexed value in a tile can have different priority to the sprite than the upper 8-15 colors. You can see this in Ghouls 'n Ghosts where some of the grass on the hill is in front and behind Arthur's feet.