mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Add some files for Image loading.
This commit is contained in:
@@ -38,10 +38,15 @@ option(
|
||||
"Build with Python module for Blender(`TINYUSDZ_WITH_PYTHON` is force set to ON"
|
||||
OFF)
|
||||
|
||||
option(TINYUSDZ_USE_SYSTEM_ZLIB
|
||||
"Use system's zlib instead of miniz for TinyEXR/TIFF" OFF)
|
||||
|
||||
# -- TIFF --
|
||||
option(TINYUSDZ_WITH_TIFF "Build with TIFF texture support" OFF)
|
||||
# ----------
|
||||
|
||||
# -- EXR --
|
||||
option(TINYUSDZ_WITH_EXR "Build with EXR HDR texture support" ON)
|
||||
option(TINYUSDZ_TINYEXR_USE_SYSTEM_ZLIB
|
||||
"Use system's zlib instead of miniz for TinyEXR" OFF)
|
||||
# ---------
|
||||
|
||||
# -- optional --
|
||||
@@ -53,8 +58,10 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/sanitizers)
|
||||
find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON)
|
||||
|
||||
if(TINYUSDZ_TINYEXR_USE_SYSTEM_ZLIB)
|
||||
find_package(ZLIB REQUIRED)
|
||||
if (TINYUSDZ_WITH_EXR OR TINYUSDZ_WITH_TIFF)
|
||||
if(TINYUSDZ_USE_SYSTEM_ZLIB)
|
||||
find_package(ZLIB REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Require strict C++14 mode(e.g. `-std=c++14`)
|
||||
@@ -109,6 +116,7 @@ set(TINYUSDZ_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/usda-parser.cc
|
||||
${PROJECT_SOURCE_DIR}/src/prim-types.cc
|
||||
${PROJECT_SOURCE_DIR}/src/io-util.cc
|
||||
${PROJECT_SOURCE_DIR}/src/image-loader.cc
|
||||
${PROJECT_SOURCE_DIR}/src/pprinter.cc)
|
||||
|
||||
if(TINYUSDZ_WITH_PXR_COMPAT_API)
|
||||
@@ -126,6 +134,11 @@ set(TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2d.c
|
||||
${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2f.c)
|
||||
|
||||
# Disable SSE for a while, since -mpclmul required to use SSE feature of fpng.
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/fpng.cpp
|
||||
PROPERTIES COMPILE_DEFINITIONS "FPNG_NO_SSE=1")
|
||||
|
||||
if(TINYUSDZ_WITH_JSON)
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/usd-to-json.cc)
|
||||
endif()
|
||||
@@ -142,25 +155,48 @@ set(TINYUSDZ_PYTHON_BINDING_SOURCES
|
||||
set(TINYUSDZ_BLENDER_PYTHON_BINDING_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/blender/bindings.cc)
|
||||
|
||||
if(TINYUSDZ_WITH_TIFF)
|
||||
if(TINYUSDZ_USE_SYSTEM_ZLIB)
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/tiny_dng_loader.cc
|
||||
PROPERTIES COMPILE_DEFINITIONS "TINY_DNG_LOADER_USE_SYSTEM_ZLIB=1")
|
||||
else()
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/tiny_dng_loader.cc
|
||||
PROPERTIES INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src/external)
|
||||
endif()
|
||||
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyexr.cc)
|
||||
endif(TINYUSDZ_WITH_TIFF)
|
||||
|
||||
if(TINYUSDZ_WITH_EXR)
|
||||
if(TINYUSDZ_TINYEXR_USE_SYSTEM_ZLIB)
|
||||
if(TINYUSDZ_USE_SYSTEM_ZLIB)
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyexr.cc
|
||||
PROPERTIES COMPILE_DEFINITIONS "TINYEXR_USE_MINIZ=0")
|
||||
else()
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/external/miniz.c)
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyexr.cc
|
||||
PROPERTIES INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src/external)
|
||||
endif()
|
||||
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyexr.cc)
|
||||
endif(TINYUSDZ_WITH_EXR)
|
||||
|
||||
if(TINYUSDZ_WITH_TIFF OR TINYUSDZ_WITH_EXR)
|
||||
|
||||
if(NOT TINYUSDZ_USE_SYSTEM_ZLIB)
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES ${PROJECT_SOURCE_DIR}/src/external/miniz.c)
|
||||
|
||||
# TODO: Set this only for clang, gcc
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/src/external/miniz.c
|
||||
PROPERTIES COMPILE_DEFINITIONS "_LARGEFILE64_SOURCE=1")
|
||||
endif()
|
||||
|
||||
list(APPEND TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyexr.cc)
|
||||
endif(TINYUSDZ_WITH_EXR)
|
||||
endif ()
|
||||
|
||||
if(TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
@@ -264,11 +300,11 @@ if(TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
endif(TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
if(TINYUSDZ_WITH_EXR)
|
||||
if(TINYUSDZ_TINYEXR_USE_SYSTEM_ZLIB)
|
||||
if(TINYUSDZ_WITH_TIFF OR TINYUSDZ_WITH_EXR)
|
||||
if(TINYUSDZ_USE_SYSTEM_ZLIB)
|
||||
list(APPEND ${TINYUSDZ_EXT_LIBRARIES} ZLIB::ZLIB)
|
||||
endif()
|
||||
endif(TINYUSDZ_WITH_EXR)
|
||||
endif()
|
||||
|
||||
#
|
||||
# -- target
|
||||
@@ -325,6 +361,11 @@ foreach(TINYUSDZ_LIB_TARGET ${TINYUSDZ_LIBS})
|
||||
PRIVATE "TINYUSDZ_BUILD_IOS")
|
||||
endif()
|
||||
|
||||
if(TINYUSDZ_WITH_TIFF)
|
||||
target_compile_definitions(${TINYUSDZ_LIB_TARGET}
|
||||
PRIVATE "TINYUSDZ_SUPPORT_TIFF")
|
||||
endif(TINYUSDZ_WITH_TIFF)
|
||||
|
||||
if(TINYUSDZ_WITH_EXR)
|
||||
target_compile_definitions(${TINYUSDZ_LIB_TARGET}
|
||||
PRIVATE "TINYUSDZ_SUPPORT_EXR")
|
||||
|
||||
5850
src/external/tiny_dng_loader.h
vendored
Normal file
5850
src/external/tiny_dng_loader.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1968
src/external/tiny_dng_writer.h
vendored
Normal file
1968
src/external/tiny_dng_writer.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
src/image-loader.cc
Normal file
1
src/image-loader.cc
Normal file
@@ -0,0 +1 @@
|
||||
#include "image-loader.hh"
|
||||
28
src/image-loader.hh
Normal file
28
src/image-loader.hh
Normal file
@@ -0,0 +1,28 @@
|
||||
// Simple image loader
|
||||
// supported file format: PNG(use fpng), JPEG(use stb_image), OpenEXR(use tinyexr), TIFF(use tinydng)
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "tinyusdz.hh"
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Weverything"
|
||||
#endif
|
||||
|
||||
#include "nonstd/expected.hpp"
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
namespace tinyusdz {
|
||||
namespace image {
|
||||
|
||||
nonstd::expected<Image, std::string> LoadImage(const std::string &filename);
|
||||
|
||||
} // namespace image
|
||||
} // namespace tinyusdz
|
||||
45
src/image-types.hh
Normal file
45
src/image-types.hh
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (c) 2022 - Present, Syoyo Fujita.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Syoyo Fujita nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace tinyusdz {
|
||||
|
||||
// Simple image class.
|
||||
// No colorspace conversion will be applied when decoding image data(e.g. from
|
||||
// .jpg, .png).
|
||||
struct Image {
|
||||
std::string uri; // filename or uri;
|
||||
|
||||
int width{-1}; // -1 = invalid
|
||||
int height{-1}; // -1 = invalid
|
||||
int channels{-1}; // Image channels. 3=RGB, 4=RGBA. -1 = invalid
|
||||
int bpp{-1}; // bits per pixel. 8=LDR, 16=HDR
|
||||
|
||||
std::vector<uint8_t> data; // Raw data.
|
||||
};
|
||||
|
||||
} // namespace tinyusdz
|
||||
68
src/texture-types.hh
Normal file
68
src/texture-types.hh
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (c) 2022 - Present, Syoyo Fujita.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Syoyo Fujita nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
enum ColorSpace {
|
||||
COLORSPACE_NONE, // No explicit colorspace
|
||||
COLORSPACE_SRGB,
|
||||
COLORSPACE_LINEAR
|
||||
};
|
||||
|
||||
//
|
||||
// Simple tile coordinate for UDIM texture
|
||||
//
|
||||
struct TileCoord {
|
||||
int32_t x{0};
|
||||
int32_t y{0};
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
|
||||
uint32_t _image_id; // ID to `Image`.
|
||||
|
||||
int32_t _width;
|
||||
int32_t _height;
|
||||
int32_t _stride; // width stride
|
||||
int32_t _channels;
|
||||
|
||||
ColorSpace colorspace{COLORSPACE_SRGB}; // Default = sRGB
|
||||
|
||||
};
|
||||
|
||||
struct UDIMTexture {
|
||||
std::vector<std::pair<TileCoord, Texture>> _textures;
|
||||
};
|
||||
|
||||
// For CPU texture mapping
|
||||
struct TextureSampler {
|
||||
|
||||
bool Sample(const Texture &tex, float u, float v, float w);
|
||||
|
||||
};
|
||||
|
||||
@@ -55,6 +55,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#endif
|
||||
|
||||
#include "prim-types.hh"
|
||||
#include "image-types.hh"
|
||||
#include "texture-types.hh"
|
||||
|
||||
namespace tinyusdz {
|
||||
|
||||
@@ -62,21 +64,6 @@ constexpr int version_major = 0;
|
||||
constexpr int version_minor = 8;
|
||||
constexpr int version_micro = 0;
|
||||
|
||||
// Simple image class.
|
||||
// No colorspace conversion will be applied when decoding image data(e.g. from
|
||||
// .jpg, .png).
|
||||
// TODO(syoyo): Add option to decode image into linear space.
|
||||
struct Image {
|
||||
std::string uri; // filename or uri;
|
||||
|
||||
int width{-1}; // -1 = invalid
|
||||
int height{-1}; // -1 = invalid
|
||||
int channels{-1}; // Image channels. 3=RGB, 4=RGBA. -1 = invalid
|
||||
int bpp{-1}; // bits per pixel. 8=LDR, 16=HDR
|
||||
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ListOp {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user