Search Unity

TextureFormat.R8 and EncodeToJPG not working as expected

Discussion in 'General Graphics' started by coldwarrior5, Apr 20, 2020.

  1. coldwarrior5

    coldwarrior5

    Joined:
    Nov 9, 2016
    Posts:
    12
    Hi, I have a question about encoding the R8 texture to JPG image format, the resulting image has blueish tint throughout instead of it being greyscale. What I mean is the RGB components of output jpg image are not the same as are with R16 texture but the G and B components are 255 which makes the image appear blueish.

    To replicate you can try this piece of code:

    Code (CSharp):
    1. renderTexture = new Texture(width, height, TextureFormat.R8, false);
    2. // Save cameraview into the texture and then
    3. RenderTexture.active = renderTexture;
    4. var bytes = renderTexture.EncodeToJPG();
    5. System.IO.File.WriteAllBytes("r8texture.jpg", bytes);
    So I do not know whether I should report this as a bug because I would expect the output to be same as with R16 which is the value being replicated across the R, G, and B channel.
     
    chadfranklin47 likes this.
  2. BartPieters

    BartPieters

    Unity Technologies

    Joined:
    Apr 12, 2019
    Posts:
    25
    Hi!

    Would you be able to file a bug report for this? This could be intended behavior for backwards compatibility but will need to be investigated. Thank you.
     
  3. coldwarrior5

    coldwarrior5

    Joined:
    Nov 9, 2016
    Posts:
    12
    Hi BartPieters,

    thank you very much for the reply. I have created a bug report with the use case.
    I just find it weird because the outputs are different based on the number of bits, I would expect for the output to be normal not skewing to certain color spectrum.