satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
56 stars 13 forks source link

Screenshots look brighter than they are - saving alpha channel? #176

Open satoshinm opened 7 years ago

satoshinm commented 7 years ago

Taking with F2:

screenshot-netcraft-2017-06-04t04_10_48 858z

and taken with Shift-Cmd-4, Space, Enter:

screen shot 2017-06-03 at 9 10 51 pm

The first screenshot taken by hitting the F2 shortcut is brighter than expected, especially noticeable around the text. First noticed with https://github.com/satoshinm/NetCraft/pull/175#issuecomment-306016772 - maybe related to alpha channels? Screenshots were added in https://github.com/satoshinm/NetCraft/issues/119 https://github.com/satoshinm/NetCraft/pull/127

satoshinm commented 7 years ago

Screenshots taken with F2 in the native app appear fine, so may be specific to WebGL:

screenshot-netcraft-2017-06-04t22 02 44z

On the web version, all I do is:

#ifdef __EMSCRIPTEN__
    EM_ASM(
        var url = document.getElementsByTagName("canvas")[0].toDataURL();
        var a = document.createElement("a");
        var timestamp = new Date().toISOString();
        a.setAttribute("download", "screenshot-netcraft-" + timestamp + ".png");
        a.setAttribute("href", url);
        a.click();
    );  
#else

whereas on native, glReadPixels(GL_RGBA) then compress to png with miniz tdefl_write_image_to_png_file_in_memory_ex. Something about premultiplied alpha? According to https://bugzilla.mozilla.org/show_bug.cgi?id=650720

It's also worth noting, that calling toDataUrl on the canvas causes it to be premultiplied before it gets to the encoder. The PNG decoder will un-premultiply it again.