public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, System.Drawing.Rectangle[] rois, int startIndex, int length) { CloudsEffectConfigToken token = (CloudsEffectConfigToken)parameters; UserBlendOp blendOp = token.BlendOp; if (blendOp is UserBlendOps.NormalBlendOp && EnvironmentParameters.PrimaryColor.A == 255 && EnvironmentParameters.SecondaryColor.A == 255) { // this is just an optimization blendOp = null; } this.scale = token.Amount1; this.power = token.Amount2 / 100.0f; this.seed = (byte)(token.Seed ^ instanceSeed); for (int i = startIndex; i < startIndex + length; ++i) { RenderClouds(dstArgs.Surface, rois[i]); if (blendOp != null) { blendOp.Apply(dstArgs.Surface, rois[i].Location, srcArgs.Surface, rois[i].Location, dstArgs.Surface, rois[i].Location, rois[i].Size); } } }
public LoadLayerContext(PhotoshopFile.Layer psdLayer, Document document, UserBlendOp blendOp, List <Layer> layersList, int idxLayersList) { this.psdLayer = psdLayer; this.document = document; this.blendOp = blendOp; this.layersList = layersList; this.idxLayersList = idxLayersList; }
private void SelectOp(UserBlendOp setOp) { foreach (object op in blendOpComboBox.Items) { if (op.ToString() == setOp.ToString()) { blendOpComboBox.SelectedItem = op; break; } } }
public BitmapLayerProperties(SerializationInfo info, StreamingContext context) { this.blendOp = (UserBlendOp)info.GetValue(blendOpTag, typeof(UserBlendOp)); // search for 'opacity' and load it if it exists this.opacity = -1; foreach (SerializationEntry entry in info) { if (entry.Name == opacityTag) { this.opacity = (int)((byte)entry.Value); break; } } }
public void SetBlendOp(UserBlendOp blendOp) { if (disposed) { throw new ObjectDisposedException("BitmapLayer"); } if (blendOp.GetType() != properties.blendOp.GetType()) { OnPropertyChanging(BitmapLayerProperties.BlendOpName); properties.blendOp = blendOp; compiledBlendOp = null; Invalidate(); OnPropertyChanged(BitmapLayerProperties.BlendOpName); } }
/// <summary> /// Creates a new effect that will render clouds onto an image. /// </summary> /// <param name="scale">The relative size of the clouds. Valid range is 2 - 1000.</param> /// <param name="power">The power of the clouds. Valid range is 0 - 100.</param> /// <param name="seed">Seed value for random generator.</param> /// <param name="fromColor">Initial cloud color.</param> /// <param name="toColor">Final cloud color.</param> /// <param name="blendMode">Blend mode to use when applying clouds.</param> public CloudsEffect (int scale = 250, int power = 50, int seed = 0, ColorBgra fromColor = new ColorBgra (), ColorBgra toColor = new ColorBgra (), BlendMode blendMode = BlendMode.Normal) { if (scale < 2 || scale > 1000) throw new ArgumentOutOfRangeException ("scale"); if (power < 0 || power > 100) throw new ArgumentOutOfRangeException ("radius"); this.scale = scale; this.power = power; this.seed = seed; this.from_color = fromColor; this.to_color = toColor; this.blend_mode = blendMode; blend_op = Utility.GetBlendModeOp (blend_mode); }
private static PSPBlendModes BlendOptoBlendMode(UserBlendOp op) { Type opType = op.GetType(); if (opType == typeof(UserBlendOps.NormalBlendOp)) { return(PSPBlendModes.Normal); } else if (opType == typeof(UserBlendOps.ColorBurnBlendOp)) { return(PSPBlendModes.Burn); } else if (opType == typeof(UserBlendOps.ColorDodgeBlendOp)) { return(PSPBlendModes.Dodge); } else if (opType == typeof(UserBlendOps.DarkenBlendOp)) { return(PSPBlendModes.Darken); } else if (opType == typeof(UserBlendOps.DifferenceBlendOp)) { return(PSPBlendModes.Difference); } else if (opType == typeof(UserBlendOps.LightenBlendOp)) { return(PSPBlendModes.Lighten); } else if (opType == typeof(UserBlendOps.MultiplyBlendOp)) { return(PSPBlendModes.Multiply); } else if (opType == typeof(UserBlendOps.OverlayBlendOp)) { return(PSPBlendModes.Overlay); } else if (opType == typeof(UserBlendOps.ScreenBlendOp)) { return(PSPBlendModes.Screen); } return(PSPBlendModes.Normal); }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { base.OnSetRenderInfo(newToken, dstArgs, srcArgs); this.Direction = newToken.GetProperty <DoubleProperty>(PropertyNames.Direction).Value *Math.PI / 180.0; this.Distance = newToken.GetProperty <Int32Property>(PropertyNames.Distance).Value; this.Spacing = newToken.GetProperty <Int32Property>(PropertyNames.Spacing).Value; this.Fade = newToken.GetProperty <BooleanProperty>(PropertyNames.Fade).Value; this.Bilinear = newToken.GetProperty <BooleanProperty>(PropertyNames.Bilinear).Value; this.SpacingX = Spacing * Math.Abs(Math.Cos(Direction)); this.SpacingY = Spacing * Math.Abs(Math.Sin(Direction)); this.DistanceX = Distance * Math.Abs(Math.Cos(Direction)); this.DistanceY = Distance * Math.Abs(Math.Sin(Direction)); this.DirectionX = Math.Sign(Math.Cos(Direction)); this.DirectionY = -Math.Sign(Math.Sin(Direction)); this.blendOp = new UserBlendOps.NormalBlendOp(); }
/// <summary> /// Creates a new effect that will render clouds onto an image. /// </summary> /// <param name="scale">The relative size of the clouds. Valid range is 2 - 1000.</param> /// <param name="power">The power of the clouds. Valid range is 0 - 100.</param> /// <param name="seed">Seed value for random generator.</param> /// <param name="fromColor">Initial cloud color.</param> /// <param name="toColor">Final cloud color.</param> /// <param name="blendMode">Blend mode to use when applying clouds.</param> public CloudsEffect(int scale = 250, int power = 50, int seed = 0, ColorBgra fromColor = new ColorBgra(), ColorBgra toColor = new ColorBgra(), BlendMode blendMode = BlendMode.Normal) { if (scale < 2 || scale > 1000) { throw new ArgumentOutOfRangeException("scale"); } if (power < 0 || power > 100) { throw new ArgumentOutOfRangeException("radius"); } this.scale = scale; this.power = power; this.seed = seed; this.from_color = fromColor; this.to_color = toColor; this.blend_mode = blendMode; blend_op = Utility.GetBlendModeOp(blend_mode); }
protected override void InitDialogFromToken(EffectConfigToken effectToken) { base.InitDialogFromToken(effectToken); UserBlendOp setOp = ((CloudsEffectConfigToken)effectToken).BlendOp; if (setOp == null) { setOp = new UserBlendOps.NormalBlendOp(); } foreach (object op in this.comboBlendModes.Items) { if (0 == string.Compare(op.ToString(), setOp.ToString(), StringComparison.CurrentCultureIgnoreCase)) { this.comboBlendModes.SelectedItem = op; break; } } }
public void SetParameters(int scale, byte seed, double power, Type blendOpType, ColorBgra primaryColor, ColorBgra secondaryColor) { this.scale = scale; int intSeed = seed; this.power = power; this.seed = (byte)(intSeed ^ instanceSeed); this.blendOp = UserBlendOps.CreateBlendOp(blendOpType); this.primaryColor = primaryColor; this.secondaryColor = secondaryColor; if (this.blendOp is UserBlendOps.NormalBlendOp && primaryColor.A == 255 && secondaryColor.A == 255) { // this is just an optimization this.blendOp = null; } }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.scale = newToken.GetProperty <Int32Property>(PropertyNames.Scale).Value; int intSeed = newToken.GetProperty <Int32Property>(PropertyNames.Seed).Value; this.seed = (byte)(intSeed ^ instanceSeed); this.power = newToken.GetProperty <DoubleProperty>(PropertyNames.Power).Value; Type blendOpType = (Type)newToken.GetProperty <StaticListChoiceProperty>(PropertyNames.BlendOp).Value; this.blendOp = UserBlendOps.CreateBlendOp(blendOpType); if (this.blendOp is UserBlendOps.NormalBlendOp && EnvironmentParameters.PrimaryColor.A == 255 && EnvironmentParameters.SecondaryColor.A == 255) { // this is just an optimization this.blendOp = null; } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
private UserBlendOp BlendModeKeyToBlendOp(PhotoshopFile.Layer layer) { UserBlendOp blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.NormalBlendOp)); switch (layer.BlendModeKey) { case "norm": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.NormalBlendOp)); break; case "dark": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.DarkenBlendOp)); break; case "lite": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.LightenBlendOp)); break; case "hue ": break; case "sat ": break; case "colr": break; case "lum ": break; case "mul ": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.MultiplyBlendOp)); break; case "scrn": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.ScreenBlendOp)); break; case "diss": break; case "over": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.OverlayBlendOp)); break; case "hLit": break; case "sLit": break; case "diff": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.DifferenceBlendOp)); break; case "smud": break; case "div ": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.ColorDodgeBlendOp)); break; case "idiv": blendOp = UserBlendOps.CreateBlendOp(typeof(UserBlendOps.ColorBurnBlendOp)); break; } return(blendOp); }
private void BlendOpToBlendModeKey(UserBlendOp op, PhotoshopFile.Layer layer) { switch (op.ToString()) { case "Normal": layer.BlendModeKey = "norm"; break; case "Multiply": layer.BlendModeKey = "mul "; break; case "Additive": layer.BlendModeKey = "norm"; break; case "ColorBurn": layer.BlendModeKey = "div "; break; case "ColorDodge": layer.BlendModeKey = "idiv"; break; case "Reflect": layer.BlendModeKey = "norm"; break; case "Glow": layer.BlendModeKey = "norm"; break; case "Overlay": layer.BlendModeKey = "over"; break; case "Difference": layer.BlendModeKey = "diff"; break; case "Negation": layer.BlendModeKey = "norm"; break; case "Lighten": layer.BlendModeKey = "lite"; break; case "Darken": layer.BlendModeKey = "dark"; break; case "Screen": layer.BlendModeKey = "scrn"; break; case "Xor": layer.BlendModeKey = "norm"; break; default: layer.BlendModeKey = "norm"; break; } }
public Document Load(Stream input) { LoadPSPFile(input); if (this.imageAttributes == null || this.layerBlock == null) { throw new FormatException(Properties.Resources.InvalidPSPFile); } if (this.imageAttributes.BitDepth <= 8 && this.globalPalette == null) { throw new FormatException(Properties.Resources.ColorPaletteNotFound); } LayerInfoChunk[] infoChunks = this.layerBlock.LayerInfo; int layerCount = infoChunks.Length; // Some PSP files may have layers that are larger than the dimensions stored in the image attributes. int maxWidth = this.imageAttributes.Width; int maxHeight = this.imageAttributes.Height; for (int i = 0; i < layerCount; i++) { Rectangle savedBounds = infoChunks[i].saveRect; if (savedBounds.Width > maxWidth) { maxWidth = savedBounds.Width; } if (savedBounds.Height > maxHeight) { maxHeight = savedBounds.Height; } } if (maxWidth <= 0 || maxHeight <= 0) { throw new FormatException(Properties.Resources.InvalidDocumentDimensions); } Document doc = new Document(maxWidth, maxHeight); if (this.imageAttributes.ResValue > 0.0) { switch (this.imageAttributes.ResUnit) { case ResolutionMetric.Inch: doc.DpuUnit = MeasurementUnit.Inch; doc.DpuX = doc.DpuY = this.imageAttributes.ResValue; break; case ResolutionMetric.Centimeter: doc.DpuUnit = MeasurementUnit.Centimeter; doc.DpuX = doc.DpuY = this.imageAttributes.ResValue; break; default: break; } } short transIndex = -1; if (this.imageAttributes.BitDepth < 24 && this.extData != null) { byte[] data; if (this.extData.Values.TryGetValue(PSPExtendedDataID.TransparencyIndex, out data)) { transIndex = BitConverter.ToInt16(data, 0); } } LayerBitmapInfoChunk[] bitmapInfoChunks = this.layerBlock.LayerBitmapInfo; for (int i = 0; i < layerCount; i++) { LayerInfoChunk info = infoChunks[i]; BitmapLayer layer = new BitmapLayer(doc.Width, doc.Height) { Name = info.name, Opacity = info.opacity }; UserBlendOp blendOp = BlendModetoBlendOp(info.blendMode); layer.SetBlendOp(blendOp); layer.Visible = (info.layerFlags & PSPLayerProperties.Visible) == PSPLayerProperties.Visible; Rectangle saveRect = info.saveRect; if (!saveRect.IsEmpty) { LayerBitmapInfoChunk bitmapInfo = bitmapInfoChunks[i]; if (bitmapInfo.bitmapCount == 1) { new UnaryPixelOps.SetAlphaChannelTo255().Apply(layer.Surface, saveRect); } int alphaIndex = 0; int bitDepth = this.imageAttributes.BitDepth; int bytesPerPixel = 1; int stride = saveRect.Width; byte[] expandedPalette = null; switch (bitDepth) { case 48: bytesPerPixel = 2; stride *= 2; break; case 4: case 1: expandedPalette = ExpandPackedPalette(saveRect, bitmapInfo, bitDepth); break; } unsafe { int palIdx = 0; NativeStructs.RGBQUAD entry; Surface surface = layer.Surface; for (int y = saveRect.Top; y < saveRect.Bottom; y++) { ColorBgra *ptr = surface.GetPointAddressUnchecked(saveRect.Left, y); ColorBgra *endPtr = ptr + saveRect.Width; int index = ((y - saveRect.Top) * stride); while (ptr < endPtr) { switch (bitDepth) { case 48: for (int ci = 0; ci < bitmapInfo.channelCount; ci++) { ChannelSubBlock ch = bitmapInfo.channels[ci]; if (ch.bitmapType == PSPDIBType.Image) { ushort col = (ushort)(ch.channelData[index] | (ch.channelData[index + 1] << 8)); // PSP format is always little endian byte clamped = (byte)((col * 255) / 65535); switch (ch.channelType) { case PSPChannelType.Red: ptr->R = clamped; break; case PSPChannelType.Green: ptr->G = clamped; break; case PSPChannelType.Blue: ptr->B = clamped; break; } } else if (ch.bitmapType == PSPDIBType.TransparencyMask) { ptr->A = ch.channelData[alphaIndex]; alphaIndex++; } } break; case 24: for (int ci = 0; ci < bitmapInfo.channelCount; ci++) { ChannelSubBlock ch = bitmapInfo.channels[ci]; if (ch.bitmapType == PSPDIBType.Image) { switch (ch.channelType) { case PSPChannelType.Red: ptr->R = ch.channelData[index]; break; case PSPChannelType.Green: ptr->G = ch.channelData[index]; break; case PSPChannelType.Blue: ptr->B = ch.channelData[index]; break; } } else if (ch.bitmapType == PSPDIBType.TransparencyMask) { ptr->A = ch.channelData[index]; } } break; case 8: for (int ci = 0; ci < bitmapInfo.channelCount; ci++) { ChannelSubBlock ch = bitmapInfo.channels[ci]; palIdx = ch.channelData[index]; entry = this.globalPalette.entries[palIdx]; switch (ch.bitmapType) { case PSPDIBType.Image: ptr->R = entry.rgbRed; ptr->G = entry.rgbGreen; ptr->B = entry.rgbBlue; if (palIdx == transIndex) { ptr->A = 0; } break; case PSPDIBType.TransparencyMask: ptr->A = entry.rgbRed; break; } } break; case 4: case 1: palIdx = expandedPalette[index]; entry = this.globalPalette.entries[palIdx]; ptr->R = entry.rgbRed; ptr->G = entry.rgbGreen; ptr->B = entry.rgbBlue; if (palIdx == transIndex) { ptr->A = 0; } else if ((bitmapInfo.bitmapCount == 2) && bitmapInfo.channels[1].bitmapType == PSPDIBType.TransparencyMask) { ptr->A = bitmapInfo.channels[1].channelData[index]; } break; default: throw new FormatException(string.Format(Properties.Resources.UnsupportedBitDepth, bitDepth)); } ptr++; index += bytesPerPixel; } } } } #if DEBUG using (Bitmap temp = layer.Surface.CreateAliasedBitmap()) { } #endif doc.Layers.Add(layer); } string creatorData = SerializeToBase64(this.creator); doc.Metadata.SetUserValue(PSPCreatorMetaData, creatorData); return(doc); }
public BitmapLayerProperties(BitmapLayerProperties cloneMe) { this.blendOp = cloneMe.blendOp; this.opacity = -1; }
public BitmapLayerProperties(UserBlendOp blendOp) { this.blendOp = blendOp; this.opacity = -1; }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.scale = newToken.GetProperty<Int32Property>(PropertyNames.Scale).Value; int intSeed = newToken.GetProperty<Int32Property>(PropertyNames.Seed).Value; this.seed = (byte)(intSeed ^ instanceSeed); this.power = newToken.GetProperty<DoubleProperty>(PropertyNames.Power).Value; Type blendOpType = (Type)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.BlendOp).Value; this.blendOp = UserBlendOps.CreateBlendOp(blendOpType); if (this.blendOp is UserBlendOps.NormalBlendOp && EnvironmentParameters.PrimaryColor.A == 255 && EnvironmentParameters.SecondaryColor.A == 255) { // this is just an optimization this.blendOp = null; } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
protected CloudsEffectConfigToken(CloudsEffectConfigToken copyMe) : base(copyMe) { this.seed = copyMe.seed; this.blendOp = copyMe.blendOp; }
public CloudsEffectConfigToken(int scale, int power, int seed, UserBlendOp blendOp) : base(scale, power) { this.seed = seed; this.blendOp = blendOp; }