Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
Scroom::Bitmap::SampleIterator< ConstBase > Class Template Reference

#include <bitmap-helpers.hh>

Inheritance diagram for Scroom::Bitmap::SampleIterator< ConstBase >:
Inheritance graph
Collaboration diagram for Scroom::Bitmap::SampleIterator< ConstBase >:
Collaboration graph

Public Types

using Base = std::remove_const_t< ConstBase >
 

Public Member Functions

 SampleIterator (ConstBase *base, int offset=0, int bps_=1)
 
Base get ()
 
void set (ConstBase value)
 
SampleIteratoroperator++ ()
 
SampleIterator operator++ (int)
 
SampleIteratoroperator+= (unsigned int x)
 
Base operator* ()
 
bool operator== (const SampleIterator< ConstBase > &other) const
 
bool operator!= (const SampleIterator< ConstBase > &other) const
 

Public Attributes

const int bps
 
const int samplesPerBase
 
const int pixelOffset
 
const ConstBase pixelMask
 
ConstBase * currentBase
 
int currentOffset
 

Static Public Attributes

static const int bitsPerBase {8 * sizeof(ConstBase) / sizeof(byte)}
 

Private Member Functions

 SampleIterator (div_t d, ConstBase *base, int bps_)
 

Static Private Member Functions

static Base mask (int bps)
 

Detailed Description

template<typename ConstBase>
class Scroom::Bitmap::SampleIterator< ConstBase >

Iterate over samples (bits) within a larger type, for example a byte

Allows you to extract (or set) specific bits in a larger datatype, as well as iterate over samples within the larger datatype, or even continuing with the next, if you reach the end of the current one

Parameters
Basethe larger type that contains the samples. Typically uint8_t

Member Typedef Documentation

◆ Base

template<typename ConstBase >
using Scroom::Bitmap::SampleIterator< ConstBase >::Base = std::remove_const_t<ConstBase>

Constructor & Destructor Documentation

◆ SampleIterator() [1/2]

template<typename ConstBase >
Scroom::Bitmap::SampleIterator< ConstBase >::SampleIterator ( div_t  d,
ConstBase *  base,
int  bps_ 
)
inlineprivate
80 : bps(bps_)
84 , currentBase(base + d.quot)
85 , currentOffset(samplesPerBase - 1 - d.rem)
86 {
87 }
static const int bitsPerBase
Definition bitmap-helpers.hh:66
const int bps
Definition bitmap-helpers.hh:68
int currentOffset
Definition bitmap-helpers.hh:74
const int pixelOffset
Definition bitmap-helpers.hh:70
const ConstBase pixelMask
Definition bitmap-helpers.hh:71
ConstBase * currentBase
Definition bitmap-helpers.hh:73
const int samplesPerBase
Definition bitmap-helpers.hh:69
auto mask
Definition ruler-tests.cc:21

◆ SampleIterator() [2/2]

template<typename ConstBase >
Scroom::Bitmap::SampleIterator< ConstBase >::SampleIterator ( ConstBase *  base,
int  offset = 0,
int  bps_ = 1 
)
inlineexplicit

Construct a new SampleIterator

Parameters
basePointer to the element that contains the current sample
offsetnumber of the sample within that element
bpsNumber of bits per sample
100 : SampleIterator(div(offset, /* samplesPerBase */ bitsPerBase / bps_), base, bps_)
101 {
102 }
SampleIterator(div_t d, ConstBase *base, int bps_)
Definition bitmap-helpers.hh:79

Member Function Documentation

◆ get()

template<typename ConstBase >
Base Scroom::Bitmap::SampleIterator< ConstBase >::get ( )
inline

Get the value of the current sample

105{ return (*currentBase >> (currentOffset * pixelOffset)) & pixelMask; }

◆ mask()

template<typename ConstBase >
static Base Scroom::Bitmap::SampleIterator< ConstBase >::mask ( int  bps)
inlinestaticprivate
77{ return (((ConstBase(1) << (bps - 1)) - 1) << 1) | 1; }

◆ operator!=()

template<typename ConstBase >
bool Scroom::Bitmap::SampleIterator< ConstBase >::operator!= ( const SampleIterator< ConstBase > &  other) const
inline
160{ return !(*this == other); }

◆ operator*()

template<typename ConstBase >
Base Scroom::Bitmap::SampleIterator< ConstBase >::operator* ( )
inline

Get the value of the current sample

153{ return (*currentBase >> (currentOffset * pixelOffset)) & pixelMask; }

◆ operator++() [1/2]

template<typename ConstBase >
SampleIterator & Scroom::Bitmap::SampleIterator< ConstBase >::operator++ ( )
inline

Move to the next sample

115 {
116 // Prefix operator
117 if(!(currentOffset--))
118 {
120 ++currentBase;
121 }
122
123 return *this;
124 }

◆ operator++() [2/2]

template<typename ConstBase >
SampleIterator Scroom::Bitmap::SampleIterator< ConstBase >::operator++ ( int  )
inline

Move to the next sample

128 {
129 // Postfix operator
130 SampleIterator<ConstBase> result = *this;
131
132 if(!(currentOffset--))
133 {
135 ++currentBase;
136 }
137
138 return result;
139 }
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94

◆ operator+=()

template<typename ConstBase >
SampleIterator & Scroom::Bitmap::SampleIterator< ConstBase >::operator+= ( unsigned int  x)
inline

Move x samples further

143 {
144 const int offset = samplesPerBase - 1 - currentOffset + x;
145 const div_t d = div(offset, samplesPerBase);
146 currentBase += d.quot;
147 currentOffset = samplesPerBase - 1 - d.rem;
148
149 return *this;
150 }

◆ operator==()

template<typename ConstBase >
bool Scroom::Bitmap::SampleIterator< ConstBase >::operator== ( const SampleIterator< ConstBase > &  other) const
inline
156 {
157 return currentBase == other.currentBase && currentOffset == other.currentOffset && bps == other.bps;
158 }

◆ set()

template<typename ConstBase >
void Scroom::Bitmap::SampleIterator< ConstBase >::set ( ConstBase  value)
inline

Set the value of the current sample

109 {
111 }
const uint8_t value
Definition blob-tests.cc:114

Referenced by Operations::reduce(), OperationsColormapped::reduce(), and Operations1bppClipped::reduce().

Here is the caller graph for this function:

Member Data Documentation

◆ bitsPerBase

template<typename ConstBase >
const int Scroom::Bitmap::SampleIterator< ConstBase >::bitsPerBase {8 * sizeof(ConstBase) / sizeof(byte)}
static
66{8 * sizeof(ConstBase) / sizeof(byte)};

◆ bps

◆ currentBase

◆ currentOffset

◆ pixelMask

◆ pixelOffset

◆ samplesPerBase


The documentation for this class was generated from the following file: