Example #1
0
std::string
IvImage::longinfo () const
{
    using Strutil::format;  // shorthand
    if (m_longinfo.empty()) {
        const ImageSpec &m_spec (spec());
        m_longinfo += "<table>";
//        m_longinfo += html_table_row (format("<b>%s</b>", m_name.c_str()).c_str(),
//                                std::string());
        if (m_spec.depth <= 1)
            m_longinfo += html_table_row ("Dimensions", 
                        format ("%d x %d pixels", m_spec.width, m_spec.height));
        else
            m_longinfo += html_table_row ("Dimensions", 
                        format ("%d x %d x %d pixels",
                                m_spec.width, m_spec.height, m_spec.depth));
        m_longinfo += html_table_row ("Channels", m_spec.nchannels);
        std::string chanlist;
        for (int i = 0;  i < m_spec.nchannels;  ++i) {
            chanlist += m_spec.channelnames[i].c_str();
            if (i != m_spec.nchannels-1)
                chanlist += ", ";
        }
        m_longinfo += html_table_row ("Channel list", chanlist);
        m_longinfo += html_table_row ("File format", file_format_name());
        m_longinfo += html_table_row ("Data format", m_file_dataformat.c_str());
        m_longinfo += html_table_row ("Data size",
             format("%.2f MB", (float)m_spec.image_bytes() / (1024.0*1024.0)));
        m_longinfo += html_table_row ("Image origin", 
                          format ("%d, %d, %d", m_spec.x, m_spec.y, m_spec.z));
        m_longinfo += html_table_row ("Full/display size", 
                          format ("%d x %d x %d", m_spec.full_width,
                                  m_spec.full_height, m_spec.full_depth));
        m_longinfo += html_table_row ("Full/display origin", 
                          format ("%d, %d, %d", m_spec.full_x,
                                  m_spec.full_y, m_spec.full_z));
        if (m_spec.tile_width)
            m_longinfo += html_table_row ("Scanline/tile",
                            format ("tiled %d x %d x %d", m_spec.tile_width,
                                    m_spec.tile_height, m_spec.tile_depth));
        else
            m_longinfo += html_table_row ("Scanline/tile", "scanline");
        if (m_spec.alpha_channel >= 0)
            m_longinfo += html_table_row ("Alpha channel", m_spec.alpha_channel);
        if (m_spec.z_channel >= 0)
            m_longinfo += html_table_row ("Depth (z) channel", m_spec.z_channel);

        BOOST_FOREACH (const ImageIOParameter &p, m_spec.extra_attribs) {
            std::string s = m_spec.metadata_val (p, true);
            m_longinfo += html_table_row (p.name().c_str(), s);
        }

        m_longinfo += "</table>";
    }
    return m_longinfo;
}
Example #2
0
static void
print_info_subimage (Oiiotool &ot,
                     int current_subimage, int num_of_subimages, int nmip,
                     ImageSpec &spec,
                     ImageInput *input, const std::string &filename,
                     const print_info_options &opt,
                     boost::regex &field_re, boost::regex &field_exclude_re,
                     ImageSpec::SerialFormat serformat,
                     ImageSpec::SerialVerbose verbose)
{
    using Strutil::format;

    int padlen = std::max (0, (int)opt.namefieldlength - (int)filename.length());
    std::string padding (padlen, ' ');
    bool printres = opt.verbose && (opt.metamatch.empty() ||
                                boost::regex_search ("resolution, width, height, depth, channels", field_re));

    // int nmip = num_of_miplevels[current_subimage];

    std::string ser = spec.serialize (serformat, verbose);

    std::vector<std::string> lines;
    Strutil::split (spec.serialize(serformat, verbose), lines, "\n");

    if (opt.compute_sha1 && (opt.metamatch.empty() ||
                             boost::regex_search ("sha-1", field_re))) {
        // Before sha-1, be sure to point back to the highest-res MIP level
        ImageSpec tmpspec;
        std::string sha = compute_sha1 (ot, input);
        if (serformat == ImageSpec::SerialText)
            lines.insert (lines.begin()+1, format("    SHA-1: %s", sha));
        else if (serformat == ImageSpec::SerialText)
            lines.insert (lines.begin()+1, format("<SHA1>%s</SHA1>", sha));
    }

    // Count MIP levels
    if (printres && nmip > 1) {
        ImageSpec mipspec;
        std::string mipdesc = format ("    MIP-map levels: %dx%d", spec.width, spec.height);
        for (int m = 1; input->seek_subimage (current_subimage, m, mipspec); ++m)
            mipdesc += format (" %dx%d", mipspec.width, mipspec.height);
        lines.insert (lines.begin()+1, mipdesc);
    }

    if (serformat == ImageSpec::SerialText) {
        // Requested a subset of metadata but not res, etc.? Kill first line.
        if (opt.metamatch.empty() ||
            boost::regex_search ("resolution, width, height, depth, channels", field_re)) {
            std::string orig_line0 = lines[0];
            if (current_subimage == 0)
                lines[0] = Strutil::format ("%s%s : ", filename, padding) + lines[0];
            else
                lines[0] = Strutil::format (" subimage %2d: ", current_subimage) + lines[0];
            if (opt.sum) {
                imagesize_t imagebytes = spec.image_bytes (true);
                // totalsize += imagebytes;
                lines[0] += format (" (%.2f MB)", (float)imagebytes / (1024.0*1024.0));
            }
            lines[0] += format (" %s", input->format_name());
            // we print info about how many subimages are stored in file
            // only when we have more then one subimage
            if ( ! opt.verbose && num_of_subimages != 1)
                lines[0] += format (" (%d subimages%s)", num_of_subimages,
                                    (nmip > 1) ? " +mipmap)" : "");
            if (! opt.verbose && num_of_subimages == 1 && (nmip > 1))
                lines[0] += " (+mipmap)";
            if (num_of_subimages > 1 && current_subimage == 0 && opt.subimages)
                lines.insert (lines.begin()+1, format (" subimage  0: %s %s",
                                                       orig_line0, input->format_name()));
        } else {
            lines.erase (lines.begin());
        }
    } else if (serformat == ImageSpec::SerialXML) {
        if (nmip > 1)
            lines.insert (lines.begin()+1,
                          format ("<miplevels>%d</miplevels>", nmip));
        if (num_of_subimages > 1)
            lines.insert (lines.begin()+1,
                          format ("<subimages>%d</subimages>", num_of_subimages));
    }

    if (current_subimage == 0 && opt.verbose && num_of_subimages != 1
        && serformat == ImageSpec::SerialText) {
        // info about num of subimages and their resolutions
        int movie = spec.get_int_attribute ("oiio:Movie");
        std::string s = format ("    %d subimages: ", num_of_subimages);
        for (int i = 0; i < num_of_subimages; ++i) {
            input->seek_subimage (i, 0, spec);
            int bits = spec.get_int_attribute ("oiio:BitsPerSample",
                                               spec.format.size()*8);
            if (i)
                s += ", ";
            if (spec.depth > 1)
                s += format ("%dx%dx%d ", spec.width, spec.height, spec.depth);
            else
                s += format ("%dx%d ", spec.width, spec.height);
            for (int c = 0; c < spec.nchannels; ++c)
                s += format ("%c%s", c ? ',' : '[',
                        brief_format_name(spec.channelformat(c), bits));
            s += "]";
            if (movie)
                break;
        }
        lines.insert (lines.begin()+1, s);
    }

    if (! opt.metamatch.empty() || ! opt.nometamatch.empty()) {
        for (size_t i = 0; i < lines.size(); ++i) {
            std::string s = lines[i].substr (0, lines[i].find(": "));
            if ((! opt.nometamatch.empty() && boost::regex_search (s, field_exclude_re)) ||
                (! opt.metamatch.empty() && ! boost::regex_search (s, field_re))) {
                lines.erase (lines.begin()+i);
                --i;
            }
        }
    }

    // Unescape the strings if we're printing for human consumption
    for (size_t i = 0; i < lines.size(); ++i) {
        lines[i] = Strutil::unescape_chars (lines[i]);
    }

    ser = Strutil::join (lines, "\n");
    if (ser[ser.size()-1] != '\n')
        ser += '\n';
    std::cout << ser;

    if (opt.dumpdata) {
        ImageSpec tmp;
        input->seek_subimage (current_subimage, 0, tmp);
        dump_data (input, opt);
    }

    if (opt.compute_stats && (opt.metamatch.empty() ||
                              boost::regex_search ("stats", field_re))) {
        for (int m = 0;  m < nmip;  ++m) {
            ImageSpec mipspec;
            input->seek_subimage (current_subimage, m, mipspec);
            if (opt.filenameprefix)
                std::cout << format ("%s : ", filename);
            if (nmip > 1) {
                std::cout << format ("    MIP %d of %d (%d x %d):\n",
                                     m, nmip, mipspec.width, mipspec.height);
            }
            print_stats (ot, filename, spec, current_subimage, m, nmip>1);
        }
    }
}