UnicodeAlphaNames.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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-2014 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. internal class UnicodeAlphaNames : ImageResource
  21. {
  22. public override ResourceID ID
  23. {
  24. get { return ResourceID.UnicodeAlphaNames; }
  25. }
  26. private List<string> channelNames = new List<string>();
  27. public List<string> ChannelNames
  28. {
  29. get { return channelNames; }
  30. }
  31. public UnicodeAlphaNames()
  32. : base(String.Empty)
  33. {
  34. }
  35. public UnicodeAlphaNames(PsdBinaryReader reader, string name, int resourceDataLength)
  36. : base(name)
  37. {
  38. var endPosition = reader.BaseStream.Position + resourceDataLength;
  39. while (reader.BaseStream.Position < endPosition)
  40. {
  41. var channelName = reader.ReadUnicodeString();
  42. // Photoshop writes out a null terminator for Unicode alpha names.
  43. // There is no null terminator on other Unicode strings in PSD files.
  44. if (channelName.EndsWith("\0"))
  45. {
  46. channelName = channelName.Substring(0, channelName.Length - 1);
  47. }
  48. ChannelNames.Add(channelName);
  49. }
  50. }
  51. }
  52. }