1#include <cgv/utils/bit_operations.h>
2#include "packing_info.h"
10 return a*(v/a) == v ? v : a*((v/a)+1);
13 : is_packed(true), bd0(d0), bd1(d1), bd2(d2), bd3(d3), ca(align)
24 bd0 = bd1 = bd2 = bd3 = 0;
28 return ci<2 ? (ci==0?bd0:bd1) : (ci==2?bd2:bd3);
32 if (ci<2)
if (ci == 0) bd0 = depth;
else bd1 = depth;
33 else if (ci == 2) bd2 = depth;
else bd3 = depth;
51bool packing_info::prepare_bit_operation(
unsigned ci,
void* ptr,
unsigned &off,
unsigned &bd,
unsigned* &iptr)
const
53 off = get_bit_offset(ci);
55 ptr =
static_cast<unsigned char*
>(ptr)+off/8;
57 iptr =
static_cast<unsigned*
>(ptr);
60bool packing_info::prepare_bit_operation(
unsigned ci,
const void* ptr,
unsigned &off,
unsigned &bd,
const unsigned* &iptr)
const
62 off = get_bit_offset(ci);
64 ptr =
static_cast<const unsigned char*
>(ptr)+off/8;
66 iptr =
static_cast<const unsigned*
>(ptr);
69unsigned packing_info::get_bit_offset(
unsigned ci)
const
72 for (
unsigned i = 0; i < ci; ++i)
80 prepare_bit_operation(ci, ptr, off, bd, iptr);
81 unsigned int i = *iptr >> off;
92 prepare_bit_operation(ci, ptr, off, bd, iptr);
93 unsigned i = *iptr >> off;
99 unsigned off, bd, *iptr;
100 prepare_bit_operation(ci, ptr, off, bd, iptr);
101 set_bits(*iptr, off, bd, (
const unsigned&) v);
106 unsigned off, bd, *iptr;
107 prepare_bit_operation(ci, ptr, off, bd, iptr);
117 for (
unsigned int i=0; i<4; ++i)
124 return !(*
this == pi);
the packing_info class stores information about packed integers structures.
static size_t align(size_t v, unsigned a)
return the next integer larger or equal to v which is dividable by a
bool is_packing() const
return whether packing is enabled
void set_bit_depth(unsigned ci, unsigned depth)
set the bit depth of the ci-th component
int get_signed(unsigned ci, const void *ptr) const
return the ci-th component of the data entry pointed to by the given pointer of a signed packed compo...
bool operator!=(const packing_info &pi) const
unequal comparison
packing_info(unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
construct packing information from alignment and bit depths.
unsigned get_bit_depth(unsigned ci) const
return the bit depth of the ci-th component
unsigned int get_unsigned(unsigned ci, const void *ptr) const
return the ci-th component of the data entry pointed to by the given pointer of an unsigned packed co...
unsigned int get_component_alignment() const
return the component alignment in bits in the packed case and in bytes in the unpacked case
void set_packing(bool enable=true)
set the packing flag
void set_component_alignment(unsigned a)
set the component alignment in bits in the packed case and in bytes in the unpacked case
bool set_unsigned(unsigned ci, void *ptr, unsigned v) const
set the ci-th component of the data entry pointed to by the given pointer of an unsigned packed compo...
bool set_signed(unsigned ci, void *ptr, int v) const
set the ci-th component of the data entry pointed to by the given pointer of a signed packed componen...
bool operator==(const packing_info &pi) const
equal comparison
void clear()
clear packing info information
namespace that holds tools that dont fit any other namespace
bool is_bit_set(unsigned int bit_idx, unsigned int bit_field)
check if a bit of a bit field is set
void enable_upper_bits(unsigned int &bit_field, unsigned int fst_bit_idx)
set all the bits of bit_field with index equal or larger than fst_bit_idx
void disable_upper_bits(unsigned int &bit_field, unsigned int fst_bit_idx)
clear all the bits of bit_field with index equal or larger than fst_bit_idx
void set_bits(unsigned int &bit_field, unsigned int off, unsigned int n, unsigned int value)
set n bits starting with index off of the given bit field from the first bits of the given integer va...