本文整理汇总了C++中ImageBuf::name方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageBuf::name方法的具体用法?C++ ImageBuf::name怎么用?C++ ImageBuf::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageBuf
的用法示例。
在下文中一共展示了ImageBuf::name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
bool
ImageBuf::copy (const ImageBuf &src)
{
if (! m_spec_valid && ! m_pixels_valid) {
// uninitialized
if (! src.m_spec_valid && ! src.m_pixels_valid)
return true; // uninitialized=uninitialized is a nop
// uninitialized = initialized : set up *this with local storage
reset (src.name(), src.spec());
}
bool selfcopy = (&src == this);
if (cachedpixels()) {
if (selfcopy) { // special case: self copy of ImageCache loads locally
return read (subimage(), miplevel(), true /*force*/);
}
reset (src.name(), src.spec());
// Now it has local pixels
}
if (selfcopy)
return true;
if (localpixels()) {
if (m_clientpixels) {
// app-owned memory
if (spec().width != src.spec().width ||
spec().height != src.spec().height ||
spec().depth != src.spec().depth ||
spec().nchannels != src.spec().nchannels) {
// size doesn't match, fail
return false;
}
this->copy_metadata (src);
} else {
// locally owned memory -- we can fully resize it
reset (src.name(), src.spec());
}
return this->copy_pixels (src);
}
return false; // all other cases fail
}
示例2: src
static void
make_texturemap (const char *maptypename = "texture map")
{
if (filenames.size() != 1) {
std::cerr << "maketx ERROR: " << maptypename
<< " requires exactly one input filename\n";
exit (EXIT_FAILURE);
}
if (! Filesystem::exists (filenames[0])) {
std::cerr << "maketx ERROR: \"" << filenames[0] << "\" does not exist\n";
exit (EXIT_FAILURE);
}
if (outputfilename.empty()) {
std::string ext = boost::filesystem::extension (filenames[0]);
int notextlen = (int) filenames[0].length() - (int) ext.length();
outputfilename = std::string (filenames[0].begin(),
filenames[0].begin() + notextlen);
outputfilename += ".tx";
}
// When was the input file last modified?
std::time_t in_time = boost::filesystem::last_write_time (filenames[0]);
// When in update mode, skip making the texture if the output already
// exists and has the same file modification time as the input file.
if (updatemode && Filesystem::exists (outputfilename) &&
(in_time == boost::filesystem::last_write_time (outputfilename))) {
std::cout << "maketx: no update required for \""
<< outputfilename << "\"\n";
return;
}
ImageBuf src (filenames[0]);
src.init_spec (filenames[0], 0, 0); // force it to get the spec, not read
// The cache might mess with the apparent data format. But for the
// purposes of what we should output, figure it out now, before the
// file has been read and cached.
TypeDesc out_dataformat = src.spec().format;
// Figure out which data format we want for output
if (! dataformatname.empty()) {
if (dataformatname == "uint8")
out_dataformat = TypeDesc::UINT8;
else if (dataformatname == "int8" || dataformatname == "sint8")
out_dataformat = TypeDesc::INT8;
else if (dataformatname == "uint16")
out_dataformat = TypeDesc::UINT16;
else if (dataformatname == "int16" || dataformatname == "sint16")
out_dataformat = TypeDesc::INT16;
else if (dataformatname == "half")
out_dataformat = TypeDesc::HALF;
else if (dataformatname == "float")
out_dataformat = TypeDesc::FLOAT;
else if (dataformatname == "double")
out_dataformat = TypeDesc::DOUBLE;
}
// We cannot compute the prman / oiio options until after out_dataformat
// has been determined, as it's required (and can potentially change
// out_dataformat too!)
if (prman) out_dataformat = set_prman_options (out_dataformat);
else if (oiio) out_dataformat = set_oiio_options (out_dataformat);
// Read the full file locally if it's less than 1 GB, otherwise
// allow the ImageBuf to use ImageCache to manage memory.
bool read_local = (src.spec().image_bytes() < size_t(1024*1024*1024));
if (verbose)
std::cout << "Reading file: " << filenames[0] << std::endl;
Timer readtimer;
if (! src.read (0, 0, read_local)) {
std::cerr
<< "maketx ERROR: Could not read \""
<< filenames[0] << "\" : " << src.geterror() << "\n";
exit (EXIT_FAILURE);
}
stat_readtime += readtimer();
// If requested - and we're a constant color - make a tiny texture instead
std::vector<float> constantColor(src.nchannels());
bool isConstantColor = ImageBufAlgo::isConstantColor (src, &constantColor[0]);
if (isConstantColor && constant_color_detect) {
int newwidth = std::max (1, std::min (src.spec().width, tile[0]));
int newheight = std::max (1, std::min (src.spec().height, tile[1]));
ImageSpec newspec = src.spec();
newspec.x = 0;
newspec.y = 0;
newspec.z = 0;
newspec.width = newwidth;
newspec.height = newheight;
newspec.depth = 1;
newspec.full_x = 0;
newspec.full_y = 0;
newspec.full_z = 0;
//.........这里部分代码省略.........
示例3: int
OIIO_NAMESPACE_BEGIN
bool
ImageBufAlgo::from_IplImage (ImageBuf &dst, const IplImage *ipl,
TypeDesc convert)
{
if (! ipl) {
DASSERT (0 && "ImageBufAlgo::fromIplImage called with NULL ipl");
dst.error ("Passed NULL source IplImage");
return false;
}
#ifdef USE_OPENCV
TypeDesc srcformat;
switch (ipl->depth) {
case int(IPL_DEPTH_8U) :
srcformat = TypeDesc::UINT8; break;
case int(IPL_DEPTH_8S) :
srcformat = TypeDesc::INT8; break;
case int(IPL_DEPTH_16U) :
srcformat = TypeDesc::UINT16; break;
case int(IPL_DEPTH_16S) :
srcformat = TypeDesc::INT16; break;
case int(IPL_DEPTH_32F) :
srcformat = TypeDesc::FLOAT; break;
case int(IPL_DEPTH_64F) :
srcformat = TypeDesc::DOUBLE; break;
default:
DASSERT (0 && "unknown IplImage type");
dst.error ("Unsupported IplImage depth %d", (int)ipl->depth);
return false;
}
TypeDesc dstformat = (convert != TypeDesc::UNKNOWN) ? convert : srcformat;
ImageSpec spec (ipl->width, ipl->height, ipl->nChannels, dstformat);
// N.B. The OpenCV headers say that ipl->alphaChannel,
// ipl->colorModel, and ipl->channelSeq are ignored by OpenCV.
if (ipl->dataOrder != IPL_DATA_ORDER_PIXEL) {
// We don't handle separate color channels, and OpenCV doesn't either
dst.error ("Unsupported IplImage data order %d", (int)ipl->dataOrder);
return false;
}
dst.reset (dst.name(), spec);
size_t pixelsize = srcformat.size()*spec.nchannels;
// Account for the origin in the line step size, to end up with the
// standard OIIO origin-at-upper-left:
size_t linestep = ipl->origin ? -ipl->widthStep : ipl->widthStep;
// Block copy and convert
convert_image (spec.nchannels, spec.width, spec.height, 1,
ipl->imageData, srcformat,
pixelsize, linestep, 0,
dst.pixeladdr(0,0), dstformat,
spec.pixel_bytes(), spec.scanline_bytes(), 0);
// FIXME - honor dataOrder. I'm not sure if it is ever used by
// OpenCV. Fix when it becomes a problem.
// OpenCV uses BGR ordering
// FIXME: what do they do with alpha?
if (spec.nchannels >= 3) {
float pixel[4];
for (int y = 0; y < spec.height; ++y) {
for (int x = 0; x < spec.width; ++x) {
dst.getpixel (x, y, pixel, 4);
float tmp = pixel[0]; pixel[0] = pixel[2]; pixel[2] = tmp;
dst.setpixel (x, y, pixel, 4);
}
}
}
// FIXME -- the copy and channel swap should happen all as one loop,
// probably templated by type.
return true;
#else
dst.error ("fromIplImage not supported -- no OpenCV support at compile time");
return false;
#endif
}
示例4: src
bool
ImageBufAlgo::make_texture (ImageBufAlgo::MakeTextureMode mode,
const std::vector<std::string> &filenames,
const std::string &_outputfilename,
const ImageSpec &_configspec,
std::ostream *outstream_ptr)
{
ASSERT (mode >= 0 && mode < ImageBufAlgo::_MakeTxLast);
Timer alltime;
ImageSpec configspec = _configspec;
// const char *modenames[] = { "texture map", "shadow map",
// "latlong environment map" };
std::stringstream localstream; // catch output when user doesn't want it
std::ostream &outstream (outstream_ptr ? *outstream_ptr : localstream);
double stat_readtime = 0;
double stat_writetime = 0;
double stat_resizetime = 0;
double stat_miptime = 0;
double stat_colorconverttime = 0;
std::string filename = filenames[0];
if (! Filesystem::exists (filename)) {
outstream << "maketx ERROR: \"" << filename << "\" does not exist\n";
return false;
}
std::string outputfilename = _outputfilename.length() ? _outputfilename
: Filesystem::replace_extension (filename, ".tx");
// When was the input file last modified?
std::time_t in_time = Filesystem::last_write_time (filename);
// When in update mode, skip making the texture if the output already
// exists and has the same file modification time as the input file.
bool updatemode = configspec.get_int_attribute ("maketx:updatemode");
if (updatemode && Filesystem::exists (outputfilename) &&
(in_time == Filesystem::last_write_time (outputfilename))) {
outstream << "maketx: no update required for \""
<< outputfilename << "\"\n";
return true;
}
bool shadowmode = (mode == ImageBufAlgo::MakeTxShadow);
bool envlatlmode = (mode == ImageBufAlgo::MakeTxEnvLatl);
// Find an ImageIO plugin that can open the output file, and open it
std::string outformat = configspec.get_string_attribute ("maketx:fileformatname",
outputfilename);
ImageOutput *out = ImageOutput::create (outformat.c_str());
if (! out) {
outstream
<< "maketx ERROR: Could not find an ImageIO plugin to write "
<< outformat << " files:" << geterror() << "\n";
return false;
}
if (! out->supports ("tiles")) {
outstream << "maketx ERROR: \"" << outputfilename
<< "\" format does not support tiled images\n";
return false;
}
ImageBuf src (filename);
src.init_spec (filename, 0, 0); // force it to get the spec, not read
// The cache might mess with the apparent data format. But for the
// purposes of what we should output, figure it out now, before the
// file has been read and cached.
TypeDesc out_dataformat = src.spec().format;
if (configspec.format != TypeDesc::UNKNOWN)
out_dataformat = configspec.format;
// We cannot compute the prman / oiio options until after out_dataformat
// has been determined, as it's required (and can potentially change
// out_dataformat too!)
if (configspec.get_int_attribute("maketx:prman_options"))
out_dataformat = set_prman_options (out_dataformat, configspec);
else if (configspec.get_int_attribute("maketx:oiio_options"))
out_dataformat = set_oiio_options (out_dataformat, configspec);
// Read the full file locally if it's less than 1 GB, otherwise
// allow the ImageBuf to use ImageCache to manage memory.
bool read_local = (src.spec().image_bytes() < size_t(1024*1024*1024));
bool verbose = configspec.get_int_attribute ("maketx:verbose");
if (verbose)
outstream << "Reading file: " << filename << std::endl;
Timer readtimer;
if (! src.read (0, 0, read_local)) {
outstream
<< "maketx ERROR: Could not read \""
<< filename << "\" : " << src.geterror() << "\n";
return false;
}
stat_readtime += readtimer();
// If requested - and we're a constant color - make a tiny texture instead
// Only safe if the full/display window is the same as the data window.
// Also note that this could affect the appearance when using "black"
// wrap mode at runtime.
//.........这里部分代码省略.........