PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/openexr-1.7.0/ImfPreviewImage.h
00001 
00002 //
00003 // Copyright (c) 2003, Industrial Light & Magic, a division of Lucas
00004 // Digital Ltd. LLC
00005 // 
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are
00010 // met:
00011 // *       Redistributions of source code must retain the above copyright
00012 // notice, this list of conditions and the following disclaimer.
00013 // *       Redistributions in binary form must reproduce the above
00014 // copyright notice, this list of conditions and the following disclaimer
00015 // in the documentation and/or other materials provided with the
00016 // distribution.
00017 // *       Neither the name of Industrial Light & Magic nor the names of
00018 // its contributors may be used to endorse or promote products derived
00019 // from this software without specific prior written permission. 
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00034 
00035 
00036 #ifndef INCLUDED_IMF_PREVIEW_IMAGE_H
00037 #define INCLUDED_IMF_PREVIEW_IMAGE_H
00038 
00039 //-----------------------------------------------------------------------------
00040 //
00041 //      class PreviewImage -- a usually small, low-dynamic range image,
00042 //      that is intended to be stored in an image file's header.
00043 //
00044 //      struct PreviewRgba -- holds the value of a PreviewImage pixel.
00045 //
00046 //-----------------------------------------------------------------------------
00047 
00048 namespace Imf {
00049 
00050 
00051 struct PreviewRgba
00052 {
00053     unsigned char       r;      // Red, green and blue components of
00054     unsigned char       g;      // the pixel's color; intensity is
00055     unsigned char       b;      // proportional to pow (x/255, 2.2),
00056                                 // where x is r, g, or b.
00057 
00058     unsigned char       a;      // The pixel's alpha; 0 == transparent,
00059                                 // 255 == opaque.
00060 
00061     PreviewRgba (unsigned char r = 0,
00062                  unsigned char g = 0,
00063                  unsigned char b = 0,
00064                  unsigned char a = 255)
00065         : r(r), g(g), b(b), a(a) {}
00066 };
00067 
00068 
00069 class PreviewImage
00070 {
00071   public:
00072 
00073     //--------------------------------------------------------------------
00074     // Constructor:
00075     //
00076     // PreviewImage(w,h,p) constructs a preview image with w by h pixels
00077     // whose initial values are specified in pixel array p.  The x and y
00078     // coordinates of the pixels in p go from 0 to w-1, and from 0 to h-1.
00079     // The pixel with coordinates (x, y) is at address p + y*w + x.
00080     // Pixel (0, 0) is in the upper left corner of the preview image.
00081     // If p is zero, the pixels in the preview image are initialized with
00082     // (r = 0, b = 0, g = 0, a = 255).
00083     //
00084     //--------------------------------------------------------------------
00085    
00086      PreviewImage (unsigned int width = 0,
00087                    unsigned int height = 0,
00088                    const PreviewRgba pixels[] = 0);
00089 
00090     //-----------------------------------------------------
00091     // Copy constructor, destructor and assignment operator
00092     //-----------------------------------------------------
00093 
00094      PreviewImage (const PreviewImage &other);
00095     ~PreviewImage ();
00096 
00097     PreviewImage &      operator = (const PreviewImage &other);
00098 
00099 
00100     //-----------------------------------------------
00101     // Access to width, height and to the pixel array
00102     //-----------------------------------------------
00103 
00104     unsigned int        width () const  {return _width;}
00105     unsigned int        height () const {return _height;}
00106 
00107     PreviewRgba *       pixels ()       {return _pixels;}
00108     const PreviewRgba * pixels () const {return _pixels;}
00109 
00110 
00111     //----------------------------
00112     // Access to individual pixels
00113     //----------------------------
00114 
00115     PreviewRgba &       pixel (unsigned int x, unsigned int y)
00116                                         {return _pixels[y * _width + x];}
00117 
00118     const PreviewRgba & pixel (unsigned int x, unsigned int y) const
00119                                         {return _pixels[y * _width + x];}
00120 
00121   private:
00122 
00123     unsigned int        _width;
00124     unsigned int        _height;
00125     PreviewRgba *       _pixels;
00126 };
00127 
00128 
00129 } // namespace Imf
00130 
00131 #endif