本文整理汇总了C++中ImageIOParameter类的典型用法代码示例。如果您正苦于以下问题:C++ ImageIOParameter类的具体用法?C++ ImageIOParameter怎么用?C++ ImageIOParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageIOParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: param
void
ImageSpec::attribute (string_view name, TypeDesc type, string_view value)
{
ImageIOParameter param (name, type, 1, NULL);
TypeDesc::BASETYPE basetype = (TypeDesc::BASETYPE)type.basetype;
if (basetype == TypeDesc::INT) {
parse_elements<int> (name, type, "%d", value, param);
} else if (basetype == TypeDesc::UINT) {
parse_elements<unsigned int> (name, type, "%u", value, param);
} else if (basetype == TypeDesc::FLOAT) {
parse_elements<float> (name, type, "%f", value, param);
} else if (basetype == TypeDesc::DOUBLE) {
parse_elements<double> (name, type, "%lf", value, param);
} else if (basetype == TypeDesc::INT64) {
parse_elements<long long> (name, type, "%lld", value, param);
} else if (basetype == TypeDesc::UINT64) {
parse_elements<unsigned long long> (name, type, "%llu", value, param);
} else if (basetype == TypeDesc::INT16) {
parse_elements<short> (name, type, "%hd", value, param);
} else if (basetype == TypeDesc::UINT16) {
parse_elements<unsigned short> (name, type, "%hu", value, param);
} else if (type == TypeDesc::STRING) {
ustring s (value);
param.init (name, TypeDesc::TypeString, 1, &s);
}
// Don't allow duplicates
ImageIOParameter *f = find_attribute (name);
if (f) {
*f = param;
} else {
extra_attribs.push_back (param);
}
}
示例2: if
void
SgiOutput::create_and_write_header()
{
sgi_pvt::SgiHeader sgi_header;
sgi_header.magic = sgi_pvt::SGI_MAGIC;
sgi_header.storage = sgi_pvt::VERBATIM;
sgi_header.bpc = m_spec.format.size();
if (m_spec.height == 1 && m_spec.nchannels == 1)
sgi_header.dimension = sgi_pvt::ONE_SCANLINE_ONE_CHANNEL;
else if (m_spec.nchannels == 1)
sgi_header.dimension = sgi_pvt::MULTI_SCANLINE_ONE_CHANNEL;
else
sgi_header.dimension = sgi_pvt::MULTI_SCANLINE_MULTI_CHANNEL;
sgi_header.xsize = m_spec.width;
sgi_header.ysize = m_spec.height;
sgi_header.zsize = m_spec.nchannels;
sgi_header.pixmin = 0;
sgi_header.pixmax = (sgi_header.bpc == 1) ? 255 : 65535;
sgi_header.dummy = 0;
ImageIOParameter *ip = m_spec.find_attribute ("ImageDescription",
TypeDesc::STRING);
if (ip && ip->data()) {
const char** img_descr = (const char**)ip->data();
strncpy (sgi_header.imagename, *img_descr, 80);
sgi_header.imagename[79] = 0;
}
sgi_header.colormap = sgi_pvt::NORMAL;
if (littleendian()) {
swap_endian(&sgi_header.magic);
swap_endian(&sgi_header.dimension);
swap_endian(&sgi_header.xsize);
swap_endian(&sgi_header.ysize);
swap_endian(&sgi_header.zsize);
swap_endian(&sgi_header.pixmin);
swap_endian(&sgi_header.pixmax);
swap_endian(&sgi_header.colormap);
}
fwrite(&sgi_header.magic, sizeof(sgi_header.magic), 1, m_fd);
fwrite(&sgi_header.storage, sizeof(sgi_header.storage), 1, m_fd);
fwrite(&sgi_header.bpc, sizeof(sgi_header.bpc), 1, m_fd);
fwrite(&sgi_header.dimension, sizeof(sgi_header.dimension), 1, m_fd);
fwrite(&sgi_header.xsize, sizeof(sgi_header.xsize), 1, m_fd);
fwrite(&sgi_header.ysize, sizeof(sgi_header.ysize), 1, m_fd);
fwrite(&sgi_header.zsize, sizeof(sgi_header.zsize), 1, m_fd);
fwrite(&sgi_header.pixmin, sizeof(sgi_header.pixmin), 1, m_fd);
fwrite(&sgi_header.pixmax, sizeof(sgi_header.pixmax), 1, m_fd);
fwrite(&sgi_header.dummy, sizeof(sgi_header.dummy), 1, m_fd);
fwrite(sgi_header.imagename, sizeof(sgi_header.imagename), 1, m_fd);
fwrite(&sgi_header.colormap, sizeof(sgi_header.colormap), 1, m_fd);
char dummy[404] = {0};
fwrite(dummy, 404, 1, m_fd);
}
示例3: find_attribute
void
ImageSpec::attribute (const std::string &name, TypeDesc type, const void *value)
{
// Don't allow duplicates
ImageIOParameter *f = find_attribute (name);
if (! f) {
extra_attribs.resize (extra_attribs.size() + 1);
f = &extra_attribs.back();
}
f->init (name, type, 1, value);
}
示例4:
void
BmpOutput::create_and_write_bitmap_header (void)
{
m_dib_header.size = WINDOWS_V3;
m_dib_header.width = m_spec.width;
m_dib_header.height = m_spec.height;
m_dib_header.cplanes = 1;
m_dib_header.compression = 0;
m_dib_header.bpp = m_spec.nchannels << 3;
m_dib_header.isize = m_spec.width * m_spec.height * m_spec.nchannels;
m_dib_header.hres = 0;
m_dib_header.vres = 0;
m_dib_header.cpalete = 0;
m_dib_header.important = 0;
ImageIOParameter *p = NULL;
p = m_spec.find_attribute ("ResolutionUnit", TypeDesc::STRING);
if (p && p->data()) {
std::string res_units = *(char**)p->data ();
if (Strutil::iequals (res_units, "m") ||
Strutil::iequals (res_units, "pixel per meter")) {
ImageIOParameter *resx = NULL, *resy = NULL;
resx = m_spec.find_attribute ("XResolution", TypeDesc::INT32);
if (resx && resx->data())
m_dib_header.hres = *(int*)resx->data ();
resy = m_spec.find_attribute ("YResolution", TypeDesc::INT32);
if (resy && resy->data())
m_dib_header.vres = *(int*)resy->data ();
}
}
m_dib_header.write_header (m_fd);
}
示例5:
std::string
ImageSpec::metadata_val (const ImageIOParameter &p, bool human) const
{
std::string out = format_raw_metadata (p, human ? 16 : 1024);
if (human) {
std::string nice;
for (int e = 0; explanation[e].oiioname; ++e) {
if (! strcmp (explanation[e].oiioname, p.name().c_str()) &&
explanation[e].explainer) {
nice = explanation[e].explainer (p, explanation[e].extradata);
break;
}
}
if (nice.length())
out = out + " (" + nice + ")";
}
return out;
}
示例6: parse_elements
static void
parse_elements (string_view name, TypeDesc type, const char *type_code,
string_view value, ImageIOParameter ¶m)
{
int num_items = type.numelements() * type.aggregate;
T *data = (T*) param.data();
// Erase any leading whitespace
value.remove_prefix (value.find_first_not_of (" \t"));
for (int i = 0; i < num_items; ++i) {
// Make a temporary copy so we for sure have a 0-terminated string.
std::string temp = value;
// Grab the first value from it
sscanf (temp.c_str(), type_code, &data[i]);
// Skip the value (eat until we find a delimiter -- space, comma, tab)
value.remove_prefix (value.find_first_of (" ,\t"));
// Skip the delimiter
value.remove_prefix (value.find_first_not_of (" ,\t"));
if (value.empty())
break; // done if nothing left to parse
}
}
示例7: error
//.........这里部分代码省略.........
case TypeDesc::INT16:
bps = 16;
sampformat = SAMPLEFORMAT_INT;
break;
case TypeDesc::UINT16:
bps = 16;
sampformat = SAMPLEFORMAT_UINT;
break;
case TypeDesc::HALF:
// Silently change requests for unsupported 'half' to 'float'
m_spec.set_format (TypeDesc::FLOAT);
case TypeDesc::FLOAT:
bps = 32;
sampformat = SAMPLEFORMAT_IEEEFP;
break;
case TypeDesc::DOUBLE:
bps = 64;
sampformat = SAMPLEFORMAT_IEEEFP;
break;
default:
error ("TIFF doesn't support %s images (\"%s\")",
m_spec.format.c_str(), name.c_str());
close();
return false;
}
TIFFSetField (m_tif, TIFFTAG_BITSPERSAMPLE, bps);
TIFFSetField (m_tif, TIFFTAG_SAMPLEFORMAT, sampformat);
int photo = (m_spec.nchannels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
TIFFSetField (m_tif, TIFFTAG_PHOTOMETRIC, photo);
// ExtraSamples tag
if (m_spec.nchannels > 3) {
bool unass = m_spec.get_int_attribute("oiio:UnassociatedAlpha", 0);
short e = m_spec.nchannels-3;
std::vector<unsigned short> extra (e);
for (int c = 0; c < e; ++c) {
if (m_spec.alpha_channel == (c+3))
extra[c] = unass ? EXTRASAMPLE_UNASSALPHA : EXTRASAMPLE_ASSOCALPHA;
else
extra[c] = EXTRASAMPLE_UNSPECIFIED;
}
TIFFSetField (m_tif, TIFFTAG_EXTRASAMPLES, e, &extra[0]);
}
// Default to LZW compression if no request came with the user spec
if (! m_spec.find_attribute("compression"))
m_spec.attribute ("compression", "lzw");
ImageIOParameter *param;
const char *str = NULL;
// Did the user request separate planar configuration?
m_planarconfig = PLANARCONFIG_CONTIG;
if ((param = m_spec.find_attribute("planarconfig", TypeDesc::STRING)) ||
(param = m_spec.find_attribute("tiff:planarconfig", TypeDesc::STRING))) {
str = *(char **)param->data();
if (str && iequals (str, "separate"))
m_planarconfig = PLANARCONFIG_SEPARATE;
}
TIFFSetField (m_tif, TIFFTAG_PLANARCONFIG, m_planarconfig);
// Automatically set date field if the client didn't supply it.
if (! m_spec.find_attribute("DateTime")) {
time_t now;
time (&now);
struct tm mytm;
Sysutil::get_local_time (&now, &mytm);
std::string date = Strutil::format ("%4d:%02d:%02d %2d:%02d:%02d",
mytm.tm_year+1900, mytm.tm_mon+1, mytm.tm_mday,
mytm.tm_hour, mytm.tm_min, mytm.tm_sec);
m_spec.attribute ("DateTime", date);
}
if (iequals (m_spec.get_string_attribute ("oiio:ColorSpace"), "sRGB"))
m_spec.attribute ("Exif:ColorSpace", 1);
// Deal with all other params
for (size_t p = 0; p < m_spec.extra_attribs.size(); ++p)
put_parameter (m_spec.extra_attribs[p].name().string(),
m_spec.extra_attribs[p].type(),
m_spec.extra_attribs[p].data());
std::vector<char> iptc;
encode_iptc_iim (m_spec, iptc);
if (iptc.size()) {
iptc.resize ((iptc.size()+3) & (0xffff-3)); // round up
TIFFSetField (m_tif, TIFFTAG_RICHTIFFIPTC, iptc.size()/4, &iptc[0]);
}
std::string xmp = encode_xmp (m_spec, true);
if (! xmp.empty())
TIFFSetField (m_tif, TIFFTAG_XMLPACKET, xmp.size(), xmp.c_str());
TIFFCheckpointDirectory (m_tif); // Ensure the header is written early
m_checkpointTimer.start(); // Initialize the to the fileopen time
m_checkpointItems = 0; // Number of tiles or scanlines we've written
return true;
}
示例8: fseek
bool
TGAOutput::close ()
{
if (m_file) {
// write out the TGA 2.0 data fields
// FIXME: write out the developer area; according to Larry,
// it's probably safe to ignore it altogether until someone complains
// that it's missing :)
fseek (m_file, 0, SEEK_END);
// write out the thumbnail, if there is one
int ofs_thumb = 0;
{
unsigned char tw = m_spec.get_int_attribute ("thumbnail_width", 0);
if (tw) {
unsigned char th = m_spec.get_int_attribute ("thumbnail_width",
0);
if (th) {
int tc = m_spec.get_int_attribute ("thumbnail_nchannels",
0);
if (tc == m_spec.nchannels) {
ImageIOParameter *p =
m_spec.find_attribute ("thumbnail_image");
if (p) {
ofs_thumb = ftell (m_file);
if (bigendian())
swap_endian (&ofs_thumb);
// dump thumbnail size
fwrite (&tw, 1, 1, m_file);
fwrite (&th, 1, 1, m_file);
// dump thumbnail data
fwrite (p->data(), p->datasize(), 1, m_file);
}
}
}
}
}
// prepare the footer
tga_footer foot = {(uint32_t)ftell (m_file), 0, "TRUEVISION-XFILE."};
if (bigendian()) {
swap_endian (&foot.ofs_ext);
swap_endian (&foot.ofs_dev);
}
// write out the extension area
// ext area size
short tmpint = 495;
if (bigendian())
swap_endian (&tmpint);
fwrite (&tmpint, sizeof (tmpint), 1, m_file);
tmpint = 0;
// author
std::string tmpstr = m_spec.get_string_attribute ("Artist", "");
fwrite (tmpstr.c_str(), std::min (tmpstr.length (), size_t(40)),
1, m_file);
// fill the rest with zeros
for (int i = 41 - std::min (tmpstr.length (), size_t(40)); i > 0; i--)
fwrite (&tmpint, 1, 1, m_file);
// image comment
tmpstr = m_spec.get_string_attribute ("ImageDescription", "");
{
char *p = (char *)tmpstr.c_str ();
int w = 0; // number of bytes written
for (int pos = 0; w < 324 && pos < (int)tmpstr.length ();
w++, pos++) {
// on line breaks, fill the remainder of the line with zeros
if (p[pos] == '\n') {
while ((w + 1) % 81 != 0) {
fwrite (&tmpint, 1, 1, m_file);
w++;
}
continue;
}
fwrite (&p[pos], 1, 1, m_file);
// null-terminate each line
if ((w + 1) % 81 == 0) {
fwrite (&tmpint, 1, 1, m_file);
w++;
}
}
// fill the rest with zeros
for (; w < 324; w++)
fwrite (&tmpint, 1, 1, m_file);
}
// timestamp
tmpstr = m_spec.get_string_attribute ("DateTime", "");
{
unsigned short y, m, d, h, i, s;
if (tmpstr.length () > 0)
sscanf (tmpstr.c_str (), "%04hu:%02hu:%02hu %02hu:%02hu:%02hu",
&y, &m, &d, &h, &i, &s);
else
y = m = d = h = i = s = 0;
//.........这里部分代码省略.........
示例9: error
//.........这里部分代码省略.........
sampformat = SAMPLEFORMAT_IEEEFP;
break;
default:
// Everything else, including UNKNOWN -- default to 8 bit
bps = 8;
sampformat = SAMPLEFORMAT_UINT;
m_spec.set_format (TypeDesc::UINT8);
break;
}
TIFFSetField (m_tif, TIFFTAG_BITSPERSAMPLE, bps);
TIFFSetField (m_tif, TIFFTAG_SAMPLEFORMAT, sampformat);
int photo = (m_spec.nchannels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK);
TIFFSetField (m_tif, TIFFTAG_PHOTOMETRIC, photo);
// ExtraSamples tag
if (m_spec.nchannels > 3) {
bool unass = m_spec.get_int_attribute("oiio:UnassociatedAlpha", 0);
short e = m_spec.nchannels-3;
std::vector<unsigned short> extra (e);
for (int c = 0; c < e; ++c) {
if (m_spec.alpha_channel == (c+3))
extra[c] = unass ? EXTRASAMPLE_UNASSALPHA : EXTRASAMPLE_ASSOCALPHA;
else
extra[c] = EXTRASAMPLE_UNSPECIFIED;
}
TIFFSetField (m_tif, TIFFTAG_EXTRASAMPLES, e, &extra[0]);
}
// Default to ZIP compression if no request came with the user spec
if (! m_spec.find_attribute("compression"))
m_spec.attribute ("compression", "zip");
ImageIOParameter *param;
const char *str = NULL;
// Did the user request separate planar configuration?
m_planarconfig = PLANARCONFIG_CONTIG;
if ((param = m_spec.find_attribute("planarconfig", TypeDesc::STRING)) ||
(param = m_spec.find_attribute("tiff:planarconfig", TypeDesc::STRING))) {
str = *(char **)param->data();
if (str && Strutil::iequals (str, "separate")) {
m_planarconfig = PLANARCONFIG_SEPARATE;
if (! m_spec.tile_width) {
// I can only seem to make separate planarconfig work when
// rowsperstrip is 1.
TIFFSetField (m_tif, TIFFTAG_ROWSPERSTRIP, 1);
}
}
}
TIFFSetField (m_tif, TIFFTAG_PLANARCONFIG, m_planarconfig);
// Automatically set date field if the client didn't supply it.
if (! m_spec.find_attribute("DateTime")) {
time_t now;
time (&now);
struct tm mytm;
Sysutil::get_local_time (&now, &mytm);
std::string date = Strutil::format ("%4d:%02d:%02d %2d:%02d:%02d",
mytm.tm_year+1900, mytm.tm_mon+1, mytm.tm_mday,
mytm.tm_hour, mytm.tm_min, mytm.tm_sec);
m_spec.attribute ("DateTime", date);
}
// Write ICC profile, if we have anything
const ImageIOParameter* icc_profile_parameter = m_spec.find_attribute(ICC_PROFILE_ATTR);
示例10: if
//.........这里部分代码省略.........
m_dpx.header.SetTemporalFrameRate (m_spec.get_float_attribute
("dpx:TemporalFrameRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetTimeOffset (m_spec.get_float_attribute
("dpx:TimeOffset", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackLevel (m_spec.get_float_attribute
("dpx:BlackLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackGain (m_spec.get_float_attribute
("dpx:BlackGain", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBreakPoint (m_spec.get_float_attribute
("dpx:BreakPoint", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetWhiteLevel (m_spec.get_float_attribute
("dpx:WhiteLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetIntegrationTimes (m_spec.get_float_attribute
("dpx:IntegrationTimes", std::numeric_limits<float>::quiet_NaN()));
float aspect = m_spec.get_float_attribute ("PixelAspectRatio", 1.0f);
int aspect_num, aspect_den;
float_to_rational (aspect, aspect_num, aspect_den);
m_dpx.header.SetAspectRatio (0, aspect_num);
m_dpx.header.SetAspectRatio (1, aspect_den);
m_dpx.header.SetXOffset ((unsigned int)std::max (0, m_spec.x));
m_dpx.header.SetYOffset ((unsigned int)std::max (0, m_spec.y));
m_dpx.header.SetXOriginalSize ((unsigned int)m_spec.full_width);
m_dpx.header.SetYOriginalSize ((unsigned int)m_spec.full_height);
static int DpxOrientations[] = { 0,
dpx::kLeftToRightTopToBottom, dpx::kRightToLeftTopToBottom,
dpx::kLeftToRightBottomToTop, dpx::kRightToLeftBottomToTop,
dpx::kTopToBottomLeftToRight, dpx::kTopToBottomRightToLeft,
dpx::kBottomToTopLeftToRight, dpx::kBottomToTopRightToLeft };
int orient = m_spec.get_int_attribute ("Orientation", 0);
orient = DpxOrientations[clamp (orient, 0, 8)];
m_dpx.header.SetImageOrientation ((dpx::Orientation)orient);
ImageIOParameter *tc = m_spec.find_attribute("smpte:TimeCode", TypeDesc::TypeTimeCode, false);
if (tc) {
unsigned int *timecode = (unsigned int*) tc->data();
m_dpx.header.timeCode = timecode[0];
m_dpx.header.userBits = timecode[1];
}
else {
std::string timecode = m_spec.get_string_attribute ("dpx:TimeCode", "");
int tmpint = m_spec.get_int_attribute ("dpx:TimeCode", ~0);
if (timecode.size () > 0)
m_dpx.header.SetTimeCode (timecode.c_str ());
else if (tmpint != ~0)
m_dpx.header.timeCode = tmpint;
m_dpx.header.userBits = m_spec.get_int_attribute ("dpx:UserBits", ~0);
}
ImageIOParameter *kc = m_spec.find_attribute("smpte:KeyCode", TypeDesc::TypeKeyCode, false);
if (kc) {
int *array = (int*) kc->data();
set_keycode_values(array);
// See if there is an overloaded dpx:Format
std::string format = m_spec.get_string_attribute ("dpx:Format", "");
if (format.size () > 0)
m_dpx.header.SetFormat (format.c_str ());
}
std::string srcdate = m_spec.get_string_attribute ("dpx:SourceDateTime", "");
if (srcdate.size () >= 19) {
// libdpx's date/time format is pretty close to OIIO's (libdpx uses
// %Y:%m:%d:%H:%M:%S%Z)
// NOTE: the following code relies on the DateTime attribute being properly
// formatted!
示例11: close
//.........这里部分代码省略.........
m_dpx.SetFileInfo (name.c_str (), // filename
NULL, // TODO: cr. date
OIIO_INTRO_STRING, // creator
project.empty () ? NULL : project.c_str (), // project
copyright.empty () ? NULL : copyright.c_str ()); // copyright
// image info
m_dpx.SetImageInfo (m_spec.width, m_spec.height);
// determine descriptor
m_desc = get_descriptor_from_string
(m_spec.get_string_attribute ("dpx:ImageDescriptor", ""));
// transfer function
dpx::Characteristic transfer;
std::string colorspace = m_spec.get_string_attribute ("oiio:ColorSpace", "");
if (iequals (colorspace, "Linear")) transfer = dpx::kLinear;
else if (iequals (colorspace, "GammaCorrected")) transfer = dpx::kUserDefined;
else if (iequals (colorspace, "Rec709")) transfer = dpx::kITUR709;
else if (iequals (colorspace, "KodakLog")) transfer = dpx::kLogarithmic;
else {
std::string dpxtransfer = m_spec.get_string_attribute ("dpx:Transfer", "");
transfer = get_characteristic_from_string (dpxtransfer);
}
// colorimetric
m_cmetr = get_characteristic_from_string
(m_spec.get_string_attribute ("dpx:Colorimetric", "User defined"));
// select packing method
dpx::Packing packing;
std::string tmpstr = m_spec.get_string_attribute ("dpx:ImagePacking", "Filled, method A");
if (iequals (tmpstr, "Packed"))
packing = dpx::kPacked;
else if (iequals (tmpstr, "Filled, method B"))
packing = dpx::kFilledMethodB;
else
packing = dpx::kFilledMethodA;
// calculate target bit depth
int bitDepth = m_spec.get_int_attribute ("oiio:BitsPerSample",
m_spec.format.size () * 8);
if (bitDepth % 8 != 0 && bitDepth != 10 && bitDepth != 12) {
error ("Unsupported bit depth %d", bitDepth);
return false;
}
// see if we'll need to convert or not
if (m_desc == dpx::kRGB || m_desc == dpx::kRGBA) {
// shortcut for RGB(A) that gets the job done
m_bytes = m_spec.scanline_bytes ();
m_wantRaw = true;
} else {
m_bytes = dpx::QueryNativeBufferSize (m_desc, m_datasize, m_spec.width, 1);
if (m_bytes == 0 && !m_wantRaw) {
error ("Unable to deliver native format data from source data");
return false;
} else if (m_bytes < 0) {
// no need to allocate another buffer
if (!m_wantRaw)
m_bytes = m_spec.scanline_bytes ();
else
m_bytes = -m_bytes;
}
}
if (m_bytes < 0)
m_bytes = -m_bytes;
m_dpx.SetElement (0, m_desc, bitDepth, transfer, m_cmetr,
packing, dpx::kNone, (m_spec.format == TypeDesc::INT8
|| m_spec.format == TypeDesc::INT16) ? 1 : 0);
// commit!
if (!m_dpx.WriteHeader ()) {
error ("Failed to write DPX header");
return false;
}
// user data
ImageIOParameter *user = m_spec.find_attribute ("dpx:UserData");
if (user && user->datasize () > 0) {
if (user->datasize () > 1024 * 1024) {
error ("User data block size exceeds 1 MB");
return false;
}
// FIXME: write the missing libdpx code
/*m_dpx.SetUserData (user->datasize ());
if (!m_dpx.WriteUserData ((void *)user->data ())) {
error ("Failed to write user data");
return false;
}*/
}
// reserve space for the image data buffer
m_buf.reserve (m_bytes * m_spec.height);
return true;
}
示例12: error
bool
ZfileOutput::open (const std::string &name, const ImageSpec &userspec,
OpenMode mode)
{
if (mode != Create) {
error ("%s does not support subimages or MIP levels", format_name());
return false;
}
close (); // Close any already-opened file
m_gz = 0;
m_file = NULL;
m_spec = userspec; // Stash the spec
// Check for things this format doesn't support
if (m_spec.width < 1 || m_spec.height < 1) {
error ("Image resolution must be at least 1x1, you asked for %d x %d",
m_spec.width, m_spec.height);
return false;
}
if (m_spec.depth < 1)
m_spec.depth = 1;
if (m_spec.depth > 1) {
error ("%s does not support volume images (depth > 1)", format_name());
return false;
}
if (m_spec.nchannels != 1) {
error ("Zfile only supports 1-4 channels, not %d", m_spec.nchannels);
return false;
}
// Force float
if (m_spec.format != TypeDesc::FLOAT)
m_spec.format = TypeDesc::FLOAT;
ZfileHeader header;
header.magic = zfile_magic;
header.width = (int)m_spec.width;
header.height = (int)m_spec.height;
ImageIOParameter *p;
static float ident[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
if ((p = m_spec.find_attribute ("worldtocamera", TypeDesc::TypeMatrix)))
memcpy (header.worldtocamera, p->data(), 16*sizeof(float));
else
memcpy (header.worldtocamera, ident, 16*sizeof(float));
if ((p = m_spec.find_attribute ("worldtoscreen", TypeDesc::TypeMatrix)))
memcpy (header.worldtoscreen, p->data(), 16*sizeof(float));
else
memcpy (header.worldtoscreen, ident, 16*sizeof(float));
if (m_spec.get_string_attribute ("compression", "none") != std::string("none")) {
FILE *fd = Filesystem::fopen (name, "wb");
if (fd) {
m_gz = gzdopen (fileno (fd), "wb");
if (!m_gz)
fclose (fd);
}
}
else
m_file = Filesystem::fopen (name, "wb");
if (! m_file && ! m_gz) {
error ("Could not open file \"%s\"", name.c_str());
return false;
}
if (m_gz)
gzwrite (m_gz, &header, sizeof(header));
else {
size_t b = fwrite (&header, sizeof(header), 1, m_file);
if (b != 1) {
error ("Failed write zfile::open (err: %d)", b);
return false;
}
}
return true;
}
示例13: close
//.........这里部分代码省略.........
("dpx:SequenceLength", 0xFFFFFFFF));
m_dpx.header.SetHeldCount (m_spec.get_int_attribute
("dpx:HeldCount", 0xFFFFFFFF));
m_dpx.header.SetFrameRate (m_spec.get_float_attribute
("dpx:FrameRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetShutterAngle (m_spec.get_float_attribute
("dpx:ShutterAngle", std::numeric_limits<float>::quiet_NaN()));
// FIXME: should we write the input version through or always default to 2.0?
/*tmpstr = m_spec.get_string_attribute ("dpx:Version", "");
if (tmpstr.size () > 0)
m_dpx.header.SetVersion (tmpstr.c_str ());*/
tmpstr = m_spec.get_string_attribute ("dpx:Format", "");
if (tmpstr.size () > 0)
m_dpx.header.SetFormat (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:FrameId", "");
if (tmpstr.size () > 0)
m_dpx.header.SetFrameId (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:SlateInfo", "");
if (tmpstr.size () > 0)
m_dpx.header.SetSlateInfo (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:SourceImageFileName", "");
if (tmpstr.size () > 0)
m_dpx.header.SetSourceImageFileName (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:InputDevice", "");
if (tmpstr.size () > 0)
m_dpx.header.SetInputDevice (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:InputDeviceSerialNumber", "");
if (tmpstr.size () > 0)
m_dpx.header.SetInputDeviceSerialNumber (tmpstr.c_str ());
m_dpx.header.SetInterlace (m_spec.get_int_attribute ("dpx:Interlace", 0xFF));
m_dpx.header.SetFieldNumber (m_spec.get_int_attribute ("dpx:FieldNumber", 0xFF));
m_dpx.header.SetHorizontalSampleRate (m_spec.get_float_attribute
("dpx:HorizontalSampleRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetVerticalSampleRate (m_spec.get_float_attribute
("dpx:VerticalSampleRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetTemporalFrameRate (m_spec.get_float_attribute
("dpx:TemporalFrameRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetTimeOffset (m_spec.get_float_attribute
("dpx:TimeOffset", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackLevel (m_spec.get_float_attribute
("dpx:BlackLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackGain (m_spec.get_float_attribute
("dpx:BlackGain", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBreakPoint (m_spec.get_float_attribute
("dpx:BreakPoint", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetWhiteLevel (m_spec.get_float_attribute
("dpx:WhiteLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetIntegrationTimes (m_spec.get_float_attribute
("dpx:IntegrationTimes", std::numeric_limits<float>::quiet_NaN()));
float aspect = m_spec.get_float_attribute ("PixelAspectRatio", 1.0f);
int aspect_num, aspect_den;
float_to_rational (aspect, aspect_num, aspect_den);
m_dpx.header.SetAspectRatio (0, aspect_num);
m_dpx.header.SetAspectRatio (1, aspect_den);
tmpstr = m_spec.get_string_attribute ("dpx:TimeCode", "");
int tmpint = m_spec.get_int_attribute ("dpx:TimeCode", ~0);
if (tmpstr.size () > 0)
m_dpx.header.SetTimeCode (tmpstr.c_str ());
else if (tmpint != ~0)
m_dpx.header.timeCode = tmpint;
m_dpx.header.userBits = m_spec.get_int_attribute ("dpx:UserBits", ~0);
tmpstr = m_spec.get_string_attribute ("dpx:SourceDateTime", "");
if (tmpstr.size () >= 19) {
// libdpx's date/time format is pretty close to OIIO's (libdpx uses
// %Y:%m:%d:%H:%M:%S%Z)
// NOTE: the following code relies on the DateTime attribute being properly
// formatted!
// assume UTC for simplicity's sake, fix it if someone complains
tmpstr[10] = ':';
tmpstr.replace (19, -1, "Z");
m_dpx.header.SetSourceTimeDate (tmpstr.c_str ());
}
// commit!
if (!m_dpx.WriteHeader ()) {
error ("Failed to write DPX header");
return false;
}
// user data
ImageIOParameter *user = m_spec.find_attribute ("dpx:UserData");
if (user && user->datasize () > 0) {
if (user->datasize () > 1024 * 1024) {
error ("User data block size exceeds 1 MB");
return false;
}
// FIXME: write the missing libdpx code
/*m_dpx.SetUserData (user->datasize ());
if (!m_dpx.WriteUserData ((void *)user->data ())) {
error ("Failed to write user data");
return false;
}*/
}
// reserve space for the image data buffer
m_buf.reserve (m_bytes * m_spec.height);
return true;
}
示例14: error
bool
RawInput::open (const std::string &name, ImageSpec &newspec, ImageSpec &config)
{
int ret;
// open the image
if ( (ret = m_processor.open_file(name.c_str()) ) != LIBRAW_SUCCESS) {
error ("Could not open file \"%s\", %s", name.c_str(), libraw_strerror(ret));
return false;
}
if ( (ret = m_processor.unpack() ) != LIBRAW_SUCCESS) {
error ("Could not unpack \"%s\", %s",name.c_str(), libraw_strerror(ret));
return false;
}
// Forcing the Libraw to adjust sizes based on the capture device orientation
m_processor.adjust_sizes_info_only();
// Set file information
m_spec = ImageSpec(m_processor.imgdata.sizes.iwidth,
m_processor.imgdata.sizes.iheight,
3, // LibRaw should only give us 3 channels
TypeDesc::UINT16);
// Output 16 bit images
m_processor.imgdata.params.output_bps = 16;
// Set the gamma curve to Linear
m_spec.attribute("oiio:ColorSpace","Linear");
m_processor.imgdata.params.gamm[0] = 1.0;
m_processor.imgdata.params.gamm[1] = 1.0;
// Check to see if the user has explicitly set the output colorspace primaries
ImageIOParameter *csp = config.find_attribute ("raw:ColorSpace", TypeDesc::STRING, false);
if (csp) {
static const char *colorspaces[] = { "raw",
"sRGB",
"Adobe",
"Wide",
"ProPhoto",
"XYZ", NULL
};
std::string cs = *(const char**) csp->data();
size_t c;
for (c=0; c < sizeof(colorspaces) / sizeof(colorspaces[0]); c++)
if (cs == colorspaces[c])
break;
if (cs == colorspaces[c])
m_processor.imgdata.params.output_color = c;
else {
error("raw:ColorSpace set to unknown value");
return false;
}
// Set the attribute in the output spec
m_spec.attribute("raw:ColorSpace", cs);
} else {
// By default we use sRGB primaries for simplicity
m_processor.imgdata.params.output_color = 1;
m_spec.attribute("raw:ColorSpace", "sRGB");
}
// Exposure adjustment
ImageIOParameter *ex = config.find_attribute ("raw:Exposure", TypeDesc::FLOAT, false);
if (ex) {
float exposure = *(float*)ex->data();
if (exposure < 0.25f || exposure > 8.0f) {
error("raw:Exposure invalid value. range 0.25f - 8.0f");
return false;
}
m_processor.imgdata.params.exp_correc = 1; // enable exposure correction
m_processor.imgdata.params.exp_shift = exposure; // set exposure correction
// Set the attribute in the output spec
m_spec.attribute ("raw:Exposure", exposure);
}
// Interpolation quality
// note: LibRaw must be compiled with demosaic pack GPL2 to use
// demosaic algorithms 5-9. It must be compiled with demosaic pack GPL3 for
// algorithm 10. If either of these packs are not includeded, it will silently use option 3 - AHD
ImageIOParameter *dm = config.find_attribute ("raw:Demosaic", TypeDesc::STRING, false);
if (dm) {
static const char *demosaic_algs[] = { "linear",
"VNG",
"PPG",
"AHD",
"DCB",
"Modified AHD",
"AFD",
"VCD",
"Mixed",
"LMMSE",
"AMaZE",
// Future demosaicing algorithms should go here
NULL
};
std::string demosaic = *(const char**) dm->data();
//.........这里部分代码省略.........
示例15: TIFFGetField
//.........这里部分代码省略.........
// std::cerr << " extra " << i << " " << sampleinfo[i] << "\n";
if (sampleinfo[i] == EXTRASAMPLE_ASSOCALPHA) {
// This is the alpha channel, associated as usual
m_spec.alpha_channel = c;
} else if (sampleinfo[i] == EXTRASAMPLE_UNASSALPHA) {
// This is the alpha channel, but color is unassociated
m_spec.alpha_channel = c;
alpha_is_unassociated = true;
m_spec.attribute ("oiio:UnassociatedAlpha", 1);
} else {
DASSERT (sampleinfo[i] == EXTRASAMPLE_UNSPECIFIED);
// This extra channel is not alpha at all. Undo any
// assumptions we previously made about this channel.
if (m_spec.alpha_channel == c) {
m_spec.channelnames[c] = Strutil::format("channel%d", c);
m_spec.alpha_channel = -1;
}
}
}
if (m_spec.alpha_channel >= 0)
m_spec.channelnames[m_spec.alpha_channel] = "A";
}
// Will we need to do alpha conversions?
m_convert_alpha = (m_spec.alpha_channel >= 0 && alpha_is_unassociated &&
! m_keep_unassociated_alpha);
// N.B. we currently ignore the following TIFF fields:
// GrayResponseCurve GrayResponseUnit
// MaxSampleValue MinSampleValue
// NewSubfileType SubfileType(deprecated)
// Colorimetry fields
// Search for an EXIF IFD in the TIFF file, and if found, rummage
// around for Exif fields.
#if TIFFLIB_VERSION > 20050912 /* compat with old TIFF libs - skip Exif */
int exifoffset = 0;
if (TIFFGetField (m_tif, TIFFTAG_EXIFIFD, &exifoffset) &&
TIFFReadEXIFDirectory (m_tif, exifoffset)) {
for (int i = 0; exif_tag_table[i].name; ++i)
find_tag (exif_tag_table[i].tifftag, exif_tag_table[i].tifftype,
exif_tag_table[i].name);
// I'm not sure what state TIFFReadEXIFDirectory leaves us.
// So to be safe, close and re-seek.
TIFFClose (m_tif);
#ifdef _WIN32
std::wstring wfilename = Filesystem::path_to_windows_native (m_filename);
m_tif = TIFFOpenW (wfilename.c_str(), "rm");
#else
m_tif = TIFFOpen (m_filename.c_str(), "rm");
#endif
TIFFSetDirectory (m_tif, m_subimage);
// A few tidbits to look for
ImageIOParameter *p;
if ((p = m_spec.find_attribute ("Exif:ColorSpace", TypeDesc::INT))) {
// Exif spec says that anything other than 0xffff==uncalibrated
// should be interpreted to be sRGB.
if (*(const int *)p->data() != 0xffff)
m_spec.attribute ("oiio::ColorSpace", "sRGB");
}
}
#endif
#if TIFFLIB_VERSION >= 20051230
// Search for IPTC metadata in IIM form -- but older versions of
// libtiff botch the size, so ignore it for very old libtiff.
int iptcsize = 0;
const void *iptcdata = NULL;
if (TIFFGetField (m_tif, TIFFTAG_RICHTIFFIPTC, &iptcsize, &iptcdata)) {
std::vector<uint32> iptc ((uint32 *)iptcdata, (uint32 *)iptcdata+iptcsize);
if (TIFFIsByteSwapped (m_tif))
TIFFSwabArrayOfLong ((uint32*)&iptc[0], iptcsize);
decode_iptc_iim (&iptc[0], iptcsize*4, m_spec);
}
#endif
// Search for an XML packet containing XMP (IPTC, Exif, etc.)
int xmlsize = 0;
const void *xmldata = NULL;
if (TIFFGetField (m_tif, TIFFTAG_XMLPACKET, &xmlsize, &xmldata)) {
// std::cerr << "Found XML data, size " << xmlsize << "\n";
if (xmldata && xmlsize) {
std::string xml ((const char *)xmldata, xmlsize);
decode_xmp (xml, m_spec);
}
}
#if 0
// Experimental -- look for photoshop data
int photoshopsize = 0;
const void *photoshopdata = NULL;
if (TIFFGetField (m_tif, TIFFTAG_PHOTOSHOP, &photoshopsize, &photoshopdata)) {
std::cerr << "Found PHOTOSHOP data, size " << photoshopsize << "\n";
if (photoshopdata && photoshopsize) {
// std::string photoshop ((const char *)photoshopdata, photoshopsize);
// std::cerr << "PHOTOSHOP:\n" << photoshop << "\n---\n";
}
}
#endif
}