Ejemplo n.º 1
0
        static private double ReadPSDDouble(BinaryReverseReader br)
        {
            double val = br.ReadDouble();

            unsafe
            {
                BinaryReverseReader.SwapBytes((byte *)&val, 8);
            }
            return(val);
        }
Ejemplo n.º 2
0
        public double ReadPSDDouble(BinaryReverseReader br)
        {
            //TODO: examine PSD format!
            double val = br.ReadDouble();

            unsafe
            {
                BinaryReverseReader.SwapBytes((byte *)&val, 8);
            }
            return(val);
        }
Ejemplo n.º 3
0
        static private void UpdatePsd(FileInfo fileInfo, Dictionary <string, Color> convertMap)
        {
            Console.Out.WriteLine("Start Convert " + fileInfo.FullName);

            var fileStream = new FileStream(fileInfo.FullName, FileMode.Open);

            if (fileStream == null)
            {
                Console.Out.WriteLine("Paramter Error, Skip");
                return;
            }

            var psdFile = new PsdFile(fileStream, new LoadContext());

            fileStream.Close();

            foreach (Layer layr in psdFile.Layers)
            {
                var layName = layr.Name.ToUpper();
                try
                {
                    var findKey = convertMap.Single(x => layName.Contains(x.Key));
                    var color   = findKey.Value;

                    var vscg       = layr.AdditionalInfo.SingleOrDefault(x => x.Key == "vscg");
                    var solidColor = layr.AdditionalInfo.SingleOrDefault(x => x.Key == "SoCo");
                    //var tysh = layr.AdditionalInfo.SingleOrDefault(x => x.Key == "TySh");
                    if (solidColor == null /*&& tysh == null*/ && vscg == null)
                    {
                        ConsoleColor oldColor = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("Convert Error : " + fileInfo.FullName);
                        Console.ForegroundColor = oldColor;
                        return;
                    }

                    if (vscg != null)
                    {
                        solidColor = vscg;
                    }

                    if (solidColor != null)
                    {
                        PhotoshopFile.PsdDescriptor eff = new PhotoshopFile.PsdDescriptor(CreateReadStream(solidColor));

                        double red   = color.R;
                        double green = color.G;
                        double blue  = color.B;
                        byte[] redBuffer, greenBuffer, blueBuffer;
                        unsafe
                        {
                            BinaryReverseReader.SwapBytes((byte *)&red, 8);
                            redBuffer = ConvertDoubleToByteArray(red);
                            BinaryReverseReader.SwapBytes((byte *)&green, 8);
                            greenBuffer = ConvertDoubleToByteArray(green);
                            BinaryReverseReader.SwapBytes((byte *)&blue, 8);
                            blueBuffer = ConvertDoubleToByteArray(blue);
                        }

                        long redOffset = 0, greenOffset = 0, blueOffset = 0;
                        GetPSDColorOffset(eff, ref redOffset, ref greenOffset, ref blueOffset);

                        BinaryReverseWriter writer = CreateWriteStream(solidColor);
                        writer.Seek((int)redOffset, SeekOrigin.Begin);
                        writer.Write(redBuffer);
                        writer.Seek((int)greenOffset, SeekOrigin.Begin);
                        writer.Write(greenBuffer);
                        writer.Seek((int)blueOffset, SeekOrigin.Begin);
                        writer.Write(blueBuffer);
                    }
                    //else if (tysh != null)
                    //{
                    //    PhotoshopFile.LayerResources.TypeToolTyShPH6 txt = new PhotoshopFile.LayerResources.TypeToolTyShPH6(CreateReadStream(tysh));
                    //    Dictionary<string, object> d = txt.StylesheetReader.GetStylesheetDataFromLongestRun();
                    //    BinaryReverseWriter writer = CreateWriteStream(tysh);
                    //    //writer.Seek((int)redOffset, SeekOrigin.Begin);
                    //    //writer.Write(redBuffer);
                    //    //writer.Seek((int)greenOffset, SeekOrigin.Begin);
                    //    //writer.Write(greenBuffer);
                    //    //writer.Seek((int)blueOffset, SeekOrigin.Begin);
                    //    //writer.Write(blueBuffer);
                    //}
                }
                catch
                {
                }
            }

            psdFile.Save(fileInfo.DirectoryName + "\\_" + fileInfo.Name, Encoding.Default);
            Console.Out.WriteLine("Convert Finished, Save to " + fileInfo.DirectoryName + "\\_" + fileInfo.Name, Encoding.Default);
        }
Ejemplo n.º 4
0
 public unsafe void WritePSDDouble(double value)
 {
     //TODO: examine PSD format!
     BinaryReverseReader.SwapBytes((byte *)&value, 2);
     base.Write(value);
 }