-
Bug
-
Resolution: Duplicate
-
P4
-
7u4
-
x86
-
os_x
FULL PRODUCT VERSION :
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
(also reproducible on 1.6)
java version "1.6.0_33"Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Tested on: OS X. Should be generic unless ImagingLib (native code) is used.
EXTRA RELEVANT SYSTEM CONFIGURATION :
(none that seems relevant)
A DESCRIPTION OF THE PROBLEM :
java.awt.image.RescaleOp computes wrong number of bands, causing IllegalArgumentException: Number of bands in src 4 does not equal number of bands in dest 2
This happens only when the scaling factors/offsets are equal to the number of color components (typically 3), and the image filtered has alpha. This happens even if the source and dest is the same!!!
The JavaDoc clearly states that the alpha information is then ignored when filtering, instead it throws an exception.
There's an obvious bug in RescaleOp.filter (BufferedImage src, BufferedImage dst), where the variable "numBands" is assigned the number of color components from src's ColorModel. Color components is 3, even for images with alpha.
Now, it get's worse, because instead of src image bands, the number of rescale factors is compared to numBands so that no band subsampling happens at the source (leading to 4 bands in the source).
(There's also a bug in the computation of the band subsampling, but it rarely happens because of the incorrect comparison...)
While the destination is compared to the actual number of bands, but the using the incorrect numBands varible (numBands-1) for subsampling (same bug as for src, leading to only 2 bands in dest).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached Java program (below).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should run without errors.
ACTUAL -
The program crashed with the exception (attached below).
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: Number of bands in src 4 does not equal number of bands in dest 2
at java.awt.image.RescaleOp.filter(RescaleOp.java:465)
at java.awt.image.RescaleOp.filter(RescaleOp.java:415)
at RescaleOpTest.main(RescaleOpTest.java:9)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
public class RescaleOpTest {
public static void main(String[] args) {
BufferedImage img = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
new RescaleOp(new float[] {1, 1, 1}, new float[] {1, 1, 1}, null).filter(img, img);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using scale factors for all 4 bands would probably work around the issue, also manually doing the band sub sampling and using the raster version of filter should work.
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
(also reproducible on 1.6)
java version "1.6.0_33"Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Tested on: OS X. Should be generic unless ImagingLib (native code) is used.
EXTRA RELEVANT SYSTEM CONFIGURATION :
(none that seems relevant)
A DESCRIPTION OF THE PROBLEM :
java.awt.image.RescaleOp computes wrong number of bands, causing IllegalArgumentException: Number of bands in src 4 does not equal number of bands in dest 2
This happens only when the scaling factors/offsets are equal to the number of color components (typically 3), and the image filtered has alpha. This happens even if the source and dest is the same!!!
The JavaDoc clearly states that the alpha information is then ignored when filtering, instead it throws an exception.
There's an obvious bug in RescaleOp.filter (BufferedImage src, BufferedImage dst), where the variable "numBands" is assigned the number of color components from src's ColorModel. Color components is 3, even for images with alpha.
Now, it get's worse, because instead of src image bands, the number of rescale factors is compared to numBands so that no band subsampling happens at the source (leading to 4 bands in the source).
(There's also a bug in the computation of the band subsampling, but it rarely happens because of the incorrect comparison...)
While the destination is compared to the actual number of bands, but the using the incorrect numBands varible (numBands-1) for subsampling (same bug as for src, leading to only 2 bands in dest).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached Java program (below).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should run without errors.
ACTUAL -
The program crashed with the exception (attached below).
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: Number of bands in src 4 does not equal number of bands in dest 2
at java.awt.image.RescaleOp.filter(RescaleOp.java:465)
at java.awt.image.RescaleOp.filter(RescaleOp.java:415)
at RescaleOpTest.main(RescaleOpTest.java:9)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
public class RescaleOpTest {
public static void main(String[] args) {
BufferedImage img = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
new RescaleOp(new float[] {1, 1, 1}, new float[] {1, 1, 1}, null).filter(img, img);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using scale factors for all 4 bands would probably work around the issue, also manually doing the band sub sampling and using the raster version of filter should work.
- duplicates
-
JDK-7028946 RescaleOp generates incompatible destination Raster
-
- Closed
-