/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. /////////////////////////////////////////////////////////////////////////////////
  24. using System;
  25. using System.Collections.Generic;
  26. namespace Photoshop
  27. {
  28. /// <summary>
  29. /// The names of the alpha channels
  30. /// </summary>
  31. public class AlphaChannels : ImageResource
  32. {
  33. private List<string> m_channelNames=new List<string>();
  34. public List<string> ChannelNames
  35. {
  36. get { return m_channelNames; }
  37. }
  38. public AlphaChannels(): base((short)ResourceIDs.AlphaChannelNames)
  39. {
  40. }
  41. public AlphaChannels(ImageResource imgRes)
  42. : base(imgRes)
  43. {
  44. BinaryReverseReader reader = imgRes.DataReader;
  45. // the names are pascal strings without padding!!!
  46. while ((reader.BaseStream.Length - reader.BaseStream.Position) > 0)
  47. {
  48. byte stringLength = reader.ReadByte();
  49. string s = new string(reader.ReadChars(stringLength));
  50. if(s.Length>0)
  51. m_channelNames.Add(s);
  52. }
  53. reader.Close();
  54. }
  55. protected override void StoreData()
  56. {
  57. System.IO.MemoryStream stream = new System.IO.MemoryStream();
  58. BinaryReverseWriter writer = new BinaryReverseWriter(stream);
  59. foreach (string name in m_channelNames)
  60. {
  61. writer.Write((byte)name.Length);
  62. writer.Write(name.ToCharArray());
  63. }
  64. writer.Close();
  65. stream.Close();
  66. Data = stream.ToArray();
  67. }
  68. }
  69. }