public override ColorModeDataSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var length = reader.ReadInt32(); var data = reader.ReadBytes(length); return(new ColorModeDataSection(length, data)); }
public void Should_correctly_read_image_data_section([NotNull] string path) { const string exportedPngPath = "files/image-data/empty.png"; using var photoshopFile = PhotoshopFile.Open(path); var image = Image.Load <Rgb24>(exportedPngPath); var channelStride = photoshopFile.Width * photoshopFile.Height; for (var i = 0; i < image.Height; i++) { var row = image.GetPixelRowSpan(i); for (var j = 0; j < image.Width; j++) { var expectedPixel = row[j]; var actualR = photoshopFile.ImageData[i * image.Width + j]; var actualG = photoshopFile.ImageData[channelStride + i * image.Width + j]; var actualB = photoshopFile.ImageData[channelStride * 2 + i * image.Width + j]; actualR.Should() .Be(expectedPixel.R); actualG.Should() .Be(expectedPixel.G); actualB.Should() .Be(expectedPixel.B); } } }
public override LayerMaskInformationSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var length = reader.ReadInt32(); var data = reader.ReadBytes(length); return(new PsdLayerMaskInformationSection(length, data)); }
public override HeaderSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var buffer = reader.ReadBytes(26); var bufferedReader = new PhotoshopFileReader(buffer); var signatureBytes = bufferedReader.ReadBytes(4); var signature = Encoding.ASCII.GetString(signatureBytes); var version = bufferedReader.ReadInt16(); var reservedBytes = bufferedReader.ReadBytes(6); var channelCount = bufferedReader.ReadInt16(); var height = bufferedReader.ReadInt32(); var width = bufferedReader.ReadInt32(); var depth = bufferedReader.ReadInt16(); var colorMode = (ColorMode)bufferedReader.ReadInt16(); return(new HeaderSection( signature, version, reservedBytes, channelCount, height, width, depth, colorMode )); }
public override ImageResourcesSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var length = reader.ReadInt32(); var data = reader.ReadBytes(length); return(new ImageResourcesSection(length, data)); }
public override LayerMaskInformationSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var length = reader.ReadInt64(); // TODO: Don't just convert to int pls var data = reader.ReadBytes((int)length); return(new PsbLayerMaskInformationSection(length, data)); }
public void Should_correctly_read_image_size([NotNull] string path, int expectedHeight, int expectedWidth) { using var photoshopFile = PhotoshopFile.Open(path); photoshopFile.Height.Should() .Be(expectedHeight); photoshopFile.Width.Should() .Be(expectedWidth); }
public override ImageDataSection Read(PhotoshopFileReader reader, PhotoshopFile photoshopFile) { var channelCount = photoshopFile.ChannelCount; var width = photoshopFile.Width; var height = photoshopFile.Height; var depth = photoshopFile.Depth; var compressionMethod = reader.ReadInt16(); var dataLength = 0; var pitch = DepthToPitch(depth, width); byte[] data; if (compressionMethod == 0) { for (var i = 0; i < channelCount; i++) { dataLength += pitch * height; } data = reader.ReadBytes(dataLength); } else if (compressionMethod == 1) { var dataBuffer = new List <byte>(); var channelLengths = new List <int[]>(); for (var i = 0; i < channelCount; i++) { var lengths = new int[height]; for (var j = 0; j < height; j++) { lengths[j] = photoshopFile.Version == 1 ? reader.ReadInt16() : reader.ReadInt32(); } channelLengths.Add(lengths); } for (int i = 0; i < channelCount; i++) { var lengths = channelLengths[i]; for (var j = 0; j < lengths.Length; j++) { var rleData = reader.ReadBytes(lengths[j]); var decompressedData = new byte[width]; DecompressRleData(rleData, decompressedData); dataBuffer.AddRange(decompressedData); } } data = dataBuffer.ToArray(); } else { throw new NotImplementedException(); } return(new ImageDataSection(compressionMethod, data)); }
public void Should_fail_to_open_non_photoshop_file(string path) { Assert.Throws <InvalidPhotoshopFileException>( () => { using var photoshopFile = PhotoshopFile.OpenPsd(path); } ); Assert.Throws <InvalidPhotoshopFileException>( () => { using var photoshopFile = PhotoshopFile.OpenPsb(path); } ); }
public Bevel(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; //string blendModeSignature = null; uint version = r.ReadUInt32(); switch (version) { case 0: this.Blur = r.ReadUInt32(); this.Data = null; break; case 2: this.Angle = (uint)r.ReadUInt16(); this.Strength = (uint)r.ReadUInt16(); this.Blur = (uint)r.ReadUInt16(); this.Unknown1 = r.ReadByte(); this.Unknown2 = r.ReadByte(); this.Unknown3 = r.ReadUInt16(); this.Unknown4 = r.ReadUInt16(); this.BlendModeKey = this.ReadBlendKey(r); this.ShadowBlendModeKey = this.ReadBlendKey(r); this.Color = r.ReadPSDColor(16, true); this.ShadowColor = r.ReadPSDColor(16, true); this.BevelStyle = r.ReadByte(); this.Opacity = r.ReadByte(); this.ShadowOpacity = r.ReadByte(); this.Enabled = r.ReadBoolean(); this.UseGlobalAngle = r.ReadBoolean(); this.Inverted = r.ReadBoolean(); System.Drawing.Color someColor = r.ReadPSDColor(16, true); System.Drawing.Color someColor2 = r.ReadPSDColor(16, true); break; } this.Data = null; }
public void Should_save_file_correctly([NotNull] string path) { using var photoshopFile = PhotoshopFile.Open(path); var tempPath = Path.GetTempPath(); var guid = Guid.NewGuid(); var tempFilePath = Path.Combine(tempPath, guid.ToString()); photoshopFile.SaveAs(tempFilePath); File.Exists(tempFilePath) .Should() .Be(true); var expectedBytes = File.ReadAllBytes(path); var actualBytes = File.ReadAllBytes(tempFilePath); actualBytes.Should() .Equal(expectedBytes); // TODO: move cleanup out of here File.Delete(tempFilePath); }
public Shadow(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; //string blendModeSignature = null; int version = r.ReadInt32(); switch (version) { case 0: this.Blur = r.ReadUInt32(); this.Intensity = r.ReadUInt32(); this.Angle = r.ReadUInt32(); this.Distance = r.ReadUInt32(); this.Color = r.ReadPSDColor(16, true); this.BlendModeKey = this.ReadBlendKey(r); //this.BlendModeSignature = r.ReadUInt32(); //this.BlendModeKey = r.ReadUInt32(); this.Enabled = r.ReadBoolean(); this.UseGlobalAngle = r.ReadBoolean(); this.Opacity = r.ReadByte(); break; case 2: this.Blur = (uint)r.ReadUInt16(); this.Intensity = r.ReadUInt32(); this.Angle = r.ReadUInt32(); this.Distance = r.ReadUInt32(); ushort something = r.ReadUInt16();//TODO:? this.Color = r.ReadPSDColor(16, true); this.BlendModeKey = this.ReadBlendKey(r); this.Enabled = r.ReadBoolean(); this.UseGlobalAngle = r.ReadBoolean(); this.Opacity = r.ReadByte(); //TODO: 10 unknown bytes! break; } this.Data = null; }
public Glow(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; //string blendModeSignature = null; uint version = r.ReadUInt32(); //two version specifications?!? switch (version) { case 0: this.Blur = r.ReadUInt32(); this.Data = null; break; case 2: this.Blur = (uint)r.ReadUInt16(); this.Intensity = r.ReadUInt32(); ushort something = r.ReadUInt16(); this.Color = r.ReadPSDColor(16, false); //Inner color (no alpha) this.BlendModeKey = this.ReadBlendKey(r); this.Enabled = r.ReadBoolean(); this.Opacity = r.ReadByte(); //TODO! if (this.Inner) this.Unknown = r.ReadByte(); this.UnknownColor = r.ReadPSDColor(16, false); //unknown color(no alpha) this.Data = r.ReadBytes((int)r.BytesToEnd); break; } }
public Effects(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; r.BaseStream.Position += 2; //unused ushort nNumEffects = r.ReadUInt16(); this._resources = new Dictionary<string, PhotoshopFile.Layer.AdjustmentLayerInfo>(); for (int nEffectNum = 0; nEffectNum < nNumEffects; nEffectNum++) { PhotoshopFile.Layer.AdjustmentLayerInfo res = new PhotoshopFile.Layer.AdjustmentLayerInfo(r, info.Layer); //if (res.Tag != "cmnS") // continue; this._resources.Add(res.Key, res); // case "sofi": //unknown } this.Data = null; }
public void Should_correctly_read_color_mode([NotNull] string path, ColorMode expectedColorMode) { using var photoshopFile = PhotoshopFile.Open(path); photoshopFile.ColorMode.Should() .Be(expectedColorMode); }
public void Should_correctly_read_depth([NotNull] string path, int expectedDepth) { using var photoshopFile = PhotoshopFile.Open(path); photoshopFile.Depth.Should() .Be(expectedDepth); }
public void Should_correctly_read_channel_count([NotNull] string path, int expectedChannelCount) { using var photoshopFile = PhotoshopFile.Open(path); photoshopFile.ChannelCount.Should() .Be(expectedChannelCount); }
public TypeToolObject(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; ushort PhotshopVersion = r.ReadUInt16(); //2 bytes, =1 Photoshop 6 (not 5) this.Transform = new Matrix2D(r); //six doubles (48 bytes) ushort TextVersion = r.ReadUInt16(); //2 bytes, =50. For Photoshop 6.0. uint DescriptorVersion = r.ReadUInt32(); //4 bytes,=16. For Photoshop 6.0. this.TxtDescriptor = DynVal.ReadDescriptor(r); //Text descriptor ushort WarpVersion = r.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0. uint WarpDescriptorVersion = r.ReadUInt32(); //4 bytes, =16. For Photoshop 6.0. engineData = (Dictionary<string, object>)TxtDescriptor.Children.Find(c => c.Name == "EngineData").Value; StylesheetReader = new TdTaStylesheetReader(engineData); //string desc = this.TxtDescriptor.getString(); this.WarpDescriptor = DynVal.ReadDescriptor(r); //Warp descriptor this.Data = r.ReadBytes((int)r.BytesToEnd); //17 bytes???? All zeroes? if (Data.Length != 17 || !(Array.TrueForAll(Data, b => b == 0))) { string s = ReadableBinary.CreateHexEditorString(Data); Debug.Write(s); } //this.WarpRect = new RectangleF(); //WarpRect.X = (float)r.ReadDouble(); //WarpRect.Y = (float)r.ReadDouble(); //this.Data. //WarpRect.Width = (float)r.ReadDouble() - WarpRect.X; //WarpRect.Height = (float)r.ReadDouble() - WarpRect.Y; //this.Data = r.ReadBytes((int)r.BytesToEnd); }
public abstract T Read([NotNull] PhotoshopFileReader reader, [NotNull] PhotoshopFile photoshopFile);
public DecompressChannelContext(PhotoshopFile.Layer.Channel ch) { this.ch = ch; }
public void Should_open_valid_file([NotNull] string path) { using var photoshopFile = PhotoshopFile.Open(path); }
public static void Flatten(this PhotoshopFile.Layer layer, PhotoshopFile.Layer destinationLayer, Color[] layerData0, Color[] layerData1) { for (int i = 0; i < layerData1.Length; i++) layerData1[i] = Blend(layerData0[i], layerData1[i]); }
public TypeTool(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader reader = this.DataReader; ushort Version = reader.ReadUInt16(); //1= Photoshop 5.0 //2D transform matrix (6 doubles) Transform = new Matrix2D(reader); //Font info: ushort FontVersion = reader.ReadUInt16(); //6 = Photoshop 5.0 ushort FaceCount = reader.ReadUInt16(); this.FontInfos = new List<FontInfo>(); for (int i = 0; i < FaceCount; i++) this.FontInfos.Add(new FontInfo(reader)); //TODO: make classes of styles as well... ushort StyleCount = reader.ReadUInt16(); for (int i = 0; i < StyleCount; i++) { ushort Mark = reader.ReadUInt16(); ushort FaceMark = reader.ReadUInt16(); uint Size = reader.ReadUInt32(); uint Tracking = reader.ReadUInt32(); uint Kerning = reader.ReadUInt32(); uint Leading = reader.ReadUInt32(); uint BaseShift = reader.ReadUInt32(); byte AutoKern = reader.ReadByte(); byte Extra = 0; if (Version <= 5) Extra = reader.ReadByte(); byte Rotate = reader.ReadByte(); } //Text information ushort Type = reader.ReadUInt16(); uint ScalingFactor = reader.ReadUInt32(); uint CharacterCount = reader.ReadUInt32(); uint HorizontalPlacement = reader.ReadUInt32(); uint VerticalPlacement = reader.ReadUInt32(); uint SelectStart = reader.ReadUInt32(); uint SelectEnd = reader.ReadUInt32(); ushort LineCount = reader.ReadUInt16(); for (int i = 0; i < LineCount; i++) { uint CharacterCountLine = reader.ReadUInt32(); ushort Orientation = reader.ReadUInt16(); ushort Alignment = reader.ReadUInt16(); ushort DoubleByteChar = reader.ReadUInt16(); ushort Style = reader.ReadUInt16(); } ushort ColorSpace = reader.ReadUInt16(); for (int i = 0; i < 4; i++) reader.ReadUInt16(); //Color compensation byte AntiAlias = reader.ReadByte(); }
public void Should_correctly_read_empty_data_section([NotNull] string path) { using var photoshopFile = PhotoshopFile.Open(path); photoshopFile.ColorModeData.Should() .BeEmpty(); }