@@ -52,24 +52,38 @@ public RasterByteABGRProvider(Raster raster, boolean hasAlpha) {
5252
5353 public void next (final byte [] row , final int offset , final int length ) {
5454 int bytesIdx = cursor .next ();
55- int i = offset ;
56- final int max = offset + length ;
5755 if (!bgrOrder && (numBands == pixelStride )) {
56+ // already in RGB(A) order, plain copy
5857 System .arraycopy (bytes , bytesIdx , row , offset , length );
58+ return ;
59+ }
60+
61+ int i = offset ;
62+ final int max = offset + length ;
63+
64+ if (numBands == 4 ) {
65+ final int r = bandOffsets [0 ];
66+ final int g = bandOffsets [1 ];
67+ final int b = bandOffsets [2 ];
68+ final int a = bandOffsets [3 ];
69+
70+ while (i < max ) {
71+ row [i ++] = bytes [bytesIdx + r ];
72+ row [i ++] = bytes [bytesIdx + g ];
73+ row [i ++] = bytes [bytesIdx + b ];
74+ row [i ++] = bytes [bytesIdx + a ];
75+ bytesIdx += pixelStride ;
76+ }
5977 } else {
78+ final int r = bandOffsets [0 ];
79+ final int g = bandOffsets [1 ];
80+ final int b = bandOffsets [2 ];
81+
6082 while (i < max ) {
61- for (int j = 0 ; j < numBands ; j ++) {
62- // We assign data pixels on the expected order
63- // So if bgrOrder (bandOffset is 2,1,0):
64- // row[i+2] = B
65- // row[i+1] = G
66- // row[i+0] = R
67- row [i + j ] = bytes [bytesIdx + bandOffsets [j ]];
68- }
69- // Pixel stride may be longer than numBands due to bandSelect
70- // sharing same dataBuffer of the original image
83+ row [i ++] = bytes [bytesIdx + r ];
84+ row [i ++] = bytes [bytesIdx + g ];
85+ row [i ++] = bytes [bytesIdx + b ];
7186 bytesIdx += pixelStride ;
72- i += numBands ;
7387 }
7488 }
7589 }
0 commit comments