278 (!(destColorSpace instanceof ICC_ColorSpace)))) {
279 /* non-ICC case */
280 dest = nonICCBIFilter(src, srcColorSpace, dest, destColorSpace);
281 } else {
282 dest = ICCBIFilter(src, srcColorSpace, dest, destColorSpace);
283 }
284
285 if (savdest != null) {
286 Graphics2D big = savdest.createGraphics();
287 try {
288 big.drawImage(dest, 0, 0, null);
289 } finally {
290 big.dispose();
291 }
292 return savdest;
293 } else {
294 return dest;
295 }
296 }
297
298 private final BufferedImage ICCBIFilter(BufferedImage src,
299 ColorSpace srcColorSpace,
300 BufferedImage dest,
301 ColorSpace destColorSpace) {
302 int nProfiles = profileList.length;
303 ICC_Profile srcProfile = null, destProfile = null;
304
305 srcProfile = ((ICC_ColorSpace) srcColorSpace).getProfile();
306
307 if (dest == null) { /* last profile in the list defines
308 the output color space */
309 if (nProfiles == 0) {
310 throw new IllegalArgumentException(
311 "Destination ColorSpace is undefined");
312 }
313 destProfile = profileList [nProfiles - 1];
314 dest = createCompatibleDestImage(src, null);
315 }
316 else {
317 if (src.getHeight() != dest.getHeight() ||
318 src.getWidth() != dest.getWidth()) {
736 /* According to ICC spec, only the least-significant 16 bits shall be
737 * used to encode the rendering intent. The most significant 16 bits
738 * shall be set to zero. Thus, we are ignoring two most significant
739 * bytes here.
740 *
741 * See http://www.color.org/ICC1v42_2006-05.pdf, section 7.2.15.
742 */
743 return ((header[index+2] & 0xff) << 8) |
744 (header[index+3] & 0xff);
745 }
746
747 /**
748 * Returns the rendering hints used by this op.
749 * @return the {@code RenderingHints} object of this
750 * {@code ColorConvertOp}
751 */
752 public final RenderingHints getRenderingHints() {
753 return hints;
754 }
755
756 private final BufferedImage nonICCBIFilter(BufferedImage src,
757 ColorSpace srcColorSpace,
758 BufferedImage dst,
759 ColorSpace dstColorSpace) {
760
761 int w = src.getWidth();
762 int h = src.getHeight();
763 ICC_ColorSpace ciespace =
764 (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
765 if (dst == null) {
766 dst = createCompatibleDestImage(src, null);
767 dstColorSpace = dst.getColorModel().getColorSpace();
768 } else {
769 if ((h != dst.getHeight()) || (w != dst.getWidth())) {
770 throw new IllegalArgumentException(
771 "Width or height of BufferedImages do not match");
772 }
773 }
774 Raster srcRas = src.getRaster();
775 WritableRaster dstRas = dst.getRaster();
776 ColorModel srcCM = src.getColorModel();
930 for (int i = 0; i < dstNumComp; i++) {
931 dstColor[i] = tmpColor[i];
932 }
933 if (needSrcAlpha) {
934 dstColor[dstNumComp] = color[srcNumComp];
935 } else if (dstHasAlpha) {
936 dstColor[dstNumComp] = 1.0f;
937 }
938 dpixel = dstCM.getDataElements(dstColor, 0, dpixel);
939 dstRas.setDataElements(x, y, dpixel);
940
941 }
942 }
943 }
944
945 return dst;
946 }
947
948 /* color convert a Raster - handles byte, ushort, int, short, float,
949 or double transferTypes */
950 private final WritableRaster nonICCRasterFilter(Raster src,
951 WritableRaster dst) {
952
953 if (CSList.length != 2) {
954 throw new IllegalArgumentException(
955 "Destination ColorSpace is undefined");
956 }
957 if (src.getNumBands() != CSList[0].getNumComponents()) {
958 throw new IllegalArgumentException(
959 "Numbers of source Raster bands and source color space " +
960 "components do not match");
961 }
962 if (dst == null) {
963 dst = createCompatibleDestRaster(src);
964 } else {
965 if (src.getHeight() != dst.getHeight() ||
966 src.getWidth() != dst.getWidth()) {
967 throw new IllegalArgumentException(
968 "Width or height of Rasters do not match");
969 }
970 if (dst.getNumBands() != CSList[1].getNumComponents()) {
|
278 (!(destColorSpace instanceof ICC_ColorSpace)))) {
279 /* non-ICC case */
280 dest = nonICCBIFilter(src, srcColorSpace, dest, destColorSpace);
281 } else {
282 dest = ICCBIFilter(src, srcColorSpace, dest, destColorSpace);
283 }
284
285 if (savdest != null) {
286 Graphics2D big = savdest.createGraphics();
287 try {
288 big.drawImage(dest, 0, 0, null);
289 } finally {
290 big.dispose();
291 }
292 return savdest;
293 } else {
294 return dest;
295 }
296 }
297
298 private BufferedImage ICCBIFilter(BufferedImage src,
299 ColorSpace srcColorSpace,
300 BufferedImage dest,
301 ColorSpace destColorSpace) {
302 int nProfiles = profileList.length;
303 ICC_Profile srcProfile = null, destProfile = null;
304
305 srcProfile = ((ICC_ColorSpace) srcColorSpace).getProfile();
306
307 if (dest == null) { /* last profile in the list defines
308 the output color space */
309 if (nProfiles == 0) {
310 throw new IllegalArgumentException(
311 "Destination ColorSpace is undefined");
312 }
313 destProfile = profileList [nProfiles - 1];
314 dest = createCompatibleDestImage(src, null);
315 }
316 else {
317 if (src.getHeight() != dest.getHeight() ||
318 src.getWidth() != dest.getWidth()) {
736 /* According to ICC spec, only the least-significant 16 bits shall be
737 * used to encode the rendering intent. The most significant 16 bits
738 * shall be set to zero. Thus, we are ignoring two most significant
739 * bytes here.
740 *
741 * See http://www.color.org/ICC1v42_2006-05.pdf, section 7.2.15.
742 */
743 return ((header[index+2] & 0xff) << 8) |
744 (header[index+3] & 0xff);
745 }
746
747 /**
748 * Returns the rendering hints used by this op.
749 * @return the {@code RenderingHints} object of this
750 * {@code ColorConvertOp}
751 */
752 public final RenderingHints getRenderingHints() {
753 return hints;
754 }
755
756 private BufferedImage nonICCBIFilter(BufferedImage src,
757 ColorSpace srcColorSpace,
758 BufferedImage dst,
759 ColorSpace dstColorSpace) {
760
761 int w = src.getWidth();
762 int h = src.getHeight();
763 ICC_ColorSpace ciespace =
764 (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
765 if (dst == null) {
766 dst = createCompatibleDestImage(src, null);
767 dstColorSpace = dst.getColorModel().getColorSpace();
768 } else {
769 if ((h != dst.getHeight()) || (w != dst.getWidth())) {
770 throw new IllegalArgumentException(
771 "Width or height of BufferedImages do not match");
772 }
773 }
774 Raster srcRas = src.getRaster();
775 WritableRaster dstRas = dst.getRaster();
776 ColorModel srcCM = src.getColorModel();
930 for (int i = 0; i < dstNumComp; i++) {
931 dstColor[i] = tmpColor[i];
932 }
933 if (needSrcAlpha) {
934 dstColor[dstNumComp] = color[srcNumComp];
935 } else if (dstHasAlpha) {
936 dstColor[dstNumComp] = 1.0f;
937 }
938 dpixel = dstCM.getDataElements(dstColor, 0, dpixel);
939 dstRas.setDataElements(x, y, dpixel);
940
941 }
942 }
943 }
944
945 return dst;
946 }
947
948 /* color convert a Raster - handles byte, ushort, int, short, float,
949 or double transferTypes */
950 private WritableRaster nonICCRasterFilter(Raster src,
951 WritableRaster dst) {
952
953 if (CSList.length != 2) {
954 throw new IllegalArgumentException(
955 "Destination ColorSpace is undefined");
956 }
957 if (src.getNumBands() != CSList[0].getNumComponents()) {
958 throw new IllegalArgumentException(
959 "Numbers of source Raster bands and source color space " +
960 "components do not match");
961 }
962 if (dst == null) {
963 dst = createCompatibleDestRaster(src);
964 } else {
965 if (src.getHeight() != dst.getHeight() ||
966 src.getWidth() != dst.getWidth()) {
967 throw new IllegalArgumentException(
968 "Width or height of Rasters do not match");
969 }
970 if (dst.getNumBands() != CSList[1].getNumComponents()) {
|