Bug in 'point' resize?

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
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Bug in 'point' resize?

Post by Drarakel »

I tried to use '-filter point -resize' - with IM v6.6.4-6 Q16, on Windows XP.
It seems to work only sometimes:

Code: Select all

convert logo: -filter point -set option:filter:verbose 1 -resize 50% test1.bmp
convert test1.bmp test1.jpg
# filter = Point
# window = Box
# support = 0
# win-support = 0
# blur = 1
# blurred_support = 0
# B,C = 0,0
Image
And now:

Code: Select all

convert logo: -filter point -set option:filter:verbose 1 -resize 50% test2.jpg
Same filter properties, but no image:
Image
But it's not directly related to the output formats..
With "-sample" (which should produce the same result as "-filter point -resize" - right?), it always works ok. Example:

Code: Select all

convert logo: -sample 50% sample.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bug in 'point' resize?

Post by anthony »

Something is VERY strange alright. But I don't know what. BMP produces the right image though on my system it also produces an error. Other formats may not produce anything!

It is very weird.

Note -sample would not be effected as it implements a point filter in a faster more direct way.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Bug in 'point' resize?

Post by Drarakel »

Yeah, it's strange that the BMP output generated a working image - especially since the direct output from IM shows again no colors:

Code: Select all

convert logo: -filter point -resize 50% -format "%c" histogram:info:-
76800: ( 0, 0, 0) #000000 black
:?

It seems that the bug came with version 6.6.4-2.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bug in 'point' resize?

Post by anthony »

Ok found the fault.

Expert Explanation...
A Box function is meant to return a value or 1.0 if the sample is within 'support' distance of center of the sampling area.
However Point filter has a 'zero' support, so when it calls on a Box weighted points have a zero weighting -- BLACK

In other words the box filter was failing when it is used as the weigthing function with zero support -- Point filter

Before the recent spate of resize filter updates the Box Filter function always returns a weight os 1.0 regardless
of the support. That is It relied on the API client (ResizeImage() in this case) to only request samples within the support range.

I have removed that weighting function limitation, and restored 'Box' to always return a 1.0 weight for all sample requests, as it did previously. I have also pleased a note to this effect in the code to prevent it becoming 'limited' in future.

It broke around version 6.6.4-0 it should be fix in the next release 6.6.4-7
I have also updated the verbose output to show that internally the weighting function is really a 'Box' (with zero support) when a 'Point' filter is requested.

Code: Select all

convert logo: -filter point -set option:filter:verbose 1 -resize 50% test.jpg
Now returns the correct image, with a verbose response of...
#
# Resize Filter (for graphing)
#
# filter = Box
# window = Box
# support = 0
# win-support = 0
# blur = 1
# blurred_support = 0
# B,C = 0,0
#
0.00 1
0.00 0
Previously (with the bug still in place) those last two values would have been both a zero value - a direct indication of a bad weighting function.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bug in 'point' resize?

Post by anthony »

I have no idea however why BMP would generate a correct image!! That was non-sensical and probably points to another bug somewhere else.

The Error I got for BMP generated images was...
convert: length and filesize do not match `/tmp/magick-XXBYWe5H' @ error/bmp.c/ReadBMPImage/790.
However that error has also vanished with the fix and the image is still producing a correct looking result.

Perhap 'BMP' actually makes its own internal call to ResizeImage()... Hmmmm.... Doesn't seem to!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Bug in 'point' resize?

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagikc 6.6.4-7 Beta available by sometime tomorrow. Thanks.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Bug in 'point' resize?

Post by Drarakel »

anthony wrote:The Error I got for BMP generated images was...
convert: length and filesize do not match `/tmp/magick-XXBYWe5H' @ error/bmp.c/ReadBMPImage/790.
I didn't get that message with my Win32 Q16 binary.
It seems (looking at the source) that IM checks the compression and the file size that's stored in the BMP header. On my system, the header values in the file from the first example look ok. But: The compression that's used here is RLE (8 bit), and this compression has issues in BMP. (See report. Though these issues should lead to real errors only rarely.) Of course, this doesn't explain why the BMP file (in this example) contained the 'real' image in the first place. Strange thing.

Anyway.. Regarding the point filter issue:
Thanks for your explanations and for the fix!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bug in 'point' resize?

Post by fmw42 »

FYI: I found that one of my scripts was broke when using -filter point -resize, also, earlier today in IM 6.6.4.6 Q16 Mac OSX Tiger, but did not have time to report the error until just now. Glad others found it, too, and reported it.
Post Reply