Support file:// URI-style file specifiers in asset map.
[libdcp.git] / src / xyz_frame.cc
index 78df3f33961179d1e0c218668172fa23d3002690..cba908836ad0b5126d884756cf370a9b84285cf4 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     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
 
 */
 
-#include <cassert>
+/** @file  src/xyz_frame.cc
+ *  @brief XZYFrame class.
+ */
+
 #include "xyz_frame.h"
+#include <cassert>
+#include <stdexcept>
 
-using namespace libdcp;
+using namespace dcp;
 
 /** Construct an XYZFrame, taking ownership of the opj_image_t */
 XYZFrame::XYZFrame (opj_image_t* image)
@@ -29,11 +34,46 @@ XYZFrame::XYZFrame (opj_image_t* image)
        assert (_opj_image->numcomps == 3);
 }
 
+/** Construct a new XYZFrame with undefined contents.
+ *  @param size Size for the frame in pixels.
+ */
+XYZFrame::XYZFrame (Size size)
+{
+       opj_image_cmptparm_t cmptparm[3];
+       
+       for (int i = 0; i < 3; ++i) {
+               cmptparm[i].dx = 1;
+               cmptparm[i].dy = 1;
+               cmptparm[i].w = size.width;
+               cmptparm[i].h = size.height;
+               cmptparm[i].x0 = 0;
+               cmptparm[i].y0 = 0;
+               cmptparm[i].prec = 12;
+               cmptparm[i].bpp = 12;
+               cmptparm[i].sgnd = 0;
+       }
+
+       /* XXX: is this _SRGB right? */
+       _opj_image = opj_image_create (3, &cmptparm[0], CLRSPC_SRGB);
+       if (_opj_image == 0) {
+               throw std::runtime_error ("could not create libopenjpeg image");
+       }
+
+       _opj_image->x0 = 0;
+       _opj_image->y0 = 0;
+       _opj_image->x1 = size.width;
+       _opj_image->y1 = size.height;
+}
+
+/** XYZFrame destructor */
 XYZFrame::~XYZFrame ()
 {
        opj_image_destroy (_opj_image);
 }
 
+/** @param c Component index (0, 1 or 2)
+ *  @return Pointer to the data for component c.
+ */
 int *
 XYZFrame::data (int c) const
 {
@@ -41,9 +81,10 @@ XYZFrame::data (int c) const
        return _opj_image->comps[c].data;
 }
 
-libdcp::Size
+/** @return Size of the image in pixels */
+dcp::Size
 XYZFrame::size () const
 {
        /* XXX: this may not be right; x0 and y0 can presumably be non-zero */
-       return libdcp::Size (_opj_image->x1, _opj_image->y1);
+       return dcp::Size (_opj_image->x1, _opj_image->y1);
 }