PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Skimpt3/Skimpt3/classes/photoshop/ImageResources/AlphaChannels.cs

http://skimpt.googlecode.com/
C# | 77 lines | 42 code | 8 blank | 27 comment | 2 complexity | a4a51988cc061da44c12763d51576a44 MD5 | raw file
 1/////////////////////////////////////////////////////////////////////////////////
 2// Copyright (C) 2006, Frank Blumenberg
 3// 
 4// See License.txt for complete licensing and attribution information.
 5// Permission is hereby granted, free of charge, to any person obtaining a copy 
 6// of this software and associated documentation files (the "Software"), to deal
 7// in the Software without restriction, including without limitation the rights
 8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 9// copies of the Software, and to permit persons to whom the Software is 
10// furnished to do so, subject to the following conditions:
11// 
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14// 
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
21// THE SOFTWARE.
22// 
23/////////////////////////////////////////////////////////////////////////////////
24using System;
25using System.Collections.Generic;
26
27namespace Photoshop
28{
29  /// <summary>
30  /// The names of the alpha channels
31  /// </summary>
32  public class AlphaChannels : ImageResource
33  {
34    private List<string> m_channelNames=new List<string>();
35    public List<string> ChannelNames
36    {
37      get { return m_channelNames; }
38    }
39
40    public AlphaChannels(): base((short)ResourceIDs.AlphaChannelNames)
41    {
42    }
43
44    public AlphaChannels(ImageResource imgRes)
45      : base(imgRes)
46    {
47      
48      BinaryReverseReader reader = imgRes.DataReader;
49      // the names are pascal strings without padding!!!
50      while ((reader.BaseStream.Length - reader.BaseStream.Position) > 0)
51      {
52        byte stringLength = reader.ReadByte();
53        string s = new string(reader.ReadChars(stringLength));
54        if(s.Length>0)
55          m_channelNames.Add(s);
56      }
57      reader.Close();
58    }
59
60    protected override void StoreData()
61    {
62      System.IO.MemoryStream stream = new System.IO.MemoryStream();
63      BinaryReverseWriter writer = new BinaryReverseWriter(stream);
64
65      foreach (string name in m_channelNames)
66      {
67        writer.Write((byte)name.Length);
68        writer.Write(name.ToCharArray());
69      }
70
71      writer.Close();
72      stream.Close();
73
74      Data = stream.ToArray();
75    }
76  }
77}