Skip to content

Commit

Permalink
Merge pull request #1204 from rleigh-dundee/cpp-pixeldata
Browse files Browse the repository at this point in the history
cpp: Add PixelBuffer<> and VariantPixelBuffer
  • Loading branch information
melissalinkert committed Aug 7, 2014
2 parents cc5f741 + 8c0ca99 commit f9ccbbd
Show file tree
Hide file tree
Showing 18 changed files with 5,400 additions and 632 deletions.
4 changes: 4 additions & 0 deletions cpp/lib/ome/bioformats/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ set(OME_BIOFORMATS_SOURCES
MetadataConfigurable.cpp
MetadataOptions.cpp
Modulo.cpp
PixelBuffer.cpp
PixelProperties.cpp
UnknownFormatException.cpp
UnsupportedCompressionException.cpp
VariantPixelBuffer.cpp
Version.cpp)

set(OME_BIOFORMATS_HEADERS
Expand All @@ -64,6 +67,7 @@ set(OME_BIOFORMATS_HEADERS
Types.h
UnknownFormatException.h
UnsupportedCompressionException.h
VariantPixelBuffer.h
Version.h)

set(OME_BIOFORMATS_DETAIL_SOURCES
Expand Down
19 changes: 9 additions & 10 deletions cpp/lib/ome/bioformats/FormatReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ namespace ome
namespace bioformats
{

class PixelBuffer;
class PixelBufferRaw;
class VariantPixelBuffer;

/**
* Interface for all biological file format readers.
Expand Down Expand Up @@ -356,7 +355,7 @@ namespace ome
*/
virtual
void
get8BitLookupTable(PixelBufferRaw& buf) const = 0;
get8BitLookupTable(VariantPixelBuffer& buf) const = 0;

/**
* Get the 16-bit color lookup table associated with the most
Expand All @@ -376,7 +375,7 @@ namespace ome
*/
virtual
void
get16BitLookupTable(PixelBufferRaw& buf) const = 0;
get16BitLookupTable(VariantPixelBuffer& buf) const = 0;

/**
* Get the Modulo subdivision of the Z dimension.
Expand Down Expand Up @@ -543,7 +542,7 @@ namespace ome
* Obtain an image plane.
*
* Obtain and copy the image plane from the current file into a
* PixelBuffer of size
* VariantPixelBuffer of size
*
* \code{.cpp}
* getSizeX * getSizeY * bytesPerPixel * getRGBChannelCount()
Expand All @@ -557,13 +556,13 @@ namespace ome
virtual
void
openBytes(dimension_size_type no,
PixelBufferRaw& buf) const = 0;
VariantPixelBuffer& buf) const = 0;

/**
* Obtain a sub-image of an image plane.
*
* Obtain and copy the sub-image of an image plane from the
* current file into a PixelBuffer of size
* current file into a VariantPixelBuffer of size
*
* \code{.cpp}
* w * h * bytesPerPixel * getRGBChannelCount()
Expand All @@ -581,7 +580,7 @@ namespace ome
virtual
void
openBytes(dimension_size_type no,
PixelBufferRaw& buf,
VariantPixelBuffer& buf,
dimension_size_type x,
dimension_size_type y,
dimension_size_type w,
Expand All @@ -591,15 +590,15 @@ namespace ome
* Obtain a thumbnail of an image plane.
*
* Obtail and copy the thumbnail for the specified image plane
* from the current file into a PixelBuffer.
* from the current file into a VariantPixelBuffer.
*
* @param no the image index within the file.
* @param buf the destination pixel buffer.
*/
virtual
void
openThumbBytes(dimension_size_type no,
PixelBufferRaw& buf) const = 0;
VariantPixelBuffer& buf) const = 0;

// Documented in superclass.
//virtual
Expand Down
139 changes: 139 additions & 0 deletions cpp/lib/ome/bioformats/PixelBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* #%L
* OME-BIOFORMATS C++ library for image IO.
* Copyright © 2006 - 2014 Open Microscopy Environment:
* - Massachusetts Institute of Technology
* - National Institutes of Health
* - University of Dundee
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of any organization.
* #L%
*/

#include <ome/bioformats/PixelBuffer.h>

namespace ome
{
namespace bioformats
{

// No switch default to avoid -Wunreachable-code errors.
// However, this then makes -Wswitch-default complain. Disable
// temporarily.
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wswitch-default"
#endif

PixelBufferBase::storage_order_type
PixelBufferBase::make_storage_order(ome::xml::model::enums::DimensionOrder order,
bool interleaved)
{
size_type ordering[dimensions];
bool ascending[dimensions] = {true, true, true, true, true, true, true, true, true};

if (interleaved)
{
ordering[0] = DIM_SUBCHANNEL;
ordering[1] = DIM_SPATIAL_X;
ordering[2] = DIM_SPATIAL_Y;
}
else
{
ordering[0] = DIM_SPATIAL_X;
ordering[1] = DIM_SPATIAL_Y;
ordering[2] = DIM_SUBCHANNEL;
}

switch(order)
{
case ome::xml::model::enums::DimensionOrder::XYZTC:
ordering[3] = DIM_MODULO_Z;
ordering[4] = DIM_SPATIAL_Z;
ordering[5] = DIM_MODULO_T;
ordering[6] = DIM_TEMPORAL_T;
ordering[7] = DIM_MODULO_C;
ordering[8] = DIM_CHANNEL;
break;
case ome::xml::model::enums::DimensionOrder::XYZCT:
ordering[3] = DIM_MODULO_Z;
ordering[4] = DIM_SPATIAL_Z;
ordering[5] = DIM_MODULO_C;
ordering[6] = DIM_CHANNEL;
ordering[7] = DIM_MODULO_T;
ordering[8] = DIM_TEMPORAL_T;
break;
case ome::xml::model::enums::DimensionOrder::XYTZC:
ordering[3] = DIM_MODULO_T;
ordering[4] = DIM_TEMPORAL_T;
ordering[5] = DIM_MODULO_Z;
ordering[6] = DIM_SPATIAL_Z;
ordering[7] = DIM_MODULO_C;
ordering[8] = DIM_CHANNEL;
break;
case ome::xml::model::enums::DimensionOrder::XYTCZ:
ordering[3] = DIM_MODULO_T;
ordering[4] = DIM_TEMPORAL_T;
ordering[5] = DIM_MODULO_C;
ordering[6] = DIM_CHANNEL;
ordering[7] = DIM_MODULO_Z;
ordering[8] = DIM_SPATIAL_Z;
break;
case ome::xml::model::enums::DimensionOrder::XYCZT:
ordering[3] = DIM_MODULO_C;
ordering[4] = DIM_CHANNEL;
ordering[5] = DIM_MODULO_Z;
ordering[6] = DIM_SPATIAL_Z;
ordering[7] = DIM_MODULO_T;
ordering[8] = DIM_TEMPORAL_T;
break;
case ome::xml::model::enums::DimensionOrder::XYCTZ:
ordering[3] = DIM_MODULO_C;
ordering[4] = DIM_CHANNEL;
ordering[5] = DIM_MODULO_T;
ordering[6] = DIM_TEMPORAL_T;
ordering[7] = DIM_MODULO_Z;
ordering[8] = DIM_SPATIAL_Z;
break;
}

return storage_order_type(ordering, ascending);
}

#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif

PixelBufferBase::storage_order_type
PixelBufferBase::default_storage_order()
{
return make_storage_order(ome::xml::model::enums::DimensionOrder::XYZTC, true);
}

}
}

0 comments on commit f9ccbbd

Please sign in to comment.