cgv
Loading...
Searching...
No Matches
cgv::data::component_format Class Reference

the component format inherits the information of a packing_info and adds information on the component type, which components are present in the data and in which order they appear More...

#include <component_format.h>

Inheritance diagram for cgv::data::component_format:
cgv::data::packing_info cgv::data::data_format cgv::render::render_buffer cgv::media::image::image cgv::render::texture

Public Member Functions

 component_format (const std::string &description)
 construct from description string, see set_component_format for docu
 
bool set_component_format (const std::string &description)
 set component format from description string, which has the following syntax.
 
void set_components (const std::string &_components)
 comma separated list of component descriptors, for example "R,G,B"
 
 component_format (cgv::type::info::TypeId _component_type=cgv::type::info::TypeId::TI_UNDEF, const std::string &_component_name_list="", unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct component format from component type, comma or colon separated list of component names, component alignment and bit depths for packed formats
 
 component_format (cgv::type::info::TypeId _component_type, ComponentFormat cf, unsigned align=1, unsigned d0=0, unsigned d1=0, unsigned d2=0, unsigned d3=0)
 construct component format from component type, standard component format, component alignment and bit depths for packed formats
 
void set_integer_interpretation (ComponentIntegerInterpretation cii)
 set the integer interpretation
 
ComponentIntegerInterpretation get_integer_interpretation () const
 return current integer interpretation
 
template<typename T >
get (int ci, const void *ptr) const
 constant access to the i-th component stored at the given location
 
template<typename T >
bool set (int ci, void *ptr, const T &v) const
 write access to the i-th component, return whether write was successful
 
bool empty () const
 return whether the component format is defined
 
void clear ()
 clear the component format
 
const packing_infoget_packing_info () const
 return the packing info by simple conversion of the this pointer
 
void set_packing_info (const packing_info &pi)
 set packing info by simply assigning to a converted this pointer
 
unsigned int get_nr_components () const
 return the number of components
 
unsigned int get_component_index (const std::string &name) const
 return the index of a component given by name or -1 if not found
 
std::string get_component_name (unsigned int i) const
 return the name of the component with index i
 
ComponentFormat get_standard_component_format () const
 return whether the component format is one of the standard formats
 
void set_component_names (const std::string &_component_name_list)
 set component names from a comma or colon separated list of names
 
void set_component_format (ComponentFormat _cf)
 set the component names from a standard component format
 
cgv::type::info::TypeId get_component_type () const
 return the component type
 
void set_component_type (cgv::type::info::TypeId _type_id)
 set the component type
 
unsigned int get_entry_size () const
 return the size of one entry of components in bytes
 
bool operator== (const component_format &cf) const
 comparison between component formats
 
bool operator!= (const component_format &cf) const
 comparison between component formats
 
- Public Member Functions inherited from cgv::data::packing_info
 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.
 
void clear ()
 clear packing info information
 
unsigned get_bit_depth (unsigned ci) const
 return the bit depth of the ci-th component
 
void set_bit_depth (unsigned ci, unsigned depth)
 set the bit depth of the ci-th component
 
bool is_packing () const
 return whether packing is enabled
 
void set_packing (bool enable=true)
 set the packing flag
 
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_component_alignment (unsigned a)
 set the component alignment in bits in the packed case and in bytes in the unpacked case
 
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 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 component
 
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 component
 
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 component
 
bool operator== (const packing_info &pi) const
 equal comparison
 
bool operator!= (const packing_info &pi) const
 unequal comparison
 

Static Public Member Functions

static const std::string & get_last_error ()
 returns an error string after parsing of description string has failed
 
- Static Public Member Functions inherited from cgv::data::packing_info
static size_t align (size_t v, unsigned a)
 return the next integer larger or equal to v which is dividable by a
 

Protected Member Functions

void extract_components ()
 extract components from component string
 
- Protected Member Functions inherited from cgv::data::packing_info
bool prepare_bit_operation (unsigned ci, void *ptr, unsigned &off, unsigned &bd, unsigned *&iptr) const
 
bool prepare_bit_operation (unsigned ci, const void *ptr, unsigned &off, unsigned &bd, const unsigned *&iptr) const
 
unsigned int get_bit_offset (unsigned ci) const
 

Protected Attributes

cgv::type::info::TypeId component_type
 store the type id of the component type
 
ComponentIntegerInterpretation component_interpretation
 interpretation of integer typed components
 
std::string component_string
 store all component names in one string separated with 0-chars
 
std::vector< unsigned short > component_positions
 store the position of each component in the component string
 
- Protected Attributes inherited from cgv::data::packing_info
bool is_packed: 1
 
unsigned bd0: 6
 
unsigned bd1: 6
 
unsigned bd2: 6
 
unsigned bd3: 6
 
unsigned ca: 6
 

Static Protected Attributes

static std::string last_error
 store the last error that appeared during parsing of a description
 

Friends

FRIEND_MEMBER_API std::ostream & operator<< (std::ostream &os, const component_format &cf)
 define stream out operator
 

Detailed Description

the component format inherits the information of a packing_info and adds information on the component type, which components are present in the data and in which order they appear

Definition at line 55 of file component_format.h.

Constructor & Destructor Documentation

◆ component_format() [1/3]

cgv::data::component_format::component_format ( const std::string &  description)
explicit

construct from description string, see set_component_format for docu

construct from description string

Definition at line 85 of file component_format.cxx.

References extract_components(), and set_component_format().

◆ component_format() [2/3]

cgv::data::component_format::component_format ( cgv::type::info::TypeId  _component_type = cgv::type::info::TypeId::TI_UNDEF,
const std::string &  _component_name_list = "",
unsigned  align = 1,
unsigned  d0 = 0,
unsigned  d1 = 0,
unsigned  d2 = 0,
unsigned  d3 = 0 
)

construct component format from component type, comma or colon separated list of component names, component alignment and bit depths for packed formats

construct packed component format from component type, component sequence, and common component bit depth

Definition at line 66 of file component_format.cxx.

References component_interpretation, and extract_components().

◆ component_format() [3/3]

cgv::data::component_format::component_format ( cgv::type::info::TypeId  _component_type,
ComponentFormat  cf,
unsigned  align = 1,
unsigned  d0 = 0,
unsigned  d1 = 0,
unsigned  d2 = 0,
unsigned  d3 = 0 
)

construct component format from component type, standard component format, component alignment and bit depths for packed formats

Definition at line 75 of file component_format.cxx.

References component_interpretation, and extract_components().

Member Function Documentation

◆ clear()

void cgv::data::component_format::clear ( )

clear the component format

Definition at line 307 of file component_format.cxx.

References cgv::data::packing_info::clear(), component_positions, component_string, and component_type.

Referenced by cgv::data::data_format::set_data_format().

◆ empty()

bool cgv::data::component_format::empty ( ) const

return whether the component format is defined

Definition at line 316 of file component_format.cxx.

References component_type.

Referenced by cgv::render::texture::create_from_image(), cgv::media::image::image_reader::read_image(), and cgv::media::image::image_reader::read_image().

◆ extract_components()

void cgv::data::component_format::extract_components ( )
protected

extract components from component string

extract component_positions from component string

Definition at line 42 of file component_format.cxx.

References component_positions, and component_string.

Referenced by component_format(), component_format(), component_format(), set_component_format(), set_component_format(), set_component_names(), and set_components().

◆ get()

template<typename T >
T cgv::data::component_format::get ( int  ci,
const void *  ptr 
) const
inline

constant access to the i-th component stored at the given location

Definition at line 134 of file component_format.h.

References cgv::type::info::type_access< T >::get(), and cgv::type::info::TI_INT64.

◆ get_component_index()

unsigned int cgv::data::component_format::get_component_index ( const std::string &  name) const

return the index of a component given by name or -1 if not found

Definition at line 328 of file component_format.cxx.

References get_component_name(), and get_nr_components().

Referenced by cgv::render::gl::read_image_to_texture(), and cgv::render::gl::read_image_to_textures().

◆ get_component_name()

std::string cgv::data::component_format::get_component_name ( unsigned int  i) const

◆ get_component_type()

◆ get_entry_size()

◆ get_integer_interpretation()

ComponentIntegerInterpretation cgv::data::component_format::get_integer_interpretation ( ) const

return current integer interpretation

Definition at line 293 of file component_format.cxx.

References component_interpretation.

Referenced by cgv::data::fmt1_compares_better().

◆ get_last_error()

const std::string & cgv::data::component_format::get_last_error ( )
static

returns an error string after parsing of description string has failed

Definition at line 301 of file component_format.cxx.

References last_error.

Referenced by cgv::render::textured_material::ensure_textures().

◆ get_nr_components()

◆ get_packing_info()

const packing_info & cgv::data::component_format::get_packing_info ( ) const

return the packing info by simple conversion of the this pointer

Definition at line 401 of file component_format.cxx.

Referenced by operator==().

◆ get_standard_component_format()

◆ operator!=()

bool cgv::data::component_format::operator!= ( const component_format cf) const

comparison between component formats

Definition at line 423 of file component_format.cxx.

◆ operator==()

bool cgv::data::component_format::operator== ( const component_format cf) const

comparison between component formats

Definition at line 409 of file component_format.cxx.

References get_component_name(), get_component_type(), get_nr_components(), and get_packing_info().

◆ set()

template<typename T >
bool cgv::data::component_format::set ( int  ci,
void *  ptr,
const T &  v 
) const
inline

write access to the i-th component, return whether write was successful

Definition at line 150 of file component_format.h.

References cgv::type::info::type_access< T >::set(), and cgv::type::info::TI_INT64.

Referenced by cgv::render::texture::write_to_file().

◆ set_component_format() [1/2]

void cgv::data::component_format::set_component_format ( ComponentFormat  _cf)

set the component names from a standard component format

set the component names from a given component format

Definition at line 374 of file component_format.cxx.

References component_string, and extract_components().

◆ set_component_format() [2/2]

bool cgv::data::component_format::set_component_format ( const std::string &  description)

set component format from description string, which has the following syntax.

set the component format from a description string

If a parse error arises, return false and set the static last_error member, which can be queried with get_last_error():

component_format <- [type] [attributes] '[' component [',' component]* ']'

component <- component_name [attributes]

attributes <- [':' bit_depth]['|' alignment]

type <- "undef" | "bool" | 
        "int8"  | "int16"  | "int32"  | "int64"  | "uint8"  | "uint16"  | "uint32"  | "uint64" |
        "sint8" | "sint16" | "sint32" | "sint64" |                                                // same as int* types but in snorm interpretation
        "_int8" | "_int16" | "_int32" | "_int64" | "_uint8" | "_uint16" | "_uint32" | "_uint64" | // same as [u]int* but in integer interpretation
        "flt16" | "flt32"  | "flt64"  | "string"

component_name : string ... name of component, i.e. "R", "Cb", "px", ...

bit_depth : unsigned int ... number of bits used to represent a component

alignment : unsigned int ... number of bits to which a component is aligned

Some examples of valid component format description strings:

  • "uint8:3|4[R,G,B,A]" ... four components represented as unsigned integers with no more than 8 bits. Actually, each component is stored with 3 bits and aligned to a bit index which is a multiple of 4
  • "uint8[R:5,G:6,B:5]" ... three components packed into 16 bits with 5 bits for R, 6 for G and 5 for B.
  • "sint8[R,G]" ... two component format of type int8 in snorm interpretation,
  • "_uint16[R]" ... one component format of type uint16 in integer interpretation,
  • "flt32[px,py]" ... two components of 32 bit floats
  • "[D]" ... one depth component without specified type, which defaults to "undef" and implies that the default depth format should be used.

Definition at line 166 of file component_format.cxx.

References cgv::data::packing_info::align(), component_interpretation, component_string, component_type, extract_components(), cgv::type::info::get_type_id(), cgv::utils::is_integer(), last_error, cgv::data::packing_info::set_bit_depth(), cgv::data::packing_info::set_component_alignment(), cgv::data::packing_info::set_packing(), cgv::utils::tokenizer::set_sep(), and cgv::utils::to_string().

Referenced by component_format(), cgv::render::texture::set_component_format(), and cgv::data::data_format::set_data_format().

◆ set_component_names()

void cgv::data::component_format::set_component_names ( const std::string &  _component_name_list)

set component names from a comma or colon separated list of names

Definition at line 367 of file component_format.cxx.

References component_string, and extract_components().

Referenced by cgv::render::gl::find_best_texture_format().

◆ set_component_type()

void cgv::data::component_format::set_component_type ( cgv::type::info::TypeId  _type_id)

set the component type

Definition at line 387 of file component_format.cxx.

References component_type.

Referenced by cgv::media::volume::volume::set_component_type().

◆ set_components()

void cgv::data::component_format::set_components ( const std::string &  _components)

comma separated list of component descriptors, for example "R,G,B"

Definition at line 59 of file component_format.cxx.

References component_string, and extract_components().

◆ set_integer_interpretation()

void cgv::data::component_format::set_integer_interpretation ( ComponentIntegerInterpretation  cii)

set the integer interpretation

Definition at line 287 of file component_format.cxx.

References component_interpretation.

◆ set_packing_info()

void cgv::data::component_format::set_packing_info ( const packing_info pi)

set packing info by simply assigning to a converted this pointer

Definition at line 405 of file component_format.cxx.

Friends And Related Symbol Documentation

◆ operator<<

FRIEND_MEMBER_API std::ostream & operator<< ( std::ostream &  os,
const component_format cf 
)
friend

define stream out operator

Definition at line 427 of file component_format.cxx.

Member Data Documentation

◆ component_interpretation

ComponentIntegerInterpretation cgv::data::component_format::component_interpretation
protected

interpretation of integer typed components

Definition at line 61 of file component_format.h.

Referenced by component_format(), component_format(), get_integer_interpretation(), set_component_format(), and set_integer_interpretation().

◆ component_positions

std::vector<unsigned short> cgv::data::component_format::component_positions
protected

store the position of each component in the component string

Definition at line 65 of file component_format.h.

Referenced by clear(), extract_components(), get_component_name(), and get_nr_components().

◆ component_string

std::string cgv::data::component_format::component_string
protected

store all component names in one string separated with 0-chars

Definition at line 63 of file component_format.h.

Referenced by clear(), extract_components(), get_component_name(), set_component_format(), set_component_format(), set_component_names(), and set_components().

◆ component_type

cgv::type::info::TypeId cgv::data::component_format::component_type
protected

store the type id of the component type

Definition at line 59 of file component_format.h.

Referenced by clear(), empty(), get_component_type(), set_component_format(), and set_component_type().

◆ last_error

std::string cgv::data::component_format::last_error
staticprotected

store the last error that appeared during parsing of a description

Definition at line 69 of file component_format.h.

Referenced by get_last_error(), set_component_format(), and cgv::data::data_format::set_data_format().


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