Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • bob.io.base bob.io.base
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • bob
  • bob.io.basebob.io.base
  • Issues
  • #14
Closed
Open
Created Sep 08, 2016 by Manuel Günther@mguentherMaintainer

automatic array casting in C++ does not work

I try to read .png images in uint8_t, regardless of their actual internal representation, i.e., 8 or 16 bit, in C++. In the current way, when I try to read a uint16 .png image using bob::io::image::read_color_image I get:

cannot efficiently retrieve blitz::Array<uint8,3> from buffer of type 'dtype: uint16 (2); shape: [3,606,544]; size: 1977984 bytes'

After reading code a little bit, I found that in https://gitlab.idiap.ch/bob/bob.io.image/blob/master/bob/io/image/include/bob.io.image/png.h#L99 I could simply replace:

png.read<T,N>(0);

with:

png.cast<T,N>(0);

Theoretically, this should read the data in any format by resetting the image buffer to the type inside the image (uint16): https://gitlab.idiap.ch/bob/bob.io.image/blob/master/bob/io/image/cpp/png.cpp#L499 read the data, and then cast it back to the desired type: https://gitlab.idiap.ch/bob/bob.io.base/blob/master/bob/io/base/include/bob.io.base/blitz_array.h#L246

Unfortunately, this doesn't compile, it gives me the error:

bob/io/base/include/bob.io.base/blitz_array.h:247:49: error: no matching function for call to ‘cast(const bob::io::base::array::blitz_array&)’

Again, reading more code, I figured out that this function doesn't exists in that namespace, but that:

return bob::core::array::cast<T,N>(*this);

in https://gitlab.idiap.ch/bob/bob.io.base/blob/master/bob/io/base/include/bob.io.base/blitz_array.h#L247 should rather be:

return bob::io::base::array::cast<T,N>(*this);

Now, this doesn't compile either, it gives me the error:

bob/core/include/bob.core/cast.h:23:30: error: invalid static_cast from type ‘const std::complex<float>’ to type ‘unsigned char’

(https://gitlab.idiap.ch/bob/bob.core/blob/master/bob/core/include/bob.core/cast.h#L23) which, in the first place looks weired, as I don't deal with complex numbers at all. However, when reading the backtrace, the code here: https://gitlab.idiap.ch/bob/bob.io.base/blob/master/bob/io/base/include/bob.io.base/array_utils.h#L117 tries to cast anything into anything, which in my case is complex<float> into uint8_t, which raises the compiler error from above.

So, my question is: was this array casting being tested in any way, and has it been working before? Has anyone ever tried to use the bob::io::base::array::cast function?

Assignee
Assign to
Time tracking