No-op: whitespace.
[libdcp.git] / src / openjpeg_image.cc
1 /*
2     Copyright (C) 2012-2015 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 /** @file  src/openjpeg_image.cc
21  *  @brief OpenJPEGImage class.
22  */
23
24 #include "openjpeg_image.h"
25 #include "dcp_assert.h"
26 #include <stdexcept>
27
28 using namespace dcp;
29
30 /** Construct an OpenJPEGImage, taking ownership of the opj_image_t */
31 OpenJPEGImage::OpenJPEGImage (opj_image_t* image)
32         : _opj_image (image)
33 {
34         DCP_ASSERT (_opj_image->numcomps == 3);
35 }
36
37 /** Construct a new OpenJPEGImage with undefined contents.
38  *  @param size Size for the frame in pixels.
39  */
40 OpenJPEGImage::OpenJPEGImage (Size size)
41 {
42         opj_image_cmptparm_t cmptparm[3];
43
44         for (int i = 0; i < 3; ++i) {
45                 cmptparm[i].dx = 1;
46                 cmptparm[i].dy = 1;
47                 cmptparm[i].w = size.width;
48                 cmptparm[i].h = size.height;
49                 cmptparm[i].x0 = 0;
50                 cmptparm[i].y0 = 0;
51                 cmptparm[i].prec = 12;
52                 cmptparm[i].bpp = 12;
53                 cmptparm[i].sgnd = 0;
54         }
55
56         /* XXX: is this _SRGB right? */
57         _opj_image = opj_image_create (3, &cmptparm[0], CLRSPC_SRGB);
58         if (_opj_image == 0) {
59                 throw std::runtime_error ("could not create libopenjpeg image");
60         }
61
62         _opj_image->x0 = 0;
63         _opj_image->y0 = 0;
64         _opj_image->x1 = size.width;
65         _opj_image->y1 = size.height;
66 }
67
68 /** OpenJPEGImage destructor */
69 OpenJPEGImage::~OpenJPEGImage ()
70 {
71         opj_image_destroy (_opj_image);
72 }
73
74 /** @param c Component index (0, 1 or 2)
75  *  @return Pointer to the data for component c.
76  */
77 int *
78 OpenJPEGImage::data (int c) const
79 {
80         DCP_ASSERT (c >= 0 && c < 3);
81         return _opj_image->comps[c].data;
82 }
83
84 /** @return Size of the image in pixels */
85 dcp::Size
86 OpenJPEGImage::size () const
87 {
88         /* XXX: this may not be right; x0 and y0 can presumably be non-zero */
89         return dcp::Size (_opj_image->x1, _opj_image->y1);
90 }