/// <summary> /// ColorConverts the image data in the source Raster. /// If the destination Raster is null, a new Raster will be created. /// The number of bands in the source and destination Rasters must /// meet the requirements explained above. The constructor used to /// create this ColorConvertOp must have provided enough information /// to define both source and destination color spaces. See above. /// Otherwise, an exception is thrown. </summary> /// <param name="src"> the source <code>Raster</code> to be converted </param> /// <param name="dest"> the destination <code>WritableRaster</code>, /// or <code>null</code> </param> /// <returns> <code>dest</code> color converted from <code>src</code> /// or a new, converted <code>WritableRaster</code> /// if <code>dest</code> is <code>null</code> </returns> /// <exception cref="IllegalArgumentException"> if the number of source or /// destination bands is incorrect, the source or destination /// color spaces are undefined, or this op was constructed /// with one of the constructors that applies only to /// operations on BufferedImages. </exception> public WritableRaster Filter(Raster src, WritableRaster dest) { if (CSList != null) { /* non-ICC case */ return(NonICCRasterFilter(src, dest)); } int nProfiles = ProfileList.Length; if (nProfiles < 2) { throw new IllegalArgumentException("Source or Destination ColorSpace is undefined"); } if (src.NumBands != ProfileList[0].NumComponents) { throw new IllegalArgumentException("Numbers of source Raster bands and source color space " + "components do not match"); } if (dest == null) { dest = CreateCompatibleDestRaster(src); } else { if (src.Height != dest.Height || src.Width != dest.Width) { throw new IllegalArgumentException("Width or height of Rasters do not match"); } if (dest.NumBands != ProfileList[nProfiles - 1].NumComponents) { throw new IllegalArgumentException("Numbers of destination Raster bands and destination " + "color space components do not match"); } } /* make a new transform if needed */ if (ThisRasterTransform == null) { int i1, whichTrans, renderState; ColorTransform[] theTransforms; /* make the transform list */ theTransforms = new ColorTransform [nProfiles]; /* initialize transform get loop */ if (ProfileList[0].ProfileClass == ICC_Profile.CLASS_OUTPUT) { /* if first profile is a printer * render as colorimetric */ renderState = ICC_Profile.IcRelativeColorimetric; } else { renderState = ICC_Profile.IcPerceptual; /* render any other * class perceptually */ } whichTrans = ColorTransform.In; PCMM mdl = CMSManager.Module; /* get the transforms from each profile */ for (i1 = 0; i1 < nProfiles; i1++) { if (i1 == nProfiles - 1) // last profile? { whichTrans = ColorTransform.Out; // get output transform } else // check for abstract profile { if ((whichTrans == ColorTransform.Simulation) && (ProfileList[i1].ProfileClass == ICC_Profile.CLASS_ABSTRACT)) { renderState = ICC_Profile.IcPerceptual; whichTrans = ColorTransform.In; } } theTransforms[i1] = mdl.createTransform(ProfileList[i1], renderState, whichTrans); /* get this profile's rendering intent to select transform * from next profile */ renderState = GetRenderingIntent(ProfileList[i1]); /* "middle" profiles use simulation transform */ whichTrans = ColorTransform.Simulation; } /* make the net transform */ ThisRasterTransform = mdl.createTransform(theTransforms); } int srcTransferType = src.TransferType; int dstTransferType = dest.TransferType; if ((srcTransferType == DataBuffer.TYPE_FLOAT) || (srcTransferType == DataBuffer.TYPE_DOUBLE) || (dstTransferType == DataBuffer.TYPE_FLOAT) || (dstTransferType == DataBuffer.TYPE_DOUBLE)) { if (SrcMinVals == null) { GetMinMaxValsFromProfiles(ProfileList[0], ProfileList[nProfiles - 1]); } /* color convert the raster */ ThisRasterTransform.colorConvert(src, dest, SrcMinVals, SrcMaxVals, DstMinVals, DstMaxVals); } else { /* color convert the raster */ ThisRasterTransform.colorConvert(src, dest); } return(dest); }
private void UpdateBITransform(ICC_Profile srcProfile, ICC_Profile destProfile) { ICC_Profile[] theProfiles; int i1, nProfiles, nTransforms, whichTrans, renderState; ColorTransform[] theTransforms; bool useSrc = false, useDest = false; nProfiles = ProfileList.Length; nTransforms = nProfiles; if ((nProfiles == 0) || (srcProfile != ProfileList[0])) { nTransforms += 1; useSrc = true; } if ((nProfiles == 0) || (destProfile != ProfileList[nProfiles - 1]) || (nTransforms < 2)) { nTransforms += 1; useDest = true; } /* make the profile list */ theProfiles = new ICC_Profile[nTransforms]; /* the list of profiles * for this Op */ int idx = 0; if (useSrc) { /* insert source as first profile */ theProfiles[idx++] = srcProfile; } for (i1 = 0; i1 < nProfiles; i1++) { /* insert profiles defined in this Op */ theProfiles[idx++] = ProfileList [i1]; } if (useDest) { /* insert dest as last profile */ theProfiles[idx] = destProfile; } /* make the transform list */ theTransforms = new ColorTransform [nTransforms]; /* initialize transform get loop */ if (theProfiles[0].ProfileClass == ICC_Profile.CLASS_OUTPUT) { /* if first profile is a printer * render as colorimetric */ renderState = ICC_Profile.IcRelativeColorimetric; } else { renderState = ICC_Profile.IcPerceptual; /* render any other * class perceptually */ } whichTrans = ColorTransform.In; PCMM mdl = CMSManager.Module; /* get the transforms from each profile */ for (i1 = 0; i1 < nTransforms; i1++) { if (i1 == nTransforms - 1) // last profile? { whichTrans = ColorTransform.Out; // get output transform } else // check for abstract profile { if ((whichTrans == ColorTransform.Simulation) && (theProfiles[i1].ProfileClass == ICC_Profile.CLASS_ABSTRACT)) { renderState = ICC_Profile.IcPerceptual; whichTrans = ColorTransform.In; } } theTransforms[i1] = mdl.createTransform(theProfiles[i1], renderState, whichTrans); /* get this profile's rendering intent to select transform * from next profile */ renderState = GetRenderingIntent(theProfiles[i1]); /* "middle" profiles use simulation transform */ whichTrans = ColorTransform.Simulation; } /* make the net transform */ ThisTransform = mdl.createTransform(theTransforms); /* update corresponding source and dest profiles */ ThisSrcProfile = srcProfile; ThisDestProfile = destProfile; }