Can you use only floating point colors in Magick++?
Can you use only floating point colors in Magick++?
Is there a way to do colors in the range of 0-1 where black is 0 and white is 1? Having to reverse and convert to ints is generating strange artifacts.
Last edited by Icetigris on 2010-07-22T16:21:38-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Is there a way to use floating point colors?
closest way is to use percentages. see http://www.imagemagick.org/script/color.php
also in fx: color in a given channel are specified in range 0-1.
also in fx: color in a given channel are specified in range 0-1.
Re: Is there a way to use floating point colors?
I need it for Magick++. I have to do a lot of workarounds to work with colors as ratios with 0 as black/transparent and 1 as white/opaque in my code. I'm just wondering if there is a way in Magick++ to only work with colors as ratios, instead of having to deal with backwards 0-MaxRGB at every step.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Can you use only floating point colors in Magick++?
Sorry I don't use any API's, only command line. You will need info from one of the IM developers.
Re: Can you use only floating point colors in Magick++?
Is this the right subforum for API questions?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Can you use only floating point colors in Magick++?
Yes.
"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?"."
"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?"."
Re: Can you use only floating point colors in Magick++?
Should I PM somebody? I've been having problems with this for over a week.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Can you use only floating point colors in Magick++?
The only person who would likely know would be magick. He usually answers these types of questions, but perhaps he is very busy at the moment. I recommend that you try posting in the Developers forum and perhaps someone with more software background might know the answer.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Can you use only floating point colors in Magick++?
Within the API for any version of IM their should be two constants. QuantumRange and QuantumScale. They are basically the inverse of each other. That is QuantumScale = 1/QuantumRange
For a IM Q16 QuantumRange = 65535 (that is 2^16-1)
A HDRI IM (storing values as floats) always uses a 16 bit quantum range.
To convert a color to a 0.0 to 1.0 range for mathematical purposes the value is multiplied by QuantumScale. To convert back (to the normal color range) after processing the number is multiplied by QuantumRange.
Most API functions return color values as floats, so you can just do the multiplications before and after your pixel processing. In many cases the maths can remove the multiplications. For example
multiply two pixel values which would be (in 0-1 range) R = P * Q would become
R = QuantumRange * ( (QuantumScale * P) * ( QuantumScale * Q ) )
which simplifies to
R = QuantumScale * P * Q
Their is lots of examples of this in the IM source "composite.c" file. which makes a good place to study how pixels are merged.
That is how all the libraries handle this so that it works for all versions of IM regardless of the compile time build Quality (Q) setting.
For a IM Q16 QuantumRange = 65535 (that is 2^16-1)
A HDRI IM (storing values as floats) always uses a 16 bit quantum range.
To convert a color to a 0.0 to 1.0 range for mathematical purposes the value is multiplied by QuantumScale. To convert back (to the normal color range) after processing the number is multiplied by QuantumRange.
Most API functions return color values as floats, so you can just do the multiplications before and after your pixel processing. In many cases the maths can remove the multiplications. For example
multiply two pixel values which would be (in 0-1 range) R = P * Q would become
R = QuantumRange * ( (QuantumScale * P) * ( QuantumScale * Q ) )
which simplifies to
R = QuantumScale * P * Q
Their is lots of examples of this in the IM source "composite.c" file. which makes a good place to study how pixels are merged.
That is how all the libraries handle this so that it works for all versions of IM regardless of the compile time build Quality (Q) setting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/