"-clamp" doesn't always clamp

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

"-clamp" doesn't always clamp

Post by snibgo »

Blurring makes an HDRI whiter than white, and "-clamp" before writing MIFF doesn't always cure it.

Windows 8.1, IM v6.9.0-0, compiled with Cygwin. Commands are Windows BAT syntax.

Code: Select all

Version: ImageMagick 6.9.0-0 Q32 x86_64 2015-02-28 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenMP
Delegates (built-in): bzlib fontconfig freetype fpx jbig jng jpeg lcms ltdl lzma png tiff x zlib
The following problem occurs with HDRI Q32, but not with HDRI Q16 or HDRI Q8.

Blurring makes an HDRI whiter than white:

Code: Select all

%IM_HDRI%convert ^
  -size 1x1 xc:White ^
  -precision 25 -format "%%[maxima]\n" +write info: ^
  -blur 0x0.5 ^
  -precision 25 -format "%%[maxima]\n" +write info: ^
  -clamp ^
  -precision 25 -format "%%[maxima]\n" +write info: ^
  m4.miff

4294967295
4294967295.000001430511475
4294967295
This is a small arithmetical glitch that I can live with, and fixed by "-clamp". This is fine.

But "-clamp" sometimes gives a value that is too large. For example, deliberately create an image that is white than white:

Code: Select all

%IM_HDRI%convert ^
  -size 1x1 xc:White ^
  -evaluate Add 111 ^
  -precision 25 -format "%%[maxima]\n" +write info: ^
-clamp ^
  +depth -define quantum:format=floating-point ^
-clamp ^
  -precision 25 -format "%%[maxima]\n" +write info: ^
-clamp ^
  m5.miff

4294967406
4294967295
The numbers output are correct, and what I would expect. But what value is in m5.miff?

Code: Select all

%IM_HDRI%convert m5.miff -precision 25 -format "%%[maxima]\n" info:
4294967296
The value is exactly one too large.

If we convert to another HDRI miff, clamping, we still get the problem:

Code: Select all

%IM_HDRI%convert ^
  m5.miff ^
-clamp ^
  +depth -define quantum:format=floating-point ^
-clamp ^
  m6.miff

%IM_HDRI%convert m6.miff -precision 25 -format "%%[maxima]\n" info:

4294967296
I get exactly the same results when using TIFF files.

I conclude that something is wrong with "-clamp" at Q32 HDRI.

(I have found no corresponding problem at the black end. )
snibgo's IM pages: im.snibgo.com
Post Reply