Rename XYZFrame -> XYZImage and ARGBFrame -> ARGBImage.
[libdcp.git] / examples / read_dcp.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /* If you are using an installed libdcp, these #includes would need to be changed to
21 #include <libdcp/dcp.h>
22 #include <libdcp/picture_mxf.h>
23 ... etc. ...
24 */
25
26 #include "dcp.h"
27 #include "cpl.h"
28 #include "reel.h"
29 #include "reel_picture_asset.h"
30 #include "mono_picture_frame.h"
31 #include "mono_picture_mxf.h"
32 #include "stereo_picture_mxf.h"
33 #include "sound_mxf.h"
34 #include "subtitle_content.h"
35 #include "argb_image.h"
36 #include <Magick++.h>
37
38 /** @file examples/read_dcp.cc
39  *  @brief Shows how to read a DCP.
40  */
41
42 int
43 main ()
44 {
45         /* Create a DCP, specifying where our existing data is */
46         dcp::DCP dcp ("/home/carl/diagonal.com/APPASSIONATA_TLR_F_UK-DEFR_CH_51_2K_LOK_20121115_DGL_OV");
47         /* Read the DCP to find out about it */
48         dcp.read ();
49
50         if (dcp.encrypted ()) {
51                 std::cout << "DCP is encrypted.\n";
52         } else {
53                 std::cout << "DCP is not encrypted.\n";
54         }
55
56         std::cout << "DCP has " << dcp.cpls().size() << " CPLs.\n";
57         std::list<boost::shared_ptr<dcp::Asset> > assets = dcp.assets ();
58         std::cout << "DCP has " << assets.size() << " assets.\n";
59         for (std::list<boost::shared_ptr<dcp::Asset> >::const_iterator i = assets.begin(); i != assets.end(); ++i) {
60                 if (boost::dynamic_pointer_cast<dcp::MonoPictureMXF> (*i)) {
61                         std::cout << "2D picture\n";
62                 } else if (boost::dynamic_pointer_cast<dcp::StereoPictureMXF> (*i)) {
63                         std::cout << "3D picture\n";
64                 } else if (boost::dynamic_pointer_cast<dcp::SoundMXF> (*i)) {
65                         std::cout << "Sound\n";
66                 } else if (boost::dynamic_pointer_cast<dcp::SubtitleContent> (*i)) {
67                         std::cout << "Subtitle\n";
68                 } else if (boost::dynamic_pointer_cast<dcp::CPL> (*i)) {
69                         std::cout << "CPL\n";
70                 }
71                 std::cout << "\t" << (*i)->file().leaf().string() << "\n";
72         }
73
74         /* Take the first CPL */
75         boost::shared_ptr<dcp::CPL> cpl = dcp.cpls().front ();
76
77         /* Get the MXF of the picture asset in the first reel */
78         boost::shared_ptr<dcp::MonoPictureMXF> picture_mxf = boost::dynamic_pointer_cast<dcp::MonoPictureMXF> (cpl->reels().front()->main_picture()->mxf ());
79
80         /* Get the 1000th frame of it */
81         boost::shared_ptr<const dcp::MonoPictureFrame> picture_frame_j2k = picture_mxf->get_frame(999);
82
83         /* Get a ARGB copy of it */
84         boost::shared_ptr<dcp::ARGBImage> picture_image_rgb = picture_frame_j2k->argb_image ();
85
86         Magick::Image image (picture_image_rgb->size().width, picture_image_rgb->size().height, "BGRA", Magick::CharPixel, picture_image_rgb->data ());
87         image.write ("frame.png");
88
89         return 0;
90 }