VGMaps

General Boards => Mapping Tips/Guides => Topic started by: JonLeung on August 06, 2007, 09:25:56 am

Title: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 06, 2007, 09:25:56 am
Hey, all.



I know there are some geniuses here when it comes to writing programs here that have to do with image files.



I'm in need of some kind of bulk colour-changing program, that can change certain RGB values into others, but over multiple .PNG files.



For example, there are a number of images used on the front page (including the randomizing thumbnails, etc.) that have a grey border with an RGB value of C8C8C8 (200, 200, 200).  However, I would like these to be C0C0C0 (192, 192, 192), and I'd rather not have to go into every individual file to change them.  Some already are 192, while some are still 200, and the inconsistency is bugging me!



Also, for many images (used on the site, such as the thumbnails, and to correct my older maps where I know palette errors exist) I would like the RGB values to be rounded to the closest multiple of 8, or in some cases the closest multiple of 16, but also including the value of 255 (often in place of 248, actually).  However, for some images (like title shots and thumbnails for Master System games), there should be other allowable values (in this case, 85 and 170).



Maybe it would be a program that looks at the palette of the selected images and converts all the files to conform to a palette file that is specified, maybe something like a text file that just lists the allowable values in either hexadecimal or decimal format.  (I know older versions of Paint Shop Pro have palette files that are essentially text lists, not sure about the current versions, but those palette files only work for 256 colours or less...)  With a text-list format, then I could make a number of custom ones dependent on what I need.



I think this would also be a good way to have some kind of control over images with many colours without poring over the palettes individually, too...



Does a program like this already exist?  Or would this be something someone could make?  I know I ask for a lot sometimes...  :P
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 06, 2007, 09:45:26 am
I don't know of any, and it'd probably be a slow and memory-intensive process. I'm not sure I see the need, though. It'd take approximately 5 minutes to replace 200,200,200 with 192,192,192 in PSP (colour replace brush, select FG/BG colours, double-click). Clamping colours to certain values is almost covered by the "posterize" function in most image editors - I'm not sure if any offer it in batch processing mode, though.



