Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

JPG incorrect brightness

Discussion in 'Scripting' started by SunnySunshine, Jun 25, 2015.

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    951
    Whenever I load a jpg-encoded image from a WWW instance, it becomes far brighter than if loaded inside the editor. PNG-images don't seem to have this problem. I'm guessing it may have something to do with linear color space.

    Any ideas how this can be circumvented? Encoding to PNG and reloading it again works, but that feels like such a hack.

    Code (CSharp):
    1. WWW www = new WWW("http://some.ip.address/someimage.jpg");
    2.  
    3. yield return www;
    4.  
    5. Texture2D tex = www.texture;
    6.  
    7. // This hack works:
    8. // tex = new Texture2D(2,2);
    9. // tex.LoadImage(www.texture.EncodeToPNG());
    10.  
    11. Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f));
    12.  
    13. // reference to Image instance
    14. image.sprite = sprite;
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I'm not seeing any difference: I modified the above to flop between the JPEG and PNG versions a few times a second and there was zero pixel changes that I could see. Can you try tinkering with the colorspace your JPEG is saved in? That stuff usually doesn't make a difference, but perhaps this does?
     
  3. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    951
    edit:
    Oh, sorry, I misread that.
    Sure I guess I could try tinkering with the image. But should that really be necessary? The majority of images on the internet are saved with gamma so Unity should be able to deal with it.

    Setting color space to gamma inside Unity fixes the issue, but I want linear...
     
    Last edited: Jun 25, 2015