2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include "image.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
|
|
|
#include "util_foreach.h"
|
|
|
|
#include "util_image.h"
|
|
|
|
#include "util_path.h"
|
|
|
|
#include "util_progress.h"
|
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
ImageManager::ImageManager()
|
|
|
|
{
|
|
|
|
need_update = true;
|
2012-05-13 12:32:44 +00:00
|
|
|
pack_images = false;
|
2011-05-31 16:21:30 +00:00
|
|
|
osl_texture_system = NULL;
|
2012-11-21 13:00:51 +00:00
|
|
|
animation_frame = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
tex_num_images = TEX_NUM_IMAGES;
|
|
|
|
tex_num_float_images = TEX_NUM_FLOAT_IMAGES;
|
|
|
|
tex_image_byte_start = TEX_IMAGE_BYTE_START;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageManager::~ImageManager()
|
|
|
|
{
|
2012-03-07 12:27:18 +00:00
|
|
|
for(size_t slot = 0; slot < images.size(); slot++)
|
2011-04-27 11:58:34 +00:00
|
|
|
assert(!images[slot]);
|
2012-03-07 12:27:18 +00:00
|
|
|
for(size_t slot = 0; slot < float_images.size(); slot++)
|
|
|
|
assert(!float_images[slot]);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-13 12:32:44 +00:00
|
|
|
void ImageManager::set_pack_images(bool pack_images_)
|
|
|
|
{
|
|
|
|
pack_images = pack_images_;
|
|
|
|
}
|
|
|
|
|
2011-05-31 16:21:30 +00:00
|
|
|
void ImageManager::set_osl_texture_system(void *texture_system)
|
|
|
|
{
|
|
|
|
osl_texture_system = texture_system;
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:38:39 +00:00
|
|
|
void ImageManager::set_extended_image_limits(const DeviceInfo& info)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2014-05-11 01:38:39 +00:00
|
|
|
if(info.type == DEVICE_CPU) {
|
|
|
|
tex_num_images = TEX_EXTENDED_NUM_IMAGES_CPU;
|
|
|
|
tex_num_float_images = TEX_EXTENDED_NUM_FLOAT_IMAGES;
|
|
|
|
tex_image_byte_start = TEX_EXTENDED_IMAGE_BYTE_START;
|
|
|
|
}
|
|
|
|
else if((info.type == DEVICE_CUDA || info.type == DEVICE_MULTI) && info.extended_images) {
|
|
|
|
tex_num_images = TEX_EXTENDED_NUM_IMAGES_GPU;
|
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 13:00:51 +00:00
|
|
|
bool ImageManager::set_animation_frame_update(int frame)
|
|
|
|
{
|
|
|
|
if(frame != animation_frame) {
|
|
|
|
animation_frame = frame;
|
|
|
|
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++)
|
|
|
|
if(images[slot] && images[slot]->animated)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for(size_t slot = 0; slot < float_images.size(); slot++)
|
|
|
|
if(float_images[slot] && float_images[slot]->animated)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-14 21:40:29 +00:00
|
|
|
bool ImageManager::is_float_image(const string& filename, void *builtin_data, bool& is_linear)
|
2012-03-07 12:27:18 +00:00
|
|
|
{
|
|
|
|
bool is_float = false;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = false;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
if(builtin_data) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(builtin_image_info_cb) {
|
2014-03-29 12:03:48 +00:00
|
|
|
int width, height, depth, channels;
|
|
|
|
builtin_image_info_cb(filename, builtin_data, is_float, width, height, depth, channels);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 21:40:29 +00:00
|
|
|
if(is_float)
|
|
|
|
is_linear = true;
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
return is_float;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageInput *in = ImageInput::create(filename);
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
if(in) {
|
|
|
|
ImageSpec spec;
|
|
|
|
|
|
|
|
if(in->open(filename, spec)) {
|
|
|
|
/* check the main format, and channel formats;
|
2012-06-09 17:22:52 +00:00
|
|
|
* if any take up more than one byte, we'll need a float texture slot */
|
2013-02-14 21:40:29 +00:00
|
|
|
if(spec.format.basesize() > 1) {
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = true;
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
for(size_t channel = 0; channel < spec.channelformats.size(); channel++) {
|
2013-02-14 21:40:29 +00:00
|
|
|
if(spec.channelformats[channel].basesize() > 1) {
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* basic color space detection, not great but better than nothing
|
|
|
|
* before we do OpenColorIO integration */
|
|
|
|
if(is_float) {
|
|
|
|
string colorspace = spec.get_string_attribute("oiio:ColorSpace");
|
|
|
|
|
|
|
|
is_linear = !(colorspace == "sRGB" ||
|
|
|
|
colorspace == "GammaCorrected" ||
|
2013-08-29 20:53:20 +00:00
|
|
|
(colorspace == "" &&
|
|
|
|
(strcmp(in->format_name(), "png") == 0 ||
|
|
|
|
strcmp(in->format_name(), "tiff") == 0 ||
|
2014-08-22 17:52:29 +00:00
|
|
|
strcmp(in->format_name(), "dpx") == 0 ||
|
2013-08-29 20:53:20 +00:00
|
|
|
strcmp(in->format_name(), "jpeg2000") == 0)));
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2013-08-29 20:53:20 +00:00
|
|
|
else {
|
2013-02-14 21:40:29 +00:00
|
|
|
is_linear = false;
|
2013-08-29 20:53:20 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
in->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_float;
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:34:57 +00:00
|
|
|
static bool image_equals(ImageManager::Image *image, const string& filename, void *builtin_data, InterpolationType interpolation)
|
2014-03-29 12:03:48 +00:00
|
|
|
{
|
|
|
|
return image->filename == filename &&
|
|
|
|
image->builtin_data == builtin_data &&
|
|
|
|
image->interpolation == interpolation;
|
|
|
|
}
|
|
|
|
|
2014-06-21 20:18:48 +00:00
|
|
|
int ImageManager::add_image(const string& filename, void *builtin_data, bool animated, float frame,
|
|
|
|
bool& is_float, bool& is_linear, InterpolationType interpolation, bool use_alpha)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
Image *img;
|
|
|
|
size_t slot;
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
/* load image info and find out if we need a float texture */
|
2013-02-14 21:40:29 +00:00
|
|
|
is_float = (pack_images)? false: is_float_image(filename, builtin_data, is_linear);
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
if(is_float) {
|
|
|
|
/* find existing image */
|
|
|
|
for(slot = 0; slot < float_images.size(); slot++) {
|
2014-06-21 20:18:48 +00:00
|
|
|
img = float_images[slot];
|
|
|
|
if(img && image_equals(img, filename, builtin_data, interpolation)) {
|
|
|
|
if(img->frame != frame) {
|
|
|
|
img->frame = frame;
|
|
|
|
img->need_load = true;
|
|
|
|
}
|
2014-10-03 09:27:05 +00:00
|
|
|
if(img->use_alpha != use_alpha) {
|
|
|
|
img->use_alpha = use_alpha;
|
|
|
|
img->need_load = true;
|
|
|
|
}
|
2014-06-21 20:18:48 +00:00
|
|
|
img->users++;
|
2012-09-04 13:29:07 +00:00
|
|
|
return slot;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
/* find free slot */
|
|
|
|
for(slot = 0; slot < float_images.size(); slot++) {
|
|
|
|
if(!float_images[slot])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(slot == float_images.size()) {
|
|
|
|
/* max images limit reached */
|
2013-12-14 14:06:18 +00:00
|
|
|
if(float_images.size() == tex_num_float_images) {
|
2012-09-04 13:29:07 +00:00
|
|
|
printf("ImageManager::add_image: float image limit reached %d, skipping '%s'\n",
|
|
|
|
tex_num_float_images, filename.c_str());
|
2012-03-07 12:27:18 +00:00
|
|
|
return -1;
|
2012-07-04 11:48:42 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
float_images.resize(float_images.size() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add new image */
|
|
|
|
img = new Image();
|
|
|
|
img->filename = filename;
|
2013-01-30 13:42:12 +00:00
|
|
|
img->builtin_data = builtin_data;
|
2012-03-07 12:27:18 +00:00
|
|
|
img->need_load = true;
|
2012-11-21 13:00:51 +00:00
|
|
|
img->animated = animated;
|
2014-06-21 20:18:48 +00:00
|
|
|
img->frame = frame;
|
2014-03-07 22:16:09 +00:00
|
|
|
img->interpolation = interpolation;
|
2012-03-07 12:27:18 +00:00
|
|
|
img->users = 1;
|
2014-05-07 14:36:44 +00:00
|
|
|
img->use_alpha = use_alpha;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
float_images[slot] = img;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
else {
|
|
|
|
for(slot = 0; slot < images.size(); slot++) {
|
2014-06-21 20:18:48 +00:00
|
|
|
img = images[slot];
|
|
|
|
if(img && image_equals(img, filename, builtin_data, interpolation)) {
|
|
|
|
if(img->frame != frame) {
|
|
|
|
img->frame = frame;
|
|
|
|
img->need_load = true;
|
|
|
|
}
|
2014-10-03 09:27:05 +00:00
|
|
|
if(img->use_alpha != use_alpha) {
|
|
|
|
img->use_alpha = use_alpha;
|
|
|
|
img->need_load = true;
|
|
|
|
}
|
2014-06-21 20:18:48 +00:00
|
|
|
img->users++;
|
2012-09-04 13:29:07 +00:00
|
|
|
return slot+tex_image_byte_start;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
/* find free slot */
|
|
|
|
for(slot = 0; slot < images.size(); slot++) {
|
|
|
|
if(!images[slot])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(slot == images.size()) {
|
|
|
|
/* max images limit reached */
|
2012-09-04 13:29:07 +00:00
|
|
|
if(images.size() == tex_num_images) {
|
2012-07-04 11:48:42 +00:00
|
|
|
printf("ImageManager::add_image: byte image limit reached %d, skipping '%s'\n",
|
2012-09-04 13:29:07 +00:00
|
|
|
tex_num_images, filename.c_str());
|
2012-03-07 12:27:18 +00:00
|
|
|
return -1;
|
2012-07-04 11:48:42 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
images.resize(images.size() + 1);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
/* add new image */
|
|
|
|
img = new Image();
|
|
|
|
img->filename = filename;
|
2013-01-30 13:42:12 +00:00
|
|
|
img->builtin_data = builtin_data;
|
2012-03-07 12:27:18 +00:00
|
|
|
img->need_load = true;
|
2012-11-21 13:00:51 +00:00
|
|
|
img->animated = animated;
|
2014-06-21 20:18:48 +00:00
|
|
|
img->frame = frame;
|
2014-03-07 22:16:09 +00:00
|
|
|
img->interpolation = interpolation;
|
2012-03-07 12:27:18 +00:00
|
|
|
img->users = 1;
|
2014-05-07 14:36:44 +00:00
|
|
|
img->use_alpha = use_alpha;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
images[slot] = img;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
slot += tex_image_byte_start;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2014-06-21 20:18:48 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = true;
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
void ImageManager::remove_image(int slot)
|
|
|
|
{
|
|
|
|
if(slot >= tex_image_byte_start) {
|
|
|
|
slot -= tex_image_byte_start;
|
|
|
|
|
|
|
|
assert(images[slot] != NULL);
|
|
|
|
|
|
|
|
/* decrement user count */
|
|
|
|
images[slot]->users--;
|
|
|
|
assert(images[slot]->users >= 0);
|
|
|
|
|
|
|
|
/* don't remove immediately, rather do it all together later on. one of
|
|
|
|
* the reasons for this is that on shader changes we add and remove nodes
|
|
|
|
* that use them, but we do not want to reload the image all the time. */
|
|
|
|
if(images[slot]->users == 0)
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* decrement user count */
|
|
|
|
float_images[slot]->users--;
|
|
|
|
assert(float_images[slot]->users >= 0);
|
|
|
|
|
|
|
|
/* don't remove immediately, rather do it all together later on. one of
|
|
|
|
* the reasons for this is that on shader changes we add and remove nodes
|
|
|
|
* that use them, but we do not want to reload the image all the time. */
|
|
|
|
if(float_images[slot]->users == 0)
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 22:16:09 +00:00
|
|
|
void ImageManager::remove_image(const string& filename, void *builtin_data, InterpolationType interpolation)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-05-31 16:21:30 +00:00
|
|
|
size_t slot;
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
for(slot = 0; slot < images.size(); slot++) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(images[slot] && image_equals(images[slot], filename, builtin_data, interpolation)) {
|
|
|
|
remove_image(slot+tex_image_byte_start);
|
2011-05-31 16:21:30 +00:00
|
|
|
break;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-31 16:21:30 +00:00
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
if(slot == images.size()) {
|
|
|
|
/* see if it's in a float texture slot */
|
|
|
|
for(slot = 0; slot < float_images.size(); slot++) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(float_images[slot] && image_equals(float_images[slot], filename, builtin_data, interpolation)) {
|
|
|
|
remove_image(slot);
|
2012-03-07 12:27:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 13:28:33 +00:00
|
|
|
/* TODO(sergey): Deduplicate with the iteration above, but make it pretty,
|
|
|
|
* without bunch of arguments passing around making code readability even
|
|
|
|
* more cluttered.
|
|
|
|
*/
|
|
|
|
void ImageManager::tag_reload_image(const string& filename, void *builtin_data, InterpolationType interpolation)
|
|
|
|
{
|
|
|
|
size_t slot;
|
|
|
|
|
|
|
|
for(slot = 0; slot < images.size(); slot++) {
|
|
|
|
if(images[slot] && image_equals(images[slot], filename, builtin_data, interpolation)) {
|
|
|
|
images[slot]->need_load = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(slot == images.size()) {
|
|
|
|
/* see if it's in a float texture slot */
|
|
|
|
for(slot = 0; slot < float_images.size(); slot++) {
|
|
|
|
if(float_images[slot] && image_equals(float_images[slot], filename, builtin_data, interpolation)) {
|
2014-08-22 11:36:00 +00:00
|
|
|
float_images[slot]->need_load = true;
|
2014-07-18 13:28:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool ImageManager::file_load_image(Image *img, device_vector<uchar4>& tex_img)
|
|
|
|
{
|
|
|
|
if(img->filename == "")
|
|
|
|
return false;
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
ImageInput *in = NULL;
|
2014-03-29 12:03:48 +00:00
|
|
|
int width, height, depth, components;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
if(!img->builtin_data) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
/* load image from file through OIIO */
|
|
|
|
in = ImageInput::create(img->filename);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(!in)
|
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
ImageSpec spec = ImageSpec();
|
|
|
|
ImageSpec config = ImageSpec();
|
|
|
|
|
|
|
|
if(img->use_alpha == false)
|
|
|
|
config.attribute("oiio:UnassociatedAlpha", 1);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
if(!in->open(img->filename, spec, config)) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
delete in;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = spec.width;
|
|
|
|
height = spec.height;
|
2014-03-29 12:03:48 +00:00
|
|
|
depth = spec.depth;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
components = spec.nchannels;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* load image using builtin images callbacks */
|
|
|
|
if(!builtin_image_info_cb || !builtin_image_pixels_cb)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool is_float;
|
2014-03-29 12:03:48 +00:00
|
|
|
builtin_image_info_cb(img->filename, img->builtin_data, is_float, width, height, depth, components);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we only handle certain number of components */
|
2013-08-30 17:01:44 +00:00
|
|
|
if(!(components >= 1 && components <= 4)) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(in) {
|
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read RGBA pixels */
|
2014-03-29 12:03:48 +00:00
|
|
|
uchar *pixels = (uchar*)tex_img.resize(width, height, depth);
|
2014-06-21 18:42:03 +00:00
|
|
|
bool cmyk = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(in) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(depth <= 1) {
|
|
|
|
int scanlinesize = width*components*sizeof(uchar);
|
|
|
|
|
|
|
|
in->read_image(TypeDesc::UINT8,
|
|
|
|
(uchar*)pixels + (height-1)*scanlinesize,
|
|
|
|
AutoStride,
|
|
|
|
-scanlinesize,
|
|
|
|
AutoStride);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
in->read_image(TypeDesc::UINT8, (uchar*)pixels);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-06-21 18:42:03 +00:00
|
|
|
cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
else {
|
2013-01-30 13:42:12 +00:00
|
|
|
builtin_image_pixels_cb(img->filename, img->builtin_data, pixels);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-06-21 18:42:03 +00:00
|
|
|
if(cmyk) {
|
|
|
|
/* CMYK */
|
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
|
|
|
pixels[i*4+2] = (pixels[i*4+2]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+1] = (pixels[i*4+1]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+0] = (pixels[i*4+0]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+3] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 2) {
|
|
|
|
/* grayscale + alpha */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2013-08-30 17:01:44 +00:00
|
|
|
pixels[i*4+3] = pixels[i*2+1];
|
|
|
|
pixels[i*4+2] = pixels[i*2+0];
|
|
|
|
pixels[i*4+1] = pixels[i*2+0];
|
|
|
|
pixels[i*4+0] = pixels[i*2+0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 3) {
|
2014-06-21 18:42:03 +00:00
|
|
|
/* RGB */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2011-04-27 11:58:34 +00:00
|
|
|
pixels[i*4+3] = 255;
|
|
|
|
pixels[i*4+2] = pixels[i*3+2];
|
|
|
|
pixels[i*4+1] = pixels[i*3+1];
|
|
|
|
pixels[i*4+0] = pixels[i*3+0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 1) {
|
2014-06-21 18:42:03 +00:00
|
|
|
/* grayscale */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2011-04-27 11:58:34 +00:00
|
|
|
pixels[i*4+3] = 255;
|
|
|
|
pixels[i*4+2] = pixels[i];
|
|
|
|
pixels[i*4+1] = pixels[i];
|
|
|
|
pixels[i*4+0] = pixels[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
if(img->use_alpha == false) {
|
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
|
|
|
pixels[i*4+3] = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
bool ImageManager::file_load_float_image(Image *img, device_vector<float4>& tex_img)
|
|
|
|
{
|
|
|
|
if(img->filename == "")
|
|
|
|
return false;
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
ImageInput *in = NULL;
|
2014-03-29 12:03:48 +00:00
|
|
|
int width, height, depth, components;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
if(!img->builtin_data) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
/* load image from file through OIIO */
|
|
|
|
in = ImageInput::create(img->filename);
|
2012-03-07 12:27:18 +00:00
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(!in)
|
|
|
|
return false;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
ImageSpec spec = ImageSpec();
|
|
|
|
ImageSpec config = ImageSpec();
|
|
|
|
|
|
|
|
if(img->use_alpha == false)
|
|
|
|
config.attribute("oiio:UnassociatedAlpha",1);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
if(!in->open(img->filename, spec, config)) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
delete in;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we only handle certain number of components */
|
|
|
|
width = spec.width;
|
|
|
|
height = spec.height;
|
2014-03-29 12:03:48 +00:00
|
|
|
depth = spec.depth;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
components = spec.nchannels;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
else {
|
|
|
|
/* load image using builtin images callbacks */
|
|
|
|
if(!builtin_image_info_cb || !builtin_image_float_pixels_cb)
|
|
|
|
return false;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
bool is_float;
|
2014-03-29 12:03:48 +00:00
|
|
|
builtin_image_info_cb(img->filename, img->builtin_data, is_float, width, height, depth, components);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2014-05-19 14:23:37 +00:00
|
|
|
if(components < 1 || width == 0 || height == 0) {
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(in) {
|
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read RGBA pixels */
|
2014-03-29 12:03:48 +00:00
|
|
|
float *pixels = (float*)tex_img.resize(width, height, depth);
|
2014-06-21 18:42:03 +00:00
|
|
|
bool cmyk = false;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
if(in) {
|
2014-05-19 14:23:37 +00:00
|
|
|
float *readpixels = pixels;
|
|
|
|
vector<float> tmppixels;
|
|
|
|
|
|
|
|
if(components > 4) {
|
|
|
|
tmppixels.resize(width*height*components);
|
|
|
|
readpixels = &tmppixels[0];
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
if(depth <= 1) {
|
|
|
|
int scanlinesize = width*components*sizeof(float);
|
|
|
|
|
|
|
|
in->read_image(TypeDesc::FLOAT,
|
2014-05-19 14:23:37 +00:00
|
|
|
(uchar*)readpixels + (height-1)*scanlinesize,
|
2014-03-29 12:03:48 +00:00
|
|
|
AutoStride,
|
|
|
|
-scanlinesize,
|
|
|
|
AutoStride);
|
|
|
|
}
|
|
|
|
else {
|
2014-05-19 14:23:37 +00:00
|
|
|
in->read_image(TypeDesc::FLOAT, (uchar*)readpixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(components > 4) {
|
|
|
|
for(int i = width*height-1; i >= 0; i--) {
|
|
|
|
pixels[i*4+3] = tmppixels[i*components+3];
|
|
|
|
pixels[i*4+2] = tmppixels[i*components+2];
|
|
|
|
pixels[i*4+1] = tmppixels[i*components+1];
|
|
|
|
pixels[i*4+0] = tmppixels[i*components+0];
|
|
|
|
}
|
|
|
|
|
|
|
|
tmppixels.clear();
|
2014-03-29 12:03:48 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2014-06-21 18:42:03 +00:00
|
|
|
cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
|
|
|
|
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
in->close();
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
else {
|
2013-01-30 13:42:12 +00:00
|
|
|
builtin_image_float_pixels_cb(img->filename, img->builtin_data, pixels);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2014-06-21 18:42:03 +00:00
|
|
|
if(cmyk) {
|
|
|
|
/* CMYK */
|
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
|
|
|
pixels[i*4+3] = 255;
|
|
|
|
pixels[i*4+2] = (pixels[i*4+2]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+1] = (pixels[i*4+1]*pixels[i*4+3])/255;
|
|
|
|
pixels[i*4+0] = (pixels[i*4+0]*pixels[i*4+3])/255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 2) {
|
|
|
|
/* grayscale + alpha */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2013-08-30 17:01:44 +00:00
|
|
|
pixels[i*4+3] = pixels[i*2+1];
|
|
|
|
pixels[i*4+2] = pixels[i*2+0];
|
|
|
|
pixels[i*4+1] = pixels[i*2+0];
|
|
|
|
pixels[i*4+0] = pixels[i*2+0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 3) {
|
2014-06-21 18:42:03 +00:00
|
|
|
/* RGB */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2012-03-07 12:27:18 +00:00
|
|
|
pixels[i*4+3] = 1.0f;
|
|
|
|
pixels[i*4+2] = pixels[i*3+2];
|
|
|
|
pixels[i*4+1] = pixels[i*3+1];
|
|
|
|
pixels[i*4+0] = pixels[i*3+0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(components == 1) {
|
2014-06-21 18:42:03 +00:00
|
|
|
/* grayscale */
|
2014-03-29 12:03:48 +00:00
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
2012-03-07 12:27:18 +00:00
|
|
|
pixels[i*4+3] = 1.0f;
|
|
|
|
pixels[i*4+2] = pixels[i];
|
|
|
|
pixels[i*4+1] = pixels[i];
|
|
|
|
pixels[i*4+0] = pixels[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 14:36:44 +00:00
|
|
|
if(img->use_alpha == false) {
|
|
|
|
for(int i = width*height*depth-1; i >= 0; i--) {
|
|
|
|
pixels[i*4+3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-05-05 19:44:33 +00:00
|
|
|
if(progress->get_cancel())
|
|
|
|
return;
|
2014-03-29 12:03:48 +00:00
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
Image *img;
|
|
|
|
bool is_float;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if(slot >= tex_image_byte_start) {
|
|
|
|
img = images[slot - tex_image_byte_start];
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = false;
|
|
|
|
}
|
|
|
|
else {
|
2012-09-04 13:29:07 +00:00
|
|
|
img = float_images[slot];
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
if(osl_texture_system && !img->builtin_data)
|
|
|
|
return;
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
if(is_float) {
|
2012-09-04 13:29:07 +00:00
|
|
|
string filename = path_filename(float_images[slot]->filename);
|
2012-05-05 19:44:33 +00:00
|
|
|
progress->set_status("Updating Images", "Loading " + filename);
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
device_vector<float4>& tex_img = dscene->tex_float_image[slot];
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2012-09-27 17:42:09 +00:00
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2012-03-07 12:27:18 +00:00
|
|
|
device->tex_free(tex_img);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
if(!file_load_float_image(img, tex_img)) {
|
2012-07-04 11:48:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
2012-03-07 12:27:18 +00:00
|
|
|
float *pixels = (float*)tex_img.resize(1, 1);
|
|
|
|
|
2012-07-04 11:48:42 +00:00
|
|
|
pixels[0] = TEX_IMAGE_MISSING_R;
|
|
|
|
pixels[1] = TEX_IMAGE_MISSING_G;
|
|
|
|
pixels[2] = TEX_IMAGE_MISSING_B;
|
|
|
|
pixels[3] = TEX_IMAGE_MISSING_A;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
string name;
|
|
|
|
|
2014-06-09 10:38:46 +00:00
|
|
|
if(slot >= 100) name = string_printf("__tex_image_float_%d", slot);
|
|
|
|
else if(slot >= 10) name = string_printf("__tex_image_float_0%d", slot);
|
2012-03-07 12:27:18 +00:00
|
|
|
else name = string_printf("__tex_image_float_00%d", slot);
|
|
|
|
|
2012-09-27 17:42:09 +00:00
|
|
|
if(!pack_images) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2014-03-07 22:16:09 +00:00
|
|
|
device->tex_alloc(name.c_str(), tex_img, img->interpolation, true);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
else {
|
2012-09-04 13:29:07 +00:00
|
|
|
string filename = path_filename(images[slot - tex_image_byte_start]->filename);
|
2012-05-05 19:44:33 +00:00
|
|
|
progress->set_status("Updating Images", "Loading " + filename);
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
device_vector<uchar4>& tex_img = dscene->tex_image[slot - tex_image_byte_start];
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2012-09-27 17:42:09 +00:00
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2012-03-07 12:27:18 +00:00
|
|
|
device->tex_free(tex_img);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
|
|
|
|
if(!file_load_image(img, tex_img)) {
|
2012-07-04 11:48:42 +00:00
|
|
|
/* on failure to load, we set a 1x1 pixels pink image */
|
2012-03-07 12:27:18 +00:00
|
|
|
uchar *pixels = (uchar*)tex_img.resize(1, 1);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-07-04 11:48:42 +00:00
|
|
|
pixels[0] = (TEX_IMAGE_MISSING_R * 255);
|
|
|
|
pixels[1] = (TEX_IMAGE_MISSING_G * 255);
|
|
|
|
pixels[2] = (TEX_IMAGE_MISSING_B * 255);
|
|
|
|
pixels[3] = (TEX_IMAGE_MISSING_A * 255);
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string name;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-06-09 10:38:46 +00:00
|
|
|
if(slot >= 100) name = string_printf("__tex_image_%d", slot);
|
|
|
|
else if(slot >= 10) name = string_printf("__tex_image_0%d", slot);
|
2012-03-07 12:27:18 +00:00
|
|
|
else name = string_printf("__tex_image_00%d", slot);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-27 17:42:09 +00:00
|
|
|
if(!pack_images) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
2014-03-07 22:16:09 +00:00
|
|
|
device->tex_alloc(name.c_str(), tex_img, img->interpolation, true);
|
2012-09-27 17:42:09 +00:00
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2012-05-05 19:44:33 +00:00
|
|
|
|
|
|
|
img->need_load = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageManager::device_free_image(Device *device, DeviceScene *dscene, int slot)
|
|
|
|
{
|
2012-03-07 12:27:18 +00:00
|
|
|
Image *img;
|
|
|
|
bool is_float;
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if(slot >= tex_image_byte_start) {
|
|
|
|
img = images[slot - tex_image_byte_start];
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = false;
|
|
|
|
}
|
|
|
|
else {
|
2012-09-04 13:29:07 +00:00
|
|
|
img = float_images[slot];
|
2012-03-07 12:27:18 +00:00
|
|
|
is_float = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(img) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(osl_texture_system && !img->builtin_data) {
|
2011-05-31 16:21:30 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
ustring filename(images[slot]->filename);
|
|
|
|
((OSL::TextureSystem*)osl_texture_system)->invalidate(filename);
|
|
|
|
#endif
|
|
|
|
}
|
2012-03-07 12:27:18 +00:00
|
|
|
else if(is_float) {
|
2012-09-27 17:42:09 +00:00
|
|
|
device_vector<float4>& tex_img = dscene->tex_float_image[slot];
|
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex_img.clear();
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
delete float_images[slot];
|
|
|
|
float_images[slot] = NULL;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2011-05-31 16:21:30 +00:00
|
|
|
else {
|
2012-09-27 17:42:09 +00:00
|
|
|
device_vector<uchar4>& tex_img = dscene->tex_image[slot - tex_image_byte_start];
|
|
|
|
|
|
|
|
if(tex_img.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(tex_img);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex_img.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
delete images[slot - tex_image_byte_start];
|
|
|
|
images[slot - tex_image_byte_start] = NULL;
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageManager::device_update(Device *device, DeviceScene *dscene, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
2012-09-27 17:42:09 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
TaskPool pool;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++) {
|
2012-05-05 19:44:33 +00:00
|
|
|
if(!images[slot])
|
|
|
|
continue;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
if(images[slot]->users == 0) {
|
2012-09-04 13:29:07 +00:00
|
|
|
device_free_image(device, dscene, slot + tex_image_byte_start);
|
2012-05-05 19:44:33 +00:00
|
|
|
}
|
|
|
|
else if(images[slot]->need_load) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(!osl_texture_system || images[slot]->builtin_data)
|
2012-09-04 13:29:07 +00:00
|
|
|
pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot + tex_image_byte_start, &progress));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 12:27:18 +00:00
|
|
|
for(size_t slot = 0; slot < float_images.size(); slot++) {
|
2012-05-05 19:44:33 +00:00
|
|
|
if(!float_images[slot])
|
|
|
|
continue;
|
2012-03-07 12:27:18 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
if(float_images[slot]->users == 0) {
|
2012-09-04 13:29:07 +00:00
|
|
|
device_free_image(device, dscene, slot);
|
2012-05-05 19:44:33 +00:00
|
|
|
}
|
|
|
|
else if(float_images[slot]->need_load) {
|
2014-03-29 12:03:48 +00:00
|
|
|
if(!osl_texture_system || float_images[slot]->builtin_data)
|
2012-09-04 13:29:07 +00:00
|
|
|
pool.push(function_bind(&ImageManager::device_load_image, this, device, dscene, slot, &progress));
|
2012-03-07 12:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
pool.wait_work();
|
|
|
|
|
2012-05-13 12:32:44 +00:00
|
|
|
if(pack_images)
|
|
|
|
device_pack_images(device, dscene, progress);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = false;
|
|
|
|
}
|
|
|
|
|
2012-05-13 12:32:44 +00:00
|
|
|
void ImageManager::device_pack_images(Device *device, DeviceScene *dscene, Progress& progess)
|
|
|
|
{
|
|
|
|
/* for OpenCL, we pack all image textures inside a single big texture, and
|
2012-06-09 17:22:52 +00:00
|
|
|
* will do our own interpolation in the kernel */
|
2012-05-13 12:32:44 +00:00
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++) {
|
|
|
|
if(!images[slot])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
device_vector<uchar4>& tex_img = dscene->tex_image[slot];
|
|
|
|
size += tex_img.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint4 *info = dscene->tex_image_packed_info.resize(images.size());
|
|
|
|
uchar4 *pixels = dscene->tex_image_packed.resize(size);
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++) {
|
|
|
|
if(!images[slot])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
device_vector<uchar4>& tex_img = dscene->tex_image[slot];
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
/* todo: support 3D textures, only CPU for now */
|
2014-03-07 22:16:09 +00:00
|
|
|
|
|
|
|
/* The image options are packed
|
|
|
|
bit 0 -> periodic
|
|
|
|
bit 1 + 2 -> interpolation type */
|
2014-03-07 23:23:45 +00:00
|
|
|
uint8_t interpolation = (images[slot]->interpolation << 1) + 1;
|
2014-03-07 22:16:09 +00:00
|
|
|
info[slot] = make_uint4(tex_img.data_width, tex_img.data_height, offset, interpolation);
|
2012-05-13 12:32:44 +00:00
|
|
|
|
|
|
|
memcpy(pixels+offset, (void*)tex_img.data_pointer, tex_img.memory_size());
|
|
|
|
offset += tex_img.size();
|
|
|
|
}
|
|
|
|
|
2014-03-07 22:16:09 +00:00
|
|
|
if(dscene->tex_image_packed.size()) {
|
|
|
|
if(dscene->tex_image_packed.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(dscene->tex_image_packed);
|
|
|
|
}
|
2012-05-13 12:32:44 +00:00
|
|
|
device->tex_alloc("__tex_image_packed", dscene->tex_image_packed);
|
2014-03-07 22:16:09 +00:00
|
|
|
}
|
|
|
|
if(dscene->tex_image_packed_info.size()) {
|
|
|
|
if(dscene->tex_image_packed_info.device_pointer) {
|
|
|
|
thread_scoped_lock device_lock(device_mutex);
|
|
|
|
device->tex_free(dscene->tex_image_packed_info);
|
|
|
|
}
|
2012-05-13 12:32:44 +00:00
|
|
|
device->tex_alloc("__tex_image_packed_info", dscene->tex_image_packed_info);
|
2014-03-07 22:16:09 +00:00
|
|
|
}
|
2012-05-13 12:32:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 12:45:52 +00:00
|
|
|
void ImageManager::device_free_builtin(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++)
|
|
|
|
if(images[slot] && images[slot]->builtin_data)
|
|
|
|
device_free_image(device, dscene, slot + tex_image_byte_start);
|
|
|
|
|
|
|
|
for(size_t slot = 0; slot < float_images.size(); slot++)
|
|
|
|
if(float_images[slot] && float_images[slot]->builtin_data)
|
|
|
|
device_free_image(device, dscene, slot);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void ImageManager::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
for(size_t slot = 0; slot < images.size(); slot++)
|
2012-09-04 13:29:07 +00:00
|
|
|
device_free_image(device, dscene, slot + tex_image_byte_start);
|
2012-03-07 12:27:18 +00:00
|
|
|
for(size_t slot = 0; slot < float_images.size(); slot++)
|
2012-09-04 13:29:07 +00:00
|
|
|
device_free_image(device, dscene, slot);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-13 12:32:44 +00:00
|
|
|
device->tex_free(dscene->tex_image_packed);
|
|
|
|
device->tex_free(dscene->tex_image_packed_info);
|
2012-09-27 17:42:09 +00:00
|
|
|
|
|
|
|
dscene->tex_image_packed.clear();
|
2012-05-13 12:32:44 +00:00
|
|
|
dscene->tex_image_packed_info.clear();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
images.clear();
|
2012-03-07 12:27:18 +00:00
|
|
|
float_images.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|