Code Monkey home page Code Monkey logo

Comments (3)

HorstBaerbel avatar HorstBaerbel commented on June 15, 2024

Is this a bug, or am I "doing it wrong"? I am simply trying to add a color to the color map at index #0.

from imagemagick6.

dlemstra avatar dlemstra commented on June 15, 2024

It might be possible that the PNG coder will remove the color unless it is used in the image. What happens when you set one of the pixels to that color?

from imagemagick6.

HorstBaerbel avatar HorstBaerbel commented on June 15, 2024

Haven't tried, but it is not usable workaround, as then you need to have a pixel you don't need in the image... :/
My use case is that I'm converting images for a paletted display system (GBA). There color No. 0 is always transparent, thus I need to add a color at palette index 0 that I don't use. My original code used was this:

Image img;
img.read("in.png"); //<-- 8bit paletted file, 255 colors
// read palette
std::vector<Color> colorMap;
for (size_t i = 0; i < img->colorMapSize(); ++i) {
    colorMap.push_back(img->colorMap(i));
}
img.colorMapSize(img.colorMapSize() + 1); //<--after this this the color map is actually 1 entry bigger
colorMap.push_back(Color("#ff00ff"));
for (size_t i = 0; i < colorMap.size(); ++i) {
    img->colorMap(i, colorMap.at(i));
}
img.syncPixels();
// increase color indices in pixels
img.modifyImage();
const auto nrOfIndices = img.columns() * img.rows();
auto pixels = img.getPixels(0, 0, img.columns(), img.rows()); // we need to call this first for getIndexes to work
auto indices = img.getIndexes();
for (size_t i = 0; i < nrOfIndices; ++i) {
    indices[i] = indices[i] + 1;
}
// sync and write modified image
img.syncPixels();
img.write("out.png"); //<--image written has still 255 colors

But this doesn't work either.

from imagemagick6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.