public ParticleType(ParticleType copyFrom) { Source = copyFrom.Source; SourceChooser = copyFrom.SourceChooser; Color = copyFrom.Color; Color2 = copyFrom.Color2; ColorMode = copyFrom.ColorMode; FadeMode = copyFrom.FadeMode; SpeedMin = copyFrom.SpeedMin; SpeedMax = copyFrom.SpeedMax; SpeedMultiplier = copyFrom.SpeedMultiplier; Acceleration = copyFrom.Acceleration; Friction = copyFrom.Friction; Direction = copyFrom.Direction; DirectionRange = copyFrom.DirectionRange; LifeMin = copyFrom.LifeMin; LifeMax = copyFrom.LifeMax; Size = copyFrom.Size; SizeRange = copyFrom.SizeRange; RotationMode = copyFrom.RotationMode; SpinMin = copyFrom.SpinMin; SpinMax = copyFrom.SpinMax; SpinFlippedChance = copyFrom.SpinFlippedChance; ScaleOut = copyFrom.ScaleOut; UseActualDeltaTime = copyFrom.UseActualDeltaTime; AllTypes.Add(this); }
private void colorModeChanged(object sender, EventArgs e) { if (((RadioButton)sender).Checked) { if (sender == radioH) { colorMode = ColorModes.Hue; } else if (sender == radioS) { colorMode = ColorModes.Saturation; } else if (sender == radioL) { colorMode = ColorModes.Luminance; } else if (sender == radioR) { colorMode = ColorModes.Red; } else if (sender == radioG) { colorMode = ColorModes.Green; } else if (sender == radioB) { colorMode = ColorModes.Blue; } this.proColorsSlider1.ColorMode = colorMode; this.proColors2DBox1.ColorMode = colorMode; } }
private void colorModeChanged(object sender, StateChangedEventArgs args) { if (args.ToggleState != Telerik.WinControls.Enumerations.ToggleState.On) { return; } if (sender == this.radioH) { this.colorMode = ColorModes.Hue; } else if (sender == this.radioS) { this.colorMode = ColorModes.Saturation; } else if (sender == this.radioL) { this.colorMode = ColorModes.Luminance; } else if (sender == this.radioR) { this.colorMode = ColorModes.Red; } else if (sender == this.radioG) { this.colorMode = ColorModes.Green; } else if (sender == this.radioB) { this.colorMode = ColorModes.Blue; } this.proColorsSlider1.ColorMode = this.colorMode; this.proColors2DBox1.ColorMode = this.colorMode; }
/// <summary> /// assigns a color mixing it with the start color of each graphics or renderer component /// </summary> /// <param name="newColor">color to assign</param> /// <param name="target">Color, Alpha or Color and Alpha</param> /// <param name="mixMode">mix mode</param> public virtual void AssignColor(Color newColor, TransitionTargets target, ColorModes mixMode) { if (GraphicsTable != null) { foreach (KeyValuePair <UnityEngine.UI.Graphic, Color> pair in GraphicsTable) { UnityEngine.UI.Graphic g = pair.Key; Color startColor = pair.Value; g.color = ApplyColorMode(startColor, newColor, target, mixMode); } } if (RenderersTable != null) { Material[] mats = null; foreach (KeyValuePair <Renderer, Color[]> pair in RenderersTable) { Renderer r = pair.Key; Color[] startColors = pair.Value; mats = UseSharedMaterials ? r.sharedMaterials : r.materials; for (int i = 0; i < mats.Length; i++) { if (mats[i].HasProperty(MaterialPropertyName)) { mats[i].SetColor(MaterialPropertyName, ApplyColorMode(startColors[i], newColor, target, mixMode)); } } } } }
private void ColorModeChangedHandler(object sender, EventArgs e) { if (sender == this.radioRed) { this.colorMode = ColorModes.Red; } else if (sender == this.radioGreen) { this.colorMode = ColorModes.Green; } else if (sender == this.radioBlue) { this.colorMode = ColorModes.Blue; } else if (sender == this.radioHue) { this.colorMode = ColorModes.Hue; } else if (sender == this.radioSaturation) { this.colorMode = ColorModes.Saturation; } else if (sender == this.radioLuminance) { this.colorMode = ColorModes.Luminance; } this.colorSlider.ColorMode = this.colorMode; this.colorBox2D.ColorMode = this.colorMode; }
/// <summary> /// Prints an image. /// </summary> /// <param name="image">Image to be printed</param> /// <param name="jobName">Name of the printing job</param> /// <param name="onFinishCallback"> /// Action to perform after printing is finished. /// Is performed even if the printing was cancelled. /// </param> /// <param name="colorMode">Color mode of printing</param> /// <param name="orientation">Sheet orientation of printing</param> /// <param name="scaleMode">Scale mode of printing</param> /// <exception cref="ArgumentNullException"></exception> public static void PrintImage([NotNull] Texture2D image, [NotNull] string jobName, Action onFinishCallback = null, ColorModes colorMode = ColorModes.Color, Orientations orientation = Orientations.Portrait, ScaleModes scaleMode = ScaleModes.Fit) { if (AGUtils.IsNotAndroid()) { return; } if (image == null) { throw new ArgumentNullException("image"); } if (jobName == null) { throw new ArgumentNullException("jobName"); } _printHelper = new AndroidJavaObject(C.AndroidPrintHelper, AGUtils.Activity); _printHelper.Call("setColorMode", (int)colorMode); _printHelper.Call("setOrientation", (int)orientation); _printHelper.Call("setScaleMode", (int)scaleMode); _onPrintSuccess = onFinishCallback; var helperClass = new AndroidJavaClass(C.PrintHelperUtilsClass); helperClass.CallStatic("printBitmap", jobName, AGUtils.Texture2DToAndroidBitmap(image), _printHelper); }
/////////////////////////////////////////////////////////////////////////// private void LoadHeader(BinaryReverseReader reader) { Debug.WriteLine("LoadHeader started at " + reader.BaseStream.Position.ToString()); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") { throw new IOException("The given stream is not a valid PSD file"); } m_version = reader.ReadInt16(); if (m_version != 1) { throw new IOException("The PSD file has an unknown version"); } //6 bytes reserved reader.BaseStream.Position += 6; m_channels = reader.ReadInt16(); m_rows = reader.ReadInt32(); m_columns = reader.ReadInt32(); m_depth = reader.ReadInt16(); m_colorMode = (ColorModes)reader.ReadInt16(); }
public ColorBox2D() { InitializeComponent(); base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); this.colorHSL = HslColor.FromAhsl(1.0, 1.0, 1.0); this.colorRGB = this.colorHSL.RgbValue; this.colorMode = ColorModes.Hue; }
public ColorStop(BinaryPSDReader r) { this.Location = r.ReadUInt32(); this.Midpoint = r.ReadUInt32(); this.ColorMode = (ColorModes)r.ReadUInt16(); this.Channels = r.ReadPSDChannelValues(4); this.Unknown = r.ReadUInt16(); }
public ProfessionalColors() { this.InitializeComponent(); this.colorMode = ColorModes.Hue; this.proColors2DBox1.ColorMode = this.colorMode; this.proColorsSlider1.ColorMode = this.colorMode; this.proColors2DBox1.ColorChanged += new ColorChangedEventHandler(this.proColors2DBox1_ColorChanged); this.proColorsSlider1.ColorChanged += new ColorChangedEventHandler(this.proColorsSlider1_ColorChanged); this.proColorsSlider1.Position = this.proColorsSlider1.Height; }
public virtual void ChangeMixMode() { ColorModes mix = ca.MixMode; int mixInt = (int)mix; mixInt++; mixInt = mixInt % 11; ca.MixMode = (ColorModes)mixInt; UpdateLabel(); }
public Header(BinaryPSDReader reader) { this.Version = reader.ReadUInt16(); if (Version != 1) throw new Exception("Can not read .psd version " + Version); byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); }
public short Opacity; // 0..100 #endregion Fields #region Constructors public DisplayInfo(ImageResource imgRes) { BinaryReverseReader reader = imgRes.GetDataReader(); this.ColorSpace = (ColorModes)reader.ReadInt16(); for(int i=0; i<4; i++) this.Color[i] = reader.ReadInt16(); this.Opacity = (short)Math.Max(0,Math.Min(100,(int)reader.ReadInt16())); this.kind = reader.ReadByte()==0?false:true; reader.Close(); }
public Image2Ascii() { activeChars = new string[] { " ·:+x#W@", " ░░▒▒▓▓█" }[0]; mCanvasSize = new Size(80, 25); mColorMode = ColorModes.GrayScale; mScanMode = ScanModes.Fast; mCharset = Charsets.Standard; mGrayScaleMode = GrayscaleModes.Average; mBackColor = Color.Black; mFont = new Font("Consolas", 12, GraphicsUnit.Pixel); SetCharSize(); }
public bool kind; // selected = false, protected = true public DisplayInfo(ImageResource imgRes) { BinaryReverseReader reader = imgRes.GetDataReader(); this.ColorSpace = (ColorModes)reader.ReadInt16(); for (int i = 0; i < 4; i++) { this.Color[i] = reader.ReadInt16(); } this.Opacity = (short)Math.Max(0, Math.Min(100, (int)reader.ReadInt16())); this.kind = reader.ReadByte() == 0?false:true; reader.Close(); }
public Header(BinaryPSDReader reader) { this.Version = reader.ReadUInt16(); if (Version != 1) { throw new Exception("Can not read .psd version " + Version); } byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); }
public ParticleType() { Color = Color2 = Color.White; ColorMode = ColorModes.Static; Speed = SpeedRange = 0; SpeedMultiplier = 1; Acceleration = Vector2.Zero; Friction = 0f; Direction = DirectionRange = 0; Life = LifeRange = 0; Size = 2; SizeRange = 0; Rotated = true; AllTypes.Add(this); }
public ParticleType() { Color = Color2 = Color.White; ColorMode = ColorModes.Static; FadeMode = FadeModes.None; SpeedMin = SpeedMax = 0; SpeedMultiplier = 1; Acceleration = Vector2.Zero; Friction = 0f; Direction = DirectionRange = 0; LifeMin = LifeMax = 0; Size = 2; SizeRange = 0; SpinMin = SpinMax = 0; SpinFlippedChance = false; RotationMode = RotationModes.None; AllTypes.Add(this); }
public Pattern(BinaryPSDReader r) { long startPos = r.BaseStream.Position; uint length = r.ReadUInt32(); uint version = r.ReadUInt32(); this.ColorMode = (ColorModes)r.ReadUInt32(); this.Loc = new EPoint(r.ReadUInt16(), r.ReadUInt16()); //TODO: signed?? this.Name = r.ReadPSDUnicodeString(); this.Id = r.ReadPascalString(); //? if (this.ColorMode == ColorModes.Indexed) { this.PaletteForXml = ""; for (int i = 0; i < 256; i++) { string s = ""; for (int j = 0; j < 3; j++) { s += r.ReadByte().ToString("X"); } this.PaletteForXml += s; } } byte[] imageData = r.ReadBytes((int)(length - (int)r.BaseStream.Position - startPos)); //TODO: what is the format? //System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData); //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream); //this.ImageData = Endogine.Serialization.ReadableBinary.CreateHexEditorString(imageData); //TODO: length isn't correct! By 6 bytes always?? if (r.BytesToEnd < 20) { r.BaseStream.Position = r.BaseStream.Length; } }
public ParticleType(ParticleType copy) { Source = copy.Source; Color = copy.Color; Color2 = copy.Color2; ColorMode = copy.ColorMode; Speed = copy.Speed; SpeedRange = copy.SpeedRange; SpeedMultiplier = copy.SpeedMultiplier; Acceleration = copy.Acceleration; Friction = copy.Friction; Direction = copy.Direction; DirectionRange = copy.DirectionRange; Life = copy.Life; LifeRange = copy.LifeRange; Size = copy.Size; SizeRange = copy.SizeRange; Rotated = copy.Rotated; RandomRotate = copy.RandomRotate; ScaleOut = copy.ScaleOut; UseActualDeltaTime = copy.UseActualDeltaTime; AllTypes.Add(this); }
protected override void AssignColorFromCurrentRenderers(Color newColor, TransitionTargets target, ColorModes mixMode) { if (RenderersTable != null) { Material[] mats = null; foreach (KeyValuePair <Renderer, Color[]> pair in RenderersTable) { Renderer r = pair.Key; Color[] startColors = pair.Value; mats = UseSharedMaterials ? r.sharedMaterials : r.materials; for (int i = 0; i < mats.Length; i++) { if (mats[i].HasProperty(MaterialPropertyName)) { if ((MyColorTransition) && (MyColorTransition.InProgress)) { mats[i].SetColor(MaterialPropertyName, ApplyColorMode(mats[i].GetColor(MaterialPropertyName), newColor, target, mixMode)); } else { mats[i].SetColor(MaterialPropertyName, ApplyColorMode(startColors[i], newColor, target, mixMode)); } } } } } }
/// <summary> /// assigns a color mixing it with the current color of each graphics or renderer component /// </summary> /// <param name="newColor">color to assign</param> /// <param name="target">Color, Alpha or Color and Alpha</param> /// <param name="mixMode">mix mode</param> public virtual void AssignColorFromCurrent(Color newColor, TransitionTargets target, ColorModes mixMode) { AssignColorFromCurrentGraphics(newColor, target, mixMode); AssignColorFromCurrentRenderers(newColor, target, mixMode); }
private void Load(Stream stream, bool ignoreImageResources, bool ignoreLayers, bool ignoreLayerBitmaps, bool ignoreMergedBitmap) { Reader reader = new Reader(stream); #region PSD인지 검사합니다. { string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") { throw new Exception("올바른 PSD File이 아닙니다."); } short version = reader.ReadInt16(); if (version != 1) { throw new Exception("PSD File의 Version이 맞지 않습니다."); } } #endregion int channels = 0; int width = 0; int height = 0; int bitsPerPixel = 0; ColorModes colorMode = ColorModes.RGB; #region Header를 읽어옵니다. { reader.BaseStream.Position += 6; // 예약분 channels = reader.ReadInt16(); height = reader.ReadInt32(); width = reader.ReadInt32(); bitsPerPixel = reader.ReadInt16(); colorMode = (ColorModes)reader.ReadInt16(); if (colorMode != ColorModes.RGB) { throw new Exception(string.Format("{0} Color Format인 PSD는 읽어올 수 없습니다. (가능한 Color Format : RGB)", colorMode)); } if (bitsPerPixel != 8) { throw new Exception(string.Format("한 Pixel이 Channel당 {0} byte인 PSD는 읽어올 수 없습니다. (가능한 Bytes : 1 Byte", bitsPerPixel / 8)); } } #endregion byte[] colorModeData = null; #region ColorModeData를 가져옵니다. { uint sectionSize = reader.ReadUInt32(); if (sectionSize > 0) { colorModeData = reader.ReadBytes((int)sectionSize); } } #endregion List <ImageResource> imageResources = new List <ImageResource>(); #region ImageResource들을 읽어옵니다. { uint sectionSize = reader.ReadUInt32(); if (sectionSize > 0) { long sectionEndPosition = reader.BaseStream.Position + (long)sectionSize; if (ignoreImageResources == false) { while (reader.BaseStream.Position < sectionEndPosition) { string signature = new string(reader.ReadChars(4)); if (signature != "8BIM" && signature != "MeSa") { throw new Exception("올바르지 않은 ImageResource가 존재합니다."); } ImageResourceID id = (ImageResourceID)reader.ReadInt16(); string name = reader.ReadPascalString(); uint size = reader.ReadUInt32(); long endPosition = reader.BaseStream.Position + (long)size; if (size > 0) { ImageResource resource = CreateImageResource(id, name, size, reader); if (resource != null) { imageResources.Add(resource); } } // 위치는 짝수로 맞춥니다. reader.BaseStream.Position = (endPosition % 2 == 0) ? endPosition : endPosition + 1; } } reader.BaseStream.Position = sectionEndPosition; } } #endregion List <Layer> layers = new List <Layer>(); #region Layer와 Mask 정보를 읽어옵니다. { uint sectionSize = reader.ReadUInt32(); if (sectionSize > 0) { long sectionEndPosition = reader.BaseStream.Position + (long)sectionSize; if (ignoreLayers == false) { #region Layer를 읽어옵니다. uint layersSize = reader.ReadUInt32(); if (layersSize > 0) { long layersEndPosition = reader.BaseStream.Position + (long)layersSize; //bool absoluteAlpha = false; short numberOfLayers = reader.ReadInt16(); if (numberOfLayers < 0) { //absoluteAlpha = true; numberOfLayers = Math.Abs(numberOfLayers); } #region Layer들의 기본 정보를 읽어서 보관합니다. for (short i = 0; i < numberOfLayers; i++) { layers.Add(new Layer(reader)); } #endregion #region Layer들의 Pixel 정보를 읽어옵니다. foreach (Layer layer in layers) { if (ignoreLayerBitmaps == false) { layer.ReadPixelData(bitsPerPixel, reader); } else { layer.SkipPixelData(bitsPerPixel, reader); } } #endregion #region Group을 정리합니다. { Stack <Layer> layerStack = new Stack <Layer>(layers.Count / 2); for (int i = layers.Count - 1; i >= 0; i--) { Layer item = layers[i]; bool isEndLayerSetTag = (item.Name.StartsWith("</Layer set>")) || (item.Name.StartsWith("</Layer group>")); if (layerStack.Count > 0 && isEndLayerSetTag == false) { layerStack.Peek().AddSubLayer(item); } if (item.IsGroup) { if (isEndLayerSetTag == false) { layerStack.Push(item); } else { layerStack.Pop(); layers.RemoveAt(i); } } } for (int i = 0; i < layers.Count;) { if (layers[i].Group != null) { layers.RemoveAt(i); } else { i++; } } } #endregion reader.BaseStream.Position = layersEndPosition; } #endregion #region Layer Global Mask 정보를 읽어옵니다. uint layerGlobalMaskSize = reader.ReadUInt32(); if (layerGlobalMaskSize > 0) { long layerGlobalMaskEndPosition = reader.BaseStream.Position + (long)layerGlobalMaskSize; reader.BaseStream.Position = layerGlobalMaskEndPosition; } #endregion #region Layer 추가 정보를 읽어옵니다. /* * while (reader.BaseStream.Position < sectionEndPosition) * { * string signature = new string(reader.ReadChars(4)); * string fourcc = new string(reader.ReadChars(4)); * uint additionalInfoLength = reader.ReadUInt32(); * long additionalInfoEndPosition = reader.BaseStream.Position + (long)additionalInfoLength; * * reader.BaseStream.Position = additionalInfoEndPosition; * } */ #endregion } reader.BaseStream.Position = sectionEndPosition; } #region Canvas 밖으로 나간 레이어 정보를 잘라냅니다. // Canvas 밖에 있는 레이어 픽셀 정보는 // 포토샵을 통해서 확인하기도 힘들고 잘라내기조차도 번거롭기 때문에 // 모두 잘라냅니다. foreach (var item in layers) { item.ClipByCanvas(width, height, true); } #endregion } #endregion Bitmap mergedImageData = null; byte[][] mergedImageChannelData = null; #region PSD 마지막 부분에 있는 합쳐진 Image를 읽어옵니다. int numberOfPixels = width * height; Compression compressionMode = (Compression)reader.ReadInt16(); mergedImageChannelData = new byte[channels][]; if (ignoreMergedBitmap == false) { #region Channel 별로 기록된 Pixel Data를 읽어옵니다. switch (compressionMode) { case Compression.RawData: for (int i = 0; i < mergedImageChannelData.Length; i++) { mergedImageChannelData[i] = reader.ReadRawPixelData(width, height, bitsPerPixel); } break; case Compression.RLECompression: // 행별로 열의 길이가 기록되어 있습니다만 무시합니다. reader.BaseStream.Position += height * channels * 2; for (int i = 0; i < mergedImageChannelData.Length; i++) { mergedImageChannelData[i] = reader.ReadRLECompressedPixelData(width, height, bitsPerPixel); } break; default: throw new Exception(string.Format("{0} 로 저장된 PSD는 읽어올 수 없습니다. (프로그래머에게 연락하세요)", compressionMode)); } #endregion #region BitmapContent에 Pixel들을 채워 넣습니다. switch (colorMode) { case ColorModes.RGB: if (channels == 3) { mergedImageData = MergeChannels(width, height, mergedImageChannelData[0], mergedImageChannelData[1], mergedImageChannelData[2], null); } else if (channels >= 4) { mergedImageData = MergeChannels(width, height, mergedImageChannelData[0], mergedImageChannelData[1], mergedImageChannelData[2], mergedImageChannelData[3]); } break; } #endregion } #endregion #region 읽어온 정보들을 Field에 설정합니다. this.Channels = channels; this.Width = width; this.Height = height; this.BitsPerPixel = bitsPerPixel; this.ColorMode = colorMode; this.imageResources = imageResources; this.layers = layers; this.readOnlyImageResources = new ReadOnlyCollection <ImageResource>(this.imageResources); this.readOnlyLayers = new ReadOnlyCollection <Layer>(this.layers); this.MergedBitmap = mergedImageData; #endregion }
protected virtual void AssignColorFromCurrentGraphics(Color newColor, TransitionTargets target, ColorModes mixMode) { if (GraphicsTable != null) { foreach (KeyValuePair <UnityEngine.UI.Graphic, Color> pair in GraphicsTable) { UnityEngine.UI.Graphic g = pair.Key; g.color = ApplyColorMode(g.color, newColor, target, mixMode); } } }
/////////////////////////////////////////////////////////////////////////// private void LoadHeader(BinaryReverseReader reader) { Debug.WriteLine("LoadHeader started at " + reader.BaseStream.Position); var signature = new string(reader.ReadChars(4)); if (signature != "8BPS") throw new IOException("The given stream is not a valid PSD file"); m_version = reader.ReadInt16(); if (m_version != 1) throw new IOException("The PSD file has an unkown version"); //6 bytes reserved reader.BaseStream.Position += 6; m_channels = reader.ReadInt16(); m_rows = reader.ReadInt32(); m_columns = reader.ReadInt32(); m_depth = reader.ReadInt16(); m_colorMode = (ColorModes) reader.ReadInt16(); }
protected Color ApplyColorMode(Color startColor, Color newColor, TransitionTargets target, ColorModes mixMode) { Color32 s32; Color32 n32; switch (mixMode) { case ColorModes.Add: newColor += startColor; newColor.r = Mathf.Clamp01(newColor.r); newColor.g = Mathf.Clamp01(newColor.g); newColor.b = Mathf.Clamp01(newColor.b); newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.AddHDR: newColor += startColor; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.Multiply: newColor.r *= startColor.r; newColor.g *= startColor.g; newColor.b *= startColor.b; newColor.a *= startColor.a; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.Subtract: newColor = startColor - newColor; newColor.r = Mathf.Clamp01(newColor.r); newColor.g = Mathf.Clamp01(newColor.g); newColor.b = Mathf.Clamp01(newColor.b); newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.Invert: ApplyColorMode(startColor, newColor, target, ColorModes.Replace); newColor = new Color(1, 1, 1, 1) - newColor; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.And: s32 = startColor; n32 = newColor; n32.r &= s32.r; n32.g &= s32.g; n32.b &= s32.b; n32.a &= s32.a; newColor = n32; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.Or: s32 = startColor; n32 = newColor; n32.r |= s32.r; n32.g |= s32.g; n32.b |= s32.b; n32.a |= s32.a; newColor = n32; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.Xor: s32 = startColor; n32 = newColor; n32.r ^= s32.r; n32.g ^= s32.g; n32.b ^= s32.b; n32.a ^= s32.a; newColor = n32; newColor.a = Mathf.Clamp01(newColor.a); break; case ColorModes.IfDarker: newColor.r = Mathf.Min(startColor.r, newColor.r); newColor.g = Mathf.Min(startColor.g, newColor.g); newColor.b = Mathf.Min(startColor.b, newColor.b); newColor.a = Mathf.Min(startColor.a, newColor.a); break; case ColorModes.IfLighter: newColor.r = Mathf.Max(startColor.r, newColor.r); newColor.g = Mathf.Max(startColor.g, newColor.g); newColor.b = Mathf.Max(startColor.b, newColor.b); newColor.a = Mathf.Max(startColor.a, newColor.a); break; case ColorModes.Replace: default: ; break; } switch (target) { case TransitionTargets.Alpha: newColor.r = startColor.r; newColor.g = startColor.g; newColor.b = startColor.b; break; case TransitionTargets.Color: newColor.a = startColor.a; break; case TransitionTargets.ColorAndAlpha: ; break; } // NoticeMessage( "start: " + startColor + " - newColor: " + newColor ); return(newColor); }
protected override void AssignColorFromCurrentGraphics(Color newColor, TransitionTargets target, ColorModes mixMode) { if (GraphicsTable != null) { foreach (KeyValuePair <Graphic, Color> pair in GraphicsTable) { Graphic g = pair.Key; if (MyColorTransition.InProgress) { g.color = ApplyColorMode(g.color, newColor, target, mixMode); } else { g.color = ApplyColorMode(GraphicsTable[g], newColor, target, mixMode); } } } }
public Document(string a_sFilename) { FileStream stream = new FileStream(a_sFilename, FileMode.Open, FileAccess.Read); //stream. BinaryReverseReader reader = new BinaryReverseReader(stream); //, System.Text.Encoding.UTF8); //System.Text.Encoding.BigEndianUnicode); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") return; #region Header this.Version = reader.ReadUInt16(); if (Version != 1) throw new Exception("Can not read .psd version " + Version); byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = (int)reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); #endregion #region Palette uint nPaletteLength = reader.ReadUInt32(); if (nPaletteLength > 0) { this.ColorData = reader.ReadBytes((int)nPaletteLength); if (this.ColorMode == ColorModes.Duotone) { } else { } } #endregion #region ImageResource section uint nResLength = reader.ReadUInt32(); ResourceIDs resID = ResourceIDs.Undefined; if (nResLength > 0) { //read settings while (true) { long nBefore = reader.BaseStream.Position; string settingSignature = new string(reader.ReadChars(4)); if (settingSignature != "8BIM") { reader.BaseStream.Position = nBefore; //TODO: it SHOULD be 4 bytes back - but sometimes ReadChars(4) advances 5 positions. WHY?!? // reader.BaseStream.Position-=4; break; } ImageResource imgRes = new ImageResource(reader); resID = (ResourceIDs)imgRes.ID; switch (resID) //imgRes.ID) { case ResourceIDs.ResolutionInfo: this.ResolutionInfo = new Endogine.Serialization.Photoshop.ImageResources.ResolutionInfo(imgRes); break; case ResourceIDs.DisplayInfo: ImageResources.DisplayInfo displayInfo = new Endogine.Serialization.Photoshop.ImageResources.DisplayInfo(imgRes); break; case ResourceIDs.CopyrightInfo: ImageResources.CopyrightInfo copyright = new Endogine.Serialization.Photoshop.ImageResources.CopyrightInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: ImageResources.Thumbnail thumbnail = new Endogine.Serialization.Photoshop.ImageResources.Thumbnail(imgRes); break; case ResourceIDs.GlobalAngle: //m_nGlobalAngle = reader.ReadInt32(); break; case ResourceIDs.IndexedColorTableCount: this.NumColors = reader.ReadInt16(); break; case ResourceIDs.TransparentIndex: //m_nTransparentIndex = reader.ReadInt16(); break; case ResourceIDs.Slices://Slices. What's that..? //Leftlong, Botmlong etc etc break; case ResourceIDs.XMLInfo: break; case ResourceIDs.Unknown: //Seems to be very common... break; } } } #endregion if (resID == ResourceIDs.Unknown4) { //it seems this one is } //reader.JumpToEvenNthByte(4); int nTotalLayersBytes = reader.ReadInt32(); long nAfterLayersDefinitions = reader.BaseStream.Position + nTotalLayersBytes; //TODO: ?? if (nTotalLayersBytes == 8) stream.Position+=nTotalLayersBytes; uint nSize = reader.ReadUInt32(); long nLayersEndPos = reader.BaseStream.Position + nSize; short nNumLayers = reader.ReadInt16(); bool bSkipFirstAlpha = false; if (nNumLayers < 0) { bSkipFirstAlpha = true; nNumLayers = (short)-nNumLayers; } List<Layer> loadOrderLayers = new List<Layer>(); this._layers = new Dictionary<int, Layer>(); for (int nLayerNum = 0; nLayerNum < nNumLayers; nLayerNum++) { Layer layerInfo = new Layer(reader, this); if (this._layers.ContainsKey(layerInfo.LayerID)) throw(new Exception("Duplicate layer IDs! " + layerInfo.LayerID.ToString())); else this._layers.Add(layerInfo.LayerID, layerInfo); loadOrderLayers.Add(layerInfo); } //I have no idea what this is: // ushort nWhat = reader.ReadUInt16(); // reader.BaseStream.Position+=(long)this.Header.Rows*2*2; //this.Header.Channels; //*bitsperpixel for (int layerNum = 0; layerNum < nNumLayers; layerNum++) { Layer layer = (Layer)loadOrderLayers[layerNum]; layer.ReadPixels(reader); } reader.BaseStream.Position = nAfterLayersDefinitions; if (false) { //the big merged bitmap (which is how the photoshop document looked when it was saved) //TODO: read! //Bitmap bmp = null; //if (bmp != null) //{ // Sprite sp = new Sprite(); // MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); // sp.Member = mb; //} } reader.Close(); stream.Close(); }
// attributes public static void ColorMode(ColorModes mode, float maxValue) { _colorMode = mode; _maxColorValue = maxValue; }
public void Load(Stream stream) { //binary reverse reader reads data types in big-endian format. BinaryReverseReader reader = new BinaryReverseReader(stream); //The headers area is used to check for a valid PSD file Debug.WriteLine("LoadHeader started at " + reader.BaseStream.Position.ToString()); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") throw new IOException("Bad or invalid file stream supplied"); //get the version number, should be 1 always if ((m_version = reader.ReadInt16()) != 1) throw new IOException("Invalid version number supplied"); //get rid of the 6 bytes reserverd in PSD format reader.BaseStream.Position += 6; //get the rest of the information from the PSD file. //Everytime ReadInt16() is called, it reads 2 bytes. //Everytime ReadInt32() is called, it reads 4 bytes. m_channels = reader.ReadInt16(); m_rows = reader.ReadInt32(); m_columns = reader.ReadInt32(); m_depth = reader.ReadInt16(); m_colorMode = (ColorModes)reader.ReadInt16(); //by end of headers, the reader has read 26 bytes into the file. /// <summary> /// If ColorMode is ColorModes.Indexed, the following 768 bytes will contain /// a 256-color palette. If the ColorMode is ColorModes.Duotone, the data /// following presumably consists of screen parameters and other related information. /// Unfortunately, it is intentionally not documented by Adobe, and non-Photoshop /// readers are advised to treat duotone images as gray-scale images. /// </summary> Debug.WriteLine("LoadColorModeData started at " + reader.BaseStream.Position.ToString()); uint paletteLength = reader.ReadUInt32(); //readUint32() advances the reader 4 bytes. if (paletteLength > 0) { ColorModeData = reader.ReadBytes((int)paletteLength); } //This part takes extensive use of classes that I didn't write therefore //I can't document much on what they do. Debug.WriteLine("LoadingImageResources started at " + reader.BaseStream.Position.ToString()); m_imageResources.Clear(); uint imgResLength = reader.ReadUInt32(); if (imgResLength > 0) { long startPosition = reader.BaseStream.Position; while ((reader.BaseStream.Position - startPosition) < imgResLength) { ImageResource imgRes = new ImageResource(reader); ResourceIDs resID = (ResourceIDs)imgRes.ID; switch (resID) { case ResourceIDs.ResolutionInfo: imgRes = new ResolutionInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: imgRes = new Thumbnail(imgRes); break; case ResourceIDs.AlphaChannelNames: imgRes = new AlphaChannels(imgRes); break; } m_imageResources.Add(imgRes); } // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = startPosition + imgResLength; //We are gonna load up all the layers and masking of the PSD now. Debug.WriteLine("LoadLayerAndMaskInfo - Part1 started at " + reader.BaseStream.Position.ToString()); uint layersAndMaskLength = reader.ReadUInt32(); if (layersAndMaskLength > 0) { //new start position startPosition = reader.BaseStream.Position; //Lets start by loading up all the layers LoadLayers(reader); //we are done the layers, load up the masks LoadGlobalLayerMask(reader); // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = startPosition + layersAndMaskLength; //we have loaded up all the information from the PSD file //into variables we can use later on. //lets finish loading the raw data that defines the image //in the picture. Debug.WriteLine("LoadImage started at " + reader.BaseStream.Position.ToString()); m_imageCompression = (ImageCompression)reader.ReadInt16(); m_imageData = new byte[m_channels][]; //--------------------------------------------------------------- if (m_imageCompression == ImageCompression.Rle) { // The RLE-compressed data is proceeded by a 2-byte data count for each row in the data, // which we're going to just skip. reader.BaseStream.Position += m_rows * m_channels * 2; } //--------------------------------------------------------------- int bytesPerRow = 0; switch (m_depth) { case 1: bytesPerRow = m_columns;//NOT Sure break; case 8: bytesPerRow = m_columns; break; case 16: bytesPerRow = m_columns * 2; break; } //--------------------------------------------------------------- for (int ch = 0; ch < m_channels; ch++) { m_imageData[ch] = new byte[m_rows * bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: reader.Read(m_imageData[ch], 0, m_imageData[ch].Length); break; case ImageCompression.Rle: { for (int i = 0; i < m_rows; i++) { int rowIndex = i * m_columns; RleHelper.DecodedRow(reader.BaseStream, m_imageData[ch], rowIndex, bytesPerRow); } } break; default: break; } } } } }
public Document(string a_sFilename) { FileStream stream = new FileStream(a_sFilename, FileMode.Open, FileAccess.Read); //stream. BinaryReverseReader reader = new BinaryReverseReader(stream); //, System.Text.Encoding.UTF8); //System.Text.Encoding.BigEndianUnicode); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") { return; } #region Header this.Version = reader.ReadUInt16(); if (Version != 1) { throw new Exception("Can not read .psd version " + Version); } byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = (int)reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); #endregion #region Palette uint nPaletteLength = reader.ReadUInt32(); if (nPaletteLength > 0) { this.ColorData = reader.ReadBytes((int)nPaletteLength); if (this.ColorMode == ColorModes.Duotone) { } else { } } #endregion #region ImageResource section uint nResLength = reader.ReadUInt32(); ResourceIDs resID = ResourceIDs.Undefined; if (nResLength > 0) { //read settings while (true) { long nBefore = reader.BaseStream.Position; string settingSignature = new string(reader.ReadChars(4)); if (settingSignature != "8BIM") { reader.BaseStream.Position = nBefore; //TODO: it SHOULD be 4 bytes back - but sometimes ReadChars(4) advances 5 positions. WHY?!? // reader.BaseStream.Position-=4; break; } ImageResource imgRes = new ImageResource(reader); resID = (ResourceIDs)imgRes.ID; switch (resID) //imgRes.ID) { case ResourceIDs.ResolutionInfo: this.ResolutionInfo = new Endogine.Serialization.Photoshop.ImageResources.ResolutionInfo(imgRes); break; case ResourceIDs.DisplayInfo: ImageResources.DisplayInfo displayInfo = new Endogine.Serialization.Photoshop.ImageResources.DisplayInfo(imgRes); break; case ResourceIDs.CopyrightInfo: ImageResources.CopyrightInfo copyright = new Endogine.Serialization.Photoshop.ImageResources.CopyrightInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: ImageResources.Thumbnail thumbnail = new Endogine.Serialization.Photoshop.ImageResources.Thumbnail(imgRes); break; case ResourceIDs.GlobalAngle: //m_nGlobalAngle = reader.ReadInt32(); break; case ResourceIDs.IndexedColorTableCount: this.NumColors = reader.ReadInt16(); break; case ResourceIDs.TransparentIndex: //m_nTransparentIndex = reader.ReadInt16(); break; case ResourceIDs.Slices: //Slices. What's that..? //Leftlong, Botmlong etc etc break; case ResourceIDs.XMLInfo: break; case ResourceIDs.Unknown: //Seems to be very common... break; } } } #endregion if (resID == ResourceIDs.Unknown4) { //it seems this one is } //reader.JumpToEvenNthByte(4); int nTotalLayersBytes = reader.ReadInt32(); long nAfterLayersDefinitions = reader.BaseStream.Position + nTotalLayersBytes; //TODO: ?? if (nTotalLayersBytes == 8) { stream.Position += nTotalLayersBytes; } uint nSize = reader.ReadUInt32(); long nLayersEndPos = reader.BaseStream.Position + nSize; short nNumLayers = reader.ReadInt16(); bool bSkipFirstAlpha = false; if (nNumLayers < 0) { bSkipFirstAlpha = true; nNumLayers = (short)-nNumLayers; } List <Layer> loadOrderLayers = new List <Layer>(); this._layers = new Dictionary <int, Layer>(); for (int nLayerNum = 0; nLayerNum < nNumLayers; nLayerNum++) { Layer layerInfo = new Layer(reader, this); if (this._layers.ContainsKey(layerInfo.LayerID)) { throw(new Exception("Duplicate layer IDs! " + layerInfo.LayerID.ToString())); } else { this._layers.Add(layerInfo.LayerID, layerInfo); } loadOrderLayers.Add(layerInfo); } //I have no idea what this is: // ushort nWhat = reader.ReadUInt16(); // reader.BaseStream.Position+=(long)this.Header.Rows*2*2; //this.Header.Channels; //*bitsperpixel for (int layerNum = 0; layerNum < nNumLayers; layerNum++) { Layer layer = (Layer)loadOrderLayers[layerNum]; layer.ReadPixels(reader); } reader.BaseStream.Position = nAfterLayersDefinitions; if (false) { //the big merged bitmap (which is how the photoshop document looked when it was saved) //TODO: read! //Bitmap bmp = null; //if (bmp != null) //{ // Sprite sp = new Sprite(); // MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); // sp.Member = mb; //} } reader.Close(); stream.Close(); }
private void OnGUI() { GUILayout.Space(15.0f); scrollPos = GUILayout.BeginScrollView(scrollPos); //Make sure we have enough graphs. int nGraphs = -1; switch (OutputMode) { case ColorModes.Custom: nGraphs = EditorGUILayout.DelayedIntField("# Graphs", chosenGraphs.Count); break; case ColorModes.Gradient: nGraphs = 1; break; case ColorModes.Make2DVec: nGraphs = 2; break; default: throw new NotImplementedException(OutputMode.ToString()); } while (nGraphs > chosenGraphs.Count) { chosenGraphs.Add(new GraphSelection()); } while (nGraphs < chosenGraphs.Count) { chosenGraphs.RemoveAt(chosenGraphs.Count - 1); } for (int graphI = 0; graphI < nGraphs; ++graphI) { GUILayout_TabIn(25.0f); var graph = chosenGraphs[graphI]; var changes = graph.DoGUILayout("Graph " + (graphI + 1), graphPaths, graphNameOptions); switch (changes) { case GraphSelection.ChangeTypes.None: break; case GraphSelection.ChangeTypes.Params: GetPreview(false); break; case GraphSelection.ChangeTypes.Everything: GetPreview(true); break; default: throw new NotImplementedException(changes.ToString()); } GUILayout_TabOut(); GUILayout.Space(25.0f); } //Do color-mode-specific UI. OutputMode = (ColorModes)EditorGUILayout.EnumPopup("Mode", OutputMode); switch (OutputMode) { case ColorModes.Gradient: //Choose the color gradient. GUILayout.Label("Gradient"); GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginVertical(); for (int i = 0; i < Output_Gradient_Colors.Count; ++i) { GUILayout.BeginHorizontal(); //Edit the color value. EditorGUI.BeginChangeCheck(); Output_Gradient_Colors[i] = EditorGUILayout.ColorField(Output_Gradient_Colors[i]); if (i > 0) { Output_Gradient_Times[i] = EditorGUILayout.Slider(Output_Gradient_Times[i], 0.0f, 1.0f); } if (EditorGUI.EndChangeCheck()) { GetPreview(true); } //Button to insert a new element. if (i > 0 && GUILayout.Button("+")) { Output_Gradient_Colors.Insert(i, Output_Gradient_Colors[i]); Output_Gradient_Times.Insert(i, Output_Gradient_Times[i] - 0.00000001f); GetPreview(true); } //Button to remove this element. if (i > 0 && Output_Gradient_Colors.Count > 2 && GUILayout.Button("-")) { Output_Gradient_Colors.RemoveAt(i); Output_Gradient_Times.RemoveAt(i); i -= 1; GetPreview(true); } GUILayout.EndHorizontal(); //Make sure elements are in order. if (i > 0 && Output_Gradient_Times[i] < Output_Gradient_Times[i - 1]) { Output_Gradient_Times[i] = Output_Gradient_Times[i - 1] + 0.000001f; GetPreview(true); } else if (i < Output_Gradient_Colors.Count - 1 && Output_Gradient_Times[i] > Output_Gradient_Times[i + 1]) { Output_Gradient_Times[i] = Output_Gradient_Times[i + 1] - 0.00001f; GetPreview(true); } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); break; case ColorModes.Make2DVec: GUILayout.BeginHorizontal(); GUILayout.Space(30.0f); GUILayout.BeginVertical(); EditorGUI.BeginChangeCheck(); Output_AngleTo2DVec_Pack01 = EditorGUILayout.Toggle("Pack into range [0,1]", Output_AngleTo2DVec_Pack01); if (EditorGUI.EndChangeCheck()) { GetPreview(true); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); break; case ColorModes.Custom: GUILayout.BeginHorizontal(); GUILayout.Space(30.0f); GUILayout.BeginVertical(); if (GUILayout.Button("Regenerate preview")) { GetPreview(true); } string args = ""; for (int graphI = 0; graphI < chosenGraphs.Count; ++graphI) { if (graphI > 0) { args += ", "; } args += "float graphResult" + (graphI + 1); } GUILayout.Label("float4 getTexOutputColor(" + args + ")"); GUILayout.Label("{"); GUILayout.BeginHorizontal(); GUILayout.Space(30.0f); GUILayout.BeginVertical(); Output_Custom_CodeBody = EditorGUILayout.TextArea(Output_Custom_CodeBody); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Label("}"); GUILayout.EndVertical(); GUILayout.EndHorizontal(); break; default: throw new NotImplementedException(OutputMode.ToString()); } GUILayout.Space(15.0f); DoCustomGUI(); GUILayout.Space(15.0f); //Show the preview texture. if (previewTex != null) { //Preview scale slider. GUILayout.BeginHorizontal(); { GUILayout.Label("Preview Scale"); //Use a nonlinear scale for the slider. float t = Mathf.Log10(previewScale); float resultT = GUILayout.HorizontalSlider(t, -2.0f, 2.0f, GUILayout.Width(position.width - 40.0f)); previewScale = Mathf.Pow(10.0f, resultT); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { //Slider for preview UV z. GUILayout.BeginVertical(); { float oldZ = previewUVz; GUILayout.Label("Z"); previewUVzMax = EditorGUILayout.FloatField(previewUVzMax, GUILayout.Width(20.0f)); previewUVz = GUILayout.VerticalSlider(previewUVz, previewUVzMin, previewUVzMax, GUILayout.Height(previewTex.height * previewScale - (15.0f * 3))); previewUVzMin = EditorGUILayout.FloatField(previewUVzMin, GUILayout.Width(20.0f)); if (oldZ != previewUVz) { GetPreview(false); } } GUILayout.EndVertical(); Rect texPos = EditorGUILayout.GetControlRect(GUILayout.Width(previewTex.width * previewScale), GUILayout.Height(previewTex.height * previewScale)); EditorGUI.DrawPreviewTexture(texPos, previewTex); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } //If a graph is selected, display a button to generate the texture. if (graphPaths.Count > 0) { if (GUILayout.Button("Generate Texture")) { GenerateTexture(); } } else { GUILayout.Space(15.0f); GUILayout.Label("No graph files detected in the project!"); } GUILayout.EndScrollView(); }
public void Load(string filename) { using (FileStream stream = new FileStream(filename, FileMode.Open)) { //binary reverse reader reads data types in big-endian format. BinaryReverseReader reader = new BinaryReverseReader(stream); #region "Headers" //The headers area is used to check for a valid PSD file Debug.WriteLine("LoadHeader started at " + reader.BaseStream.Position.ToString()); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") { throw new IOException("Bad or invalid file stream supplied"); } //get the version number, should be 1 always if ((m_version = reader.ReadInt16()) != 1) { throw new IOException("Invalid version number supplied"); } //get rid of the 6 bytes reserverd in PSD format reader.BaseStream.Position += 6; //get the rest of the information from the PSD file. //Everytime ReadInt16() is called, it reads 2 bytes. //Everytime ReadInt32() is called, it reads 4 bytes. m_channels = reader.ReadInt16(); m_rows = reader.ReadInt32(); m_columns = reader.ReadInt32(); m_depth = reader.ReadInt16(); m_colorMode = (ColorModes)reader.ReadInt16(); //by end of headers, the reader has read 26 bytes into the file. #endregion //End Headers #region "ColorModeData" /// <summary> /// If ColorMode is ColorModes.Indexed, the following 768 bytes will contain /// a 256-color palette. If the ColorMode is ColorModes.Duotone, the data /// following presumably consists of screen parameters and other related information. /// Unfortunately, it is intentionally not documented by Adobe, and non-Photoshop /// readers are advised to treat duotone images as gray-scale images. /// </summary> Debug.WriteLine("LoadColorModeData started at " + reader.BaseStream.Position.ToString()); uint paletteLength = reader.ReadUInt32(); //readUint32() advances the reader 4 bytes. if (paletteLength > 0) { ColorModeData = reader.ReadBytes((int)paletteLength); } #endregion //End ColorModeData #region "Loading Image Resources" //This part takes extensive use of classes that I didn't write therefore //I can't document much on what they do. Debug.WriteLine("LoadingImageResources started at " + reader.BaseStream.Position.ToString()); m_imageResources.Clear(); uint imgResLength = reader.ReadUInt32(); if (imgResLength <= 0) { return; } long startPosition = reader.BaseStream.Position; while ((reader.BaseStream.Position - startPosition) < imgResLength) { ImageResource imgRes = new ImageResource(reader); ResourceIDs resID = (ResourceIDs)imgRes.ID; switch (resID) { case ResourceIDs.ResolutionInfo: imgRes = new ResolutionInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: imgRes = new Thumbnail(imgRes); break; case ResourceIDs.AlphaChannelNames: imgRes = new AlphaChannels(imgRes); break; } m_imageResources.Add(imgRes); } // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = startPosition + imgResLength; #endregion //End LoadingImageResources #region "Layer and Mask Info" //We are gonna load up all the layers and masking of the PSD now. Debug.WriteLine("LoadLayerAndMaskInfo - Part1 started at " + reader.BaseStream.Position.ToString()); uint layersAndMaskLength = reader.ReadUInt32(); if (layersAndMaskLength <= 0) { return; } //new start position startPosition = reader.BaseStream.Position; //Lets start by loading up all the layers LoadLayers(reader); //we are done the layers, load up the masks LoadGlobalLayerMask(reader); // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = startPosition + layersAndMaskLength; #endregion //End Layer and Mask info #region "Loading Final Image" //we have loaded up all the information from the PSD file //into variables we can use later on. //lets finish loading the raw data that defines the image //in the picture. Debug.WriteLine("LoadImage started at " + reader.BaseStream.Position.ToString()); m_imageCompression = (ImageCompression)reader.ReadInt16(); m_imageData = new byte[m_channels][]; //--------------------------------------------------------------- if (m_imageCompression == ImageCompression.Rle) { // The RLE-compressed data is proceeded by a 2-byte data count for each row in the data, // which we're going to just skip. reader.BaseStream.Position += m_rows * m_channels * 2; } //--------------------------------------------------------------- int bytesPerRow = 0; switch (m_depth) { case 1: bytesPerRow = m_columns; //NOT Shure break; case 8: bytesPerRow = m_columns; break; case 16: bytesPerRow = m_columns * 2; break; } //--------------------------------------------------------------- for (int ch = 0; ch < m_channels; ch++) { m_imageData[ch] = new byte[m_rows * bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: reader.Read(m_imageData[ch], 0, m_imageData[ch].Length); break; case ImageCompression.Rle: { for (int i = 0; i < m_rows; i++) { int rowIndex = i * m_columns; RleHelper.DecodedRow(reader.BaseStream, m_imageData[ch], rowIndex, bytesPerRow); } } break; default: break; } } #endregion //End LoadingFinalImage } } //end Load()
public Pattern(BinaryPSDReader r) { long startPos = r.BaseStream.Position; uint length = r.ReadUInt32(); uint version = r.ReadUInt32(); this.ColorMode = (ColorModes)r.ReadUInt32(); this.Loc = new EPoint(r.ReadUInt16(), r.ReadUInt16()); //TODO: signed?? this.Name = r.ReadPSDUnicodeString(); this.Id = r.ReadPascalString(); //? if (this.ColorMode == ColorModes.Indexed) { this.PaletteForXml = ""; for (int i = 0; i < 256; i++) { string s = ""; for (int j = 0; j < 3; j++) s += r.ReadByte().ToString("X"); this.PaletteForXml += s; } } byte[] imageData = r.ReadBytes((int)(length - (int)r.BaseStream.Position - startPos)); //TODO: what is the format? //System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData); //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream); //this.ImageData = Endogine.Serialization.ReadableBinary.CreateHexEditorString(imageData); //TODO: length isn't correct! By 6 bytes always?? if (r.BytesToEnd < 20) r.BaseStream.Position = r.BaseStream.Length; }