png with wrong palette

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
Avocadora
Posts: 2
Joined: 2020-04-07T03:18:14-07:00
Authentication code: 1152

png with wrong palette

Post by Avocadora »

I have 2 files in bytes format.

pic250_0.bytes https://drive.google.com/open?id=1HACBV ... nhE3-cTvDE
palette.bytes https://drive.google.com/open?id=1dHbFj ... Lv8d8DImap

When I open them in ImageMagick Display I can see that they are a image and the palette, but the image doesn't have the colors of the palette. I managed to save them in png.

pic256_0.png https://drive.google.com/open?id=1pue2x ... LRBOVZ294W
Image
palette.png https://drive.google.com/open?id=1y-0vL ... roH0HzVAbm
Image

I want the image in png with the palette colors.
I'd like to know if there is a way to do this. I have more images that I'd like to do the same.

Thank you very much.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: png with wrong palette

Post by snibgo »

Your *.bytes file are actually PNG files. I suggest you use the PNG extension.

IM does not have methods for directly manipulating palettes. Gimp does, and may be better for your purposes.

Your pic256_0.bytes has useful values in the red and alpha channels. Perhaps you want to use the red values as an index into pallet.bytes, so we can treat pallet.bytes as a clut file. We also save the alpha from pic256_0.bytes and restore it at the end. Windows BAT script:

Code: Select all

magick ^
  pic256_0.bytes ^
  ( +clone ^
    -alpha extract ^
    -write mpr:ALPH ^
    +delete ^
  ) ^
  -alpha off ^
  -separate ^
  -delete 1-2 ^
  -duplicate 2 ^
  -combine ^
  pallet.bytes ^
  -clut ^
  mpr:ALPH ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  pic256_out.png
Image
snibgo's IM pages: im.snibgo.com

Avocadora
Posts: 2
Joined: 2020-04-07T03:18:14-07:00
Authentication code: 1152

Re: png with wrong palette

Post by Avocadora »

Wow! It works.

Thank you very much!!!

Locked