本文整理汇总了C++中ImageBuf::geterror方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageBuf::geterror方法的具体用法?C++ ImageBuf::geterror怎么用?C++ ImageBuf::geterror使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageBuf
的用法示例。
在下文中一共展示了ImageBuf::geterror方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2:
static bool
read_input (const std::string &filename, ImageBuf &img,
int subimage=0, int miplevel=0)
{
if (img.subimage() >= 0 && img.subimage() == subimage)
return true;
if (img.init_spec (filename, subimage, miplevel) &&
img.read (subimage, miplevel, false, TypeDesc::FLOAT))
return true;
std::cerr << "oiiotool ERROR: Could not read " << filename << ":\n\t"
<< img.geterror() << "\n";
return false;
}
示例3:
static bool
read_input (const std::string &filename, ImageBuf &img,
ImageCache *cache, int subimage=0, int miplevel=0)
{
if (img.subimage() >= 0 &&
img.subimage() == subimage && img.miplevel() == miplevel)
return true;
img.reset (filename, cache);
if (img.read (subimage, miplevel, false, TypeDesc::TypeFloat))
return true;
std::cerr << "idiff ERROR: Could not read " << filename << ":\n\t"
<< img.geterror() << "\n";
return false;
}
示例4: nonfinite_pixel_samp
static void
print_stats (Oiiotool &ot,
const std::string &filename,
const ImageSpec &originalspec,
int subimage=0, int miplevel=0, bool indentmip=false)
{
const char *indent = indentmip ? " " : " ";
ImageBuf input;
if (! read_input (filename, input, subimage, miplevel)) {
ot.error ("stats", input.geterror());
return;
}
PixelStats stats;
if (! computePixelStats (stats, input)) {
std::string err = input.geterror();
ot.error ("stats", Strutil::format ("unable to compute: %s",
err.empty() ? "unspecified error" : err.c_str()));
return;
}
// The original spec is used, otherwise the bit depth will
// be reported incorrectly (as FLOAT)
unsigned int maxval = (unsigned int)get_intsample_maxval (originalspec);
printf ("%sStats Min: ", indent);
for (unsigned int i=0; i<stats.min.size(); ++i) {
print_stats_num (stats.min[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Max: ", indent);
for (unsigned int i=0; i<stats.max.size(); ++i) {
print_stats_num (stats.max[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Avg: ", indent);
for (unsigned int i=0; i<stats.avg.size(); ++i) {
print_stats_num (stats.avg[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats StdDev: ", indent);
for (unsigned int i=0; i<stats.stddev.size(); ++i) {
print_stats_num (stats.stddev[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats NanCount: ", indent);
for (unsigned int i=0; i<stats.nancount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.nancount[i]);
}
printf ("\n");
printf ("%sStats InfCount: ", indent);
for (unsigned int i=0; i<stats.infcount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.infcount[i]);
}
printf ("\n");
printf ("%sStats FiniteCount: ", indent);
for (unsigned int i=0; i<stats.finitecount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.finitecount[i]);
}
printf ("\n");
if (input.deep()) {
const DeepData *dd (input.deepdata());
size_t npixels = dd->pixels();
size_t totalsamples = 0, emptypixels = 0;
size_t maxsamples = 0, minsamples = std::numeric_limits<size_t>::max();
size_t maxsamples_npixels = 0;
float mindepth = std::numeric_limits<float>::max();
float maxdepth = -std::numeric_limits<float>::max();
Imath::V3i maxsamples_pixel(-1,-1,-1), minsamples_pixel(-1,-1,-1);
Imath::V3i mindepth_pixel(-1,-1,-1), maxdepth_pixel(-1,-1,-1);
Imath::V3i nonfinite_pixel(-1,-1,-1);
int nonfinite_pixel_samp(-1), nonfinite_pixel_chan(-1);
size_t sampoffset = 0;
int nchannels = dd->channels();
int depthchannel = -1;
long long nonfinites = 0;
for (int c = 0; c < nchannels; ++c)
if (Strutil::iequals (originalspec.channelnames[c], "Z"))
depthchannel = c;
int xend = originalspec.x + originalspec.width;
int yend = originalspec.y + originalspec.height;
int zend = originalspec.z + originalspec.depth;
size_t p = 0;
std::vector<size_t> nsamples_histogram;
for (int z = originalspec.z; z < zend; ++z) {
//.........这里部分代码省略.........
示例5: printf
static void
print_stats (const std::string &filename,
const ImageSpec &originalspec,
int subimage=0, int miplevel=0, bool indentmip=false)
{
const char *indent = indentmip ? " " : " ";
ImageBuf input;
if (! read_input (filename, input, subimage, miplevel)) {
std::cerr << "Stats: read error: " << input.geterror() << "\n";
return;
}
PixelStats stats;
if (! computePixelStats (stats, input)) {
printf ("%sStats: (unable to compute)\n", indent);
return;
}
// The original spec is used, otherwise the bit depth will
// be reported incorrectly (as FLOAT)
unsigned int maxval = (unsigned int)get_intsample_maxval (originalspec);
printf ("%sStats Min: ", indent);
for (unsigned int i=0; i<stats.min.size(); ++i) {
print_stats_num (stats.min[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Max: ", indent);
for (unsigned int i=0; i<stats.max.size(); ++i) {
print_stats_num (stats.max[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Avg: ", indent);
for (unsigned int i=0; i<stats.avg.size(); ++i) {
print_stats_num (stats.avg[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats StdDev: ", indent);
for (unsigned int i=0; i<stats.stddev.size(); ++i) {
print_stats_num (stats.stddev[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats NanCount: ", indent);
for (unsigned int i=0; i<stats.nancount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.nancount[i]);
}
printf ("\n");
printf ("%sStats InfCount: ", indent);
for (unsigned int i=0; i<stats.infcount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.infcount[i]);
}
printf ("\n");
printf ("%sStats FiniteCount: ", indent);
for (unsigned int i=0; i<stats.finitecount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.finitecount[i]);
}
printf ("\n");
if (input.deep()) {
const DeepData *dd (input.deepdata());
size_t npixels = dd->nsamples.size();
size_t totalsamples = 0, emptypixels = 0;
size_t maxsamples = 0, minsamples = std::numeric_limits<size_t>::max();
for (size_t p = 0; p < npixels; ++p) {
size_t c = size_t(dd->nsamples[p]);
totalsamples += c;
if (c > maxsamples)
maxsamples = c;
if (c < minsamples)
minsamples = c;
if (c == 0)
++emptypixels;
}
printf ("%sMin deep samples in any pixel : %llu\n", indent, (unsigned long long)minsamples);
printf ("%sMax deep samples in any pixel : %llu\n", indent, (unsigned long long)maxsamples);
printf ("%sAverage deep samples per pixel: %.2f\n", indent, double(totalsamples)/double(npixels));
printf ("%sTotal deep samples in all pixels: %llu\n", indent, (unsigned long long)totalsamples);
printf ("%sPixels with deep samples : %llu\n", indent, (unsigned long long)(npixels-emptypixels));
printf ("%sPixels with no deep samples: %llu\n", indent, (unsigned long long)emptypixels);
} else {
std::vector<float> constantValues(input.spec().nchannels);
if (isConstantColor(input, &constantValues[0])) {
printf ("%sConstant: Yes\n", indent);
printf ("%sConstant Color: ", indent);
for (unsigned int i=0; i<constantValues.size(); ++i) {
//.........这里部分代码省略.........
示例6: outspec
//.........这里部分代码省略.........
opt.missingcolor.init ((float *)&missing, 0);
opt.swrap = opt.twrap = opt.rwrap = TextureOptions::WrapPeriodic;
int shadepoints = blocksize*blocksize;
Imath::V3f *P = ALLOCA (Imath::V3f, shadepoints);
Runflag *runflags = ALLOCA (Runflag, shadepoints);
Imath::V3f *dPdx = ALLOCA (Imath::V3f, shadepoints);
Imath::V3f *dPdy = ALLOCA (Imath::V3f, shadepoints);
Imath::V3f *dPdz = ALLOCA (Imath::V3f, shadepoints);
float *result = ALLOCA (float, shadepoints*nchannels);
for (int iter = 0; iter < iters; ++iter) {
// Iterate over blocks
// Trick: switch to second texture, if given, for second iteration
if (iter && filenames.size() > 1)
filename = ustring (filenames[1]);
for (int by = 0; by < output_yres; by+=blocksize) {
for (int bx = 0; bx < output_xres; bx+=blocksize) {
// Process pixels within a block. First save the texture warp
// (s,t) and derivatives into SIMD vectors.
int idx = 0;
for (int y = by; y < by+blocksize; ++y) {
for (int x = bx; x < bx+blocksize; ++x) {
if (x < output_xres && y < output_yres) {
if (nowarp) {
P[idx][0] = (float)x/output_xres * sscale;
P[idx][1] = (float)y/output_yres * tscale;
P[idx][2] = 0.5f * sscale;
P[idx] += offset;
dPdx[idx][0] = 1.0f/output_xres * sscale;
dPdx[idx][1] = 0;
dPdx[idx][2] = 0;
dPdy[idx][0] = 0;
dPdy[idx][1] = 1.0f/output_yres * tscale;
dPdy[idx][2] = 0;
dPdz[idx].setValue (0,0,0);
} else {
Imath::V3f coord = warp ((float)x/output_xres,
(float)y/output_yres,
0.5, xform);
coord.x *= sscale;
coord.y *= tscale;
coord += offset;
Imath::V3f coordx = warp ((float)(x+1)/output_xres,
(float)y/output_yres,
0.5, xform);
coordx.x *= sscale;
coordx.y *= tscale;
coordx += offset;
Imath::V3f coordy = warp ((float)x/output_xres,
(float)(y+1)/output_yres,
0.5, xform);
coordy.x *= sscale;
coordy.y *= tscale;
coordy += offset;
P[idx] = coord;
dPdx[idx] = coordx - coord;
dPdy[idx] = coordy - coord;
dPdz[idx].setValue (0,0,0);
}
runflags[idx] = RunFlagOn;
} else {
runflags[idx] = RunFlagOff;
}
++idx;
}
}
// Call the texture system to do the filtering.
bool ok = texsys->texture3d (filename, opt, runflags, 0, shadepoints,
Varying(P), Varying(dPdx),
Varying(dPdy), Varying(dPdz),
result);
if (! ok) {
std::string e = texsys->geterror ();
if (! e.empty())
std::cerr << "ERROR: " << e << "\n";
}
for (int i = 0; i < shadepoints*nchannels; ++i)
result[i] *= scalefactor;
// Save filtered pixels back to the image.
idx = 0;
for (int y = by; y < by+blocksize; ++y) {
for (int x = bx; x < bx+blocksize; ++x) {
if (runflags[idx]) {
image.setpixel (x, y, result + idx*nchannels);
}
++idx;
}
}
}
}
}
if (! image.save ())
std::cerr << "Error writing " << output_filename
<< " : " << image.geterror() << "\n";
}
示例7: printf
static void
print_stats (const std::string &filename,
const ImageSpec &originalspec,
int subimage=0, int miplevel=0, bool indentmip=false)
{
const char *indent = indentmip ? " " : " ";
ImageBuf input;
if (! read_input (filename, input, subimage, miplevel)) {
std::cerr << "Stats: read error: " << input.geterror() << "\n";
return;
}
PixelStats stats;
if (! computePixelStats (stats, input)) {
printf ("%sStats: (unable to compute)\n", indent);
return;
}
// The original spec is used, otherwise the bit depth will
// be reported incorrectly (as FLOAT)
unsigned int maxval = (unsigned int)get_intsample_maxval (originalspec);
printf ("%sStats Min: ", indent);
for (unsigned int i=0; i<stats.min.size(); ++i) {
print_stats_num (stats.min[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Max: ", indent);
for (unsigned int i=0; i<stats.max.size(); ++i) {
print_stats_num (stats.max[i], maxval, true);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats Avg: ", indent);
for (unsigned int i=0; i<stats.avg.size(); ++i) {
print_stats_num (stats.avg[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats StdDev: ", indent);
for (unsigned int i=0; i<stats.stddev.size(); ++i) {
print_stats_num (stats.stddev[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
printf ("%sStats NanCount: ", indent);
for (unsigned int i=0; i<stats.nancount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.nancount[i]);
}
printf ("\n");
printf ("%sStats InfCount: ", indent);
for (unsigned int i=0; i<stats.infcount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.infcount[i]);
}
printf ("\n");
printf ("%sStats FiniteCount: ", indent);
for (unsigned int i=0; i<stats.finitecount.size(); ++i) {
printf ("%llu ", (unsigned long long)stats.finitecount[i]);
}
printf ("\n");
std::vector<float> constantValues(input.spec().nchannels);
if(isConstantColor(input, &constantValues[0])) {
printf ("%sConstant: Yes\n", indent);
printf ("%sConstant Color: ", indent);
for (unsigned int i=0; i<constantValues.size(); ++i) {
print_stats_num (constantValues[i], maxval, false);
printf (" ");
}
print_stats_footer (maxval);
printf ("\n");
}
else {
printf ("%sConstant: No\n", indent);
}
if(isMonochrome(input)) {
printf ("%sMonochrome: Yes\n", indent);
} else {
printf ("%sMonochrome: No\n", indent);
}
}
示例8: 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;
//.........这里部分代码省略.........
示例9: decalList
void
SMT::pasteDecals(ImageBuf *bigBuf)
{
printf("WARNING: decal pasting is not yet implemented\n");
return;
// load definitions file
vector<type> list;
// Parse the file
printf( "INFO: Reading %s\n", decalFile.c_str() );
ifstream decalList( decalFile.c_str() );
string line;
string cell;
vector<string> tokens;
while ( getline( decalList, line ) ) {
stringstream lineStream( line );
tokens.clear();
while( getline( lineStream, cell, ',' ) ) tokens.push_back( cell );
if(tokens.size() <2 ) continue;
// use parsed line
coord xy;
type *decal;
// search for existing decal filename
bool found = false;
for(unsigned int i = 0; i < list.size(); ++i ) {
if( !list[i].imageName.compare( tokens[0].c_str() ) ) {
decal = &list[i];
found = true;
break;
}
}
if( !found ) {
decal = new type;
decal->imageName = tokens[0].c_str();
}
xy.x = atoi( tokens[1].c_str() );
xy.y = atoi( tokens[2].c_str() );
decal->coordinates.push_back(xy);
if( !found ) list.push_back(*decal);
}
// loop through list of decals.
for(unsigned int i = 0; i < list.size(); ++i ) {
if( verbose )printf(" %i %s ", (int)list[i].coordinates.size(),
list[i].imageName.c_str() );
ImageBuf decalBuf( list[i].imageName );
decalBuf.read( 0, 0, false, TypeDesc::FLOAT );
if( !decalBuf.initialized() ) {
printf("ERROR: could not load %s\n", list[i].imageName.c_str() );
continue;
}
ImageSpec decalSpec = decalBuf.spec();
printf("(%i,%i)%i\n", decalSpec.width, decalSpec.height,
decalSpec.nchannels );
// loop through list of coordinates
for(unsigned int j = 0; j < list[i].coordinates.size(); ++j ) {
coord xy = list[i].coordinates[j];
ROI roi( xy.x, xy.x + decalSpec.width,
xy.y, xy.y + decalSpec.height,
0,1,
0,5);
ImageBuf pasteBuf;
ImageBufAlgo::crop(pasteBuf, *bigBuf, roi);
ImageBuf compBuf;
if( !ImageBufAlgo::over( compBuf, decalBuf, pasteBuf) ) {
cout << "ERROR with composite: ";
cout << compBuf.geterror() << endl;
continue;
}
char filename[256];
sprintf(filename, "test%i.png", j);
compBuf.save(filename);
}
}
return;
}
示例10: main
int main (int argc, char *argv[])
{
// Arguments
if(argc != 3)
{
std::cerr << "mkthumbnail usage : mkthumbnail <input> <output>" << std::endl;
return EXIT_FAILURE;
}
std::string inputname=argv[1];
std::string outputname=argv[2];
std::string colortransfer_to = "sRGB";
std::string colortransfer_from = "sRGB";
// Colorspace selection
if(extensionIs(inputname, "exr") )
{
colortransfer_from="Linear";
}
else if(extensionIs(inputname, "dpx"))
{
colortransfer_from="KodakLog";
}
else
{
colortransfer_from="sRGB";
}
bool ok = true;
ImageBuf in;
if (! read_input (inputname, in))
{
std::cerr << "mkthumbnail: read error: " << in.geterror() << "\n";
return EXIT_FAILURE;
}
ColorTransfer *from_func = ColorTransfer::create (colortransfer_from + "_to_linear");
if (from_func == NULL) {
std::cerr << "mkthumbnail: --colorspace needs a 'colorspace' of "
<< "Linear, Gamma, sRGB, AdobeRGB, Rec709 or KodakLog\n";
return EXIT_FAILURE;
}
ColorTransfer *to_func = ColorTransfer::create (std::string("linear_to_") + colortransfer_to);
if (to_func == NULL) {
std::cerr << "mkthumbnail: --transfer needs a 'colorspace' of "
<< "Linear, Gamma, sRGB, AdobeRGB, Rec709 or KodakLog\n";
return EXIT_FAILURE;
}
std::cout << "Converting [" << colortransfer_from << "] " << inputname
<< " to [" << colortransfer_to << "] " << outputname << "\n";
//
ImageBuf linear;
ImageBuf outtmp;
ImageBufAlgo::colortransfer (linear, in, from_func);
ImageBufAlgo::colortransfer (outtmp, linear, to_func);
std::cout << "finished color transfer\n";
// Pixel aspect ratio
const ImageIOParameter *aspect = in.spec().find_attribute ("pixelaspectratio", TypeDesc::FLOAT);
float pixel_ratio = aspect ? *(float *)aspect->data() : 1.0f;
float ratio = ((float)in.spec().height+(float)in.spec().y)/((float)in.spec().width+(float)in.spec().x);
pixel_ratio = pixel_ratio != 0.f ? pixel_ratio : 1.f;
const int resize_w = 480; // resize target width
int resize_y = (int)((float)resize_w*ratio/pixel_ratio);
int resize_x = resize_w;
ImageSpec outspec = outtmp.spec();
outspec.x = 0;
outspec.y = 0;
outspec.full_x = 0;
outspec.full_y = 0;
outspec.width = resize_x;
outspec.height = resize_y;
outspec.full_width = resize_x;
outspec.full_height = resize_y;
ImageBuf out (outputname, outspec);
float pixel[3] = { .1f, .1f, .1f };
ImageBufAlgo::fill (out, pixel);
if(!ImageBufAlgo::resize (out, outtmp, out.xbegin(), out.xend(),
out.ybegin(), out.yend()))
{
std::cerr << "mkthumbnail: unable to resize image, " << out.geterror() << std::endl;
return EXIT_FAILURE;
}
if(out.spec().nchannels>3)
{
std::cout << "Changing number of channels to 3 "<< "\n";
ImageBuf newout("temp", out.spec());
setNbChannels (newout, out, 3);
out = newout;
}
if(!out.save (outputname))
{
std::cerr << "mkthumbnail: unable to save output image, " << out.geterror() << std::endl;
//.........这里部分代码省略.........
示例11: u_subimages
bool
ImageRec::read (ReadPolicy readpolicy)
{
if (elaborated())
return true;
static ustring u_subimages("subimages"), u_miplevels("miplevels");
static boost::regex regex_sha ("SHA-1=[[:xdigit:]]*[ ]*");
int subimages = 0;
ustring uname (name());
if (! m_imagecache->get_image_info (uname, 0, 0, u_subimages,
TypeDesc::TypeInt, &subimages)) {
error ("file not found: \"%s\"", name());
return false; // Image not found
}
m_subimages.resize (subimages);
bool allok = true;
for (int s = 0; s < subimages; ++s) {
int miplevels = 0;
m_imagecache->get_image_info (uname, s, 0, u_miplevels,
TypeDesc::TypeInt, &miplevels);
m_subimages[s].m_miplevels.resize (miplevels);
m_subimages[s].m_specs.resize (miplevels);
for (int m = 0; m < miplevels; ++m) {
// Force a read now for reasonable-sized first images in the
// file. This can greatly speed up the multithread case for
// tiled images by not having multiple threads working on the
// same image lock against each other on the file handle.
// We guess that "reasonable size" is 50 MB, that's enough to
// hold a 2048x1536 RGBA float image. Larger things will
// simply fall back on ImageCache.
bool forceread = (s == 0 && m == 0 &&
m_imagecache->imagespec(uname,s,m)->image_bytes() < 50*1024*1024);
ImageBuf *ib = new ImageBuf (name(), m_imagecache);
// If we were requested to bypass the cache, force a full read.
if (readpolicy & ReadNoCache)
forceread = true;
// Convert to float unless asked to keep native.
TypeDesc convert = (readpolicy & ReadNative)
? ib->nativespec().format : TypeDesc::FLOAT;
if (! forceread &&
convert != TypeDesc::UINT8 && convert != TypeDesc::UINT16 &&
convert != TypeDesc::HALF && convert != TypeDesc::FLOAT) {
// If we're still trying to use the cache but it doesn't
// support the native type, force a full read.
forceread = true;
}
bool ok = ib->read (s, m, forceread, convert);
if (!ok)
error ("%s", ib->geterror());
allok &= ok;
// Remove any existing SHA-1 hash from the spec.
ib->specmod().erase_attribute ("oiio:SHA-1");
std::string desc = ib->spec().get_string_attribute ("ImageDescription");
if (desc.size())
ib->specmod().attribute ("ImageDescription",
boost::regex_replace (desc, regex_sha, ""));
m_subimages[s].m_miplevels[m].reset (ib);
m_subimages[s].m_specs[m] = ib->spec();
// For ImageRec purposes, we need to restore a few of the
// native settings.
const ImageSpec &nativespec (ib->nativespec());
// m_subimages[s].m_specs[m].format = nativespec.format;
m_subimages[s].m_specs[m].tile_width = nativespec.tile_width;
m_subimages[s].m_specs[m].tile_height = nativespec.tile_height;
m_subimages[s].m_specs[m].tile_depth = nativespec.tile_depth;
}
}
m_time = Filesystem::last_write_time (name());
m_elaborated = true;
return allok;
}
示例12: 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.
//.........这里部分代码省略.........
示例13: formatres
static bool
write_mipmap (ImageBufAlgo::MakeTextureMode mode,
ImageBuf &img, const ImageSpec &outspec_template,
std::string outputfilename, ImageOutput *out,
TypeDesc outputdatatype, bool mipmap,
Filter2D *filter, const ImageSpec &configspec,
std::ostream &outstream,
double &stat_writetime, double &stat_miptime)
{
bool envlatlmode = (mode == ImageBufAlgo::MakeTxEnvLatl);
ImageSpec outspec = outspec_template;
outspec.set_format (outputdatatype);
if (mipmap && !out->supports ("multiimage") && !out->supports ("mipmap")) {
outstream << "maketx ERROR: \"" << outputfilename
<< "\" format does not support multires images\n";
return false;
}
if (! mipmap && ! strcmp (out->format_name(), "openexr")) {
// Send hint to OpenEXR driver that we won't specify a MIPmap
outspec.attribute ("openexr:levelmode", 0 /* ONE_LEVEL */);
}
if (mipmap && ! strcmp (out->format_name(), "openexr")) {
outspec.attribute ("openexr:roundingmode", 0 /* ROUND_DOWN */);
}
// OpenEXR always uses border sampling for environment maps
bool src_samples_border;
if (envlatlmode && !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);
Timer writetimer;
if (! out->open (outputfilename.c_str(), outspec)) {
outstream << "maketx ERROR: Could not open \"" << outputfilename
<< "\" : " << out->geterror() << "\n";
return false;
}
// Write out the image
bool verbose = configspec.get_int_attribute ("maketx:verbose");
if (verbose) {
outstream << " Writing file: " << outputfilename << std::endl;
outstream << " Filter \"" << filter->name() << "\" width = "
<< filter->width() << "\n";
outstream << " Top level is " << formatres(outspec) << std::endl;
}
if (! img.write (out)) {
// ImageBuf::write transfers any errors from the ImageOutput to
// the ImageBuf.
outstream << "maketx ERROR: Write failed \" : " << img.geterror() << "\n";
out->close ();
return false;
}
stat_writetime += writetimer();
if (mipmap) { // Mipmap levels:
if (verbose)
outstream << " Mipmapping...\n" << std::flush;
std::vector<std::string> mipimages;
std::string mipimages_unsplit = configspec.get_string_attribute ("maketx:mipimages");
if (mipimages_unsplit.length())
Strutil::split (mipimages_unsplit, mipimages, ";");
ImageBuf tmp;
ImageBuf *big = &img, *small = &tmp;
while (outspec.width > 1 || outspec.height > 1) {
Timer miptimer;
ImageSpec smallspec;
if (mipimages.size()) {
// Special case -- the user specified a custom MIP level
small->reset (mipimages[0]);
small->read (0, 0, true, TypeDesc::FLOAT);
smallspec = small->spec();
if (smallspec.nchannels != outspec.nchannels) {
outstream << "WARNING: Custom mip level \"" << mipimages[0]
<< " had the wrong number of channels.\n";
ImageBuf *t = new ImageBuf (mipimages[0], smallspec);
ImageBufAlgo::setNumChannels(*t, *small, outspec.nchannels);
std::swap (t, small);
delete t;
}
smallspec.tile_width = outspec.tile_width;
smallspec.tile_height = outspec.tile_height;
smallspec.tile_depth = outspec.tile_depth;
mipimages.erase (mipimages.begin());
} else {
// Resize a factor of two smaller
smallspec = outspec;
smallspec.width = big->spec().width;
smallspec.height = big->spec().height;
//.........这里部分代码省略.........
示例14: outspec
//.........这里部分代码省略.........
float theta = atan2f (yt, xt);
// See OSL's Dual2 for partial derivs of
// atan2, hypot, and 1/x
float denom = 1.0f / (xt*xt + yt*yt);
float dtheta_dx = yt*dxt_dx * denom;
float dtheta_dy = -xt*dyt_dy * denom;
s[idx] = 4.0f * theta / (2.0f * M_PI);
dsdx[idx] = 4.0f * dtheta_dx / (2.0f * M_PI);
dsdy[idx] = 4.0f * dtheta_dy / (2.0f * M_PI);
float h = hypot(xt,yt);
float dh_dx = xt*dxt_dx / h;
float dh_dy = yt*dyt_dy / h;
h *= M_SQRT2;
dh_dx *= M_SQRT2; dh_dy *= M_SQRT2;
float hinv = 1.0f / h;
t[idx] = hinv;
dtdx[idx] = hinv * (-hinv * dh_dx);
dtdy[idx] = hinv * (-hinv * dh_dy);
} else {
Imath::V3f coord = warp ((float)x/output_xres,
(float)y/output_yres,
xform);
coord.x *= sscale;
coord.y *= tscale;
coord += offset;
Imath::V3f coordx = warp ((float)(x+1)/output_xres,
(float)y/output_yres,
xform);
coordx.x *= sscale;
coordx.y *= tscale;
coordx += offset;
Imath::V3f coordy = warp ((float)x/output_xres,
(float)(y+1)/output_yres,
xform);
coordy.x *= sscale;
coordy.y *= tscale;
coordy += offset;
s[idx] = coord[0];
t[idx] = coord[1];
dsdx[idx] = coordx[0] - coord[0];
dtdx[idx] = coordx[1] - coord[1];
dsdy[idx] = coordy[0] - coord[0];
dtdy[idx] = coordy[1] - coord[1];
}
runflags[idx] = RunFlagOn;
} else {
runflags[idx] = RunFlagOff;
}
++idx;
}
}
// Call the texture system to do the filtering.
bool ok;
if (blocksize == 1) {
if (use_handle)
ok = texsys->texture (texture_handle, perthread_info, opt1,
s[0], t[0], dsdx[0], dtdx[0],
dsdy[0], dtdy[0], result);
else
ok = texsys->texture (filename, opt1,
s[0], t[0], dsdx[0], dtdx[0],
dsdy[0], dtdy[0], result);
} else {
ok = texsys->texture (filename, opt, runflags, 0,
shadepoints, Varying(s), Varying(t),
Varying(dsdx), Varying(dtdx),
Varying(dsdy), Varying(dtdy), result);
}
if (! ok) {
std::string e = texsys->geterror ();
if (! e.empty())
std::cerr << "ERROR: " << e << "\n";
}
for (int i = 0; i < shadepoints*nchannels; ++i)
result[i] *= scalefactor;
// Save filtered pixels back to the image.
idx = 0;
for (int y = by; y < by+blocksize; ++y) {
for (int x = bx; x < bx+blocksize; ++x) {
if (runflags[idx]) {
image.setpixel (x, y, result + idx*nchannels);
}
++idx;
}
}
}
}
if (resetstats) {
std::cout << texsys->getstats(2) << "\n";
texsys->reset_stats ();
}
}
if (! image.save ())
std::cerr << "Error writing " << output_filename
<< " : " << image.geterror() << "\n";
}