Author Topic: Does anyone know of a program to control colours? Bulk palette adjusting?  (Read 52263 times)

0 Members and 3 Guests are viewing this topic.

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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

Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
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.

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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?

Online TerraEsperZ

  • Hero Member
  • *****
  • Posts: 2326
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
Current project:
Mega Man: Powered Up (PSP)

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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.

Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
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...

Offline DarkWolf

  • Hero Member
  • *****
  • Posts: 640
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.

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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.

Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
http://www.smspower.org/maxim/forumstuff/Colour changer 001.zip



I just realised it screws up with paletted images...

Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
Colour changer 002.zip



Seems to work better now (it upconverts to 32-bit though). Doing this stuff in Java was a bad idea...

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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..."?

Offline DarkWolf

  • Hero Member
  • *****
  • Posts: 640
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


Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
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...

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3697
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.

Offline Maxim

  • Hero Member
  • *****
  • Posts: 974
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?