diff --git a/dlib/image_loader/png_loader.h b/dlib/image_loader/png_loader.h index 58956b41c..7f0898031 100644 --- a/dlib/image_loader/png_loader.h +++ b/dlib/image_loader/png_loader.h @@ -40,17 +40,26 @@ namespace dlib #endif t.set_size( height_, width_ ); - for ( unsigned n = 0; n < height_;n++ ) + + + if (is_gray()) { - const unsigned char* v = get_row( n ); - for ( unsigned m = 0; m < width_;m++ ) + for ( unsigned n = 0; n < height_;n++ ) { - if ( is_gray() ) + const unsigned char* v = get_row( n ); + for ( unsigned m = 0; m < width_;m++ ) { unsigned char p = v[m]; assign_pixel( t[n][m], p ); } - else if ( is_rgb() ) + } + } + else if (is_rgb()) + { + for ( unsigned n = 0; n < height_;n++ ) + { + const unsigned char* v = get_row( n ); + for ( unsigned m = 0; m < width_;m++ ) { rgb_pixel p; p.red = v[m*3]; @@ -58,7 +67,14 @@ namespace dlib p.blue = v[m*3+2]; assign_pixel( t[n][m], p ); } - else if ( is_rgba() ) + } + } + else if (is_rgba()) + { + for ( unsigned n = 0; n < height_;n++ ) + { + const unsigned char* v = get_row( n ); + for ( unsigned m = 0; m < width_;m++ ) { rgb_alpha_pixel p; p.red = v[m*4];