89template<
typename StorageType>
97 const OIIO::TypeDesc typedesc,
103 const int channels = metadata.
channels;
104 int64_t read_x_stride = x_stride;
105 int64_t read_y_stride = y_stride;
108 StorageType *readpixels = pixels;
111 tmppixels.resize(
w * h * channels);
112 readpixels = &tmppixels[0];
113 read_x_stride = channels *
sizeof(StorageType);
114 read_y_stride =
w * channels *
sizeof(StorageType);
117 if (!
in->read_tiles(0,
136 for (
int64_t j = 0; j < h; j++) {
137 const StorageType *in_pixels = tmppixels.data() + j *
w * channels;
138 StorageType *out_pixels = pixels + j * (y_stride /
sizeof(StorageType));
140 out_pixels[i * 4 + 3] = in_pixels[i * channels + 3];
141 out_pixels[i * 4 + 2] = in_pixels[i * channels + 2];
142 out_pixels[i * 4 + 1] = in_pixels[i * channels + 1];
143 out_pixels[i * 4 + 0] = in_pixels[i * channels + 0];
154 x_stride /
sizeof(StorageType),
155 y_stride /
sizeof(StorageType),
156 y_stride /
sizeof(StorageType));
174 switch (metadata.
type) {
178 in, metadata, miplevel,
x,
y,
w, h, TypeDesc::UINT8, x_stride, y_stride, pixels);
191 reinterpret_cast<uint16_t *
>(pixels));
205 reinterpret_cast<half *
>(pixels));
218 reinterpret_cast<float *
>(pixels));
243 const int x_adjacent,
244 const int y_adjacent,
251 int64_t x_new =
x + x_adjacent * tile_size;
252 int64_t y_new =
y + y_adjacent * tile_size;
254 const bool in_range = x_new >= 0 && x_new < width && y_new >= 0 && y_new < height;
256 const int64_t pad_x = (x_adjacent < 0) ? 0 : (x_adjacent == 0) ? padding : padding +
w;
257 const int64_t pad_y = (y_adjacent < 0) ? 0 : (y_adjacent == 0) ? padding : padding + h;
258 const int64_t pad_w = (x_adjacent == 0) ?
w : padding;
259 const int64_t pad_h = (y_adjacent == 0) ? h : padding;
265 for (
int64_t j = 0; j < pad_h; j++) {
266 for (
int64_t i = 0; i < pad_w; i++) {
267 const int64_t source_x = (x_adjacent < 0) ? 0 : (x_adjacent == 0) ? i :
w - 1;
268 const int64_t source_y = (y_adjacent < 0) ? 0 : (y_adjacent == 0) ? j : h - 1;
270 std::copy_n(pixels + (padding + source_x) * x_stride + (padding + source_y) * y_stride,
272 pixels + (pad_x + i) * x_stride + (pad_y + j) * y_stride);
279 for (
int64_t j = 0; j < pad_h; j++) {
280 for (
int64_t i = 0; i < pad_w; i++) {
281 const int64_t source_x = (x_adjacent < 0) ? padding - 1 - i :
282 (x_adjacent == 0) ? i :
284 const int64_t source_y = (y_adjacent < 0) ? padding - 1 - j :
285 (y_adjacent == 0) ? j :
288 std::copy_n(pixels + (padding + source_x) * x_stride + (padding + source_y) * y_stride,
290 pixels + (pad_x + i) * x_stride + (pad_y + j) * y_stride);
297 for (
int64_t j = 0; j < pad_h; j++) {
298 std::fill_n(pixels + pad_x * x_stride + (pad_y + j) * y_stride, x_stride * pad_w, 0);
305 x_new = (
divide_up(width, tile_size) - 1) * tile_size;
307 else if (x_new >= width) {
312 y_new = (
divide_up(height, tile_size) - 1) * tile_size;
314 else if (y_new >= height) {
326 const int64_t adj_tile_w = std::min(width - x_new, tile_size);
327 const int64_t adj_tile_h = std::min(height - y_new, tile_size);
339 tile_size * x_stride,
344 const int64_t tile_x = (x_adjacent < 0) ? adj_tile_w - padding : 0;
345 const int64_t tile_y = (y_adjacent < 0) ? adj_tile_h - padding : 0;
347 for (
int64_t j = 0; j < pad_h; j++) {
348 std::copy_n(tile_pixels.data() + tile_x * x_stride + (tile_y + j) * (tile_size * x_stride),
350 pixels + pad_x * x_stride + (pad_y + j) * y_stride);
382 return std::unique_ptr<ImageInput>();
385 ImageSpec spec = ImageSpec();
387 config.attribute(
"oiio:UnassociatedAlpha", 1);
389 if (!
in->open(filepath, spec, config)) {
391 return std::unique_ptr<ImageInput>();
415 pixels + padding * x_stride + padding * y_stride);
419 for (
int j = -1; j <= 1; j++) {
420 for (
int i = -1; i <= 1; i++) {
421 if (i == 0 && j == 0) {
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
const std::unique_ptr< T > & get() const
CacheHandleGuard< T > acquire(CacheLimiter< T > &limiter, const std::function< std::unique_ptr< T >()> &creator)
bool texture_cache_file_handle_failed
const string & get_filepath() const
bool equals(const ImageLoader &other) const override
OIIOImageLoader(const string &filepath)
string texture_cache_filepath_
bool load_metadata(ImageMetaData &metadata, const ImageLoaderParams ¶ms, Progress &progress) override
CacheHandle< ImageInput > texture_cache_file_handle
bool load_pixels(const ImageMetaData &metadata, void *pixels) override
~OIIOImageLoader() override
bool load_pixels_tile(const ImageMetaData &metadata, int miplevel, int64_t x, int64_t y, int64_t w, int64_t h, int64_t x_stride, int64_t y_stride, int64_t padding, ExtensionType extension, uint8_t *pixels) override
string name() const override
string original_filepath_
void set_status(const string &status_, const string &substatus_="")
#define CCL_NAMESPACE_END
#define assert(assertion)
bool resolve_tx(const string &filepath, const string &texture_cache_path, ustring colorspace, const ImageAlphaType alpha_type, const ImageFormatType format_type, string &out_filepath, ImageMetaData &out_metadata)
bool make_tx(const string &filepath, const string &out_filepath, ustring colorspace, const ImageAlphaType alpha_type, const ImageFormatType format_type)
static bool oiio_load_pixels_tile_adjacent(const unique_ptr< ImageInput > &in, const ImageMetaData &metadata, const int64_t width, const int64_t height, const int miplevel, const int64_t x, const int64_t y, const int64_t w, const int64_t h, const int64_t x_stride, const int64_t y_stride, const int x_adjacent, const int y_adjacent, const int64_t padding, const ExtensionType extension, uint8_t *pixels)
static bool oiio_load_pixels_tile(const unique_ptr< ImageInput > &in, const ImageMetaData &metadata, const int miplevel, const int64_t x, const int64_t y, const int64_t w, const int64_t h, const OIIO::TypeDesc typedesc, const int64_t x_stride, const int64_t y_stride, StorageType *pixels)
static CCL_NAMESPACE_BEGIN CacheLimiter< ImageInput > cache_limiter_image_input(128)
string path_filename(const string &path)
string texture_cache_path
std::atomic< int > & tx_failure_num
std::atomic< int > & load_failure_num
ImageAlphaType alpha_type
ccl_device_inline size_t divide_up(const size_t x, const size_t y)
@ IMAGE_DATA_TYPE_NANOVDB_FP16
@ IMAGE_DATA_TYPE_USHORT4
@ IMAGE_DATA_TYPE_NANOVDB_EMPTY
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT4
@ IMAGE_DATA_TYPE_NANOVDB_FPN