Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Texture2D.FromStream support for 1bit PNGs #6001

Closed
tomspilman opened this issue Oct 12, 2017 · 9 comments
Closed

Fix Texture2D.FromStream support for 1bit PNGs #6001

tomspilman opened this issue Oct 12, 2017 · 9 comments
Assignees

Comments

@tomspilman
Copy link
Member

tomspilman commented Oct 12, 2017

Ran across a 1bpp PNG image that our existing Texture2D.FromStream would not load.

We should add this format to the unit tests and ensure it works.

You can download this white 1bpp texture here:

https://user-images.githubusercontent.com/103522/31480817-aafc0bde-aee5-11e7-9cb5-77491b4d3ae2.png

@KonajuGames
Copy link
Contributor

As raised back in #2424 and with @rds1983's StbSharp library, I'll have a go at integrating the StbSharp code into MonoGame (to avoid the extra assembly).

@KonajuGames KonajuGames self-assigned this Oct 12, 2017
@tomspilman
Copy link
Member Author

I'll have a go at integrating the StbSharp code into MonoGame (to avoid the extra assembly).

I suggest making StbSharp the default for all platform except consoles for now.

Then remove all our old image loading code.

@KonajuGames
Copy link
Contributor

KonajuGames commented Oct 12, 2017 via email

@rds1983
Copy link
Contributor

rds1983 commented Oct 13, 2017

Maybe I misunderstood the discussion, but wanted to say that StbSharp is already integrated in the MG: https://github.com/MonoGame/MonoGame/tree/develop/MonoGame.Framework/Utilities/Imaging
It is used for Texture2D.FromStream only for the DesktopGL version. And it seems to load fine the image attached to this ticket.

@KonajuGames
Copy link
Contributor

I did remember it had been done, but didn't find it. Probably because of the Utilities/Imaging directory. I'll extend the DesktopGL version of Texture2D.FromStream to all platforms.

@KonajuGames
Copy link
Contributor

STB doesn't support TIF or DDS. Do we consider that much a loss? XNA supported PNG, JPG, GIF. STB supports PNG, JPG, GIF, BMP, PSD, TGA plus others that never get used in the real world.

KonajuGames pushed a commit to KonajuGames/MonoGame that referenced this issue Oct 13, 2017
StbSharp is now used for all implementations of Texture2D.FromStream(GraphicsDevice, Stream), avoiding discrepancies with OS-provided image loading routines.

As a result of this, DirectX platforms no longer support TIF or DDS through FromStream().

Added unit tests for loading 1-, 8-, 24- and 32-bit PNGs.

Fixes MonoGame#6001
@KonajuGames
Copy link
Contributor

Added PR #6008 to fix this and use StbSharp for all implementations of Texture2D.FromStream(GraphicsDevice, Stream). More details in the PR description.

@KonajuGames
Copy link
Contributor

KonajuGames commented Oct 14, 2017

@rds1983 If you update your StbSharp library, we could use ImageWriter for Texture2D.SaveAsJpg() and Texture2D.SaveAsPng() since JPG support has been added to stb_image_write.h back in March.

@rds1983
Copy link
Contributor

rds1983 commented Oct 14, 2017

I think SaveAsPng already uses StbSharp, while SaveAsJpg uses TinyJpeg:

internal void SaveAsImage(Stream stream, int width, int height, ImageWriterFormat format)

However I'll surely port latest stb_image_write.h as it'll allow to drop TinyJpeg.

KonajuGames pushed a commit to KonajuGames/MonoGame that referenced this issue Feb 21, 2018
StbSharp is now used for all implementations of Texture2D.FromStream(GraphicsDevice, Stream), avoiding discrepancies with OS-provided image loading routines.

As a result of this, DirectX platforms no longer support TIF or DDS through FromStream().

Added unit tests for loading 1-, 8-, 24- and 32-bit PNGs.

Fixes MonoGame#6001
nkast pushed a commit to nkast/MonoGame that referenced this issue May 6, 2018
StbSharp is now used for all implementations of Texture2D.FromStream(GraphicsDevice, Stream), avoiding discrepancies with OS-provided image loading routines.

As a result of this, DirectX platforms no longer support TIF or DDS through FromStream().

Added unit tests for loading 1-, 8-, 24- and 32-bit PNGs.

Fixes MonoGame#6001
nkast pushed a commit to nkast/MonoGame that referenced this issue Jun 26, 2018
StbSharp is now used for all implementations of Texture2D.FromStream(GraphicsDevice, Stream), avoiding discrepancies with OS-provided image loading routines.

As a result of this, DirectX platforms no longer support TIF or DDS through FromStream().

Added unit tests for loading 1-, 8-, 24- and 32-bit PNGs.

Fixes MonoGame#6001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants