cgv
cgv::media::image::image_reader Class Reference

#include <image_reader.h>

Inheritance diagram for cgv::media::image::image_reader:
cgv::base::base cgv::data::ref_counted cgv::reflect::self_reflection_tag

Public Member Functions

 image_reader (data_format &file_format, std::vector< data_format > *palette_formats=0)
 construct an image image_reader from a file name More...
 
std::string get_type_name () const
 overload to return the type name of this object
 
std::string get_property_declarations ()
 return a semicolon separated list of property declarations of the form "name:type", by default an empty list is returned
 
const std::string & get_last_error () const
 return a reference to the last error message
 
bool read_image (const std::string &file_name, data_view &dv, std::vector< data_view > *palettes=0)
 read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading More...
 
bool read_image (const std::string &file_name, const data_view &dv, const std::vector< data_view > *palettes=0)
 read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading More...
 
bool open (const std::string &file_name)
 open the file and read the image header in order to determine the data format of the file, which is stored in the data format specified in the constructor More...
 
data_formatget_file_format () const
 return the data format of the image file More...
 
bool supports_multiple_images () const
 whether the file can contain several images
 
unsigned get_nr_images () const
 return the number of images in the file, what can cause the whole file to be scanned
 
float get_image_duration () const
 return the duration of the current image in seconds, if returned value is 0, no duration is available More...
 
unsigned get_current_image () const
 return the index of the current image
 
bool seek_image (unsigned idx)
 jump to a specific image and return whether this was successful
 
bool read_palette (unsigned int i, data_view &dv)
 read the i-th palette in case of a paletted file format, and handle the data view as in the read_image method the standard implementation returns false More...
 
bool read_palette (unsigned int i, const data_view &dv)
 read the i-th palette in case of a paletted file format, and handle the data view as in the read_image method the standard implementation returns false More...
 
bool supports_per_line_read () const
 return whether the reader supports per line reading (only valid after successfully opening an image file) More...
 
bool read_line (data_view &dv)
 read the next line into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done More...
 
bool read_line (const data_view &dv)
 read line into a preallocated data view of the correct format More...
 
bool read_image (data_view &dv, std::vector< data_view > *palettes=0)
 read an opened image data and palettes into a data views that are optionally allocated. More...
 
bool read_image (const data_view &dv, const std::vector< data_view > *palettes=0)
 read image to a data_view with the correct format and an allocated pointer More...
 
bool close ()
 close the image file
 
virtual std::string get_default_options () const
 overload to provide default options for registration
 
virtual void on_register ()
 overload to handle register events that is sent after the instance has been registered More...
 
virtual void unregister ()
 overload to handle unregistration of instances
 
virtual void stream_stats (std::ostream &)
 overload to show the content of this object
 
virtual data::ref_ptr< named, true > get_named ()
 cast upward to named
 
virtual data::ref_ptr< node, true > get_node ()
 cast upward to node
 
virtual data::ref_ptr< group, true > get_group ()
 cast upward to group
 
template<class T >
data::ref_ptr< T, true > cast ()
 cast to arbitrary class, but use the casts to named, node and group from the interface
 
template<class T >
T * get_interface ()
 use dynamic type cast to check for the given interface
 
template<class T >
const T * get_const_interface () const
 use dynamic type cast to check for the given interface
 
virtual void update ()
 this virtual update allows for example to ask a view to update the viewed value. The default implementation is empty.
 
virtual void * get_user_data () const
 this virtual method allows to pass application specific data for internal purposes More...
 
int get_ref_count () const
 read access to current count
 

Static Public Member Functions

static const std::string & get_supported_extensions (char sep=';')
 return a string with a list of supported extensions, where the list entries are separated with the passed character that defaults to a semicolon
 
static std::string construct_filter_string ()
 use this to generate a file_open_dialog or file_save_dialog
 

Protected Member Functions

bool set_void (const std::string &property, const std::string &type, const void *value)
 abstract interface for the setter, by default it simply returns false
 
bool get_void (const std::string &property, const std::string &type, void *value)
 abstract interface for the getter, by default it simply returns false
 
void set_ref_count (int c) const
 write access is also const to allow ref counted pointers to const instances
 

Static Protected Member Functions

