Thumbnail.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-2013 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. using System.IO;
  18. using System.Diagnostics;
  19. using PDNWrapper;
  20. //using PDNWrapper.Imaging;
  21. namespace PhotoshopFile
  22. {
  23. /// <summary>
  24. /// Summary description for Thumbnail.
  25. /// </summary>
  26. internal class Thumbnail : RawImageResource
  27. {
  28. public Thumbnail(ResourceID id, string name)
  29. : base(id, name)
  30. {
  31. }
  32. public Thumbnail(PsdBinaryReader psdReader, ResourceID id, string name, int numBytes)
  33. : base(psdReader, "8BIM", id, name, numBytes)
  34. {
  35. using (var memoryStream = new MemoryStream(Data))
  36. using (var reader = new PsdBinaryReader(memoryStream, psdReader))
  37. {
  38. const int HEADER_LENGTH = 28;
  39. var format = reader.ReadUInt32();
  40. //var width = reader.ReadUInt32();
  41. //var height = reader.ReadUInt32();
  42. //var widthBytes = reader.ReadUInt32();
  43. //var size = reader.ReadUInt32();
  44. //var compressedSize = reader.ReadUInt32();
  45. //var bitPerPixel = reader.ReadUInt16();
  46. //var planes = reader.ReadUInt16();
  47. // Raw RGB bitmap
  48. if (format == 0)
  49. {
  50. //Image = new Bitmap((int)width, (int)height, PixelFormat.Format24bppRgb);
  51. }
  52. // JPEG bitmap
  53. else if (format == 1)
  54. {
  55. byte[] imgData = reader.ReadBytes(numBytes - HEADER_LENGTH);
  56. using (MemoryStream stream = new MemoryStream(imgData))
  57. {
  58. //var bitmap = new Bitmap(stream);
  59. //Image = (Bitmap)bitmap.Clone();
  60. }
  61. // Reverse BGR pixels from old thumbnail format
  62. if (id == ResourceID.ThumbnailBgr)
  63. {
  64. //for(int y=0;y<m_thumbnailImage.Height;y++)
  65. // for (int x = 0; x < m_thumbnailImage.Width; x++)
  66. // {
  67. // Color c=m_thumbnailImage.GetPixel(x,y);
  68. // Color c2=Color.FromArgb(c.B, c.G, c.R);
  69. // m_thumbnailImage.SetPixel(x, y, c);
  70. // }
  71. }
  72. }
  73. else
  74. {
  75. throw new PsdInvalidException("Unknown thumbnail format.");
  76. }
  77. }
  78. }
  79. }
  80. }