Skip to content

Commit 08223f2

Browse files
hansonrhansonr
authored andcommitted
Fix for BufferedImage rotation
buffer.data must be accessed without replacement, as there are two other references to it.
1 parent 0f324b1 commit 08223f2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sources/net.sf.j2s.java.core/src/java/awt/image/BufferedImage.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,9 +1709,9 @@ public void setPixels() {
17091709
*/
17101710
{
17111711
}
1712-
_pix = toIntARGB(data);
1712+
DataBufferInt buffer = (DataBufferInt) raster.getDataBuffer();
1713+
toIntARGB(data, _pix = buffer.data);
17131714
_imgNode = canvas;
1714-
((DataBufferInt) raster.getDataBuffer()).data = _pix;
17151715
_havePix = true;
17161716
}
17171717

@@ -1724,18 +1724,19 @@ public void setPixels() {
17241724
* @return array of ARGB values
17251725
*
17261726
*/
1727-
int[] toIntARGB(int[] imgData) {
1727+
void toIntARGB(int[] imgData, int[] iData) {
17281728
/*
17291729
* red=imgData.data[0];
17301730
* green=imgData.data[1];
17311731
* blue=imgData.data[2];
17321732
* alpha=imgData.data[3];
17331733
*/
17341734
int n = imgData.length / 4;
1735-
int[] iData = new int[n];
1736-
for (int i = 0, j = 0; i < n; j++)
1737-
iData[i++] = (imgData[j++] << 16) | (imgData[j++] << 8) | imgData[j++] | 0xFF000000;
1738-
return iData;
1735+
int a;
1736+
for (int i = 0, j = 0; i < n;) {
1737+
int argb = (imgData[j++] << 16) | (imgData[j++] << 8) | imgData[j++] | 0xFF000000;
1738+
iData[i++] = (imgData[j++] == 0 ? 0 : argb);
1739+
}
17391740
}
17401741

17411742
/**

0 commit comments

Comments
 (0)