[Approved] Thumbnails creation fails with "indexed pixel format" exception. (1 Viewer)

cul8er

Retired Team Member
  • Premium Supporter
  • August 31, 2006
    2,159
    2,679
    Home Country
    Sweden Sweden
    The Picture.cs in the MediaPortal.Util namespace uses some code for creating thumbs that fails on quite a number of images. The error thrown is "a graphics object cannot be created from an image that has an indexed pixel format".

    By replacing the current code in the CreateThumbnail methods;
    Code:
    myBitmap = new Bitmap(iWidth, iHeight, aDrawingImage.PixelFormat);         
    using (Graphics g = Graphics.FromImage(myBitmap))
    {
    	g.CompositingQuality = Thumbs.Compositing;
    	g.InterpolationMode = Thumbs.Interpolation;
    	g.SmoothingMode = Thumbs.Smoothing;
    	g.DrawImage(aDrawingImage, new Rectangle(0, 0, iWidth, iHeight));
    	myTargetThumb = myBitmap;
    }

    with this code;
    Code:
    myBitmap = (Bitmap)System.Drawing.Image.FromFile(aInputFilename, true);
    Bitmap tmp = new Bitmap(iWidth, iHeight);
    using (Graphics g = Graphics.FromImage(tmp))
    {
        g.CompositingQuality = Thumbs.Compositing;
        g.InterpolationMode = Thumbs.Interpolation;
        g.SmoothingMode = Thumbs.Smoothing;
        g.DrawImage(myBitmap, new Rectangle(0, 0, iWidth, iHeight));
        myTargetThumb = myBitmap;
    }
    if (tmp != null)
    {
        tmp.SafeDispose();
    }

    solved the problem and I get many more thumbs downloaded for artists in MP.

    best regards
    cul8er
     

    chemelli

    Retired Team Member
  • Premium Supporter
  • September 28, 2006
    6,159
    2,264
    49
    Milano, Italy
    Home Country
    Italy Italy
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Evaluating...

    Simone
     

    arion_p

    Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    re: Thumbnails creation fails with "indexed pixel format" exception.

    I cannot reproduce the issue to test your patch. Can you please provide steps to reproduce and possibly a couple of sample images that exhibit this behaviour?
     

    arion_p

    Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Any news on this one?
     

    cul8er

    Retired Team Member
  • Premium Supporter
  • August 31, 2006
    2,159
    2,679
    Home Country
    Sweden Sweden
    • Thread starter
    • Moderator
    • #5
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Hi,

    Sorry for no noticing this sooner (thanks for the PM chemelli). I will investigate what picture it was that got this error and get back to you in a day or so.

    best regards
    cul8er
     

    chemelli

    Retired Team Member
  • Premium Supporter
  • September 28, 2006
    6,159
    2,264
    49
    Milano, Italy
    Home Country
    Italy Italy
    re: Thumbnails creation fails with "indexed pixel format" exception.

    can we close this as "unable to reproduce" ?

    Simone
     

    cul8er

    Retired Team Member
  • Premium Supporter
  • August 31, 2006
    2,159
    2,679
    Home Country
    Sweden Sweden
    • Thread starter
    • Moderator
    • #7
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Hi,

    Here is how you can reproduce this error;
    1. Have a song with the artist Toto
    2. Open MP Configuration
    3. Goto Plugins\Audioscrobbler
    4. Goto Coverart and press Refresh and in my case I have no thumbs for Artist Toto. I then press Lookup.
    5. After the lookup I can see that the image is still missing.

    Then Open Configuration.log (I have attached the appropriate part below) and see that the scraper actually found an image and it was downloaded (you can also find that image in the TEMP directory). But the thumb in the Thumbs directory in MP never got that image.

    Change the code I suggested and rerun this and the thumb will be generated.

    best regards
    cul8er
     

    arion_p

    Retired Team Member
  • Premium Supporter
  • February 7, 2007
    3,373
    1,626
    Athens
    Home Country
    Greece Greece
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Ah, now I see. The problem is not with images with indexed pixel format but with B&W images (the image referred to in your log is a 8-bit B&W JPG and it is kind of rare - usually even B&W images are encoded as color in JPG). Nonetheless this is an issue and should be fixed.

    I will take a look at the issue and your patch.
     

    cul8er

    Retired Team Member
  • Premium Supporter
  • August 31, 2006
    2,159
    2,679
    Home Country
    Sweden Sweden
    • Thread starter
    • Moderator
    • #9
    re: Thumbnails creation fails with "indexed pixel format" exception.

    Hi,

    Thank you. Perhaps I have misinterpreted the C# error message ;)

    Please see this for the index error.

    The index error is usually received from these images;
    PixelFormatUndefined
    PixelFormatDontCare
    PixelFormat1bppIndexed
    PixelFormat4bppIndexed
    PixelFormat8bppIndexed
    PixelFormat16bppGrayScale
    PixelFormat16bppARGB1555

    cheers
    cul8er
     

    Users who are viewing this thread

    Top Bottom