Ultimately, it sounds like something you'd have to have a custom tool for. Do you have any programming or scripting experience? I'm fairly sure you could do it in about 30 lines of PHP, for example.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 06, 2007, 09:53:20 am
My computer programming or scripting experience is limited and not that useful.  (When I thought I was going to take computing science in university, the pre-computing computer classes were pretty much the last year that they taught Turbo Pascal.  We didn't learn any C++ or even any HTML - you know, anything remotely useful.  (I didn't end up following through with that, and took Film and Media Studies, and I graduated in one of the last years that they had the 9-point grading system, so I don't even know what my marks are on the standard 4.0 grade system.  Great timing...))



So at least what you're saying is that you at least understand what I'm essentially saying in my request, and that something like that should be possible, just that it might take a while to actually run?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: TerraEsperZ on August 06, 2007, 10:37:43 am
Well, .PNG files with palettes (256 colors or less) would be easier to change I think since you only have to change the color value in the palette itself, whereas 24 bits images have no palette so you'd have to scan the entire file and change the RGB value of all the pixels matching the input color.



That's not even taking into account the fact that .PNG files are compressed, so for 24 bits images you'd first have to decompressed it before changing anything and then recompressing it, and if your tool handles that last part it most likely won't be as optimized as with PNGGauntlet.



As usual, I'm not even sure I know what I'm talking about :P



---

"With the first link, the chain is forged. The first speech censored, the first thought forbidden, the first freedom denied, chains us all irrevocably." [...] The first time any man's freedom is trodden on, we're all damaged. - Captain Jean-Luc Picard



B*tch, meet reality. Reality, meet b*tch. - Me
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 06, 2007, 10:50:28 am
I think most of the images I deal with would be limited to 256 colours anyway.  (Anything that would have more probably wouldn't have that much more, though I know that already takes us into 24-bit colours.)



All of the thumbnails (where the concern mostly is) are 256 colours, and usually just have considerably fewer.  A program that deals with just those would help immensely.  If it was limited to those, then, should it be easy and not too time-consuming?



I could always run a PNG-optimizing tool like PNGGauntlet at the end of it all.  I just want the colours adjusted easily, and such a program would be continue to be a handy tool as a palette check for all future images.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 06, 2007, 11:06:49 am
As I said, it's probably pretty easy. I'll see if I have time to look at it tonight - I have plans to put out a new release of Picross SMS, fun fun fun...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: DarkWolf on August 06, 2007, 11:54:13 am
That would be easy in PHP and also something like C# (I think, I've only coded 0.5 programs in C#).  If Maxim doesn't come up with something or is too busy I'll see if I can write you something.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 06, 2007, 12:04:57 pm
Thanks, you guys are awesome.  :D



Going back to the original post, I think there are two different yet similar goals, which are essentially:

1. to be able to replace a specific colour (in multiple files) with another specific colour.

2. to be able to replace/adjust ALL colours in multiple files to conform to any of several predetermined palettes.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 06, 2007, 03:09:31 pm
http://www.smspower.org/maxim/forumstuff/Colour changer 001.zip



I just realised it screws up with paletted images...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 06, 2007, 03:23:05 pm
Colour changer 002.zip



Seems to work better now (it upconverts to 32-bit though). Doing this stuff in Java was a bad idea...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 06, 2007, 03:27:48 pm
Well, now I'm a little jealous.  Your web site is blocked from work, so I can't give that a quick test drive.  SMSPower.org falls into the web category of "Games".  And yet VGMaps.com isn't blocked.  All the cool sites are blocked, yet mine isn't?



I guess VGMaps.com isn't cool or popular enough to be blocked.  ;_;



If it hadn't said "Games", I would've assumed it got blocked because the link says "Maxim" which could be confused with the magazine or something...



Anyway, what did you mean by "it screws up with paletted images..."?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: DarkWolf on August 06, 2007, 05:23:55 pm
OOOOOoooo Let me try!!!



I've been meaning to find an excuse to try out libgd with C.



Warning before you try it:  This program will overwrite the original PNGs.  You've been warned.  I may go back and put some more time into this program if you find it useful.  As with Maxim's, outputs are true color, (you're going to want to re-pngout them anyway).  Colors must be in hex (sorry laziness again).  If you never learned it in class or whatever:



FF0080



FF == Red

00 == Green

80 == Blue



You can shorten it too, i.e. black = 000000 or 0.  Thanks sscanf!



Usage: colorswap (file) (original color in hex) (new color in hex)



I've also included all_png.bat.  You can use it as such:



all_png (original color in hex) (new color in hex)



And it will change all *.png files in the directory you dump all the files to.



colorswap.zip

Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 07, 2007, 01:35:24 am
Stupid web filters :( The one at my last job blocked www.smspower.org but let through wwww.smspower.org (which works identically)...



Java tries to keep images in the original format, so in a paletted image with only red and blue, if you set a pixel to pink (for example) it automagically chooses red since that's the closest available colour. And upconverting to full 32-bit is not an easy operation. I'd imagine it'll be slower then the libgd way as well...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 07, 2007, 07:59:46 am
I'll try out DarkWolf's later today...I have already used Maxim's Colour Changer 002 last night to remove many unwanted 200-value greys from the thumbnails.  Awesome!



Is there a way to replace individual R, G, and B values?  Like if I want every R, G, or B value of 127 to be changed to 128 regardless of what the others are (which would be untouched, unless I specified those values to change, too).  Then I could probably make a batch file to convert all 256 possible values to whatever I want them to be, instead of all 16 million values (doubt that such a huge batch file would even run...)



I don't have much, but I'll probably give you guys a bunch of Coins for your work.  I really have to make cooler items though, or come up with something else to show my appreication.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 07, 2007, 08:12:10 am
I do it for the fun, no compensation necessary. Adding what you mentioned - channel-independent changing - wouldn't be too hard, but would the posterisation you mentioned in your first post achieve the same thing?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 07, 2007, 07:31:23 pm
Well, I must be doing something wrong, 'cause in Paint Shop Pro I choose "Posterise" and nothing seems to happen...



I could be doing something wrong.  Let me try GIMP instead of this ancient Paint Shop Pro...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 07, 2007, 07:42:34 pm
Posterize lets you choose the number of "levels". For example, Master System screens have 4 levels - 0, 85, 170, 255 - so choose 4 and all colours are adjusted to be the nearest colour with those levels.



I use PSP7 (I realise it's traditional to choose an ancient version and never upgrade), but it's been there since I started using it in PSP3.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 07, 2007, 07:59:32 pm
I'm using PSP 3.11 (aheh) but I must be missing something...I can only select up to 7 levels (and not 16) and when I tried it in GIMP 2.0 it didn't work either, and then I tried it again and it made my computer crash.  >_<
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 16, 2007, 09:50:24 am
Since I apparently can't figure out how to posterize properly, would someone be able to make independent colour channel adjusting?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 17, 2007, 03:05:42 am
Shouldn't be too hard. Do you want to specify a full palette, or just a posterisation level? The latter probably won't work as well with non-RGB video chips like the NES's (which works in a kind of HSL colour space), posterisation only works when there are n equally-spaced brightness levels for each colour channel. Is there any standard file format for palettes? Or would a reference image be a better option? Hmm, it's getting tricky...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 17, 2007, 07:49:00 am
I'd like to specify a full palette.  I was thinking that what would be handy is if I could specify what value should be adjusted to whatever other specific value.  In many cases I would want numbers to round up or down to a multiple of 8.  Or up or down to a multiple of 16.  But sometimes I want to allow certain values like 255 as well, which is why I don't trust leaving it to posterization.



Sure, this could mean I'd have to write out 256 entries in a text file or a convoluted batch file, but I'd only have to make the configurations once for each thing I'd like to try.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on August 17, 2007, 08:22:25 am
The problem with multiples of 8 or 16 is that they may not be appropriate, especially with different sources producing different colour ranges. For example, stock Gens screenshots range from 0..248 for red and blue channels and 0..252 for green (depending on your graphics card). Rounding each of those to the nearest 8 would disrupt the overall balance between the channels in some cases. On the other hand, specifying 512 colour mappings (for the full 512 possible colours) would be a lot of work. Posterising would also be inappropriate because the colours are starting out as non-full-range - the "correct" adjustment would be to scale the colour channels first, which is becoming really rather complicated.



Can you provide some example images and describe what needs to be done to them?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on August 17, 2007, 09:25:27 am
Some of my older maps (I don't know...try my A Link To The Past - Light World maps, or better yet, my April 2005 Link's Awakening Advance map) may have colour errors.  Due to whatever copying and pasting in Paint Shop Pro 3.12, or whatever old thing I used back then, if the palette of the current WIP was 16.7 million colours, for whatever reason RGB values would shift over by like 1-3 when copied and pasted.



I took a peek at the A Link To The Past maps of the same areas on ian-albert.com to see if I could derive some kind of palette file from his work and saw the same problem there.



I'm not going to go all palette-nazi on everyone's maps, just my own.  By adjusting everything to multiples of 8 I feel the maps that aren't correct could be easily fixed.



The problem arises if I want to do something else with the screen captures, like the thumbnails on the front page, and I plan to make more front-page "features" as well.  The thumbnails have particular greys, but due to the copy-and-paste nature of them, many early ones have errors too.



So a palette adjustment thing by individual RGB value that can be applied to multiple images would be a way to fix the unseen things that have been bugging me since the beginning of time (or at least the beginning of VGMaps.com).
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: TerraEsperZ on August 17, 2007, 01:48:30 pm
I ran into similar problems with a combinaison of Gens and Irfanview on my first couple of Sonic CD maps.



See, my desktop is always set to 32 bits color, but Gens always switches it to 16 bits while it runs. So far so good. I ran into a problem when I started assembling screenshots while the emulator was running because whenever I copied a screenshot from Irfanview, it would copy to to clipboard the image being displayed (now in 16 bits) instead of the actual data from the file which was 24 bits. Almost all the colors thus ended up having their individual color channel shifted by a few unit, so everything I would paste on the map canvas while Gens was open would have different color values that wouldn't be apparent to the naked eye but would cause a lot of problems when trying to alter pixels of a specific color value across the whole map.



Paint however remembered the real RGB value of the pixels already there even though the colors displayed might be different because of the 16 bits setting of the desktop. Let's say that I would have a big blue square. The left half of this square is made of (0,0,255) blue while the right half is made of (0,0,252) blue. But because of the 16 bits mode, everything is being displayed as (0,0,252) even though Paint *knows* that internally, both areas have different colors. So, while Gens was still running and causing everything without me suspecting foul play, I would use the Fill tool to try and recolor the whole square only to see that only half of it changed. And when I copied the whole thing in Irfanview to check the RGB values of pixels on both sides, it would give the value of what was displayed which was all (0,0,252) everywhere. All in all, I ended up tracking down the problem, then spent an hour or two recoloring all the problematic pixels on the two maps in question, and now always close Gens once the screenshots have been taken before doing any real assembly in Paint.



---

"With the first link, the chain is forged. The first speech censored, the first thought forbidden, the first freedom denied, chains us all irrevocably." [...] The first time any man's freedom is trodden on, we're all damaged. - Captain Jean-Luc Picard



B*tch, meet reality. Reality, meet b*tch. - Me
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on September 01, 2007, 09:52:23 am
Don't know if Maxim was still getting around to doing this (making the channel-independent adjusting thing) but it would be nice.  :D



I'm thinking of checking the colours on my Light World map from The Legend Of Zelda: A Link To The Past, and then if it's not a problem with the printing people, getting a large framed poster of it made up.  I don't like the pictures in our household, but some game-related ones would be nice, and more than just crinkly old Nintendo Power posters...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on September 02, 2007, 02:22:33 am
Don't hold your breath...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on March 20, 2008, 07:17:37 am
Is it a good assumption that all colours on NES/Super NES palettes would be a multiple of 8 (when in decimal)?



That was the purpose of my request for channel-independent colour adjustment...I might have mentioned this before, but before I was all palette-aware, many images that I assembled while in 16.7 million-colour mode on old Paint Shop Pro 3.12 would shift the palette values a little bit when pasted.  I don't know why.  Or if I pasted something overtop of another, you could use the fill tool to see that the underlying image still existed, hiding, because the colours pasted overtop were shifted a certain amount as well.



Be reducing the colours to an indexed 256-colour palette (as many have been when I went on my PNGGauntlet rampage), then following it up with a "only-multiple-of-eight-RGB values-allowed" colour convertor, that would get rid of all these slight shifts that irk my older images and maps...



EDIT: I noticed I did say the same thing four posts earlier...  >_<



I really should learn how to code anything (other than oldschool BASIC :P) one of these days...
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on March 20, 2008, 07:57:33 am
If you have your Windows desktop set to 16-bit colour then you can get this kind of thing, although it ought not to be a problem in Paint Shop Pro, more so in Paint.



Mapping consoles' colour definitions to RGB colours is an imprecise art. The NES at least is not even based on RGB, instead it is based on HSL or something similar which does not map easily or necessarily linearly to RGB. Other consoles are RGB based but are often non-linear in their mapping. Emulator authors can take different approaches to implementing them, too, which leads to colour differences between emulators.



Thus, "only multiples of eight" won't help much - it'll clamp colours to those points, but it won't necessarily correct the mistakes you refer to, and it'll mess up all the colours elsewhere.
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: JonLeung on March 20, 2008, 10:35:10 am
Are there any consoles that are more rigid in their colour definitions?  Do most emulators use approximations?  That must be where I think the "multiples-of-eight" thing comes from.



Back to the 0-85-170-255 Sega Master System example, isn't that a fairly set definition?  Or is that again considered a choice of the emulator coder?
Title: RE: Does anyone know of a program to control colours? Bulk palette adjusting?
Post by: Maxim on March 20, 2008, 11:41:59 am
Let's talk Master System :)



It defines its colours is RGB with 2 bits per channel, so you have all three channels going from 0 to 3 (64 possible colours). To map that linearly to 0..255 you get the values 0, 85, 170, 255. That's what Meka does.



If you look at that on a typical monitor, the dark colours are a lot darker than they appear on a TV. It also affects the balance of colours some games. But people are kind of used to it so that's becoming the standard.



Some emulator authors did't like over-bright colours. Old versions of Meka used the values 0, 65, 130, 195. eSMS used 0, 57, 123, 189. (eSMS became Emukon but I didn't check its screenshots recently.) I didn't check any other emulators, since Massage and BrSMS are prehistoric relics now, Kega can't save an unfiltered screenshot as far as I can tell, and SMS Plus is hard to find/use (and its page is down at the moment).