Menu

#9 OctreeQuantizer sometimes resizes images before quantizing

pending-fixed
3
2012-01-15
2010-05-29
No

The OctreeQuantizer is resizing some images whilst quantizing them. Although it keeps the original image size, it shrinks or grows the image whilst drawing the original image onto the quantized image, and if shrinking the image, it fills the remainder of the quantized image with transparent pixels.

Discussion

  • Simon Bridewell

    Simon Bridewell - 2010-05-29

    Original JPEG image

     
  • Simon Bridewell

    Simon Bridewell - 2010-05-29

    Quantized image showing resizing effect

     
  • Simon Bridewell

    Simon Bridewell - 2010-05-29

    I've added an example - a photo in JPEG format and the bitmap which OctreeQuantizer creates from it.

    This bug seems to affect mainly photos which are loaded from file as 24 BPP RGB format.

     
  • Simon Bridewell

    Simon Bridewell - 2010-05-29

    And the solution...

    I spent the best part of 2 weeks trying to work out where I'd introduced this bug, before finally discovering that it was present in the original Octree quantizer code I'd downloaded from http://msdn.microsoft.com/en-us/library/aa479306.aspx

    The Quantizer.Quantize method in the GifComponents.Tools namespace (it's in the ImageManipulation namespace in the original source code) contains the following:

    using( Graphics g = Graphics.FromImage ( copy ) )
    {
    g.PageUnit = GraphicsUnit.Pixel;

    // Draw the source image onto the copy bitmap,
    // which will effect a widening as appropriate.
    g.DrawImageUnscaled ( source, bounds );
    }

    Replace this with the following:

    using( Graphics g = Graphics.FromImage ( copy ) )
    {
    // Draw the source image onto the copy bitmap,
    // which will effect a widening as appropriate.
    g.DrawImage( source, bounds, bounds, GraphicsUnit.Pixel );
    }

    This will ensure that the original will be drawn onto the copy correctly, even if they have different resolutions.

    I'll commit this fix to the repository when I've finished changing all the quantizer types to share a common base class, but here it is if anyone wants to apply it to their local copies before then.

     
  • Simon Bridewell

    Simon Bridewell - 2012-01-15

    Fix has been committed to the repository

     
  • Simon Bridewell

    Simon Bridewell - 2012-01-15
    • status: open --> pending-fixed
     
  • Nobody/Anonymous

    Woah! I'm really enjoying the template/theme of this website. It's simple, yet effective. A lot of times it's very hard to get that "perfect balance" between usability and visual appeal. I must say you've done a fantastic job with this. In addition, the blog loads extremely fast for me on Internet explorer. Superb Blog!
    north face jackets on sale http://iggcwmgyfp.wallinside.com/

     
  • Nobody/Anonymous

    My programmer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using Movable-type on various websites for about a year and am anxious about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can import all my wordpress content into it? Any help would be greatly appreciated!
    north face outlet http://tfkbyrwbrp.moonfruit.com/

     

Log in to post a comment.

MongoDB Logo MongoDB