libdcp
read_dcp.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
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.
10 
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.
15 
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/>.
18 */
19 
20 /* If you are using an installed libdcp, these #includes would need to be changed to
21 #include <dcp/dcp.h>
22 #include <dcp/picture_asset.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_asset.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"
38 #include "rgb_xyz.h"
39 /* This DISABLE/ENABLE pair is just to ignore some warnings from Magick++.h; they
40  * can be removed.
41  */
42 LIBDCP_DISABLE_WARNINGS
43 #include <Magick++.h>
44 LIBDCP_ENABLE_WARNINGS
45 #include <boost/scoped_array.hpp>
46 
51 int
52 main ()
53 {
54  /* Create a DCP, specifying where our existing data is */
55  dcp::DCP dcp ("/home/carl/Test_DCP");
56  /* Read the DCP to find out about it */
57  dcp.read ();
58 
59  if (dcp.all_encrypted()) {
60  std::cout << "DCP is encrypted.\n";
61  } else if (dcp.any_encrypted()) {
62  std::cout << "DCP is partially encrypted.\n";
63  } else {
64  std::cout << "DCP is not encrypted.\n";
65  }
66 
67  std::cout << "DCP has " << dcp.cpls().size() << " CPLs.\n";
68  auto assets = dcp.assets ();
69  std::cout << "DCP has " << assets.size() << " assets.\n";
70  for (auto i: assets) {
71  if (std::dynamic_pointer_cast<dcp::MonoPictureAsset>(i)) {
72  std::cout << "2D picture\n";
73  } else if (std::dynamic_pointer_cast<dcp::StereoPictureAsset>(i)) {
74  std::cout << "3D picture\n";
75  } else if (std::dynamic_pointer_cast<dcp::SoundAsset>(i)) {
76  std::cout << "Sound\n";
77  } else if (std::dynamic_pointer_cast<dcp::SubtitleAsset>(i)) {
78  std::cout << "Subtitle\n";
79  } else if (std::dynamic_pointer_cast<dcp::CPL>(i)) {
80  std::cout << "CPL\n";
81  }
82  std::cout << "\t" << i->file()->leaf().string() << "\n";
83  }
84 
85  /* Take the first CPL */
86  auto cpl = dcp.cpls().front();
87 
88  /* Get the picture asset in the first reel */
89  auto picture_asset = std::dynamic_pointer_cast<dcp::MonoPictureAsset>(
90  cpl->reels()[0]->main_picture()->asset()
91  );
92 
93  /* Get a reader for it */
94  auto picture_asset_reader = picture_asset->start_read();
95 
96  /* Get the 1000th frame of it */
97  auto picture_frame_j2k = picture_asset_reader->get_frame(999);
98 
99  /* Get the frame as an XYZ image */
100  auto picture_image_xyz = picture_frame_j2k->xyz_image ();
101 
102  /* Convert to ARGB */
103  boost::scoped_array<uint8_t> rgba (new uint8_t[picture_image_xyz->size().width * picture_image_xyz->size().height * 4]);
104  dcp::xyz_to_rgba (picture_image_xyz, dcp::ColourConversion::srgb_to_xyz(), rgba.get(), picture_image_xyz->size().width * 4);
105 
106  Magick::Image image (picture_image_xyz->size().width, picture_image_xyz->size().height, "BGRA", Magick::CharPixel, rgba.get ());
107  image.write ("frame.png");
108 
109  return 0;
110 }
A class to create or read a DCP.
Definition: dcp.h:83
ColourConversion class.
CPL class.
DCP class.
MonoPictureAssetReader typedef.
MonoPictureFrame class.
Namespace for everything in libdcp.
Definition: array_data.h:50
void xyz_to_rgba(std::shared_ptr< const OpenJPEGImage >, ColourConversion const &conversion, uint8_t *rgba, int stride)
Definition: rgb_xyz.cc:62
OpenJPEGImage class.
ReelPictureAsset class.
Conversion between RGB and XYZ.
SoundAsset class.
StereoPictureAsset class.
SubtitleAsset class.