From 3541f4c9bd91169e55a82b9fa46767b46ca06188 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 21 Aug 2012 19:07:10 +0100 Subject: Clarify (a bit) byte ordering for RGBA frames. --- src/argb_frame.cc | 41 +++++++++++++++++++++++++++++++++++++++++ src/argb_frame.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/picture_frame.cc | 28 ++++++++++++++++------------ src/picture_frame.h | 4 ++-- src/rgba_frame.cc | 41 ----------------------------------------- src/rgba_frame.h | 43 ------------------------------------------- src/wscript | 4 ++-- 7 files changed, 104 insertions(+), 100 deletions(-) create mode 100644 src/argb_frame.cc create mode 100644 src/argb_frame.h delete mode 100644 src/rgba_frame.cc delete mode 100644 src/rgba_frame.h (limited to 'src') diff --git a/src/argb_frame.cc b/src/argb_frame.cc new file mode 100644 index 00000000..7a9ad2b9 --- /dev/null +++ b/src/argb_frame.cc @@ -0,0 +1,41 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "argb_frame.h" + +using namespace libdcp; + +ARGBFrame::ARGBFrame (int width, int height) + : _width (width) + , _height (height) +{ + _data = new uint8_t[width * height * 4]; +} + + +ARGBFrame::~ARGBFrame () +{ + delete[] _data; +} + +int +ARGBFrame::stride () const +{ + return _width * 4; +} diff --git a/src/argb_frame.h b/src/argb_frame.h new file mode 100644 index 00000000..bc78b8fb --- /dev/null +++ b/src/argb_frame.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include + +namespace libdcp +{ + +class ARGBFrame +{ +public: + ARGBFrame (int width, int height); + ~ARGBFrame (); + + uint8_t* data () const { + return _data; + } + + int stride () const; + +private: + int _width; + int _height; + uint8_t* _data; +}; + +} diff --git a/src/picture_frame.cc b/src/picture_frame.cc index 844f0183..09ef4ae4 100644 --- a/src/picture_frame.cc +++ b/src/picture_frame.cc @@ -22,7 +22,7 @@ #include "KM_fileio.h" #include "picture_frame.h" #include "exceptions.h" -#include "rgba_frame.h" +#include "argb_frame.h" #include "lut.h" using namespace std; @@ -61,8 +61,12 @@ PictureFrame::size () const return _buffer->Size (); } -shared_ptr -PictureFrame::rgba_frame () const +/** @return An ARGB representation of this frame. This is ARGB in the + * Cairo sense, so that each pixel takes up 4 bytes; the first byte + * is blue, second green, third red and fourth alpha (always 255). + */ +shared_ptr +PictureFrame::argb_frame () const { /* JPEG2000 -> decompressed XYZ */ @@ -94,12 +98,12 @@ PictureFrame::rgba_frame () const int* xyz_y = xyz_frame->comps[1].data; int* xyz_z = xyz_frame->comps[2].data; - shared_ptr rgba_frame (new RGBAFrame (xyz_frame->x1, xyz_frame->y1)); + shared_ptr argb_frame (new ARGBFrame (xyz_frame->x1, xyz_frame->y1)); - uint8_t* rgba = rgba_frame->data (); + uint8_t* argb = argb_frame->data (); for (int y = 0; y < xyz_frame->y1; ++y) { - uint8_t* rgba_line = rgba; + uint8_t* argb_line = argb; for (int x = 0; x < xyz_frame->x1; ++x) { assert (*xyz_x >= 0 && *xyz_y >= 0 && *xyz_z >= 0 && *xyz_x < 4096 && *xyz_x < 4096 && *xyz_z < 4096); @@ -129,17 +133,17 @@ PictureFrame::rgba_frame () const d.b = max (d.b, 0.0); /* Out gamma LUT */ - *rgba_line++ = lut_out[(int) (d.r * COLOR_DEPTH)]; - *rgba_line++ = lut_out[(int) (d.g * COLOR_DEPTH)]; - *rgba_line++ = lut_out[(int) (d.b * COLOR_DEPTH)]; - *rgba_line++ = 0xff; + *argb_line++ = lut_out[(int) (d.b * COLOR_DEPTH)]; + *argb_line++ = lut_out[(int) (d.g * COLOR_DEPTH)]; + *argb_line++ = lut_out[(int) (d.r * COLOR_DEPTH)]; + *argb_line++ = 0xff; } - rgba += rgba_frame->stride (); + argb += argb_frame->stride (); } opj_cio_close (cio); opj_image_destroy (xyz_frame); - return rgba_frame; + return argb_frame; } diff --git a/src/picture_frame.h b/src/picture_frame.h index bb347294..76891d9f 100644 --- a/src/picture_frame.h +++ b/src/picture_frame.h @@ -29,7 +29,7 @@ namespace ASDCP { namespace libdcp { -class RGBAFrame; +class ARGBFrame; class PictureFrame { @@ -40,7 +40,7 @@ public: uint8_t const * data () const; int size () const; - boost::shared_ptr rgba_frame () const; + boost::shared_ptr argb_frame () const; private: ASDCP::JP2K::FrameBuffer* _buffer; diff --git a/src/rgba_frame.cc b/src/rgba_frame.cc deleted file mode 100644 index 36157cd3..00000000 --- a/src/rgba_frame.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "rgba_frame.h" - -using namespace libdcp; - -RGBAFrame::RGBAFrame (int width, int height) - : _width (width) - , _height (height) -{ - _data = new uint8_t[width * height * 4]; -} - - -RGBAFrame::~RGBAFrame () -{ - delete[] _data; -} - -int -RGBAFrame::stride () const -{ - return _width * 4; -} diff --git a/src/rgba_frame.h b/src/rgba_frame.h deleted file mode 100644 index ef1fbaae..00000000 --- a/src/rgba_frame.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include - -namespace libdcp -{ - -class RGBAFrame -{ -public: - RGBAFrame (int width, int height); - ~RGBAFrame (); - - uint8_t* data () const { - return _data; - } - - int stride () const; - -private: - int _width; - int _height; - uint8_t* _data; -}; - -} diff --git a/src/wscript b/src/wscript index bef62a93..1ca88bc6 100644 --- a/src/wscript +++ b/src/wscript @@ -18,7 +18,7 @@ def build(bld): picture_frame.cc pkl.cc reel.cc - rgba_frame.cc + argb_frame.cc sound_asset.cc sound_frame.cc subtitle_asset.cc @@ -39,7 +39,7 @@ def build(bld): picture_asset.h picture_frame.h reel.h - rgba_frame.h + argb_frame.h sound_asset.h sound_frame.h subtitle_asset.h -- cgit v1.2.3