ImfPreviewImage.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_PREVIEW_IMAGE_H
  6. #define INCLUDED_IMF_PREVIEW_IMAGE_H
  7. #include "ImfForward.h"
  8. //-----------------------------------------------------------------------------
  9. //
  10. // class PreviewImage -- a usually small, low-dynamic range image,
  11. // that is intended to be stored in an image file's header.
  12. //
  13. // struct PreviewRgba -- holds the value of a PreviewImage pixel.
  14. //
  15. //-----------------------------------------------------------------------------
  16. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  17. struct IMF_EXPORT_TYPE PreviewRgba
  18. {
  19. unsigned char r; // Red, green and blue components of
  20. unsigned char g; // the pixel's color; intensity is
  21. unsigned char b; // proportional to pow (x/255, 2.2),
  22. // where x is r, g, or b.
  23. unsigned char a; // The pixel's alpha; 0 == transparent,
  24. // 255 == opaque.
  25. PreviewRgba (unsigned char r = 0,
  26. unsigned char g = 0,
  27. unsigned char b = 0,
  28. unsigned char a = 255)
  29. : r(r), g(g), b(b), a(a) {}
  30. };
  31. class IMF_EXPORT_TYPE PreviewImage
  32. {
  33. public:
  34. //--------------------------------------------------------------------
  35. // Constructor:
  36. //
  37. // PreviewImage(w,h,p) constructs a preview image with w by h pixels
  38. // whose initial values are specified in pixel array p. The x and y
  39. // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1.
  40. // The pixel with coordinates (x, y) is at address p + y*w + x.
  41. // Pixel (0, 0) is in the upper left corner of the preview image.
  42. // If p is zero, the pixels in the preview image are initialized with
  43. // (r = 0, b = 0, g = 0, a = 255).
  44. //
  45. //--------------------------------------------------------------------
  46. IMF_EXPORT
  47. PreviewImage (unsigned int width = 0,
  48. unsigned int height = 0,
  49. const PreviewRgba pixels[] = 0);
  50. //-----------------------------------------------------
  51. // Copy constructor, destructor and assignment operator
  52. //-----------------------------------------------------
  53. IMF_EXPORT
  54. PreviewImage (const PreviewImage &other);
  55. IMF_EXPORT
  56. ~PreviewImage ();
  57. IMF_EXPORT
  58. PreviewImage & operator = (const PreviewImage &other);
  59. //-----------------------------------------------
  60. // Access to width, height and to the pixel array
  61. //-----------------------------------------------
  62. inline
  63. unsigned int width () const {return _width;}
  64. inline
  65. unsigned int height () const {return _height;}
  66. inline
  67. PreviewRgba * pixels () {return _pixels;}
  68. inline
  69. const PreviewRgba * pixels () const {return _pixels;}
  70. //----------------------------
  71. // Access to individual pixels
  72. //----------------------------
  73. inline
  74. PreviewRgba & pixel (unsigned int x, unsigned int y)
  75. {return _pixels[y * _width + x];}
  76. inline
  77. const PreviewRgba & pixel (unsigned int x, unsigned int y) const
  78. {return _pixels[y * _width + x];}
  79. private:
  80. unsigned int _width;
  81. unsigned int _height;
  82. PreviewRgba * _pixels;
  83. };
  84. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  85. #endif