ResolutionInfo.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Portions of this file are provided under the BSD 3-clause License:
  11. // Copyright (c) 2006, Jonas Beckeman
  12. //
  13. // See LICENSE.txt for complete licensing and attribution information.
  14. //
  15. /////////////////////////////////////////////////////////////////////////////////
  16. using System;
  17. namespace PhotoshopFile
  18. {
  19. /// <summary>
  20. /// Summary description for ResolutionInfo.
  21. /// </summary>
  22. public class ResolutionInfo : ImageResource
  23. {
  24. public override ResourceID ID => ResourceID.ResolutionInfo;
  25. /// <summary>
  26. /// Horizontal DPI.
  27. /// </summary>
  28. public UFixed16_16 HDpi { get; set; }
  29. /// <summary>
  30. /// Vertical DPI.
  31. /// </summary>
  32. public UFixed16_16 VDpi { get; set; }
  33. /// <summary>
  34. /// 1 = pixels per inch, 2 = pixels per centimeter
  35. /// </summary>
  36. public enum ResUnit
  37. {
  38. PxPerInch = 1,
  39. PxPerCm = 2
  40. }
  41. /// <summary>
  42. /// Display units for horizontal resolution. This only affects the
  43. /// user interface; the resolution is still stored in the PSD file
  44. /// as pixels/inch.
  45. /// </summary>
  46. public ResUnit HResDisplayUnit { get; set; }
  47. /// <summary>
  48. /// Display units for vertical resolution.
  49. /// </summary>
  50. public ResUnit VResDisplayUnit { get; set; }
  51. /// <summary>
  52. /// Physical units.
  53. /// </summary>
  54. public enum Unit
  55. {
  56. Inches = 1,
  57. Centimeters = 2,
  58. Points = 3,
  59. Picas = 4,
  60. Columns = 5
  61. }
  62. public Unit WidthDisplayUnit { get; set; }
  63. public Unit HeightDisplayUnit { get; set; }
  64. public ResolutionInfo() : base(String.Empty)
  65. {
  66. }
  67. public ResolutionInfo(PsdBinaryReader reader, string name)
  68. : base(name)
  69. {
  70. this.HDpi = new UFixed16_16(reader.ReadUInt32());
  71. this.HResDisplayUnit = (ResUnit)reader.ReadInt16();
  72. this.WidthDisplayUnit = (Unit)reader.ReadInt16();
  73. this.VDpi = new UFixed16_16(reader.ReadUInt32());
  74. this.VResDisplayUnit = (ResUnit)reader.ReadInt16();
  75. this.HeightDisplayUnit = (Unit)reader.ReadInt16();
  76. }
  77. protected override void WriteData(PsdBinaryWriter writer)
  78. {
  79. writer.Write(HDpi.Integer);
  80. writer.Write(HDpi.Fraction);
  81. writer.Write((Int16)HResDisplayUnit);
  82. writer.Write((Int16)WidthDisplayUnit);
  83. writer.Write(VDpi.Integer);
  84. writer.Write(VDpi.Fraction);
  85. writer.Write((Int16)VResDisplayUnit);
  86. writer.Write((Int16)HeightDisplayUnit);
  87. }
  88. }
  89. }