AlphaChannelNames.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Photoshop PSD FileType Plugin for Paint.NET
  4. // http://psdplugin.codeplex.com/
  5. //
  6. // This software is provided under the MIT License:
  7. // Copyright (c) 2006-2007 Frank Blumenberg
  8. // Copyright (c) 2010-2017 Tao Yue
  9. //
  10. // See LICENSE.txt for complete licensing and attribution information.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////////
  13. using System;
  14. using System.Collections.Generic;
  15. namespace PhotoshopFile
  16. {
  17. /// <summary>
  18. /// The names of the alpha channels
  19. /// </summary>
  20. public class AlphaChannelNames : ImageResource
  21. {
  22. public override ResourceID ID => ResourceID.AlphaChannelNames;
  23. private List<string> channelNames = new List<string>();
  24. public List<string> ChannelNames => channelNames;
  25. public AlphaChannelNames() : base(String.Empty)
  26. {
  27. }
  28. public AlphaChannelNames(PsdBinaryReader reader, string name, int resourceDataLength)
  29. : base(name)
  30. {
  31. var endPosition = reader.BaseStream.Position + resourceDataLength;
  32. // Alpha channel names are Pascal strings, with no padding in-between.
  33. while (reader.BaseStream.Position < endPosition)
  34. {
  35. var channelName = reader.ReadPascalString(1);
  36. ChannelNames.Add(channelName);
  37. }
  38. }
  39. protected override void WriteData(PsdBinaryWriter writer)
  40. {
  41. foreach (var channelName in ChannelNames)
  42. {
  43. writer.WritePascalString(channelName, 1);
  44. }
  45. }
  46. }
  47. }