summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-01-14 20:15:43 +0000
committerCarl Hetherington <cth@carlh.net>2013-01-14 20:15:43 +0000
commited6a471b61d36a3ba7e8696fa3e5606406c5cf62 (patch)
tree3ca098925eb269c4cd41ff22124773ba7d36c14b /src/util.cc
parent67cf9c95d190b1f2a67d73c0a7f712e213b6e71a (diff)
parent62ee85a258aa9329544d8542dfbcc40ce8177a7a (diff)
Merge master
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/util.cc b/src/util.cc
index f2ee35e3..8277b2bf 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -51,6 +51,9 @@ using std::list;
using boost::shared_ptr;
using namespace libdcp;
+/** Create a UUID.
+ * @return UUID.
+ */
string
libdcp::make_uuid ()
{
@@ -61,11 +64,14 @@ libdcp::make_uuid ()
return string (buffer);
}
+
+/** Create a digest for a file.
+ * @param filename File name.
+ * @return Digest.
+ */
string
-libdcp::make_digest (string filename, boost::signals2::signal<void (float)>* progress)
+libdcp::make_digest (string filename)
{
- int const file_size = boost::filesystem::file_size (filename);
-
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
throw FileError ("could not open file to compute digest", filename);
@@ -88,10 +94,6 @@ libdcp::make_digest (string filename, boost::signals2::signal<void (float)>* pro
SHA1_Update (&sha, read_buffer.Data(), read);
done += read;
-
- if (progress) {
- (*progress) (0.5 + (0.5 * done / file_size));
- }
}
byte_t byte_buffer[20];
@@ -101,6 +103,11 @@ libdcp::make_digest (string filename, boost::signals2::signal<void (float)>* pro
return Kumu::base64encode (byte_buffer, 20, digest, 64);
}
+/** Convert a content kind to a string which can be used in a
+ * <ContentKind> node.
+ * @param kind ContentKind.
+ * @return string.
+ */
string
libdcp::content_kind_to_string (ContentKind kind)
{
@@ -130,9 +137,16 @@ libdcp::content_kind_to_string (ContentKind kind)
assert (false);
}
+/** Convert a string from a <ContentKind> node to a libdcp ContentKind.
+ * Reasonably tolerant about varying case.
+ * @param type Content kind string.
+ * @return libdcp ContentKind.
+ */
libdcp::ContentKind
libdcp::content_kind_from_string (string type)
{
+ /* XXX: should probably just convert type to lower-case and have done with it */
+
if (type == "feature") {
return FEATURE;
} else if (type == "short") {
@@ -157,27 +171,16 @@ libdcp::content_kind_from_string (string type)
assert (false);
}
-
-bool
-libdcp::starts_with (string big, string little)
-{
- if (little.size() > big.size()) {
- return false;
- }
-
- return big.substr (0, little.length()) == little;
-}
-
-bool
-libdcp::ends_with (string big, string little)
-{
- if (little.size() > big.size()) {
- return false;
- }
-
- return big.compare (big.length() - little.length(), little.length(), little) == 0;
-}
+/** Decompress a JPEG2000 image to a bitmap.
+ * @param data JPEG2000 data.
+ * @param size Size of data in bytes.
+ * @param reduce A power of 2 by which to reduce the size of the decoded image;
+ * e.g. 0 reduces by (2^0 == 1), ie keeping the same size.
+ * 1 reduces by (2^1 == 2), ie halving the size of the image.
+ * This is useful for scaling 4K DCP images down to 2K.
+ * @return openjpeg image, which the caller must call opj_image_destroy() on.
+ */
opj_image_t *
libdcp::decompress_j2k (uint8_t* data, int64_t size, int reduce)
{
@@ -201,6 +204,10 @@ libdcp::decompress_j2k (uint8_t* data, int64_t size, int reduce)
return image;
}
+/** Convert an openjpeg XYZ image to RGB.
+ * @param xyz_frame Frame in XYZ.
+ * @return RGB image.
+ */
shared_ptr<ARGBFrame>
libdcp::xyz_to_rgb (opj_image_t* xyz_frame)
{
@@ -263,6 +270,9 @@ libdcp::xyz_to_rgb (opj_image_t* xyz_frame)
return argb_frame;
}
+/** @param s A string.
+ * @return true if the string contains only space, newline or tab characters, or is empty.
+ */
bool
libdcp::empty_or_white_space (string s)
{