Skip to content
Snippets Groups Projects
Commit 288b4f97 authored by Manuel Günther's avatar Manuel Günther
Browse files

Added way of reading and writing 16-bit png images; still no tests

parent 9fffd374
Branches
No related tags found
1 merge request!21Resolve "16 bit PNG images are stored as big endian"
...@@ -159,6 +159,22 @@ void imbuffer_to_rgb(const size_t size, const T* im, T* r, T* g, T* b) ...@@ -159,6 +159,22 @@ void imbuffer_to_rgb(const size_t size, const T* im, T* r, T* g, T* b)
} }
} }
static uint16_t switch_endianess(const uint16_t p){
return p / 256 + p % 256 * 256;
}
template <>
void imbuffer_to_rgb(const size_t size, const uint16_t* im, uint16_t* r, uint16_t* g, uint16_t* b)
{
for(size_t k=0; k<size; ++k)
{
*r++ = switch_endianess(*im++);
*g++ = switch_endianess(*im++);
*b++ = switch_endianess(*im++);
}
}
template <typename T> static template <typename T> static
void im_load_color(png_structp png_ptr, bob::io::base::array::interface& b) void im_load_color(png_structp png_ptr, bob::io::base::array::interface& b)
{ {
...@@ -330,6 +346,18 @@ void rgb_to_imbuffer(const size_t size, const T* r, const T* g, const T* b, T* i ...@@ -330,6 +346,18 @@ void rgb_to_imbuffer(const size_t size, const T* r, const T* g, const T* b, T* i
} }
} }
template <>
void rgb_to_imbuffer(const size_t size, const uint16_t* r, const uint16_t* g, const uint16_t* b, uint16_t* im)
{
for (size_t k=0; k<size; ++k)
{
*im++ = switch_endianess(*r++);
*im++ = switch_endianess(*g++);
*im++ = switch_endianess(*b++);
}
}
template <typename T> template <typename T>
static void im_save_color(const bob::io::base::array::interface& b, png_structp png_ptr) static void im_save_color(const bob::io::base::array::interface& b, png_structp png_ptr)
{ {
......
...@@ -96,7 +96,7 @@ namespace bob { namespace io { namespace image { ...@@ -96,7 +96,7 @@ namespace bob { namespace io { namespace image {
template <class T, int N> template <class T, int N>
blitz::Array<T,N> read_png(const std::string& filename){ blitz::Array<T,N> read_png(const std::string& filename){
PNGFile png(filename.c_str(), 'r'); PNGFile png(filename.c_str(), 'r');
return png.read<T,N>(0); return png.cast<T,N>(0);
} }
template <class T, int N> template <class T, int N>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment