本文整理汇总了C++中ImageIOParameter::data方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageIOParameter::data方法的具体用法?C++ ImageIOParameter::data怎么用?C++ ImageIOParameter::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageIOParameter
的用法示例。
在下文中一共展示了ImageIOParameter::data方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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);
}
示例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: sscanf
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
}
}
示例4: 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;
}
示例5: prep_subimage
bool
DPXOutput::open (const std::string &name, const ImageSpec &userspec,
OpenMode mode)
{
if (mode == Create) {
m_subimage = 0;
if (m_subimage_specs.size() < 1) {
m_subimage_specs.resize (1);
m_subimage_specs[0] = userspec;
m_subimages_to_write = 1;
}
} else if (mode == AppendSubimage) {
if (m_write_pending)
write_buffer ();
++m_subimage;
if (m_subimage >= m_subimages_to_write) {
error ("Exceeded the pre-declared number of subimages (%d)",
m_subimages_to_write);
return false;
}
return prep_subimage (m_subimage, true);
// Nothing else to do, the header taken care of when we opened with
// Create.
} else if (mode == AppendMIPLevel) {
error ("DPX does not support MIP-maps");
return false;
}
// From here out, all the heavy lifting is done for Create
ASSERT (mode == Create);
if (is_opened())
close (); // Close any already-opened file
m_stream = new OutStream();
if (! m_stream->Open(name.c_str ())) {
error ("Could not open file \"%s\"", name.c_str ());
return false;
}
m_dpx.SetOutStream (m_stream);
m_dpx.Start ();
m_subimage = 0;
ImageSpec &m_spec (m_subimage_specs[m_subimage]); // alias 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;
else if (m_spec.depth > 1) {
error ("DPX does not support volume images (depth > 1)");
return false;
}
// some metadata
std::string software = m_spec.get_string_attribute ("Software", "");
std::string project = m_spec.get_string_attribute ("DocumentName", "");
std::string copyright = m_spec.get_string_attribute ("Copyright", "");
std::string datestr = m_spec.get_string_attribute ("DateTime", "");
if (datestr.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
datestr[10] = ':';
datestr.replace (19, -1, "Z");
}
// check if the client wants endianness reverse to native
// assume big endian per Jeremy's request, unless little endian is
// explicitly specified
std::string endian = m_spec.get_string_attribute ("oiio:Endian", littleendian() ? "little" : "big");
m_wantSwap = (littleendian() != Strutil::iequals (endian, "little"));
m_dpx.SetFileInfo (name.c_str (), // filename
datestr.c_str (), // cr. date
software.empty () ? OIIO_INTRO_STRING : software.c_str (), // creator
project.empty () ? NULL : project.c_str (), // project
copyright.empty () ? NULL : copyright.c_str (), // copyright
m_spec.get_int_attribute ("dpx:EncryptKey", ~0), // encryption key
m_wantSwap);
// image info
m_dpx.SetImageInfo (m_spec.width, m_spec.height);
for (int s = 0; s < m_subimages_to_write; ++s) {
prep_subimage (s, false);
m_dpx.header.SetBitDepth (s, m_bitdepth);
ImageSpec &spec (m_subimage_specs[s]);
bool datasign = (spec.format == TypeDesc::INT8 ||
spec.format == TypeDesc::INT16);
m_dpx.SetElement (s, m_desc, m_bitdepth, m_transfer, m_cmetr,
m_packing, dpx::kNone, datasign,
spec.get_int_attribute ("dpx:LowData", 0xFFFFFFFF),
spec.get_float_attribute ("dpx:LowQuantity", std::numeric_limits<float>::quiet_NaN()),
//.........这里部分代码省略.........
示例6: 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;
}
示例7: error
OIIO_PLUGIN_EXPORTS_END
bool
HdrOutput::open (const std::string &name, const ImageSpec &newspec,
OpenMode mode)
{
if (mode != Create) {
error ("%s does not support subimages or MIP levels", format_name());
return false;
}
// Save spec for later use
m_spec = newspec;
// HDR always behaves like floating point
m_spec.set_format (TypeDesc::FLOAT);
// Check for things HDR can't support
if (m_spec.nchannels != 3) {
error ("HDR can only support 3-channel images");
return false;
}
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;
}
m_spec.set_format (TypeDesc::FLOAT); // Native rgbe is float32 only
m_fd = Filesystem::fopen (name, "wb");
if (m_fd == NULL) {
error ("Unable to open file");
return false;
}
rgbe_header_info h;
h.valid = 0;
// Most readers seem to think that rgbe files are valid only if they
// identify themselves as from "RADIANCE".
h.valid |= RGBE_VALID_PROGRAMTYPE;
Strutil::safe_strcpy (h.programtype, "RADIANCE", sizeof(h.programtype));
ImageIOParameter *p;
p = m_spec.find_attribute ("Orientation", TypeDesc::INT);
if (p) {
h.valid |= RGBE_VALID_ORIENTATION;
h.orientation = * (int *)p->data();
}
// FIXME -- should we do anything about gamma, exposure, software,
// pixaspect, primaries? (N.B. rgbe.c doesn't even handle most of them)
int r = RGBE_WriteHeader (m_fd, m_spec.width, m_spec.height, &h, rgbe_error);
if (r != RGBE_RETURN_SUCCESS)
error ("%s", rgbe_error);
return true;
}
示例8: if
//.........这里部分代码省略.........
// 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
}
示例9: if
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();
//.........这里部分代码省略.........
示例10: error
bool
OpenEXROutput::open (const std::string &name, const ImageSpec &userspec,
OpenMode mode)
{
if (mode == AppendSubimage) {
error ("%s does not support subimages", format_name());
return false;
}
if (mode == AppendMIPLevel && (m_output_scanline || m_output_tiled)) {
// Special case for appending to an open file -- we don't need
// to close and reopen
if (m_spec.tile_width && m_levelmode != Imf::ONE_LEVEL) {
// OpenEXR does not support differing tile sizes on different
// MIP-map levels. Reject the open() if not using the original
// tile sizes.
if (userspec.tile_width != m_spec.tile_width ||
userspec.tile_height != m_spec.tile_height) {
error ("OpenEXR tiles must have the same size on all MIPmap levels");
return false;
}
// Copy the new mip level size. Keep everything else from the
// original level.
m_spec.width = userspec.width;
m_spec.height = userspec.height;
// N.B. do we need to copy anything else from userspec?
++m_miplevel;
return true;
}
}
m_spec = userspec; // Stash the spec
if (m_spec.width < 1 || m_spec.height < 1) {
error ("Image resolution must be at least 1x1, you asked for %d x %d",
userspec.width, userspec.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.full_width <= 0)
m_spec.full_width = m_spec.width;
if (m_spec.full_height <= 0)
m_spec.full_height = m_spec.height;
// Force use of one of the three data types that OpenEXR supports
switch (m_spec.format.basetype) {
case TypeDesc::UINT:
m_spec.format = TypeDesc::UINT;
break;
case TypeDesc::FLOAT:
case TypeDesc::DOUBLE:
m_spec.format = TypeDesc::FLOAT;
break;
default:
// Everything else defaults to half
m_spec.format = TypeDesc::HALF;
}
Imath::Box2i dataWindow (Imath::V2i (m_spec.x, m_spec.y),
Imath::V2i (m_spec.width + m_spec.x - 1,
m_spec.height + m_spec.y - 1));
Imath::Box2i displayWindow (Imath::V2i (m_spec.full_x, m_spec.full_y),
Imath::V2i (m_spec.full_width+m_spec.full_x-1,
m_spec.full_height+m_spec.full_y-1));
m_header = new Imf::Header (displayWindow, dataWindow);
// Insert channels into the header. Also give the channels names if
// the user botched it.
static const char *default_chan_names[] = { "R", "G", "B", "A" };
m_spec.channelnames.resize (m_spec.nchannels);
for (int c = 0; c < m_spec.nchannels; ++c) {
if (m_spec.channelnames[c].empty())
m_spec.channelnames[c] = (c<4) ? default_chan_names[c]
: Strutil::format ("unknown %d", c);
TypeDesc format = m_spec.channelformats.size() ?
m_spec.channelformats[c] : m_spec.format;
Imf::PixelType ptype;
switch (format.basetype) {
case TypeDesc::UINT:
ptype = Imf::UINT;
format = TypeDesc::UINT;
break;
case TypeDesc::FLOAT:
case TypeDesc::DOUBLE:
ptype = Imf::FLOAT;
format = TypeDesc::FLOAT;
break;
default:
// Everything else defaults to half
ptype = Imf::HALF;
format = TypeDesc::HALF;
}
#ifdef OPENEXR_VERSION_IS_1_6_OR_LATER
//.........这里部分代码省略.........
示例11: if
//.........这里部分代码省略.........
TIFFSetField (m_tif, TIFFTAG_SAMPLESPERPIXEL, m_outputchans);
if (m_spec.format != TypeDesc::UINT8 || m_spec.format != TypeDesc::UINT16) {
m_spec.format = TypeDesc::UINT8;
m_bitspersample = 8;
TIFFSetField (m_tif, TIFFTAG_BITSPERSAMPLE, m_bitspersample);
TIFFSetField (m_tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
}
}
}
TIFFSetField (m_tif, TIFFTAG_PHOTOMETRIC, m_photometric);
// ExtraSamples tag
if (m_spec.nchannels > 3 && m_photometric != PHOTOMETRIC_SEPARATED) {
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]);
}
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;
}
// Can't deal with the headache of separate image planes when using
// bit packing, or CMYK. Just punt by forcing contig in those cases.
if (m_bitspersample != spec().format.size()*8 ||
m_photometric == PHOTOMETRIC_SEPARATED)
m_planarconfig = PLANARCONFIG_CONTIG;
if (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);
if (icc_profile_parameter != NULL) {
示例12: error
//.........这里部分代码省略.........
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);
if (icc_profile_parameter != NULL) {
unsigned char *icc_profile = (unsigned char*)icc_profile_parameter->data();
uint32 length = icc_profile_parameter->type().size();
if (icc_profile && length)
TIFFSetField (m_tif, TIFFTAG_ICCPROFILE, length, icc_profile);
}
示例13: 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;
//.........这里部分代码省略.........
示例14: if
//.........这里部分代码省略.........
// The libtiff docs say that only uncompressed images, or those with
// rowsperstrip==1, support random access to scanlines.
m_no_random_access = (compress != COMPRESSION_NONE && rowsperstrip != 1);
short resunit = -1;
TIFFGetField (m_tif, TIFFTAG_RESOLUTIONUNIT, &resunit);
switch (resunit) {
case RESUNIT_NONE : m_spec.attribute ("ResolutionUnit", "none"); break;
case RESUNIT_INCH : m_spec.attribute ("ResolutionUnit", "in"); break;
case RESUNIT_CENTIMETER : m_spec.attribute ("ResolutionUnit", "cm"); break;
}
get_matrix_attribute ("worldtocamera", TIFFTAG_PIXAR_MATRIX_WORLDTOCAMERA);
get_matrix_attribute ("worldtoscreen", TIFFTAG_PIXAR_MATRIX_WORLDTOSCREEN);
get_int_attribute ("tiff:subfiletype", TIFFTAG_SUBFILETYPE);
// FIXME -- should subfiletype be "conventionized" and used for all
// plugins uniformly?
// FIXME: do we care about fillorder for 1-bit and 4-bit images?
// Special names for shadow maps
char *s = NULL;
TIFFGetField (m_tif, TIFFTAG_PIXAR_TEXTUREFORMAT, &s);
if (s)
m_emulate_mipmap = true;
if (s && ! strcmp (s, "Shadow")) {
for (int c = 0; c < m_spec.nchannels; ++c)
m_spec.channelnames[c] = "z";
}
// N.B. we currently ignore the following TIFF fields:
// ExtraSamples
// 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);
m_tif = TIFFOpen (m_filename.c_str(), "rm");
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
}