本文整理汇总了C++中ImageOutput::close方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageOutput::close方法的具体用法?C++ ImageOutput::close怎么用?C++ ImageOutput::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageOutput
的用法示例。
在下文中一共展示了ImageOutput::close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeImage
/**
* @brief Write imgage.
* @details Write compostied image to the file system.
*/
void writeImage() {
// Transfer to something OpenImageIO understands
oiioPixels.resize(newWidth*newHeight*4*sizeof(float));
for (int row = 0; row < newHeight; row++)
for (int col = 0; col < newWidth; col++){
oiioPixels[(row*newWidth+col)*4 + 0] = warppedPixels[row][col].r;
oiioPixels[(row*newWidth+col)*4 + 1] = warppedPixels[row][col].g;
oiioPixels[(row*newWidth+col)*4 + 2] = warppedPixels[row][col].b;
oiioPixels[(row*newWidth+col)*4 + 3] = warppedPixels[row][col].a;
}
// Create output image
ImageOutput *out = ImageOutput::create(outImage);
// Error handeling
if (!out) {
printf("Error writing image: %s\n", geterror().c_str());
exit(EXIT_FAILURE);
}
// Create output image spec
ImageSpec spec (newWidth, newHeight, 4, TypeDesc::FLOAT);
// Open output image file
out->open(outImage, spec);
// Write output image to disk and close
out->write_image(TypeDesc::FLOAT, &oiioPixels[0]);
out->close();
delete out;
}
示例2: Simulate
void Ibl::Simulate(std::string const& filename)
{
auto width = 2000U;
auto height = 1000U;
std::vector<float> data(width * height);
std::fill(data.begin(), data.end(), 0.f);
for (int i = 0; i < 100000; ++i)
{
auto xy = SampleCoord(RadeonRays::float2(RadeonRays::rand_float(), RadeonRays::rand_float()));
data[xy.y * width + xy.x] += 1.f;
}
using namespace OpenImageIO;
ImageOutput* out = ImageOutput::create(filename);
if (!out)
{
throw std::runtime_error("Can't create image file on disk");
}
ImageSpec spec(width, height, 1, TypeDesc::UINT8);
out->open(filename, spec);
out->write_image(TypeDesc::FLOAT, &data[0]);
out->close();
delete out;
}
示例3: writeOIIOImage
void lux::writeOIIOImage( const char* fname, Image& img, const map<string,string>& labels, float displayBrightness, float displayGamma )
{
float* imagedata = new float[ img.Width()* img.Height() * 3 ];
// fill image with the contents of img
long index = 0;
for( int j=0;j<img.Height();j++ )
{
for( int i=0;i<img.Width();i++ )
{
vector<float> pix = img.pixel(i,img.Height() - j - 1);
for( size_t c=0;c<3;c++ )
{
pix[c] = imagePlaneValue( pix[c], displayGamma, displayBrightness );
imagedata[index++] = pix[c];
}
}
}
ImageOutput *out = ImageOutput::create (fname);
if( !out )
{
cout << "Not able to write an image to file " << fname << endl;
}
else
{
ImageSpec spec (img.Width(), img.Height(), 3, TypeDesc::FLOAT);
spec.attribute("user", "imageTools");
spec.attribute("writer", "OIIOFiles" );
if( labels.size() > 0 )
{
map<string,string>::const_iterator lab = labels.begin();
while( lab != labels.end() )
{
const string& name = lab->first;
const string& value = lab->second;
spec.attribute( name, value );
lab++;
}
}
out->open (fname, spec);
out->write_image (TypeDesc::FLOAT, imagedata);
out->close ();
cout <<endl<<endl<< "File " << fname << " written to file"<< endl;
delete out;
}
delete[] imagedata;
}
示例4: SaveFrameBuffer
void SaveFrameBuffer(std::string const& name, float3 const* data)
{
OIIO_NAMESPACE_USING;
std::vector<float3> tempbuf(g_window_width * g_window_height);
tempbuf.assign(data, data + g_window_width*g_window_height);
ImageOutput* out = ImageOutput::create(name);
if (!out)
{
throw std::runtime_error("Can't create image file on disk");
}
ImageSpec spec(g_window_width, g_window_height, 3, TypeDesc::FLOAT);
out->open(name, spec);
out->write_image(TypeDesc::FLOAT, &tempbuf[0], sizeof(float3));
out->close();
}
示例5: DumpPdf
void Ibl::DumpPdf(std::string const& filename)
{
auto width = 2000U;
auto height = 1000U;
std::vector<float> data(width * height);
for (auto x = 0U; x < width; ++x)
for (auto y = 0U; y < height; ++y)
{
data[y * width + x] = GetPdf(RadeonRays::float2((float)x / m_width, (float)y / m_height));
}
auto max = std::max_element(data.cbegin(), data.cend());
std::for_each(data.begin(), data.end(), [=](float& v)
{
v /= *max;
});
using namespace OpenImageIO;
ImageOutput* out = ImageOutput::create(filename);
if (!out)
{
throw std::runtime_error("Can't create image file on disk");
}
ImageSpec spec(width, height, 1, TypeDesc::UINT8);
out->open(filename, spec);
out->write_image(TypeDesc::FLOAT, &data[0]);
out->close();
delete out;
}
示例6: ir
static int
output_file (int argc, const char *argv[])
{
ASSERT (argc == 2 && !strcmp(argv[0],"-o"));
std::string filename = argv[1];
if (! ot.curimg.get()) {
std::cerr << "oiiotool ERROR: -o " << filename << " did not have any current image to output.\n";
return 0;
}
if (ot.noclobber && Filesystem::exists(filename)) {
std::cerr << "oiiotool ERROR: Output file \"" << filename
<< "\" already exists, not overwriting.\n";
return 0;
}
if (ot.verbose)
std::cout << "Writing " << argv[1] << "\n";
ImageOutput *out = ImageOutput::create (filename.c_str());
if (! out) {
std::cerr << "oiiotool ERROR: " << geterror() << "\n";
return 0;
}
bool supports_displaywindow = out->supports ("displaywindow");
ot.read ();
ImageRecRef saveimg = ot.curimg;
ImageRecRef ir (ot.curimg);
if (! supports_displaywindow && ot.output_autocrop &&
(ir->spec()->x != ir->spec()->full_x ||
ir->spec()->y != ir->spec()->full_y ||
ir->spec()->width != ir->spec()->full_width ||
ir->spec()->height != ir->spec()->full_height)) {
const char *argv[] = { "croptofull" };
int action_croptofull (int argc, const char *argv[]); // forward decl
action_croptofull (1, argv);
ir = ot.curimg;
}
ImageOutput::OpenMode mode = ImageOutput::Create; // initial open
for (int s = 0, send = ir->subimages(); s < send; ++s) {
for (int m = 0, mend = ir->miplevels(s); m < mend; ++m) {
ImageSpec spec = *ir->spec(s,m);
adjust_output_options (spec, ot);
if (! out->open (filename, spec, mode)) {
std::cerr << "oiiotool ERROR: " << out->geterror() << "\n";
return 0;
}
if (! (*ir)(s,m).write (out)) {
std::cerr << "oiiotool ERROR: " << (*ir)(s,m).geterror() << "\n";
return 0;
}
if (mend > 1) {
if (out->supports("mipmap")) {
mode = ImageOutput::AppendMIPLevel; // for next level
} else if (out->supports("multiimage")) {
mode = ImageOutput::AppendSubimage;
} else {
std::cout << "oiiotool WARNING: " << out->format_name()
<< " does not support MIP-maps for "
<< filename << "\n";
break;
}
}
}
mode = ImageOutput::AppendSubimage; // for next subimage
if (send > 1 && ! out->supports("multiimage")) {
std::cout << "oiiotool WARNING: " << out->format_name()
<< " does not support multiple subimages for "
<< filename << "\n";
break;
}
}
out->close ();
delete out;
if (ot.output_adjust_time) {
std::string metadatatime = ir->spec(0,0)->get_string_attribute ("DateTime");
std::time_t in_time = ir->time();
if (! metadatatime.empty())
DateTime_to_time_t (metadatatime.c_str(), in_time);
boost::filesystem::last_write_time (filename, in_time);
}
ot.curimg = saveimg;
return 0;
}
示例7: geterror
//.........这里部分代码省略.........
!strcmp(out->format_name(), "openexr")) {
src_samples_border = true;
outspec.attribute ("oiio:updirection", "y");
outspec.attribute ("oiio:sampleborder", 1);
}
if (envlatlmode && src_samples_border)
fix_latl_edges (img);
if (! out->open (outputfilename.c_str(), outspec)) {
std::cerr << "maketx ERROR: Could not open \"" << outputfilename
<< "\" : " << out->geterror() << "\n";
exit (EXIT_FAILURE);
}
// Write out the image
if (verbose) {
std::cout << " Writing file: " << outputfilename << std::endl;
std::cout << " Filter \"" << filter->name() << "\" width = "
<< filter->width() << "\n";
}
bool ok = true;
ok &= img.write (out);
stat_writetime += writetimer();
if (mipmap) { // Mipmap levels:
if (verbose)
std::cout << " Mipmapping...\n" << std::flush;
ImageBuf tmp;
ImageBuf *big = &img, *small = &tmp;
while (ok && (outspec.width > 1 || outspec.height > 1)) {
Timer miptimer;
// Resize a factor of two smaller
ImageSpec smallspec = outspec;
smallspec.width = big->spec().width;
smallspec.height = big->spec().height;
smallspec.depth = big->spec().depth;
if (smallspec.width > 1)
smallspec.width /= 2;
if (smallspec.height > 1)
smallspec.height /= 2;
smallspec.full_width = smallspec.width;
smallspec.full_height = smallspec.height;
smallspec.full_depth = smallspec.depth;
smallspec.set_format (TypeDesc::FLOAT);
small->alloc (smallspec); // Realocate with new size
if (filtername == "box" && filter->width() == 1.0f)
parallel_image (resize_block, small, big,
smallspec.x, smallspec.x+smallspec.width,
smallspec.y, smallspec.y+smallspec.height,
nthreads);
else
parallel_image (resize_block_HQ, small, big,
smallspec.x, smallspec.x+smallspec.width,
smallspec.y, smallspec.y+smallspec.height,
nthreads);
stat_miptime += miptimer();
outspec = smallspec;
outspec.set_format (outputdatatype);
if (envlatlmode && src_samples_border)
fix_latl_edges (*small);
Timer writetimer;
// If the format explicitly supports MIP-maps, use that,
// otherwise try to simulate MIP-mapping with multi-image.
bool ok = false;
ImageOutput::OpenMode mode = out->supports ("mipmap") ?
ImageOutput::AppendMIPLevel : ImageOutput::AppendSubimage;
if (! out->open (outputfilename.c_str(), outspec, mode)) {
std::cerr << "maketx ERROR: Could not append \"" << outputfilename
<< "\" : " << out->geterror() << "\n";
exit (EXIT_FAILURE);
}
ok &= small->write (out);
stat_writetime += writetimer();
if (verbose)
std::cout << " " << smallspec.width << 'x'
<< smallspec.height << "\n" << std::flush;
std::swap (big, small);
}
}
if (verbose)
std::cout << " Wrote file: " << outputfilename << std::endl;
writetimer.reset ();
writetimer.start ();
if (ok)
ok &= out->close ();
stat_writetime += writetimer ();
delete out;
if (! ok) {
std::cerr << "maketx ERROR writing \"" << outputfilename
<< "\" : " << out->geterror() << "\n";
exit (EXIT_FAILURE);
}
}
示例8: 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;
//.........这里部分代码省略.........
示例9: writeImage
// Function to write an image using OpenImageIO that reads and stores the pixel bein g displayed on screen using OpenGL
void writeImage() {
// Store the Output File Type in outfiletype, example .ppm or .jpg
string outfiletype = outfilename.substr(outfilename.find("."));
// Create ImageOutput instance using the outfilename & exit if error in creating
ImageOutput *out = ImageOutput::create(outfilename);
if (!out) {
cerr << "Could not create an ImageOutput for "
<< outfilename << "\nError: "
<< geterror()<<endl;
exit(-1);
}
// Set outputchannels to 3 if outputfiletype is either ppm/pnm/pgm/pbm/hdr/rgbe else let it be equal to the number of channels of the input image (either 3 or 4)
int outputchannels = (outfiletype==".ppm" || outfiletype==".pnm" || outfiletype==".pgm" || outfiletype==".pbm" || outfiletype==".hdr" || outfiletype==".rgbe" ? 3 : channels1 );
// Allocate memory based on the number of channels
unsigned char *oiio_pixels = new unsigned char[xresWarped*yresWarped*outputchannels];
// Check if memory has been allocated successfully
if (oiio_pixels==0) {
// Memory not allocated successfully! Display message and Exit
cout<<"Couldn't allocate memory. Exiting!"<<endl;
exit(-1);
delete out;
}
// If number of channels is 4 then read in RGBA format using GL_RGBA
if(outputchannels==4) {
for(int i=0, k=0; i<yresWarped && k<(xresWarped*yresWarped*outputchannels); i++) {
for(int j=0; j<xresWarped; j++, k+=4) {
oiio_pixels[k] = pixmapWarped[i][j].red;
oiio_pixels[k+1] = pixmapWarped[i][j].green;
oiio_pixels[k+2] = pixmapWarped[i][j].blue;
oiio_pixels[k+3] = pixmapWarped[i][j].alpha;
}
}
}
// If number of channels is 3 then read in RGB format using GL_RGB
else if(outputchannels==3) {
for(int i=0, k=0; i<yresWarped && k<(xresWarped*yresWarped*outputchannels); i++) {
for(int j=0; j<xresWarped; j++, k+=3) {
oiio_pixels[k] = pixmapWarped[i][j].red;
oiio_pixels[k+1] = pixmapWarped[i][j].green;
oiio_pixels[k+2] = pixmapWarped[i][j].blue;
}
}
}
// Create ImageSpec for the output image with name outfile
ImageSpec spec(xresWarped,yresWarped,outputchannels,TypeDesc::UINT8);
if (! out->open (outfilename, spec)) {
cerr << "Could not open "
<< outfilename << "\nError: "
<< out->geterror()<< endl;
delete out;
delete [] oiio_pixels;
exit(-1);
}
// This particular call to write flips the image for us
int scanlinesize = xresWarped * outputchannels * sizeof(oiio_pixels[0]);
if(! out->write_image (TypeDesc::UINT8, (unsigned char*)oiio_pixels+(yresWarped-1)*scanlinesize, AutoStride, -scanlinesize, AutoStride)) {
cerr << "Could not write pixels to "
<< outfilename << "\nError: "
<< out->geterror()<< endl;
delete out;
delete [] oiio_pixels;
exit(-1);
}
// Close the output file
if(! out->close ()) {
std::cerr << "Error closing "
<< outfilename << "\nError: "
<< out->geterror() << endl;
delete out;
delete [] oiio_pixels;
exit(-1);
}
delete out;
delete [] oiio_pixels;
}
示例10: ufilename
//.........这里部分代码省略.........
ImageSpec outspec = inspec;
bool nocopy = adjust_spec (in, out, inspec, outspec);
if (miplevel > 0) {
// Moving to next MIP level
ImageOutput::OpenMode mode;
if (out->supports ("mipmap"))
mode = ImageOutput::AppendMIPLevel;
else if (out->supports ("multiimage") &&
out->supports ("appendsubimage")) {
mode = ImageOutput::AppendSubimage; // use if we must
if (! mip_to_subimage_warning
&& strcmp(out->format_name(),"tiff")) {
std::cerr << "iconvert WARNING: " << out->format_name()
<< " does not support MIPmaps.\n";
std::cerr << "\tStoring the MIPmap levels in subimages.\n";
}
mip_to_subimage_warning = true;
} else {
std::cerr << "iconvert WARNING: " << out->format_name()
<< " does not support MIPmaps.\n";
std::cerr << "\tOnly the first level has been copied.\n";
break; // on to the next subimage
}
ok = out->open (tempname.c_str(), outspec, mode);
} else if (subimage > 0) {
// Moving to next subimage
ok = out->open (tempname.c_str(), outspec,
ImageOutput::AppendSubimage);
} else {
// First time opening
if (subimagespecs.size())
ok = out->open (tempname.c_str(), int(subimagespecs.size()),
&subimagespecs[0]);
else
ok = out->open (tempname.c_str(), outspec, ImageOutput::Create);
}
if (! ok) {
std::string err = out->geterror();
std::cerr << "iconvert ERROR: "
<< (err.length() ? err : Strutil::format("Could not open \"%s\"", out_filename))
<< "\n";
ok = false;
break;
}
if (! nocopy) {
ok = out->copy_image (in);
if (! ok)
std::cerr << "iconvert ERROR copying \"" << in_filename
<< "\" to \"" << out_filename << "\" :\n\t"
<< out->geterror() << "\n";
} else {
// Need to do it by hand for some reason. Future expansion in which
// only a subset of channels are copied, or some such.
std::vector<char> pixels ((size_t)outspec.image_bytes(true));
ok = in->read_image (outspec.format, &pixels[0]);
if (! ok) {
std::cerr << "iconvert ERROR reading \"" << in_filename
<< "\" : " << in->geterror() << "\n";
} else {
ok = out->write_image (outspec.format, &pixels[0]);
if (! ok)
std::cerr << "iconvert ERROR writing \"" << out_filename
<< "\" : " << out->geterror() << "\n";
}
}
++miplevel;
} while (ok && in->seek_subimage(subimage,miplevel,inspec));
}
out->close ();
delete out;
in->close ();
delete in;
// Figure out a time for the input file -- either one supplied by
// the metadata, or the actual time stamp of the input file.
std::time_t in_time;
if (metadatatime.empty() ||
! DateTime_to_time_t (metadatatime.c_str(), in_time))
in_time = Filesystem::last_write_time (in_filename);
if (out_filename != tempname) {
if (ok) {
Filesystem::remove (out_filename);
Filesystem::rename (tempname, out_filename);
}
else
Filesystem::remove (tempname);
}
// If user requested, try to adjust the file's modification time to
// the creation time indicated by the file's DateTime metadata.
if (ok && adjust_time)
Filesystem::last_write_time (out_filename, in_time);
return ok;
}