Commit c15924fa authored by Daniel Crispell's avatar Daniel Crispell Committed by Davis E. King

add support for loading of RGBA JPEG images (#409)

parent 0f60ba36
...@@ -60,6 +60,13 @@ namespace dlib ...@@ -60,6 +60,13 @@ namespace dlib
return (output_components_ == 3); return (output_components_ == 3);
} }
// ----------------------------------------------------------------------------------------
bool jpeg_loader::is_rgba() const
{
return (output_components_ == 4);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
struct jpeg_loader_error_mgr struct jpeg_loader_error_mgr
...@@ -123,7 +130,8 @@ namespace dlib ...@@ -123,7 +130,8 @@ namespace dlib
output_components_ = cinfo.output_components; output_components_ = cinfo.output_components;
if (output_components_ != 1 && if (output_components_ != 1 &&
output_components_ != 3) output_components_ != 3 &&
output_components_ != 4)
{ {
fclose( fp ); fclose( fp );
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
......
...@@ -23,6 +23,7 @@ namespace dlib ...@@ -23,6 +23,7 @@ namespace dlib
bool is_gray() const; bool is_gray() const;
bool is_rgb() const; bool is_rgb() const;
bool is_rgba() const;
template<typename T> template<typename T>
void get_image( T& t_) const void get_image( T& t_) const
...@@ -37,7 +38,6 @@ namespace dlib ...@@ -37,7 +38,6 @@ namespace dlib
COMPILE_TIME_ASSERT(sizeof(T) == 0); COMPILE_TIME_ASSERT(sizeof(T) == 0);
#endif #endif
image_view<T> t(t_); image_view<T> t(t_);
t.set_size( height_, width_ ); t.set_size( height_, width_ );
for ( unsigned n = 0; n < height_;n++ ) for ( unsigned n = 0; n < height_;n++ )
{ {
...@@ -49,6 +49,14 @@ namespace dlib ...@@ -49,6 +49,14 @@ namespace dlib
unsigned char p = v[m]; unsigned char p = v[m];
assign_pixel( t[n][m], p ); assign_pixel( t[n][m], p );
} }
else if ( is_rgba() ) {
rgb_alpha_pixel p;
p.red = v[m*4];
p.green = v[m*4+1];
p.blue = v[m*4+2];
p.alpha = v[m*4+3];
assign_pixel( t[n][m], p );
}
else // if ( is_rgb() ) else // if ( is_rgb() )
{ {
rgb_pixel p; rgb_pixel p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment