openvg/openvgrefimplementation/sfopenvg/sfopenvg/riPixelPipe.h
changeset 43 7579f232bae7
equal deleted inserted replaced
36:01a6848ebfd7 43:7579f232bae7
       
     1 #ifndef __RIPIXELPIPE_H
       
     2 #define __RIPIXELPIPE_H
       
     3 
       
     4 /*------------------------------------------------------------------------
       
     5  *
       
     6  * OpenVG 1.1 Reference Implementation
       
     7  * -----------------------------------
       
     8  *
       
     9  * Copyright (c) 2007 The Khronos Group Inc.
       
    10  *
       
    11  * Permission is hereby granted, free of charge, to any person obtaining a
       
    12  * copy of this software and /or associated documentation files
       
    13  * (the "Materials "), to deal in the Materials without restriction,
       
    14  * including without limitation the rights to use, copy, modify, merge,
       
    15  * publish, distribute, sublicense, and/or sell copies of the Materials,
       
    16  * and to permit persons to whom the Materials are furnished to do so,
       
    17  * subject to the following conditions: 
       
    18  *
       
    19  * The above copyright notice and this permission notice shall be included 
       
    20  * in all copies or substantial portions of the Materials. 
       
    21  *
       
    22  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    26  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    27  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    28  * THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    29  *
       
    30  *//**
       
    31  * \file
       
    32  * \brief	Paint and PixelPipe classes.
       
    33  * \note	
       
    34  *//*-------------------------------------------------------------------*/
       
    35 
       
    36 #ifndef __RIMATH_H
       
    37 #include "riMath.h"
       
    38 #endif
       
    39 
       
    40 #ifndef __RIIMAGE_H
       
    41 #include "riImage.h"
       
    42 #endif
       
    43 
       
    44 //=======================================================================
       
    45 
       
    46 namespace OpenVGRI
       
    47 {
       
    48 
       
    49 /*-------------------------------------------------------------------*//*!
       
    50 * \brief	Storage and operations for VGPaint.
       
    51 * \param	
       
    52 * \return	
       
    53 * \note		
       
    54 *//*-------------------------------------------------------------------*/
       
    55 
       
    56 class Paint
       
    57 {
       
    58 public:
       
    59 	Paint();
       
    60 	~Paint();
       
    61 	void					addReference()							{ m_referenceCount++; }
       
    62 	int						removeReference()						{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
       
    63 
       
    64 	struct GradientStop
       
    65 	{
       
    66 		GradientStop() : offset(0.0f), color(0.0f, 0.0f, 0.0f, 0.0f, Color::sRGBA) {}
       
    67 		RIfloat		offset;
       
    68 		Color		color;
       
    69 	};
       
    70 
       
    71 	VGPaintType				m_paintType;
       
    72 	Color					m_paintColor;
       
    73 	Color					m_inputPaintColor;
       
    74 	VGColorRampSpreadMode	m_colorRampSpreadMode;
       
    75 	Array<GradientStop>		m_colorRampStops;
       
    76 	Array<GradientStop>		m_inputColorRampStops;
       
    77 	VGboolean				m_colorRampPremultiplied;
       
    78 	Vector2					m_inputLinearGradientPoint0;
       
    79 	Vector2					m_inputLinearGradientPoint1;
       
    80 	Vector2					m_inputRadialGradientCenter;
       
    81 	Vector2					m_inputRadialGradientFocalPoint;
       
    82 	RIfloat					m_inputRadialGradientRadius;
       
    83 	Vector2					m_linearGradientPoint0;
       
    84 	Vector2					m_linearGradientPoint1;
       
    85 	Vector2					m_radialGradientCenter;
       
    86 	Vector2					m_radialGradientFocalPoint;
       
    87 	RIfloat					m_radialGradientRadius;
       
    88 	VGTilingMode			m_patternTilingMode;
       
    89 	Image*					m_pattern;
       
    90 private:
       
    91 	Paint(const Paint&);						//!< Not allowed.
       
    92 	const Paint& operator=(const Paint&);		//!< Not allowed.
       
    93 
       
    94 	int						m_referenceCount;
       
    95 };
       
    96 
       
    97 /*-------------------------------------------------------------------*//*!
       
    98 * \brief	Encapsulates all information needed for painting a pixel.
       
    99 * \param	
       
   100 * \return	
       
   101 * \note		
       
   102 *//*-------------------------------------------------------------------*/
       
   103 	
       
   104 class PixelPipe
       
   105 {
       
   106 public:
       
   107 	PixelPipe();	//throws bad_alloc
       
   108 	~PixelPipe();
       
   109 
       
   110 	void	pixelPipe(int x, int y, RIfloat coverage, unsigned int sampleMask) const;	//rasterizer calls this function for each pixel
       
   111 
       
   112 	void	setDrawable(Drawable* drawable);
       
   113 	void	setBlendMode(VGBlendMode blendMode);
       
   114 	void	setMask(bool masking);
       
   115 	void	setImage(Image* image, VGImageMode imageMode);	//image = NULL disables drawImage functionality
       
   116 	void	setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix);
       
   117 	void	setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix);
       
   118 	void	setImageQuality(VGImageQuality imageQuality);
       
   119 	void	setTileFillColor(const Color& c);
       
   120 	void	setPaint(const Paint* paint);
       
   121     void    setColorTransform(bool enable, RIfloat values[8]);
       
   122 
       
   123 private:
       
   124 	void	linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
       
   125 	void	radialGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
       
   126 	Color	integrateColorRamp(RIfloat gmin, RIfloat gmax) const;
       
   127 	Color	colorRamp(RIfloat gradient, RIfloat rho) const;
       
   128 	Color	blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const;
       
   129     void    colorTransform(Color& c) const;
       
   130 
       
   131 	PixelPipe(const PixelPipe&);						//!< Not allowed.
       
   132 	const PixelPipe& operator=(const PixelPipe&);		//!< Not allowed.
       
   133 
       
   134 	Drawable*               m_drawable;
       
   135 	bool					m_masking;
       
   136 	Image*					m_image;
       
   137 	const Paint*			m_paint;
       
   138 	Paint					m_defaultPaint;
       
   139 	VGBlendMode				m_blendMode;
       
   140 	VGImageMode				m_imageMode;
       
   141 	VGImageQuality			m_imageQuality;
       
   142 	Color					m_tileFillColor;
       
   143     bool                    m_colorTransform;
       
   144     RIfloat                 m_colorTransformValues[8];
       
   145 	Matrix3x3				m_surfaceToPaintMatrix;
       
   146 	Matrix3x3				m_surfaceToImageMatrix;
       
   147 };
       
   148 
       
   149 //=======================================================================
       
   150 
       
   151 }	//namespace OpenVGRI
       
   152 
       
   153 //=======================================================================
       
   154 
       
   155 #endif /* __RIPIXELPIPE_H */