public LayerInfoChunk(PaintDotNet.Layer layer, PSPBlendModes blendMode, Rectangle savedBounds, ushort majorVersion) { if (majorVersion > PSPConstants.majorVersion5) { this.chunkSize = Version6BaseChunkSize + (uint)Encoding.ASCII.GetByteCount(layer.Name); } else { this.chunkSize = 0U; } this.name = layer.Name; this.type = majorVersion > PSPConstants.majorVersion5 ? PSPLayerType.Raster : 0; this.imageRect = layer.Bounds; this.saveRect = savedBounds; this.opacity = layer.Opacity; this.blendMode = blendMode; this.layerFlags = PSPLayerProperties.None; if (layer.Visible) { this.layerFlags |= PSPLayerProperties.Visible; } this.protectedTransparency = 0; this.linkGroup = 0; this.maskRect = Rectangle.Empty; this.saveMaskRect = Rectangle.Empty; this.maskLinked = 0; this.invertMaskOnBlend = 0; this.blendRangeCount = 0; this.blendRanges = null; this.v5BitmapCount = 0; this.v5ChannelCount = 0; this.useHighlightColor = 0; this.highlightColor = 0; }
private static UserBlendOp BlendModetoBlendOp(PSPBlendModes mode) { switch (mode) { case PSPBlendModes.Normal: return(new UserBlendOps.NormalBlendOp()); case PSPBlendModes.Darken: return(new UserBlendOps.DarkenBlendOp()); case PSPBlendModes.Lighten: return(new UserBlendOps.LightenBlendOp()); case PSPBlendModes.Multiply: return(new UserBlendOps.MultiplyBlendOp()); case PSPBlendModes.Screen: return(new UserBlendOps.ScreenBlendOp()); case PSPBlendModes.Overlay: return(new UserBlendOps.OverlayBlendOp()); case PSPBlendModes.Difference: return(new UserBlendOps.DifferenceBlendOp()); case PSPBlendModes.Dodge: return(new UserBlendOps.ColorDodgeBlendOp()); case PSPBlendModes.Burn: return(new UserBlendOps.ColorBurnBlendOp()); default: return(new UserBlendOps.NormalBlendOp()); } }
public LayerInfoChunk(BufferedBinaryReader br, ushort majorVersion) { long startOffset = br.Position; if (majorVersion > PSPConstants.majorVersion5) { this.chunkSize = br.ReadUInt32(); ushort nameLen = br.ReadUInt16(); this.name = br.ReadAsciiString(nameLen); } else { this.chunkSize = 0; this.name = br.ReadAsciiString(256).TrimEnd(new char[] { '\0' }); } this.type = (PSPLayerType)br.ReadByte(); if (majorVersion <= PSPConstants.majorVersion5 && this.type == PSPLayerType.Undefined) { this.type = PSPLayerType.Raster; } this.imageRect = Rectangle.FromLTRB(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); this.saveRect = Rectangle.FromLTRB(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); this.opacity = br.ReadByte(); this.blendMode = (PSPBlendModes)br.ReadByte(); this.layerFlags = (PSPLayerProperties)br.ReadByte(); this.protectedTransparency = br.ReadByte(); this.linkGroup = br.ReadByte(); this.maskRect = Rectangle.FromLTRB(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); this.saveMaskRect = Rectangle.FromLTRB(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); this.maskLinked = br.ReadByte(); this.maskDisabled = br.ReadByte(); this.invertMaskOnBlend = br.ReadByte(); this.blendRangeCount = br.ReadUInt16(); this.blendRanges = new BlendRange[5]; for (int i = 0; i < 5; i++) { this.blendRanges[i] = new BlendRange { sourceRange = br.ReadUInt32(), destRange = br.ReadUInt32() }; } this.v5BitmapCount = 0; this.v5ChannelCount = 0; this.useHighlightColor = 0; this.highlightColor = 0; if (majorVersion >= PSPConstants.majorVersion8) { this.useHighlightColor = br.ReadByte(); this.highlightColor = br.ReadUInt32(); } else if (majorVersion <= PSPConstants.majorVersion5) { this.v5BitmapCount = br.ReadUInt16(); this.v5ChannelCount = br.ReadUInt16(); } long dif = this.chunkSize - (br.Position - startOffset); if (dif > 0) { br.Position += dif; } }