本文整理汇总了C++中ImageBuf::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageBuf::copy方法的具体用法?C++ ImageBuf::copy怎么用?C++ ImageBuf::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageBuf
的用法示例。
在下文中一共展示了ImageBuf::copy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fixNonFinite
// DEPRECATED 2-argument version
bool
ImageBufAlgo::fixNonFinite (ImageBuf &dst, const ImageBuf &src,
NonFiniteFixMode mode, int *pixelsFixed)
{
ROI roi;
IBAprep (roi, &dst, &src);
if (dst.nchannels() != src.nchannels()) {
dst.error ("channel number mismatch: %d vs. %d",
dst.spec().nchannels, src.spec().nchannels);
return false;
}
if ((const ImageBuf *)&dst != &src)
if (! dst.copy (src))
return false;
return fixNonFinite (dst, mode, pixelsFixed, roi);
}
示例2:
bool
ImageBufAlgo::convolve (ImageBuf &dst, const ImageBuf &src,
const ImageBuf &kernel, bool normalize,
ROI roi, int nthreads)
{
if (! IBAprep (roi, &dst, &src, IBAprep_REQUIRE_SAME_NCHANNELS))
return false;
bool ok;
const ImageBuf *K = &kernel;
ImageBuf Ktmp;
if (kernel.spec().format != TypeDesc::FLOAT) {
Ktmp.copy (kernel, TypeDesc::FLOAT);
K = &Ktmp;
}
OIIO_DISPATCH_COMMON_TYPES2 (ok, "convolve", convolve_,
dst.spec().format, src.spec().format,
dst, src, *K, normalize, roi, nthreads);
return ok;
}
示例3: switch
bool
ImageBufAlgo::reorient (ImageBuf &dst, const ImageBuf &src, int nthreads)
{
ImageBuf tmp;
bool ok = false;
switch (src.orientation()) {
case 1:
ok = dst.copy (src);
break;
case 2:
ok = ImageBufAlgo::flop (dst, src);
break;
case 3:
ok = ImageBufAlgo::rotate180 (dst, src);
break;
case 4:
ok = ImageBufAlgo::flip (dst, src);
break;
case 5:
ok = ImageBufAlgo::rotate270 (tmp, src);
if (ok)
ok = ImageBufAlgo::flop (dst, tmp);
else
dst.error ("%s", tmp.geterror());
break;
case 6:
ok = ImageBufAlgo::rotate90 (dst, src);
break;
case 7:
ok = ImageBufAlgo::flip (tmp, src);
if (ok)
ok = ImageBufAlgo::rotate90 (dst, tmp);
else
dst.error ("%s", tmp.geterror());
break;
case 8:
ok = ImageBufAlgo::rotate270 (dst, src);
break;
}
dst.set_orientation (1);
return ok;
}
示例4:
bool
ImageBufAlgo::flatten (ImageBuf &dst, const ImageBuf &src,
ROI roi, int nthreads)
{
if (! src.deep()) {
// For some reason, we were asked to flatten an already-flat image.
// So just copy it.
return dst.copy (src);
}
// Construct an ideal spec for dst, which is like src but not deep.
ImageSpec force_spec = src.spec();
force_spec.deep = false;
force_spec.channelformats.clear();
if (! IBAprep (roi, &dst, &src, NULL, &force_spec, IBAprep_SUPPORT_DEEP))
return false;
if (dst.spec().deep) {
dst.error ("Cannot flatten to a deep image");
return false;
}
const ImageSpec &srcspec (src.spec());
int alpha_channel, RA_channel, GA_channel, BA_channel;
int R_channel, G_channel, B_channel, Z_channel, Zback_channel;
if (! find_deep_channels (srcspec, alpha_channel,
RA_channel, GA_channel, BA_channel,
R_channel, G_channel, B_channel,
Z_channel, Zback_channel)) {
dst.error ("No alpha channel could be identified");
return false;
}
bool ok;
OIIO_DISPATCH_TYPES (ok, "flatten", flatten_, dst.spec().format,
dst, src, roi, nthreads);
return ok;
}
示例5: bigSpec
ImageBuf *
SMT::buildBig()
{
if( verbose && sourceFiles.size() > 1 ) {
cout << "INFO: Collating source images\n";
cout << " nFiles: " << sourceFiles.size() << endl;
cout << " stride: " << stride << endl;
if( sourceFiles.size() % stride != 0 )
cout << "WARNING: number of source files isnt divisible by stride,"
" black spots will exist\n";
}
// Get values to fix
ImageBuf *regionBuf = new ImageBuf(sourceFiles[0]);
regionBuf->read(0,0,false, TypeDesc::UINT8);
if( !regionBuf->initialized() ) {
if( !quiet )printf("ERROR: could not build big image\n");
return NULL;
}
ImageSpec regionSpec = regionBuf->spec();
delete regionBuf;
// Construct the big buffer
ImageSpec bigSpec(
regionSpec.width * stride,
regionSpec.height * sourceFiles.size() / stride,
4,
TypeDesc::UINT8 );
if( verbose )printf(" Allocating: (%i,%i)%i\n",
bigSpec.width, bigSpec.height, bigSpec.nchannels );
ImageBuf *bigBuf = new ImageBuf( "big", bigSpec );
// Fill the alpha channel
const float fill[] = { 0, 0, 0, 255 };
ImageBufAlgo::fill( *bigBuf, fill );
// Collate the source Files
int nFiles = sourceFiles.size();
for( int i = 0; i < nFiles; ++i ) {
if( verbose )printf( "\033[0G copying %i of %i, %s",
i + 1, nFiles, sourceFiles[i].c_str() );
regionBuf = new ImageBuf( sourceFiles[i] );
regionBuf->read( 0, 0, false, TypeDesc::UINT8 );
if( !regionBuf->initialized() ) {
if( !quiet )printf( "\nERROR: %s could not be loaded.\n",
sourceFiles[i].c_str() );
continue;
}
regionSpec = regionBuf->spec();
int x = regionSpec.width * (i % stride);
int y = regionSpec.height * (i / stride);
y = bigSpec.height - y - regionSpec.height;
ImageBufAlgo::paste( *bigBuf, x, y, 0, 0, *regionBuf );
}
if( verbose )cout << endl;
// rescale constructed big image to wanted size
ROI roi( 0, width * 512 , 0, length * 512, 0, 1, 0, 4 );
ImageBuf fixBuf;
if( bigSpec.width != roi.xend || bigSpec.height != roi.yend ) {
if( verbose )
printf( "WARNING: Image is (%i,%i), wanted (%i, %i),"
" Resampling.\n",
bigSpec.width, bigSpec.height, roi.xend, roi.yend );
ImageBufAlgo::resample( fixBuf, *bigBuf, true, roi );
bigBuf->copy( fixBuf );
}
return bigBuf;
}
示例6: smt
bool
SMT::save()
{
// Make sure we have some source images before continuing
if( sourceFiles.size() == 0) {
if( !quiet )cout << "ERROR: No source images to convert" << endl;
return true;
}
// Build SMT Header //
//////////////////////
char filename[256];
sprintf(filename, "%s.smt", outPrefix.c_str());
if( verbose ) printf("\nINFO: Creating %s\n", filename );
fstream smt( filename, ios::binary | ios::out );
if( !smt.good() ) {
cout << "ERROR: fstream error." << endl;
return true;
}
SMTHeader header;
header.tileRes = tileRes;
header.tileType = tileType;
if( verbose ) {
cout << " Version: " << header.version << endl;
cout << " nTiles: n/a\n";
printf( " tileRes: (%i,%i)%i.\n", tileRes, tileRes, 4);
cout << " tileType: ";
if( tileType == DXT1 ) cout << "DXT1" << endl;
cout << " tileSize: " << tileSize << " bytes" << endl;
}
smt.write( (char *)&header, sizeof(SMTHeader) );
smt.close();
// setup size for index dimensions
int tcx = width * 16; // tile count x
int tcz = length * 16; // tile count z
unsigned int *indexPixels = new unsigned int[tcx * tcz];
// Load source image
if( verbose )cout << "INFO: Loading Source Image(s)\n";
ImageBuf *bigBuf = buildBig();
ImageSpec bigSpec = bigBuf->spec();
// Process decals
if( !decalFile.empty() ) {
if( verbose )cout << "INFO: Processing decals\n";
pasteDecals( bigBuf );
}
// Swizzle channels
if( verbose )cout << "INFO: Swizzling channels\n";
ImageBuf fixBuf;
int map[] = { 2, 1, 0, 3 };
ImageBufAlgo::channels( fixBuf, *bigBuf, 4, map );
bigBuf->copy( fixBuf );
fixBuf.clear();
// Process Tiles
if( verbose )cout << "INFO: Processing tiles\n";
// Time reporting vars
timeval t1, t2;
double elapsedTime;
deque<double> readings;
double averageTime = 0;
double intervalTime = 0;
// Loop vars
int totalTiles = tcx * tcz;
int currentTile;
// Tile Vars
ROI roi;
ImageSpec tileSpec(tileRes, tileRes, 4, TypeDesc::UINT8 );
// Comparison vars
bool match;
bool yee = false;
unsigned int i;
string hash;
vector<string> hashTable;
TileBufListEntry *listEntry;
deque<TileBufListEntry *> tileList;
// Open smt file for writing tiles
smt.open(filename, ios::binary | ios::out | ios::app );
// loop through tile columns
for ( int z = 0; z < tcz; z++) {
// loop through tile rows
for ( int x = 0; x < tcx; x++) {
currentTile = z * tcx + x + 1;
gettimeofday(&t1, NULL);
// pull a region of the big image to use as a tile.
roi.xbegin = x * tileRes;
roi.xend = x * tileRes + tileRes;
//.........这里部分代码省略.........
示例7: src
//.........这里部分代码省略.........
src.spec().full_x == 0 && src.spec().full_y == 0 &&
src.spec().full_z == 0 && src.spec().full_width == src.spec().width &&
src.spec().full_height == src.spec().height &&
src.spec().full_depth == src.spec().depth) {
isConstantColor = ImageBufAlgo::isConstantColor (src, &constantColor[0]);
if (isConstantColor) {
// Reset the image, to a new image, at the tile size
ImageSpec newspec = src.spec();
newspec.width = std::min (configspec.tile_width, src.spec().width);
newspec.height = std::min (configspec.tile_height, src.spec().height);
newspec.depth = std::min (configspec.tile_depth, src.spec().depth);
newspec.full_width = newspec.width;
newspec.full_height = newspec.height;
newspec.full_depth = newspec.depth;
std::string name = src.name() + ".constant_color";
src.reset(name, newspec);
ImageBufAlgo::fill (src, &constantColor[0]);
if (verbose) {
outstream << " Constant color image detected. ";
outstream << "Creating " << newspec.width << "x" << newspec.height << " texture instead.\n";
}
}
}
int nchannels = configspec.get_int_attribute ("maketx:nchannels", -1);
// If requested -- and alpha is 1.0 everywhere -- drop it.
if (configspec.get_int_attribute("maketx:opaque_detect") &&
src.spec().alpha_channel == src.nchannels()-1 &&
nchannels <= 0 &&
ImageBufAlgo::isConstantChannel(src,src.spec().alpha_channel,1.0f)) {
ImageBuf newsrc(src.name() + ".noalpha", src.spec());
ImageBufAlgo::setNumChannels (newsrc, src, src.nchannels()-1);
src.copy (newsrc);
if (verbose) {
outstream << " Alpha==1 image detected. Dropping the alpha channel.\n";
}
}
// If requested - and we're a monochrome image - drop the extra channels
if (configspec.get_int_attribute("maketx:monochrome_detect") &&
nchannels <= 0 &&
src.nchannels() == 3 && src.spec().alpha_channel < 0 && // RGB only
ImageBufAlgo::isMonochrome(src)) {
ImageBuf newsrc(src.name() + ".monochrome", src.spec());
ImageBufAlgo::setNumChannels (newsrc, src, 1);
src.copy (newsrc);
if (verbose) {
outstream << " Monochrome image detected. Converting to single channel texture.\n";
}
}
// If we've otherwise explicitly requested to write out a
// specific number of channels, do it.
if ((nchannels > 0) && (nchannels != src.nchannels())) {
ImageBuf newsrc(src.name() + ".channels", src.spec());
ImageBufAlgo::setNumChannels (newsrc, src, nchannels);
src.copy (newsrc);
if (verbose) {
outstream << " Overriding number of channels to " << nchannels << "\n";
}
}
if (shadowmode) {
// Some special checks for shadow maps
if (src.spec().nchannels != 1) {
示例8: roi
bool
SMF::saveGrass()
{
if( verbose )cout << "INFO: saveGrass\n";
SMFEHGrass *grassHeader = NULL;
for( unsigned int i = 0; i < extraHeaders.size(); ++i ) {
if( extraHeaders[ i ]->type == 1 )
grassHeader = reinterpret_cast<SMFEHGrass *>( extraHeaders[ i ] );
}
if( !grassHeader )return true;
ImageBuf *imageBuf = NULL;
ROI roi( 0, width * 16,
0, length * 16,
0, 1,
0, 1);
ImageSpec imageSpec(roi.xend, roi.yend, roi.chend, TypeDesc::UINT8 );
if( is_smf(grassFile) ) {
// Load from SMF
SMF sourcesmf(grassFile);
imageBuf = sourcesmf.getGrass();
}
if( !imageBuf ) {
// Load image file
imageBuf = new ImageBuf( grassFile );
imageBuf->read( 0, 0, false, TypeDesc::UINT8 );
if( imageBuf->initialized() ) {
delete imageBuf;
imageBuf = NULL;
}
}
if( !imageBuf ) {
// Generate blank
imageBuf = new ImageBuf( "grass", imageSpec );
}
imageSpec = imageBuf->specmod();
ImageBuf fixBuf;
// Fix the number of channels
if( imageSpec.nchannels != roi.chend ) {
int map[] = {0};
ImageBufAlgo::channels(fixBuf, *imageBuf, roi.chend, map );
imageBuf->copy( fixBuf );
fixBuf.clear();
}
// Fix the Dimensions
if ( imageSpec.width != roi.xend || imageSpec.height != roi.yend ) {
if( verbose )
printf( "\tWARNING: %s is (%i,%i), wanted (%i, %i) Resampling.\n",
typeFile.c_str(), imageSpec.width, imageSpec.height, roi.xend, roi.yend);
ImageBufAlgo::resample(fixBuf, *imageBuf, false, roi);
imageBuf->copy( fixBuf );
fixBuf.clear();
}
unsigned char *pixels = (unsigned char *)imageBuf->localpixels();
char filename[256];
sprintf( filename, "%s.smf", outPrefix.c_str() );
if( verbose )printf( " Source: %s.\n", grassFile.c_str() );
fstream smf(filename, ios::binary | ios::in | ios::out);
smf.seekp(grassHeader->grassPtr);
smf.write( (char *)pixels, imageBuf->spec().image_bytes() );
smf.close();
delete imageBuf;
if( is_smf( grassFile ) ) delete [] pixels;
return false;
}
示例9: smf
bool
SMF::saveTilemap()
{
if( verbose )cout << "INFO: saveTilemap\n";
char filename[256];
sprintf( filename, "%s.smf", outPrefix.c_str() );
fstream smf(filename, ios::binary | ios::in | ios::out);
smf.seekp(tilesPtr);
// Tiles Header
int nTileFiles = smtList.size();
smf.write( (char *)&nTileFiles, 4);
smf.write( (char *)&nTiles, 4);
if(verbose)printf( " %i tiles referenced in %i files\n", nTiles, nTileFiles );
// SMT Names
for(unsigned int i = 0; i < smtList.size(); ++i) {
if( verbose )printf( "\t%i %s\n", smtTiles[i], smtList[i].c_str() );
smf.write( (char *)&smtTiles[i], 4);
smf.write( smtList[i].c_str(), smtList[i].size() +1 );
}
// Dimensions of displacement map.
ImageBuf *imageBuf = NULL;
ROI roi( 0, width * 16, // xbegin, xend
0, length * 16, // ybegin, yend
0, 1, // zbegin, zend
0, 1); // chbegin, chend
ImageSpec imageSpec( roi.xend, roi.yend, roi.chend, TypeDesc::UINT );
if( is_smf(tilemapFile) ) {
// Load from SMF
SMF sourcesmf(tilemapFile);
imageBuf = sourcesmf.getTilemap();
}
if( !imageBuf ) {
// load image file
imageBuf = new ImageBuf( tilemapFile );
imageBuf->read( 0, 0, false, TypeDesc::UINT );
if( !imageBuf->initialized() ) {
delete imageBuf;
imageBuf = NULL;
}
}
if( !imageBuf ) {
// Generate blank
imageBuf = new ImageBuf( "tilemap", imageSpec );
for ( unsigned int i = 0; i < imageSpec.image_pixels(); ++i )
((unsigned int *)imageBuf->localpixels())[ i ] = i;
}
imageSpec = imageBuf->specmod();
ImageBuf fixBuf;
// Fix the number of channels
if( imageSpec.nchannels != roi.chend ) {
int map[] = {0};
ImageBufAlgo::channels(fixBuf, *imageBuf, roi.chend, map);
imageBuf->copy(fixBuf);
fixBuf.clear();
}
// Fix the size
// FIXME image should never be resized, instead tiling either from an edge or centred.
if ( imageSpec.width != roi.xend || imageSpec.height != roi.yend ) {
if( verbose )
printf( "\tWARNING: %s is (%i,%i), wanted (%i, %i), Resampling.\n",
tilemapFile.c_str(), imageSpec.width, imageSpec.height, roi.xend, roi.yend );
ImageBufAlgo::resample(fixBuf, *imageBuf, false, roi);
imageBuf->copy(fixBuf);
fixBuf.clear();
}
unsigned int *pixels = (unsigned int *)imageBuf->localpixels();
// write the data to the smf
smf.write( (char *)pixels, imageBuf->spec().image_bytes() );
smf.close();
delete imageBuf;
if( is_smf( tilemapFile ) ) delete [] pixels;
return false;
}
示例10: if
bool
ImageBufAlgo::deepen (ImageBuf &dst, const ImageBuf &src, float zvalue,
ROI roi, int nthreads)
{
if (src.deep()) {
// For some reason, we were asked to deepen an already-deep image.
// So just copy it.
return dst.copy (src);
// FIXME: once paste works for deep files, this should really be
// return paste (dst, roi.xbegin, roi.ybegin, roi.zbegin, roi.chbegin,
// src, roi, nthreads);
}
// Construct an ideal spec for dst, which is like src but deep.
const ImageSpec &srcspec (src.spec());
int nc = srcspec.nchannels;
int zback_channel = -1;
ImageSpec force_spec = srcspec;
force_spec.deep = true;
force_spec.set_format (TypeDesc::FLOAT);
force_spec.channelformats.clear();
for (int c = 0; c < nc; ++c) {
if (force_spec.channelnames[c] == "Z")
force_spec.z_channel = c;
else if (force_spec.channelnames[c] == "Zback")
zback_channel = c;
}
bool add_z_channel = (force_spec.z_channel < 0);
if (add_z_channel) {
// No z channel? Make one.
force_spec.z_channel = force_spec.nchannels++;
force_spec.channelnames.push_back ("Z");
}
if (! IBAprep (roi, &dst, &src, NULL, &force_spec, IBAprep_SUPPORT_DEEP))
return false;
if (! dst.deep()) {
dst.error ("Cannot deepen to a flat image");
return false;
}
float *pixel = OIIO_ALLOCA (float, nc);
// First, figure out which pixels get a sample and which do not
for (int z = roi.zbegin; z < roi.zend; ++z)
for (int y = roi.ybegin; y < roi.yend; ++y)
for (int x = roi.xbegin; x < roi.xend; ++x) {
bool has_sample = false;
src.getpixel (x, y, z, pixel);
for (int c = 0; c < nc; ++c)
if (c != force_spec.z_channel && c != zback_channel
&& pixel[c] != 0.0f) {
has_sample = true;
break;
}
if (! has_sample && ! add_z_channel)
for (int c = 0; c < nc; ++c)
if ((c == force_spec.z_channel || c == zback_channel)
&& (pixel[c] != 0.0f && pixel[c] < 1e30)) {
has_sample = true;
break;
}
if (has_sample)
dst.set_deep_samples (x, y, z, 1);
}
dst.deep_alloc ();
// Now actually set the values
for (int z = roi.zbegin; z < roi.zend; ++z)
for (int y = roi.ybegin; y < roi.yend; ++y)
for (int x = roi.xbegin; x < roi.xend; ++x) {
if (dst.deep_samples (x, y, z) == 0)
continue;
for (int c = 0; c < nc; ++c)
dst.set_deep_value (x, y, z, c, 0 /*sample*/,
src.getchannel (x, y, z, c));
if (add_z_channel)
dst.set_deep_value (x, y, z, nc, 0, zvalue);
}
bool ok = true;
// FIXME -- the above doesn't split into threads. Someday, it should
// be refactored like this:
// OIIO_DISPATCH_COMMON_TYPES2 (ok, "deepen", deepen_,
// dst.spec().format, srcspec.format,
// dst, src, add_z_channel, z, roi, nthreads);
return ok;
}