template<class T >
static data::ref_ptr< T, true > cast_dynamic (base *b)
 use dynamic cast for upcast to given class
 

Protected Attributes

data_formatfile_format_ptr
 store the data format
 
std::vector< data_format > * palette_formats
 store a pointer to the palette format vector
 
abst_image_readerrd
 store a pointer to the chosen reader
 
std::string last_error
 last error message in case no reader is available
 

property interface

virtual bool self_reflect (cgv::reflect::reflection_handler &)
 used for simple self reflection More...
 
virtual void on_set (void *member_ptr)
 this callback is called when the set_void method has changed a member and can be overloaded in derived class
 
virtual bool call_void (const std::string &method, const std::vector< std::string > &param_value_types, const std::vector< const void * > &param_value_ptrs, const std::string &result_type="", void *result_value_ptr=0)
 abstract interface to call an action More...
 
void set (const std::string &property, const char *value)
 specialization of set method to support const char* as strings
 
template<typename T >
void set (const std::string &property, const T &value)
 set a property of the element to the given value and perform standard conversions if necessary. More...
 
template<typename T >
get (const std::string &property)
 query a property of the element and perform standard conversions if necessary. More...
 
void multi_set (const std::string &property_assignments, bool report_error=true)
 set several properties More...
 
bool is_property (const std::string &property_name, std::string *type_name=0)
 check if the given name specifies a property. More...
 
void * find_member_ptr (const std::string &property_name, std::string *type_name=0)
 find a member pointer by name. More...
 

Detailed Description

the image reader chooses a specific reader automatically based on the extension of the given file name. In the open method it sets the format passed by reference to the reader in the constructor.

Constructor & Destructor Documentation

◆ image_reader()

cgv::media::image::image_reader::image_reader ( data_format file_format,
std::vector< data_format > *  palette_formats = 0 
)

construct an image image_reader from a file name

construct an image reader from a reference to a data format instance in which the format of the image file will be stored after a call to the open method. If also images with palettes should be handled, provide also a vector of data formats for the palettes. By default no vector is provided such that the reader converts paletted image formats to non paletted ones. In case palettes are used, the components in the file_format will be '0', '1', ... for the components that reference the i-th palette.

Member Function Documentation

◆ call_void()

bool cgv::base::base::call_void ( const std::string &  method,
const std::vector< std::string > &  param_value_types,
const std::vector< const void * > &  param_value_ptrs,
const std::string &  result_type = "",
void *  result_value_ptr = 0 
)
virtualinherited

abstract interface to call an action

overload to implement the execution of a method based on the method name and the given parameters

, i.e. a class method based on the action name and the given parameters. The default implementation uses the self_reflect() method to dispatch this call. If not found, the get_void method returns false.

◆ find_member_ptr()

void * cgv::base::base::find_member_ptr ( const std::string &  property_name,
std::string *  type_name = 0 
)
inherited

find a member pointer by name.

If not found the null pointer is returned. If the type name string pointer is provided, the type of the property is copied to the referenced string.

◆ get()

template<typename T >
T cgv::base::base::get ( const std::string &  property)
inlineinherited

query a property of the element and perform standard conversions if necessary.

This templated version simply extracts the type of the value from the reference and calls the set_void() method. Note that this only works if the template cgv::type::info::type_name<T> is overloaded for the value type.

◆ get_file_format()

data_format * cgv::media::image::image_reader::get_file_format ( ) const

return the data format of the image file

return the image info

◆ get_image_duration()

float cgv::media::image::image_reader::get_image_duration ( ) const

return the duration of the current image in seconds, if returned value is 0, no duration is available

return the duration of the current image in seconds

◆ get_user_data()

void * cgv::base::base::get_user_data ( ) const
virtualinherited

this virtual method allows to pass application specific data for internal purposes

this virtual method allows derived classes to pass application specific data

◆ is_property()

bool cgv::base::base::is_property ( const std::string &  property_name,
std::string *  type_name = 0 
)
inherited

check if the given name specifies a property.

If the type name string pointer is provided, the type of the property is copied to the referenced string.

◆ multi_set()

void cgv::base::base::multi_set ( const std::string &  property_assignments,
bool  report_error = true 
)
inherited

set several properties

set several properties, which are defined as colon separated assignments, where the types are derived automatically

