2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
20 /* If you are using an installed libdcp, these #includes would need to be changed to
22 #include <dcp/picture_asset.h>
29 #include "reel_picture_asset.h"
30 #include "mono_picture_frame.h"
31 #include "mono_picture_asset.h"
32 #include "mono_picture_asset_reader.h"
33 #include "stereo_picture_asset.h"
34 #include "sound_asset.h"
35 #include "subtitle_asset.h"
36 #include "openjpeg_image.h"
37 #include "colour_conversion.h"
40 #include <boost/scoped_array.hpp>
42 /** @file examples/read_dcp.cc
43 * @brief Shows how to read a DCP.
49 /* Create a DCP, specifying where our existing data is */
50 dcp::DCP dcp ("/home/carl/diagonal.com/APPASSIONATA_TLR_F_UK-DEFR_CH_51_2K_LOK_20121115_DGL_OV");
51 /* Read the DCP to find out about it */
54 if (dcp.encrypted ()) {
55 std::cout << "DCP is encrypted.\n";
57 std::cout << "DCP is not encrypted.\n";
60 std::cout << "DCP has " << dcp.cpls().size() << " CPLs.\n";
61 std::list<boost::shared_ptr<dcp::Asset> > assets = dcp.assets ();
62 std::cout << "DCP has " << assets.size() << " assets.\n";
63 for (std::list<boost::shared_ptr<dcp::Asset> >::const_iterator i = assets.begin(); i != assets.end(); ++i) {
64 if (boost::dynamic_pointer_cast<dcp::MonoPictureAsset> (*i)) {
65 std::cout << "2D picture\n";
66 } else if (boost::dynamic_pointer_cast<dcp::StereoPictureAsset> (*i)) {
67 std::cout << "3D picture\n";
68 } else if (boost::dynamic_pointer_cast<dcp::SoundAsset> (*i)) {
69 std::cout << "Sound\n";
70 } else if (boost::dynamic_pointer_cast<dcp::SubtitleAsset> (*i)) {
71 std::cout << "Subtitle\n";
72 } else if (boost::dynamic_pointer_cast<dcp::CPL> (*i)) {
75 std::cout << "\t" << (*i)->file().leaf().string() << "\n";
78 /* Take the first CPL */
79 boost::shared_ptr<dcp::CPL> cpl = dcp.cpls().front ();
81 /* Get the picture asset in the first reel */
82 boost::shared_ptr<dcp::MonoPictureAsset> picture_asset = boost::dynamic_pointer_cast<dcp::MonoPictureAsset> (
83 cpl->reels().front()->main_picture()->asset()
86 /* Get a reader for it */
87 boost::shared_ptr<dcp::MonoPictureAssetReader> picture_asset_reader = picture_asset->start_read();
89 /* Get the 1000th frame of it */
90 boost::shared_ptr<const dcp::MonoPictureFrame> picture_frame_j2k = picture_asset_reader->get_frame(999);
92 /* Get the frame as an XYZ image */
93 boost::shared_ptr<const dcp::OpenJPEGImage> picture_image_xyz = picture_frame_j2k->xyz_image ();
96 boost::scoped_array<uint8_t> rgba (new uint8_t[picture_image_xyz->size().width * picture_image_xyz->size().height * 4]);
97 dcp::xyz_to_rgba (picture_image_xyz, dcp::ColourConversion::srgb_to_xyz(), rgba.get ());
99 Magick::Image image (picture_image_xyz->size().width, picture_image_xyz->size().height, "BGRA", Magick::CharPixel, rgba.get ());
100 image.write ("frame.png");