Skip to content

Using JPEG PNG OSS

Chuck Walbourn edited this page Mar 12, 2024 · 8 revisions
DirectXTex

The DirectXTex library makes use of the Windows Imaging Component (WIC) which includes a number of built-in codecs for BMP, JPEG, PNG, etc. On Windows Subsystem for Linux, however, WIC is not present so only the DDS, HDR, and TGA file formats are supported by the library.

Using CMake there is an option to opt-in to using the Open Source libjpeg (ENABLE_LIBJPEG_SUPPORT) and/or libpng (ENABLE_LIBPNG_SUPPORT) libraries to provide support for these file formats on Windows Subsystem for Linux.

The CMake option to use these libraries is also supported on Windows, but this is not recommended for both security servicing and code size reasons. They are supported on Windows for testing purposes.

libjpeg

The files Auxiliary/DirectXTexJPEG.h and DirectXTexJPEG.cpp implement the following wrapper functions for libjpeg (ijg-libjpeg or libjpeg-turbo).

Using vcpkg

With the vcpkg C++ Package Manager, you can opt in to the png feature to include this functionality for Linux:

vcpkg install directxtex[png]

License

The libjpeg-turbo library is licensed under BSD-3-Clause, while ijg-libjpeg has a custom license.

Functions

HRESULT GetMetadataFromJPEGFile(const wchar_t* szFile, TexMetadata& metadata);
HRESULT LoadFromJPEGFile(const wchar_t* szFile, TexMetadata* metadata, ScratchImage& image);
HRESULT SaveToJPEGFile(const Image& image, const wchar_t* szFile);

libpng

The files Auxiliary/DirectXTexPNG.h and DirectXTexPNG.cpp implement the following wrapper functions for libpng.

Using vcpkg

With the vcpkg C++ Package Manager, you can opt in to the jpeg feature to include this functionality for Linux:

vcpkg install directxtex[jpeg]

License

The libpng library is licensed under a custom license known as the PNG Reference Library License.

Functions

HRESULT GetMetadataFromPNGFile(const wchar_t* szFile, TexMetadata& metadata);
HRESULT LoadFromPNGFile(const wchar_t* szFile, TexMetadata* metadata, ScratchImage& image);
HRESULT SaveToPNGFile(const Image& image, const wchar_t* szFile);

References

Credit

Thanks to Park DongHa for their contribution of these functions to the library.