X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Futil.h;h=857f872f63c4d4a6f9805f5207d856de80eb9920;hb=491ac453512ac1982f62fc0d2a310586427601d7;hp=b6c945a5a812933f6598c2811985b83e965f81b7;hpb=4de6f6e4f4df4cc9b28b98188d36082b26e81345;p=libdcp.git diff --git a/src/util.h b/src/util.h index b6c945a5..857f872f 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,26 +17,95 @@ */ +#ifndef LIBDCP_UTIL_H +#define LIBDCP_UTIL_H + /** @file src/util.h * @brief Utility methods. */ +#include "types.h" +#include +#include +#include +#include +#include #include -#include +#include + +namespace xmlpp { + class Element; +} + +namespace dcp { -namespace libdcp { +class ARGBFrame; +class CertificateChain; +class GammaLUT; +class XYZFrame; -/** Create a UUID. - * @return UUID. +/** @struct Size + * @brief The integer, two-dimensional size of something. */ +struct Size +{ + Size () + : width (0) + , height (0) + {} + + Size (int w, int h) + : width (w) + , height (h) + {} + + float ratio () const { + return float (width) / height; + } + + int width; + int height; +}; + +extern bool operator== (Size const & a, Size const & b); +extern bool operator!= (Size const & a, Size const & b); +extern std::ostream& operator<< (std::ostream& s, Size const & a); + extern std::string make_uuid (); +extern std::string make_digest (boost::filesystem::path filename, boost::function); +extern std::string content_kind_to_string (ContentKind kind); +extern ContentKind content_kind_from_string (std::string kind); +extern bool empty_or_white_space (std::string s); +extern boost::shared_ptr decompress_j2k (uint8_t* data, int64_t size, int reduce); +extern bool ids_equal (std::string a, std::string b); -/** Create a digest for a file. - * @param filename File name. - * @param progress If non-0, a signal which will be emitted periodically to update - * progress; the parameter will start at 0.5 and proceed to 1. - * @return Digest. - */ -extern std::string make_digest (std::string filename, sigc::signal1* progress); +extern void init (); + +extern void sign (xmlpp::Element* parent, CertificateChain const & certificates, boost::filesystem::path signer_key, Standard standard); +extern void add_signature_value (xmlpp::Element* parent, CertificateChain const & certificates, boost::filesystem::path signer_key, std::string const & ns); +extern void add_signer (xmlpp::Element* parent, CertificateChain const & certificates, std::string const & ns); + +extern int base64_decode (std::string const & in, unsigned char* out, int out_length); +extern boost::optional relative_to_root (boost::filesystem::path root, boost::filesystem::path file); +extern FILE * fopen_boost (boost::filesystem::path, std::string); +extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 65536); +extern std::string private_key_fingerprint (std::string key); +template +std::list > +list_of_type (std::list > const & from) +{ + std::list > out; + for (typename std::list >::const_iterator i = from.begin(); i != from.end(); ++i) { + boost::shared_ptr check = boost::dynamic_pointer_cast (*i); + if (check) { + out.push_back (check); + } + } + + return out; +} + } + +#endif