예제 #1
0
        internal Channel(PsdBinaryReader reader, Layer layer)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, Channel");

            ID     = reader.ReadInt16();
            Length = (layer.PsdFile.IsLargeDocument)
              ? reader.ReadInt64()
              : reader.ReadInt32();
            Layer = layer;

            Util.DebugMessage(reader.BaseStream, $"Load, End, Channel, {ID}");
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////

        public BlendingRanges(PsdBinaryReader reader, Layer layer)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, BlendingRanges");

            Layer = layer;
            var dataLength = reader.ReadInt32();

            if (dataLength <= 0)
            {
                return;
            }

            Data = reader.ReadBytes(dataLength);

            Util.DebugMessage(reader.BaseStream, "Load, End, BlendingRanges");
        }
예제 #3
0
        public static LayerInfo Load(PsdBinaryReader reader)
        {
            var signature = reader.ReadAsciiChars(4);

            if (signature != "8BIM")
            {
                throw new PsdInvalidException("Could not read LayerInfo due to signature mismatch." + signature);
            }

            var key    = reader.ReadAsciiChars(4);
            var length = reader.ReadInt32();
//            var startPosition = reader.BaseStream.Position;

//            UnityEngine.Debug.Log("EffectLayerFactory key:" + key);

            LayerInfo result;

            switch (key)
            {
            case "iglw":
            case "oglw":
                result = new GlowEffect(reader, key);
                break;

            case "dsdw":
            case "isdw":
                result = new ShadowEffect(reader, key);
                break;

            case "bevl":
                result = new BevelEffect(reader, key);
                break;

            default:
                result = new RawLayerInfo(reader, key, (int)length);
                break;
            }

            return(result);
        }
예제 #4
0
        public static ImageResource CreateImageResource(PsdBinaryReader reader)
        {
            Util.DebugMessage(reader.BaseStream, "Load, Begin, ImageResource");

            var signature     = reader.ReadAsciiChars(4);
            var resourceIdInt = reader.ReadUInt16();
            var name          = reader.ReadPascalString(2);
            var dataLength    = (int)reader.ReadInt32();

            var dataPaddedLength = Util.RoundUp(dataLength, 2);
            var endPosition      = reader.BaseStream.Position + dataPaddedLength;

            ImageResource resource   = null;
            var           resourceId = (ResourceID)resourceIdInt;

            switch (resourceId)
            {
            case ResourceID.ResolutionInfo:
                resource = new ResolutionInfo(reader, name);
                break;

            case ResourceID.ThumbnailRgb:
            case ResourceID.ThumbnailBgr:
                resource = new Thumbnail(reader, resourceId, name, dataLength);
                break;

            case ResourceID.AlphaChannelNames:
                resource = new AlphaChannelNames(reader, name, dataLength);
                break;

            case ResourceID.UnicodeAlphaNames:
                resource = new UnicodeAlphaNames(reader, name, dataLength);
                break;

            case ResourceID.VersionInfo:
                resource = new VersionInfo(reader, name);
                break;

            default:
                resource = new RawImageResource(reader, signature, resourceId, name, dataLength);
                break;
            }

            Util.DebugMessage(reader.BaseStream,
                              $"Load, End, ImageResource, {resourceId}");

            // Reposition the reader if we do not consume the full resource block.
            // This takes care of the even-padding, and also preserves forward-
            // compatibility in case a resource block is later extended with
            // additional properties.
            if (reader.BaseStream.Position < endPosition)
            {
                reader.BaseStream.Position = endPosition;
            }

            // However, overruns are definitely an error.
            if (reader.BaseStream.Position > endPosition)
            {
                throw new PsdInvalidException("Corruption detected in resource.");
            }

            return(resource);
        }