The PNG format specifies an optional color palette (PLTE chunk). I want to edit this palette with Julia but do not find a starting point. Is there an existing library which provides this kind of “low level” control over PNG files?

Check out https://github.com/JuliaIO/PNGFiles.jl

What you want may not be exported, but should be there


Ok, I see. Thanks. I think it uses ImageMagick internally and that I won’t be able to edit the palette with it.
As an alternative, I tried to modify the palette bits directly but I have to recompute the CRC checksum to avoid breaking the file. (https://www.w3.org/TR/PNG-Chunks.html)

(edit) my attempt using CRC
f=open("img.png","r") # open image
raw=read(f); close(f) # read raw data
raw[804:806]=[UInt8(255),UInt8(255),UInt8(255)] # replace one color of palette
raw[810:813] = reinterpret(UInt8, [crc32(raw[38:809])]) # compute and replace checksum
f=open("img.png","w"); write(f,raw) # overwrite

PNGFiles uses libpng, in case that helps.

There are a few functions related to PLTE:

Yes, these are api calls, using pointers. I do not feel comfortable enough to play with it. For info, I added my attempt suing CRC in my last message (does not work yet).

Finally I’m using GIMP to edit the color palette. I have no more time to try automatizing it :cry: