/src/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImage.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 131 lines · 39 code · 28 blank · 64 comment · 0 complexity · 5f6fef488ff55aee5122c36b8f7d5d65 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2003, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. #ifndef INCLUDED_IMF_PREVIEW_IMAGE_H
  35. #define INCLUDED_IMF_PREVIEW_IMAGE_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // class PreviewImage -- a usually small, low-dynamic range image,
  39. // that is intended to be stored in an image file's header.
  40. //
  41. // struct PreviewRgba -- holds the value of a PreviewImage pixel.
  42. //
  43. //-----------------------------------------------------------------------------
  44. namespace Imf {
  45. struct PreviewRgba
  46. {
  47. unsigned char r; // Red, green and blue components of
  48. unsigned char g; // the pixel's color; intensity is
  49. unsigned char b; // proportional to pow (x/255, 2.2),
  50. // where x is r, g, or b.
  51. unsigned char a; // The pixel's alpha; 0 == transparent,
  52. // 255 == opaque.
  53. PreviewRgba (unsigned char r = 0,
  54. unsigned char g = 0,
  55. unsigned char b = 0,
  56. unsigned char a = 255)
  57. : r(r), g(g), b(b), a(a) {}
  58. };
  59. class PreviewImage
  60. {
  61. public:
  62. //--------------------------------------------------------------------
  63. // Constructor:
  64. //
  65. // PreviewImage(w,h,p) constructs a preview image with w by h pixels
  66. // whose initial values are specified in pixel array p. The x and y
  67. // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1.
  68. // The pixel with coordinates (x, y) is at address p + y*w + x.
  69. // Pixel (0, 0) is in the upper left corner of the preview image.
  70. // If p is zero, the pixels in the preview image are initialized with
  71. // (r = 0, b = 0, g = 0, a = 255).
  72. //
  73. //--------------------------------------------------------------------
  74. PreviewImage (unsigned int width = 0,
  75. unsigned int height = 0,
  76. const PreviewRgba pixels[] = 0);
  77. //-----------------------------------------------------
  78. // Copy constructor, destructor and assignment operator
  79. //-----------------------------------------------------
  80. PreviewImage (const PreviewImage &other);
  81. ~PreviewImage ();
  82. PreviewImage & operator = (const PreviewImage &other);
  83. //-----------------------------------------------
  84. // Access to width, height and to the pixel array
  85. //-----------------------------------------------
  86. unsigned int width () const {return _width;}
  87. unsigned int height () const {return _height;}
  88. PreviewRgba * pixels () {return _pixels;}
  89. const PreviewRgba * pixels () const {return _pixels;}
  90. //----------------------------
  91. // Access to individual pixels
  92. //----------------------------
  93. PreviewRgba & pixel (unsigned int x, unsigned int y)
  94. {return _pixels[y * _width + x];}
  95. const PreviewRgba & pixel (unsigned int x, unsigned int y) const
  96. {return _pixels[y * _width + x];}
  97. private:
  98. unsigned int _width;
  99. unsigned int _height;
  100. PreviewRgba * _pixels;
  101. };
  102. } // namespace Imf
  103. #endif