Mercurial > hg > octave-image
changeset 359:262afafd9d88
Better support for alpha channels (from Eugeniy Mikhailov)
author | hauberg |
---|---|
date | Fri, 13 Mar 2009 09:33:49 +0000 |
parents | d2cc787481bf |
children | 99f847fb0cc3 |
files | src/pngread.cc |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pngread.cc +++ b/src/pngread.cc @@ -87,6 +87,10 @@ if (pic->bit_depth > 1 && pic->bit_depth < 8) pic->bit_depth = 8; + int isAlfaChannelPresent = 0; + if ( pic->color_type & PNG_COLOR_MASK_ALPHA) + isAlfaChannelPresent=1; + NDArray out(dim); dim.resize(2); @@ -94,6 +98,7 @@ Array<int> coord = Array<int> (3); + int ElementsPerPixel=out.dims()(2)+isAlfaChannelPresent; for (unsigned long j=0; j < pic->height; j++) { coord(0) = j; for (unsigned long i=0; i < pic->width; i++) { @@ -101,9 +106,12 @@ for (int c = 0; c < out.dims()(2); c++) { coord(2) = c; - out(coord) = pic->row_pointers[j][i*4+c]; + out(coord) = pic->row_pointers[j][i*ElementsPerPixel+c]; } - alpha(j,i) = pic->row_pointers[j][i*4+3]; + if (isAlfaChannelPresent) + alpha(j,i) = pic->row_pointers[j][i*ElementsPerPixel+(ElementsPerPixel-1)]; + else + alpha(j,i) = 1; } } out = out.squeeze();