Back to Arangodb

Metafunctions

3rdParty/boost/1.78.0/libs/gil/doc/html/design/metafunctions.html

3.12.9.18.2 KB
Original Source

Metafunctions

Overview

Flexibility comes at a price. GIL types can be very long and hard to read. To address this problem, GIL provides typedefs to refer to any standard image, pixel iterator, pixel locator, pixel reference or pixel value.

They follow this pattern:

\*ColorSpace\*+\*BitDepth\*+["s|f"]+["c"]+["\_planar"]+["\_step"]+\*ClassType\*+"\_t"

where ColorSpace also indicates the ordering of components.

Examples are rgb, bgr, cmyk, rgba. BitDepth can be, for example, 8,16,32. By default the bits are unsigned integral type. Append s to the bit depth to indicate signed integral, or f to indicate floating point. c indicates object whose associated pixel reference is immutable. _planar indicates planar organization (as opposed to interleaved). _step indicates the type has a dynamic step and ClassType is _image (image, using a standard allocator), _view (image view), _loc (pixel locator), _ptr (pixel iterator), _ref (pixel reference), _pixel (pixel value).

Here are examples:

bgr8\_image\_ti;// 8-bit unsigned (unsigned char) interleaved BGR imagecmyk16\_pixel\_t;x;// 16-bit unsigned (unsigned short) CMYK pixel value;cmyk16sc\_planar\_ref\_tp(x);// const reference to a 16-bit signed integral (signed short) planar CMYK pixel x.rgb32f\_planar\_step\_ptr\_tii;// step iterator to a floating point 32-bit (float) planar RGB pixel.

Homogeneous memory-based images

GIL provides the metafunctions that return the types of standard homogeneous memory-based GIL constructs given a channel type, a layout, and whether the construct is planar, has a step along the X direction, and is mutable:

template\<typenameChannelValue,typenameLayout,boolIsPlanar=false,boolIsMutable=true\>structpixel\_reference\_type{typedef...type;};template\<typenameChannel,typenameLayout\>structpixel\_value\_type{typedef...type;};template\<typenameChannelValue,typenameLayout,boolIsPlanar=false,boolIsStep=false,boolIsMutable=true\>structiterator\_type{typedef...type;};template\<typenameChannelValue,typenameLayout,boolIsPlanar=false,boolIsXStep=false,boolIsMutable=true\>structlocator\_type{typedef...type;};template\<typenameChannelValue,typenameLayout,boolIsPlanar=false,boolIsXStep=false,boolIsMutable=true\>structview\_type{typedef...type;};template\<typenameChannelValue,typenameLayout,boolIsPlanar=false,typenameAlloc=std::allocator\<unsignedchar\>\>structimage\_type{typedef...type;};template\<typenameBitField,typenameChannelBitSizeVector,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image\_type{typedef...type;};template\<typenameChannelBitSizeVector,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image\_type{typedef...type;};

Packed and bit-aligned images

There are also helper metafunctions to construct packed and bit-aligned images with up to five channels:

template\<typenameBitField,unsignedSize1,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image1\_type{typedef...type;};template\<typenameBitField,unsignedSize1,unsignedSize2,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image2\_type{typedef...type;};template\<typenameBitField,unsignedSize1,unsignedSize2,unsignedSize3,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image3\_type{typedef...type;};template\<typenameBitField,unsignedSize1,unsignedSize2,unsignedSize3,unsignedSize4,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image4\_type{typedef...type;};template\<typenameBitField,unsignedSize1,unsignedSize2,unsignedSize3,unsignedSize4,unsignedSize5,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structpacked\_image5\_type{typedef...type;};template\<unsignedSize1,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image1\_type{typedef...type;};template\<unsignedSize1,unsignedSize2,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image2\_type{typedef...type;};template\<unsignedSize1,unsignedSize2,unsignedSize3,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image3\_type{typedef...type;};template\<unsignedSize1,unsignedSize2,unsignedSize3,unsignedSize4,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image4\_type{typedef...type;};template\<unsignedSize1,unsignedSize2,unsignedSize3,unsignedSize4,unsignedSize5,typenameLayout,typenameAlloc=std::allocator\<unsignedchar\>\>structbit\_aligned\_image5\_type{typedef...type;};

Iterators and views

Here ChannelValue models ChannelValueConcept. We don’t need IsYStep because GIL’s memory-based locator and view already allow the vertical step to be specified dynamically. Iterators and views can be constructed from a pixel type:

template\<typenamePixel,boolIsPlanar=false,boolIsStep=false,boolIsMutable=true\>structiterator\_type\_from\_pixel{typedef...type;};template\<typenamePixel,boolIsPlanar=false,boolIsStepX=false,boolIsMutable=true\>structview\_type\_from\_pixel{typedef...type;};

Using a heterogeneous pixel type will result in heterogeneous iterators and views. Types can also be constructed from horizontal iterator:

template\<typenameXIterator\>structtype\_from\_x\_iterator{typedef...step\_iterator\_t;typedef...xy\_locator\_t;typedef...view\_t;};

Pixel components

You can get pixel-related types of any pixel-based GIL constructs (pixels, iterators, locators and views) using the following metafunctions provided by PixelBasedConcept, HomogeneousPixelBasedConcept and metafunctions built on top of them:

template\<typenameT\>structcolor\_space\_type{typedef...type;};template\<typenameT\>structchannel\_mapping\_type{typedef...type;};template\<typenameT\>structis\_planar{typedef...type;};// Defined by homogeneous constructstemplate\<typenameT\>structchannel\_type{typedef...type;};template\<typenameT\>structnum\_channels{typedef...type;};

Deriving and manipulating existing types

There are metafunctions to construct the type of a construct from an existing type by changing one or more of its properties:

template\<typenamePixelReference,typenameChannelValue,typenameLayout,typenameIsPlanar,typenameIsMutable\>structderived\_pixel\_reference\_type{typedef...type;// Models PixelConcept};template\<typenameIterator,typenameChannelValue,typenameLayout,typenameIsPlanar,typenameIsStep,typenameIsMutable\>structderived\_iterator\_type{typedef...type;// Models PixelIteratorConcept};template\<typenameView,typenameChannelValue,typenameLayout,typenameIsPlanar,typenameIsXStep,typenameIsMutable\>structderived\_view\_type{typedef...type;// Models ImageViewConcept};template\<typenameImage,typenameChannelValue,typenameLayout,typenameIsPlanar\>structderived\_image\_type{typedef...type;// Models ImageConcept};

You can replace one or more of its properties and use boost::use_default for the rest. In this case IsPlanar, IsStep and IsMutable are MPL boolean constants. For example, here is how to create the type of a view just like View, but being grayscale and planar:

usingVT=typenamederived\_view\_type\<View,boost::use\_default,gray\_t,mpl::true\_\>::type;

Type traits

These are metafunctions, some of which return integral types which can be evaluated like this:

static\_assert(is\_planar\<rgb8\_planar\_view\_t\>::value==true,"");

GIL also supports type analysis metafunctions of the form:

[pixel\_reference/iterator/locator/view/image]+"\_is\_"+[basic/mutable/step]

For example:

if(view\_is\_mutable\<View\>::value){...}

A basic GIL construct is a memory-based construct that uses the built-in GIL classes and does not have any function object to invoke upon dereferencing. For example, a simple planar or interleaved, step or non-step RGB image view is basic, but a color converted view or a virtual view is not.