Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/image.cpp
| Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | device_memory *ImageManager::image_memory(int flat_slot) | ||||
| ImageDataType type; | ImageDataType type; | ||||
| int slot = flattened_slot_to_type_index(flat_slot, &type); | int slot = flattened_slot_to_type_index(flat_slot, &type); | ||||
| Image *img = images[type][slot]; | Image *img = images[type][slot]; | ||||
| return img->mem; | return img->mem; | ||||
| } | } | ||||
| bool ImageManager::get_image_metadata(int flat_slot, | |||||
| ImageMetaData& metadata) | |||||
| { | |||||
| if(flat_slot == -1) { | |||||
| return false; | |||||
| } | |||||
| ImageDataType type; | |||||
| int slot = flattened_slot_to_type_index(flat_slot, &type); | |||||
| Image *img = images[type][slot]; | |||||
| if(img) { | |||||
| metadata = img->metadata; | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| bool ImageManager::get_image_metadata(const string& filename, | bool ImageManager::get_image_metadata(const string& filename, | ||||
| void *builtin_data, | void *builtin_data, | ||||
| ImageMetaData& metadata) | ImageMetaData& metadata) | ||||
| { | { | ||||
| memset(&metadata, 0, sizeof(metadata)); | memset(&metadata, 0, sizeof(metadata)); | ||||
| if(builtin_data) { | if(builtin_data) { | ||||
| if(builtin_image_info_cb) { | if(builtin_image_info_cb) { | ||||
| ▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | int ImageManager::add_image(const string& filename, | ||||
| if(slot == images[type].size()) { | if(slot == images[type].size()) { | ||||
| images[type].resize(images[type].size() + 1); | images[type].resize(images[type].size() + 1); | ||||
| } | } | ||||
| /* Add new image. */ | /* Add new image. */ | ||||
| img = new Image(); | img = new Image(); | ||||
| img->filename = filename; | img->filename = filename; | ||||
| img->builtin_data = builtin_data; | img->builtin_data = builtin_data; | ||||
| img->builtin_free_cache = metadata.builtin_free_cache; | img->metadata = metadata; | ||||
| img->need_load = true; | img->need_load = true; | ||||
| img->animated = animated; | img->animated = animated; | ||||
| img->frame = frame; | img->frame = frame; | ||||
| img->interpolation = interpolation; | img->interpolation = interpolation; | ||||
| img->extension = extension; | img->extension = extension; | ||||
| img->users = 1; | img->users = 1; | ||||
| img->use_alpha = use_alpha; | img->use_alpha = use_alpha; | ||||
| img->mem = NULL; | img->mem = NULL; | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | for(size_t slot = 0; slot < images[type].size(); slot++) { | ||||
| images[type][slot]->need_load = true; | images[type][slot]->need_load = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool ImageManager::file_load_image_generic(Image *img, | bool ImageManager::file_load_image_generic(Image *img, | ||||
| ImageInput **in, | ImageInput **in) | ||||
| int &width, | |||||
| int &height, | |||||
| int &depth, | |||||
| int &components) | |||||
| { | { | ||||
| if(img->filename == "") | if(img->filename == "") | ||||
| return false; | return false; | ||||
| if(!img->builtin_data) { | if(!img->builtin_data) { | ||||
| /* NOTE: Error logging is done in meta data acquisition. */ | /* NOTE: Error logging is done in meta data acquisition. */ | ||||
| if(!path_exists(img->filename) || path_is_directory(img->filename)) { | if(!path_exists(img->filename) || path_is_directory(img->filename)) { | ||||
| return false; | return false; | ||||
| Show All 11 Lines | if(!img->builtin_data) { | ||||
| if(img->use_alpha == false) | if(img->use_alpha == false) | ||||
| config.attribute("oiio:UnassociatedAlpha", 1); | config.attribute("oiio:UnassociatedAlpha", 1); | ||||
| if(!(*in)->open(img->filename, spec, config)) { | if(!(*in)->open(img->filename, spec, config)) { | ||||
| delete *in; | delete *in; | ||||
| *in = NULL; | *in = NULL; | ||||
| return false; | return false; | ||||
| } | } | ||||
| width = spec.width; | |||||
| height = spec.height; | |||||
| depth = spec.depth; | |||||
| components = spec.nchannels; | |||||
| } | } | ||||
| else { | else { | ||||
| /* load image using builtin images callbacks */ | /* load image using builtin images callbacks */ | ||||
| if(!builtin_image_info_cb || !builtin_image_pixels_cb) | if(!builtin_image_info_cb || !builtin_image_pixels_cb) | ||||
| return false; | return false; | ||||
| ImageMetaData metadata; | |||||
| builtin_image_info_cb(img->filename, img->builtin_data, metadata); | |||||
| width = metadata.width; | |||||
| height = metadata.height; | |||||
| depth = metadata.depth; | |||||
| components = metadata.channels; | |||||
| } | } | ||||
| /* we only handle certain number of components */ | /* we only handle certain number of components */ | ||||
| if(!(components >= 1 && components <= 4)) { | if(!(img->metadata.channels >= 1 && img->metadata.channels <= 4)) { | ||||
| if(*in) { | if(*in) { | ||||
| (*in)->close(); | (*in)->close(); | ||||
| delete *in; | delete *in; | ||||
| *in = NULL; | *in = NULL; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| template<TypeDesc::BASETYPE FileFormat, | template<TypeDesc::BASETYPE FileFormat, | ||||
| typename StorageType, | typename StorageType, | ||||
| typename DeviceType> | typename DeviceType> | ||||
| bool ImageManager::file_load_image(Image *img, | bool ImageManager::file_load_image(Image *img, | ||||
| ImageDataType type, | ImageDataType type, | ||||
| int texture_limit, | int texture_limit, | ||||
| device_vector<DeviceType>& tex_img) | device_vector<DeviceType>& tex_img) | ||||
| { | { | ||||
| const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1; | const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1; | ||||
| ImageInput *in = NULL; | ImageInput *in = NULL; | ||||
| int width, height, depth, components; | if(!file_load_image_generic(img, &in)) { | ||||
| if(!file_load_image_generic(img, &in, width, height, depth, components)) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| /* Get metadata. */ | |||||
| int width = img->metadata.width; | |||||
| int height = img->metadata.height; | |||||
| int depth = img->metadata.depth; | |||||
| int components = img->metadata.channels; | |||||
| /* Read RGBA pixels. */ | /* Read RGBA pixels. */ | ||||
| vector<StorageType> pixels_storage; | vector<StorageType> pixels_storage; | ||||
| StorageType *pixels; | StorageType *pixels; | ||||
| const size_t max_size = max(max(width, height), depth); | const size_t max_size = max(max(width, height), depth); | ||||
| if(max_size == 0) { | if(max_size == 0) { | ||||
| /* Don't bother with invalid images. */ | /* Don't bother with invalid images. */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if(in) { | ||||
| delete in; | delete in; | ||||
| } | } | ||||
| else { | else { | ||||
| if(FileFormat == TypeDesc::FLOAT) { | if(FileFormat == TypeDesc::FLOAT) { | ||||
| builtin_image_float_pixels_cb(img->filename, | builtin_image_float_pixels_cb(img->filename, | ||||
| img->builtin_data, | img->builtin_data, | ||||
| (float*)&pixels[0], | (float*)&pixels[0], | ||||
| num_pixels * components, | num_pixels * components, | ||||
| img->builtin_free_cache); | img->metadata.builtin_free_cache); | ||||
| } | } | ||||
| else if(FileFormat == TypeDesc::UINT8) { | else if(FileFormat == TypeDesc::UINT8) { | ||||
| builtin_image_pixels_cb(img->filename, | builtin_image_pixels_cb(img->filename, | ||||
| img->builtin_data, | img->builtin_data, | ||||
| (uchar*)&pixels[0], | (uchar*)&pixels[0], | ||||
| num_pixels * components, | num_pixels * components, | ||||
| img->builtin_free_cache); | img->metadata.builtin_free_cache); | ||||
| } | } | ||||
| else { | else { | ||||
| /* TODO(dingto): Support half for ImBuf. */ | /* TODO(dingto): Support half for ImBuf. */ | ||||
| } | } | ||||
| } | } | ||||
| /* Check if we actually have a float4 slot, in case components == 1, | /* Check if we actually have a float4 slot, in case components == 1, | ||||
| * but device doesn't support single channel textures. | * but device doesn't support single channel textures. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 392 Lines • Show Last 20 Lines | |||||