, which are defined as colon separated assignments, where the types are derived automatically to bool, int, double or std::string.

◆ on_register()

void cgv::base::base::on_register ( )
virtualinherited

overload to handle register events that is sent after the instance has been registered

overload to return a type info structure. By default an empty pointer is returned.

◆ open()

bool cgv::media::image::image_reader::open ( const std::string &  file_name)

open the file and read the image header in order to determine the data format of the file, which is stored in the data format specified in the constructor

open the file and read the image header in order to determine the data format

◆ read_image() [1/4]

bool cgv::media::image::image_reader::read_image ( const data_view dv,
const std::vector< data_view > *  palettes = 0 
)

read image to a data_view with the correct format and an allocated pointer

read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading

◆ read_image() [2/4]

bool cgv::media::image::image_reader::read_image ( const std::string &  file_name,
const data_view dv,
const std::vector< data_view > *  palettes = 0 
)

read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading

read the image into the given data view that must have the correct format and an allocated data pointer.

◆ read_image() [3/4]

bool cgv::media::image::image_reader::read_image ( const std::string &  file_name,
data_view dv,
std::vector< data_view > *  palettes = 0 
)

read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading

read the whole image into the given data view. If the data view is empty, set the format and allocate memory to hold the image data. The newly allocate data pointer will belong to the data view afterwards. If the data pointer of the data view is already allocated, use this in the same way as the alternate version of read_image with the const data_view argument does.

◆ read_image() [4/4]

bool cgv::media::image::image_reader::read_image ( data_view dv,
std::vector< data_view > *  palettes = 0 
)

read an opened image data and palettes into a data views that are optionally allocated.

read the whole image into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done. If image file has not been opened yet, open it and close it after reading

read an image from an opened image file into the given data view. If the data format of the view has not been specified, set it to the data format of the file. If the data pointer is empty, allocate enough memory to hold the image. The pointer is then owned by the view.

◆ read_line() [1/2]

bool cgv::media::image::image_reader::read_line ( const data_view dv)

read line into a preallocated data view of the correct format

read the next line into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done

◆ read_line() [2/2]

bool cgv::media::image::image_reader::read_line ( data_view dv)

read the next line into the given data pointer, set data format if not yet specified and allocate the data ptr if not yet done

read the next line into the given data view. If the data format of the view has not been specified, set it to the data format of the file, construct a 1d subview and allocate memory for a line only. The data pointer is then owned by the view.

◆ read_palette() [1/2]

bool cgv::media::image::image_reader::read_palette ( unsigned int  i,
const data_view dv 
)

read the i-th palette in case of a paletted file format, and handle the data view as in the read_image method the standard implementation returns false

read the i-th palette in case of a paletted file format, the standard implementation returns false

In case of files with animated images, the palette can change for each image. Therefore call this method before each call to read_image().

◆ read_palette() [2/2]

bool cgv::media::image::image_reader::read_palette ( unsigned int  i,
data_view dv 
)

read the i-th palette in case of a paletted file format, and handle the data view as in the read_image method the standard implementation returns false

read the i-th palette in case of a paletted file format, the standard implementation returns false

In case of files with animated images, the palette can change for each image. Therefore call this method before each call to read_image().

◆ self_reflect()

bool cgv::base::base::self_reflect ( cgv::reflect::reflection_handler )
virtualinherited

used for simple self reflection

is used by default implementation of set_void, get_void and get_property_declarations

The overloaded implementation is used by the default implementations of set_void, get_void and get_property_declarations with corresponding reflection handlers. The default implementation of self_reflect is empty.

Reimplemented in cgv::render::render_config, and cgv::render::shader_config.

◆ set()

template<typename T >
void cgv::base::base::set ( const std::string &  property,
const T &  value 
)
inlineinherited

set a property of the element to the given value and perform standard conversions if necessary.

This templated version simply extracts the type of the value from the reference and calls the set_void() method. Note that this only works if the template cgv::type::info::type_name<T> is overloaded for the value type.

◆ supports_per_line_read()

bool cgv::media::image::image_reader::supports_per_line_read ( ) const

return whether the reader supports per line reading (only valid after successfully opening an image file)

whether the image_reader supports per line reading (only valid after successful opening an image file


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