ImageData.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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-2016 Tao Yue
  9. //
  10. // See LICENSE.txt for complete licensing and attribution information.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////////
  13. using System;
  14. using PDNWrapper;
  15. using System.IO.Compression;
  16. namespace PhotoshopFile.Compression
  17. {
  18. internal abstract class ImageData
  19. {
  20. public int BitDepth { get; private set; }
  21. public int BytesPerRow { get; private set; }
  22. public Size Size { get; private set; }
  23. protected abstract bool AltersWrittenData { get; }
  24. protected ImageData(Size size, int bitDepth)
  25. {
  26. Size = size;
  27. BitDepth = bitDepth;
  28. BytesPerRow = Util.BytesPerRow(size, bitDepth);
  29. }
  30. /// <summary>
  31. /// Reads decompressed image data.
  32. /// </summary>
  33. public virtual byte[] Read()
  34. {
  35. var imageLongLength = (long)BytesPerRow * Size.Height;
  36. Util.CheckByteArrayLength(imageLongLength);
  37. var buffer = new byte[imageLongLength];
  38. Read(buffer);
  39. return buffer;
  40. }
  41. internal abstract void Read(byte[] buffer);
  42. /// <summary>
  43. /// Reads compressed image data.
  44. /// </summary>
  45. public abstract byte[] ReadCompressed();
  46. }
  47. }