Menu

#662 Broken -colorize

v1.0_(example)
closed-fixed
None
5
2022-02-07
2022-02-05
No

I'm currently working with GM 1.3.35 on Raspberry Pi witch is working great for the purpose.

Meanwhile on my macOS (10.14.6 and 12.02) -colorize seems to be broken in latest version of GM 1.3.37.

I'm using exact same line such as below, but get different result on RPi with 1.3.35 and macOS with 1.3.37.
gm convert -modulate 140,0 -colorize 0,255,255 IN.jpg OUT.jpg

Example in attachment with same line as above.
- Left: Image as input
- Middle: Result from RPi with GM 1.3.35
- Right: Result from macOS with GM 1.3.37

1 Attachments

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    Please provide the full output from 'gm -version' for the working and
    non-working versions.

    Perhaps the compiler and OpenMP used are different. For example,
    GCC/GOMP vs Clang/OMP.

    Regardless, I will investigate.

    Bob

    Bob Friesenhahn
    bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
    GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
    Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

     
    • Stian Giltvedt

      Stian Giltvedt - 2022-02-05

      Sure! Check attachments from both installations. Seems that OpenMP aren't installed with 1.3.37 on macOS.

       
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    Can you please attach the input JPEG file gzipped or a common archive format which will protect it from modification by SourceForge? The input file might be relevant.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    I cropped your original from the PNG file and used that for testing.
    I did find a bug but also decided that neither of the results are ok.

    The documentation for -colorize says this:

      -colorize <value>
              colorize the image with the pen color
    
              Specify  the  amount  of  colorization as a percentage. You can apply
              separate colorization values to the red, green, and blue channels  of
              the image with a colorization value list delimited with slashes (e.g.
              0/0/50).
    
              The -colorize option may be used in  conjunction  with  -modulate  to
              produce a nice sepia toned image like:
    
                  gm convert input.ppm -modulate 115,0,100 \
                            -colorize 7,21,50 output.ppm.
    

    Notice that it says that the value is a percentage of the range. That means the normal range is perhaps 0 to 100. So if you bump the value by 101% then the value needs to be fully saturated (maximum value). Due to a defect in the code the value was being "wrapped" (because it became a negative value stored as a positive) by the GCC compiler, but Clang is less forgiving about undefined behavior so it did something else. So the solution is to assure that saturating behavior works as expected given that the math is done using floating point arithmetic.

    This means that the results from GraphicsMagick may be different than before.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    To clarify, the expected range of the values provided -colorize are indeed 0-100 (a percentage) so 255 is out of range. But it will make it handle the out of range values by clipping.

     

    Last edit: Bob Friesenhahn 2022-02-05
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    Mercurial changeset 16659:3207580e44c9 has fixes for this and the fix is in today's development snapshot.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05
    • status: open --> closed-fixed
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2022-02-05

    I am marking this as fixed, although the result will be different than either GM build you have using the values you supplied.

     
  • Stian Giltvedt

    Stian Giltvedt - 2022-02-07

    @bfriesen: Thank you for clarify! I definitely overlooked the detail that -colorize value should be in percentage. I was a bit overwhelmed of all details in documentation when I fiddled with my script and wrote wrong kind of the range.

    Now I've changed to percentage and get exact same result in both setup. Interesting way to discover this strange bug even it was wrong kind of the range, by mistake.

    Thank you for your time, help and amazing work of GraphicsMagick.

     

    Last edit: Stian Giltvedt 2022-02-07
    • Bob Friesenhahn

      Bob Friesenhahn - 2022-02-07

      On Mon, 7 Feb 2022, Stian Giltvedt wrote:

      @bfriesen: Thank you for clarify! I definitely overlooked the detail that -colorized value should be in percentage. I was a bit overwhelmed of all details in documentation when I fiddled with my script and wrote wrong kind of the range.

      Now I've changed to percentage and get exact same result in both setup. Interesting way to discover this strange bug even it was wrong kind of the range, by mistake.

      Thank you for your time, help and amazing work of GraphicsMagick.

      Thank you very much for reporting the problem.

      Bob

       

Log in to post a comment.

MongoDB Logo MongoDB