2

I'm working on a project converting images packed into a proprietary container format into individual PNG images which then get repacked into a more flexible container format. One of the odder restrictions for this is that the order of the colormap entries are critical for proper operation of the end application (the palettes of some images depend on the palettes of other images currently displayed).

Is there some way I can, preferably in Perl, directly manipulate the colormap of a PNG? I'm using PerlMagick to generate the PNG files pixel-by-pixel. Please let me know if it would be helpful for me to more directly describe what I'm up to.

(expanding on this because of Mark's suggestion)

The screen is filled first with background elements, like a decorative frame and a compass rose. Parts of the compass rose light up to indicate which direction the player can go. These lit up sections are separate images which take their coloring cues from specific slots in the colormaps for the background element images. Therefore the content and order of the colormaps for the background elements are critical.

(even more expanding)

I'll lay out exactly what I'm doing now. The original container format was created by Infocom in the late 1980s for its graphical text adventures. For each of the graphical games, three graphics files were made, one for CGA, EGA, and MCGA. Some EGA graphics files were spread across two containers. For play on modern Z-machine interpreters, the format was reverse-engineered and the graphics within were converted to PNG and repacked into Blorb containers (https://www.eblong.com/zarf/blorb/). Section 11.3 talks about the color-changing behavior. Just the MCGA packs were repacked like this. I want to create packs for the CGA and EGA packs. Unfortunately, I've been unable to contact the person who prepared these Blorb files to get information about this colormap problem. The reverse-engineering of Infocom's format seems to be lost. So I took existing tools, mainly pix2gif.c from Ztools (http://ifarchive.org/indexes/if-archive/infocom/tools/ztools/) and translated it to Perl to better understand it. With this Perl program, Imanaged to extract the EGA and CGA data. I've modified my own tools (https://gitlab.com/DavidGriffith/blorbtools) to support the special requirements of these games.

Starting off with the MCGA-targeted graphics, I cannot get to the point of replicating the look of playing a game with the older Blorb files available here: http://ifarchive.org/indexes/if-archive/infocom/media/blorb. The images with changing palettes are drawn with the wrong colors. There are other problems with the EGA and CGA graphics, but have to do with resolution and are not relevant here.

These the specific games involved are Infocom's games "Arthur", "Shogun", "Journey", and "Zork Zero". I maintain one of the Z-machine interpreters capable of playing these games, which can be found at https://gitlab.com/DavidGriffith/frotz.

Frotz
  • 535
  • 4
  • 21
  • 2
    A better description and example would probably help, though I'm not that hopeful that you'll get a Perl solution. – Mark Setchell Dec 02 '21 at 07:30
  • See IM's -remap function. See [here](https://stackoverflow.com/questions/25253247/remap-posterize-image-colors-using-list-of-colors-in-imagemagick#25265526) for an example. – xenoid Dec 02 '21 at 08:28
  • Thank you for the improved description. It's still rather vague without representative input images and expected results... – Mark Setchell Dec 03 '21 at 09:01
  • Are you saying you have a .png image that somehow depends on another .png images palette? – turtle Dec 03 '21 at 17:12
  • Yes. To save space back in the late 1980s, rather than putting multiple images that differ only in color, the writers just changed the palettes based on what's already onscreen. – Frotz Dec 03 '21 at 23:22
  • 1
    Thanks for explaining, its an interesting project, so say for simplicity sake, your going to use a 1 bit pixel depth and have a 2 color palette. Your color pallet is fixed say 1 = white 2 = black, when you generate (reverse engineer?) the png images some are generated with 1 = black 2 = white and you need to fix this order? Is this what your trying to do https://stackoverflow.com/questions/29587679/imagemagick-preserve-custom-palette-when-joining-2-pngs – turtle Dec 07 '21 at 18:48
  • Thanks. I think this approach will work as long as I can have my script automatically determine the correct order of the colormap entries. Could you repost that in the form of an answer so you can get credit? – Frotz Dec 12 '21 at 00:39
  • 1
    I did another, similar answer here, of mapping to a known palette but with Python https://stackoverflow.com/a/66534376/2836621 – Mark Setchell Dec 12 '21 at 08:55

0 Answers0