PCX2SNES (somehow) incorectly generates palette colors

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

PCX2SNES (somehow) incorectly generates palette colors

Post by Drew Sebastino »

I had noticed this when making my school presentation and found it to be a serious flaw, but hadn't gotten the chance to make a post or had forgotten, but it's summer for me now. Anyway, I made a text file for myself that has all 32 shades per 5bit channel RGB translated to 8bit per channel RGB by taking 255, dividing it by 31 to get about 8.2258, then multiplying that number by 0-31 and recording the products:

Code: Select all

0
8
16
25
33
41
49
58
66
74
82
91
99
107
115
123
132
140
148
156
165
173
181
189
197
205
213
222
230
239
247
255
However, even though I had used only these numbers for the colors in my indexed picture, PCX2SNES did not generate a palette with color entries that corresponded to what they should be. Then I thought that maybe, they were just dividing 256 by 32 and either treating everything darker than 8 as 8 in 24bit RGB before transferring it to 0 in 15bit RGB, or treating everything brighter than 248 as 248 in 24bit RGB before transferring it to 31 in 15bit RGB, so 24bit RGB is just 15bit RGB multiplied by 8. But based on the colors I got, and what I can't even wrap my mind around as to why it was made to do this, it can't be doing either of these, because despite my picture only having different shades of pure gray (all channels have the same value), the colors it generated did not always have the same brightness in every channel, which I can only assume is because they did not separate the color channels or something when performing calculations on them. Needless to say, the result looked like ass and I had to edit the colors in a hex editor, which was a lot more time consuming and taxing on my brain than it should have been. :lol:

So incase you haven't arrived at this conclusion already, do yourself a favor and don't use PCX2SNES. :wink:
Last edited by Drew Sebastino on Tue May 23, 2017 11:34 am, edited 1 time in total.
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by nicklausw »

I've always assumed that pcx2snes secretly runs neviksti's palette correction program inside itself before calculating the palette. My only guess as to why it isn't always accurate.

Is that true? No one's ever gonna dig through an x86 binary to find out so I say forget about it and use snes tile tool.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by calima »

The source is available according to google?
User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by nicklausw »

calima wrote:The source is available according to google?
Seems so. Would have been nice back in early 2015 when I couldn't find it anywhere, and part of me doesn't even want to take back my earlier statement for that reason. Distributing executables only for a one-file C program is bleh.
User avatar
HihiDanni
Posts: 186
Joined: Tue Apr 05, 2016 5:25 pm

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by HihiDanni »

Isn't pcx2snes really old? I've been using gfx2snes (which is also kind of buggy I think).

This reminds me that I'm glad I made my own palette editor so I can fix the colors post conversion but now that I think about it, I display those colors on-screen by multiplying the channel value by 8... But I don't think too much of it because I mostly just care about the colors fading smoothly with each step (something you can't count on when you don't know exactly how the colors will be quantized).
SNES NTSC 2/1/3 1CHIP | serial number UN318588627
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by rainwarrior »

I probably say this too often, but... it might be a good idea to write your own tool. :beer: :D
93143
Posts: 1715
Joined: Fri Jul 04, 2014 9:31 pm

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by 93143 »

I've looked at this before. IIRC it's alternating the error sign over the RGB channels in an attempt to improve brightness preservation, or something like that.

This might just possibly be somewhat justified when processing an arbitrary 24-bit image, but when the image is using pre-quantized pseudo-15-bit colour, adding chroma dither will make it look worse.

I write my own tools in Matlab. With all the weird stuff I do, I basically end up writing a new tool every time I want to do something...
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by dougeff »

In GIMP, you can switch to indexed mode, and specify the number of colors. Then you can open the color map dialogue box, to view/edit the colors.

Then i suppose you could convert from hex to 15 bit, or write a tool, like rainwarrior is often suggesting, to get the values from an indexed image file.

Why reinvent the wheel? If GIMP does a good job, why waste time writing the code?
nesdoug.com -- blog/tutorial on programming for the NES
Revenant
Posts: 462
Joined: Sat Apr 25, 2015 1:47 pm
Location: FL

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by Revenant »

dougeff wrote:If GIMP does a good job, why waste time writing the code?
I think GIMP's history of being buggy and having serious UI design issues leaves a lot of people preferring to use basically any other available option, including the DIY approach.

Of course, there are other image editors with easy support for indexed images and palette editing, but the only one I've personally used myself is Paint Shop Pro.
User avatar
HihiDanni
Posts: 186
Joined: Tue Apr 05, 2016 5:25 pm

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by HihiDanni »

GIMP is not a particularly great choice for pixel art. Right now I'm thinking the best way to go about this is to export from Aseprite without worrying too much about quantizing the colors, then double-checking and correcting them after the conversion using a raw SNES palette editor.
SNES NTSC 2/1/3 1CHIP | serial number UN318588627
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by tokumaru »

If you know how to work with indexed images, GIMP and Photoshop can be decent pixel art editors. Photoshop even allows you to change the image's aspect ratio (maybe GIMP does too?), which's really useful for retro consoles that hardly ever had square pixels. I don't think I've seen this feature in other common pixel art tools.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by rainwarrior »

tokumaru wrote:If you know how to work with indexed images, GIMP and Photoshop can be decent pixel art editors. Photoshop even allows you to change the image's aspect ratio (maybe GIMP does too?), which's really useful for retro consoles that hardly ever had square pixels. I don't think I've seen this feature in other common pixel art tools.
I use GIMP for most of my pixel art. I much prefer it to Asperite for everything except animation; GIMP has no real animation tools. I found aseprite is a lot more intuitive (especially when working with palettes), but once over the learning hump with GIMP it has a much better set of drawing features, IMO.

This tutorial really helped me get into GIMP: https://www.youtube.com/watch?v=PONe4IIYSnQ

Yes, GIMP has PAR options. Turn off "Dot for Dot" in the "View" menu, and then go to "Image -> Print Size..." to adjust its aspect ratio. (You can have multiple views open too, in case you want to view both at once, or edit on a 1:1 version while seeing those changes in the different PAR.)
93143
Posts: 1715
Joined: Fri Jul 04, 2014 9:31 pm

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by 93143 »

GIMP also has a Posterize function that, when set to 32 levels, gives you effectively 15-bit colour. The "Colorcube Analysis" tool counts the number of colours in an image, so you can tell if you're over the limit even if you aren't using Indexed mode. You can even save bitmaps in X1R5G5B5, eliminating the need for your custom SNES graphics tool to do any colour conversion (unless it's on a platform that can't read 15-bit bitmaps...).
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: PCX2SNES (somehow) incorectly generates palette colors

Post by Drew Sebastino »

93143 wrote:You can even save bitmaps in X1R5G5B5, eliminating the need for your custom SNES graphics tool to do any colour conversion
really?!? :D
93143 wrote:(unless it's on a platform that can't read 15-bit bitmaps...).
Oh... :cry:

Well, you can use PCX2SNES (I still haven't tried anything else yet, as I haven't converted any graphics since making this thread) and after it generates the wrong palette, open up the 15bit bitmap (you can even put all the different colors in order at the top left of the image) in HxD and use those hex values instead of trying to do it in your head, which, if you're me, should be 100x faster. :lol:
Post Reply