egl/sfopenvg/riImage.cpp
author Jose Thachil<jose.thachil@cell-telecom.com>
Wed, 12 May 2010 11:20:41 +0100
branchEGL_MERGE
changeset 57 2bf8a359aa2f
permissions -rw-r--r--
Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg Subject to some fixes in uiresources and uiaccelerator, this version removes the EGL 1 panics. A quick attempt to use the compositor renderstage wasn't successful, but not apparently due to EGL issues. There are a lot of RDebug::Printf statements still in this code, which will be removed in the next commit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     1
/*------------------------------------------------------------------------
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     2
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     3
 * OpenVG 1.1 Reference Implementation
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     4
 * -----------------------------------
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     5
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     6
 * Copyright (c) 2007 The Khronos Group Inc.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     7
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     8
 * Permission is hereby granted, free of charge, to any person obtaining a
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
     9
 * copy of this software and /or associated documentation files
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    10
 * (the "Materials "), to deal in the Materials without restriction,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    11
 * including without limitation the rights to use, copy, modify, merge,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    12
 * publish, distribute, sublicense, and/or sell copies of the Materials,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    13
 * and to permit persons to whom the Materials are furnished to do so,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    14
 * subject to the following conditions: 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    15
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    16
 * The above copyright notice and this permission notice shall be included 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    17
 * in all copies or substantial portions of the Materials. 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    18
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    19
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    22
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    23
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    24
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    25
 * THE USE OR OTHER DEALINGS IN THE MATERIALS.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    26
 *
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    27
 *//**
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    28
 * \file
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    29
 * \brief	Implementation of Color and Image functions.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    30
 * \note	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    31
 *//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    32
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    33
#include "riImage.h"
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    34
#include "riRasterizer.h"
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    35
//==============================================================================================
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    36
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    37
namespace OpenVGRI
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    38
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    39
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    40
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    41
* \brief	Converts from numBits into a shifted mask
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    42
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    43
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    44
* \note
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    45
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    46
	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    47
static unsigned int bitsToMask(unsigned int bits, unsigned int shift)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    48
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    49
	return ((1<<bits)-1) << shift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    50
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    51
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    52
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    53
* \brief	Converts from color (RIfloat) to an int with 1.0f mapped to the
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    54
*			given maximum with round-to-nearest semantics.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    55
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    56
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    57
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    58
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    59
	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    60
static unsigned int colorToInt(RIfloat c, int maxc)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    61
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    62
	return RI_INT_MIN(RI_INT_MAX((int)floor(c * (RIfloat)maxc + 0.5f), 0), maxc);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    63
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    64
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    65
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    66
* \brief	Converts from int to color (RIfloat) with the given maximum
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    67
*			mapped to 1.0f.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    68
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    69
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    70
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    71
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    72
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    73
static RI_INLINE RIfloat intToColor(unsigned int i, unsigned int maxi)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    74
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    75
	return (RIfloat)(i & maxi) / (RIfloat)maxi;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    76
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    77
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    78
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    79
* \brief	Converts from packed integer in a given format to a Color.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    80
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    81
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    82
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    83
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    84
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    85
void Color::unpack(unsigned int inputData, const Color::Descriptor& inputDesc)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    86
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    87
	int rb = inputDesc.redBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    88
	int gb = inputDesc.greenBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    89
	int bb = inputDesc.blueBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    90
	int ab = inputDesc.alphaBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    91
	int lb = inputDesc.luminanceBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    92
	int rs = inputDesc.redShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    93
	int gs = inputDesc.greenShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    94
	int bs = inputDesc.blueShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    95
	int as = inputDesc.alphaShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    96
	int ls = inputDesc.luminanceShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    97
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    98
	m_format = inputDesc.internalFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
    99
	if(lb)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   100
	{	//luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   101
		r = g = b = intToColor(inputData >> ls, (1<<lb)-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   102
		a = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   103
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   104
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   105
	{	//rgba
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   106
		r = rb ? intToColor(inputData >> rs, (1<<rb)-1) : (RIfloat)1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   107
		g = gb ? intToColor(inputData >> gs, (1<<gb)-1) : (RIfloat)1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   108
		b = bb ? intToColor(inputData >> bs, (1<<bb)-1) : (RIfloat)1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   109
		a = ab ? intToColor(inputData >> as, (1<<ab)-1) : (RIfloat)1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   110
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   111
		if(isPremultiplied())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   112
		{	//clamp premultiplied color to alpha to enforce consistency
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   113
			r = RI_MIN(r, a);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   114
			g = RI_MIN(g, a);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   115
			b = RI_MIN(b, a);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   116
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   117
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   118
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   119
    assertConsistency();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   120
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   121
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   122
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   123
* \brief	Converts from Color to a packed integer in a given format.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   124
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   125
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   126
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   127
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   128
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   129
unsigned int Color::pack(const Color::Descriptor& outputDesc) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   130
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   131
    assertConsistency();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   132
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   133
	int rb = outputDesc.redBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   134
	int gb = outputDesc.greenBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   135
	int bb = outputDesc.blueBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   136
	int ab = outputDesc.alphaBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   137
	int lb = outputDesc.luminanceBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   138
	int rs = outputDesc.redShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   139
	int gs = outputDesc.greenShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   140
	int bs = outputDesc.blueShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   141
	int as = outputDesc.alphaShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   142
	int ls = outputDesc.luminanceShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   143
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   144
	if(lb)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   145
	{	//luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   146
		RI_ASSERT(isLuminance());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   147
		return colorToInt(r, (1<<lb)-1) << ls;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   148
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   149
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   150
	{	//rgb
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   151
		RI_ASSERT(!isLuminance());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   152
		unsigned int cr = rb ? colorToInt(r, (1<<rb)-1) : 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   153
		unsigned int cg = gb ? colorToInt(g, (1<<gb)-1) : 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   154
		unsigned int cb = bb ? colorToInt(b, (1<<bb)-1) : 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   155
		unsigned int ca = ab ? colorToInt(a, (1<<ab)-1) : 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   156
		return (cr << rs) | (cg << gs) | (cb << bs) | (ca << as);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   157
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   158
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   159
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   160
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   161
* \brief	Converts from the current internal format to another.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   162
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   163
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   164
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   165
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   166
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   167
static RIfloat gamma(RIfloat c)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   168
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   169
	if( c <= 0.00304f )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   170
		c *= 12.92f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   171
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   172
		c = 1.0556f * (RIfloat)pow(c, 1.0f/2.4f) - 0.0556f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   173
	return c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   174
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   175
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   176
static RIfloat invgamma(RIfloat c)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   177
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   178
	if( c <= 0.03928f )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   179
		c /= 12.92f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   180
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   181
		c = (RIfloat)pow((c + 0.0556f)/1.0556f, 2.4f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   182
	return c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   183
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   184
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   185
static RIfloat lRGBtoL(RIfloat r, RIfloat g, RIfloat b)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   186
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   187
	return 0.2126f*r + 0.7152f*g + 0.0722f*b;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   188
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   189
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   190
void Color::convert(InternalFormat outputFormat)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   191
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   192
    assertConsistency();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   193
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   194
	if( m_format == outputFormat )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   195
		return;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   196
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   197
	if(isPremultiplied())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   198
	{	//unpremultiply
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   199
		RIfloat ooa = (a != 0.0f) ? 1.0f / a : (RIfloat)0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   200
		r *= ooa;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   201
		g *= ooa;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   202
		b *= ooa;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   203
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   204
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   205
	//From Section 3.4.2 of OpenVG spec
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   206
	//1: sRGB = gamma(lRGB)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   207
	//2: lRGB = invgamma(sRGB)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   208
	//3: lL = 0.2126 lR + 0.7152 lG + 0.0722 lB
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   209
	//4: lRGB = lL
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   210
	//5: sL = gamma(lL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   211
	//6: lL = invgamma(sL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   212
	//7: sRGB = sL
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   213
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   214
	//Source/Dest lRGB sRGB   lL   sL 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   215
	//lRGB          -    1    3    3,5 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   216
	//sRGB          2    -    2,3  2,3,5 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   217
	//lL            4    4,1  -    5 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   218
	//sL            7,2  7    6    - 
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   219
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   220
	const unsigned int shift = 3;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   221
	unsigned int conversion = (m_format & (NONLINEAR | LUMINANCE)) | ((outputFormat & (NONLINEAR | LUMINANCE)) << shift);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   222
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   223
	switch(conversion)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   224
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   225
	case lRGBA | (sRGBA << shift): r = gamma(r); g = gamma(g); b = gamma(b); break;							//1
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   226
	case lRGBA | (lLA << shift)  : r = g = b = lRGBtoL(r, g, b); break;										//3
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   227
	case lRGBA | (sLA << shift)  : r = g = b = gamma(lRGBtoL(r, g, b)); break;								//3,5
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   228
	case sRGBA | (lRGBA << shift): r = invgamma(r); g = invgamma(g); b = invgamma(b); break;				//2
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   229
	case sRGBA | (lLA << shift)  : r = g = b = lRGBtoL(invgamma(r), invgamma(g), invgamma(b)); break;		//2,3
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   230
	case sRGBA | (sLA << shift)  : r = g = b = gamma(lRGBtoL(invgamma(r), invgamma(g), invgamma(b))); break;//2,3,5
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   231
	case lLA   | (lRGBA << shift): break;																	//4
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   232
	case lLA   | (sRGBA << shift): r = g = b = gamma(r); break;												//4,1
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   233
	case lLA   | (sLA << shift)  : r = g = b = gamma(r); break;												//5
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   234
	case sLA   | (lRGBA << shift): r = g = b = invgamma(r); break;											//7,2
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   235
	case sLA   | (sRGBA << shift): break;																	//7
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   236
	case sLA   | (lLA << shift)  : r = g = b = invgamma(r); break;											//6
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   237
	default: RI_ASSERT((m_format & (LUMINANCE | NONLINEAR)) == (outputFormat & (LUMINANCE | NONLINEAR))); break;	//nop
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   238
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   239
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   240
	if(outputFormat & PREMULTIPLIED)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   241
	{	//premultiply
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   242
		r *= a;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   243
		g *= a;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   244
		b *= a;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   245
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   246
	m_format = outputFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   247
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   248
    assertConsistency();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   249
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   250
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   251
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   252
* \brief	Creates a pixel format descriptor out of VGImageFormat
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   253
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   254
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   255
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   256
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   257
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   258
Color::Descriptor Color::formatToDescriptor(VGImageFormat format)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   259
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   260
	Descriptor desc;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   261
	memset(&desc, 0, sizeof(Descriptor));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   262
	RI_ASSERT(isValidImageFormat(format));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   263
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   264
	int baseFormat = (int)format & 15;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   265
	const int numBaseFormats = 15;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   266
	RI_ASSERT(baseFormat >= 0 && baseFormat < numBaseFormats);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   267
	int swizzleBits = ((int)format >> 6) & 3;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   268
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   269
	/* base formats
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   270
	VG_sRGBX_8888                               =  0,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   271
	VG_sRGBA_8888                               =  1,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   272
	VG_sRGBA_8888_PRE                           =  2,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   273
	VG_sRGB_565                                 =  3,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   274
	VG_sRGBA_5551                               =  4,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   275
	VG_sRGBA_4444                               =  5,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   276
	VG_sL_8                                     =  6,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   277
	VG_lRGBX_8888                               =  7,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   278
	VG_lRGBA_8888                               =  8,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   279
	VG_lRGBA_8888_PRE                           =  9,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   280
	VG_lL_8                                     = 10,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   281
	VG_A_8                                      = 11,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   282
	VG_BW_1                                     = 12,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   283
	VG_A_1                                      = 13,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   284
	VG_A_4                                      = 14,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   285
	*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   286
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   287
	static const int redBits[numBaseFormats] =       {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   288
	static const int greenBits[numBaseFormats] =     {8, 8, 8, 6, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   289
	static const int blueBits[numBaseFormats] =      {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   290
	static const int alphaBits[numBaseFormats] =     {0, 8, 8, 0, 1, 4, 0, 0, 8, 8, 0, 8, 0, 1, 4};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   291
	static const int luminanceBits[numBaseFormats] = {0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 1, 0, 0};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   292
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   293
	static const int redShifts[4*numBaseFormats] = {24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0,	//RGBA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   294
													16, 16, 16, 11, 10, 8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//ARGB
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   295
													8,  8,  8,  0,  1,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//BGRA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   296
													0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0};	//ABGR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   297
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   298
	static const int greenShifts[4*numBaseFormats] = {16, 16, 16, 5,  6,  8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//RGBA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   299
													  8,  8,  8,  5,  5,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//ARGB
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   300
													  16, 16, 16, 5,  6,  8,  0, 16, 16, 16, 0, 0, 0, 0, 0,	//BGRA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   301
													  8,  8,  8,  5,  5,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0};//ABGR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   302
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   303
	static const int blueShifts[4*numBaseFormats] =  {8,  8,  8,  0,  1,  4,  0, 8,  8,  8,  0, 0, 0, 0, 0,	//RGBA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   304
													  0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//ARGB
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   305
													  24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0,	//BGRA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   306
													  16, 16, 16, 11, 10, 8,  0, 16, 16, 16, 0, 0, 0, 0, 0};//ABGR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   307
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   308
	static const int alphaShifts[4*numBaseFormats] = {0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//RGBA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   309
													  0,  24, 24, 0,  15, 12, 0, 0,  24, 24, 0, 0, 0, 0, 0,	//ARGB
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   310
													  0,  0,  0,  0,  0,  0,  0, 0,  0,  0,  0, 0, 0, 0, 0,	//BGRA
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   311
													  0,  24, 24, 0,  15, 12, 0, 0,  24, 24, 0, 0, 0, 0, 0};//ABGR
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   312
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   313
	static const int bpps[numBaseFormats] = {32, 32, 32, 16, 16, 16, 8, 32, 32, 32, 8, 8, 1, 1, 4};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   314
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   315
	static const InternalFormat internalFormats[numBaseFormats] = {sRGBA, sRGBA, sRGBA_PRE, sRGBA, sRGBA, sRGBA, sLA, lRGBA, lRGBA, lRGBA_PRE, lLA, lRGBA, lLA, lRGBA, lRGBA};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   316
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   317
	desc.redBits = redBits[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   318
	desc.greenBits = greenBits[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   319
	desc.blueBits = blueBits[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   320
	desc.alphaBits = alphaBits[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   321
	desc.luminanceBits = luminanceBits[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   322
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   323
	desc.redShift = redShifts[swizzleBits * numBaseFormats + baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   324
	desc.greenShift = greenShifts[swizzleBits * numBaseFormats + baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   325
	desc.blueShift = blueShifts[swizzleBits * numBaseFormats + baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   326
	desc.alphaShift = alphaShifts[swizzleBits * numBaseFormats + baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   327
	desc.luminanceShift = 0;	//always zero
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   328
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   329
	desc.format = format;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   330
	desc.bitsPerPixel = bpps[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   331
	desc.internalFormat = internalFormats[baseFormat];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   332
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   333
	return desc;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   334
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   335
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   336
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   337
* \brief	Checks if the pixel format descriptor is valid (i.e. all the
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   338
*           values are supported by the RI)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   339
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   340
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   341
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   342
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   343
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   344
bool Color::isValidDescriptor(const Color::Descriptor& desc)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   345
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   346
	//A valid descriptor has 1, 2, 4, 8, 16, or 32 bits per pixel, and either luminance or rgba channels, but not both.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   347
	//Any of the rgba channels can be missing, and not all bits need to be used. Maximum channel bit depth is 8.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   348
	int rb = desc.redBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   349
	int gb = desc.greenBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   350
	int bb = desc.blueBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   351
	int ab = desc.alphaBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   352
	int lb = desc.luminanceBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   353
	int rs = desc.redShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   354
	int gs = desc.greenShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   355
	int bs = desc.blueShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   356
	int as = desc.alphaShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   357
	int ls = desc.luminanceShift;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   358
	int bpp = desc.bitsPerPixel;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   359
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   360
	int rgbaBits = rb + gb + bb + ab;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   361
	if(rb < 0 || rb > 8 || rs < 0 || rs + rb > bpp || !(rb || !rs))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   362
		return false;	//invalid channel description
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   363
	if(gb < 0 || gb > 8 || gs < 0 || gs + gb > bpp || !(gb || !gs))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   364
		return false;	//invalid channel description
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   365
	if(bb < 0 || bb > 8 || bs < 0 || bs + bb > bpp || !(bb || !bs))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   366
		return false;	//invalid channel description
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   367
	if(ab < 0 || ab > 8 || as < 0 || as + ab > bpp || !(ab || !as))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   368
		return false;	//invalid channel description
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   369
	if(lb < 0 || lb > 8 || ls < 0 || ls + lb > bpp || !(lb || !ls))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   370
		return false;	//invalid channel description
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   371
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   372
	if(rgbaBits && lb)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   373
		return false;	//can't have both rgba and luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   374
	if(!rgbaBits && !lb)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   375
		return false;	//must have either rgba or luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   376
	if(rgbaBits)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   377
	{	//rgba
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   378
		if(rb+gb+bb == 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   379
		{	//alpha only
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   380
			if(rs || gs || bs || as || ls)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   381
				return false;	//wrong shifts (even alpha shift must be zero)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   382
			if((ab != 1 && ab != 2  && ab != 4 && ab != 8) || bpp != ab)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   383
				return false;	//alpha size must be 1, 2, 4, or, 8, bpp must match
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   384
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   385
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   386
		{	//rgba
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   387
			if(rgbaBits > bpp)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   388
				return false;	//bpp must be greater than or equal to the sum of rgba bits
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   389
			if(!(bpp == 32 || bpp == 16 || bpp == 8))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   390
				return false;	//only 1, 2, and 4 byte formats are supported for rgba
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   391
			
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   392
			unsigned int rm = bitsToMask((unsigned int)rb, (unsigned int)rs);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   393
			unsigned int gm = bitsToMask((unsigned int)gb, (unsigned int)gs);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   394
			unsigned int bm = bitsToMask((unsigned int)bb, (unsigned int)bs);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   395
			unsigned int am = bitsToMask((unsigned int)ab, (unsigned int)as);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   396
			if((rm & gm) || (rm & bm) || (rm & am) || (gm & bm) || (gm & am) || (bm & am))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   397
				return false;	//channels overlap
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   398
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   399
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   400
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   401
	{	//luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   402
		if(rs || gs || bs || as || ls)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   403
			return false;	//wrong shifts (even luminance shift must be zero)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   404
		if(!(lb == 1 || lb == 8) || bpp != lb)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   405
			return false;	//luminance size must be either 1 or 8, bpp must match
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   406
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   407
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   408
	if(desc.format != -1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   409
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   410
		if(!isValidImageFormat(desc.format))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   411
			return false;	//invalid image format
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   412
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   413
		Descriptor d = formatToDescriptor(desc.format);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   414
		if(d.redBits != rb || d.greenBits != gb || d.blueBits != bb || d.alphaBits != ab || d.luminanceBits != lb ||
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   415
		   d.redShift != rs || d.greenShift != gs || d.blueShift != bs || d.alphaShift != as || d.luminanceShift != ls ||
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   416
		   d.bitsPerPixel != bpp)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   417
		   return false;	//if the descriptor has a VGImageFormat, it must match the bits, shifts, and bpp
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   418
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   419
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   420
	if((unsigned int)desc.internalFormat & ~(Color::PREMULTIPLIED | Color::NONLINEAR | Color::LUMINANCE))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   421
		return false;	//invalid internal format
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   422
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   423
	return true;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   424
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   425
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   426
//==============================================================================================
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   427
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   428
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   429
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   430
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   431
//==============================================================================================
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   432
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   433
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   434
* \brief	Constructs a blank image.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   435
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   436
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   437
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   438
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   439
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   440
Image::Image(const Color::Descriptor& desc, int width, int height, VGbitfield allowedQuality) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   441
	m_desc(desc),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   442
	m_width(width),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   443
	m_height(height),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   444
	m_allowedQuality(allowedQuality),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   445
	m_inUse(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   446
	m_stride(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   447
	m_data(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   448
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   449
	m_ownsData(true),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   450
	m_parent(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   451
    m_storageOffsetX(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   452
    m_storageOffsetY(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   453
	m_mipmapsValid(false),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   454
	m_mipmaps()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   455
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   456
	RI_ASSERT(Color::isValidDescriptor(m_desc));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   457
	RI_ASSERT(width > 0 && height > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   458
	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   459
	m_stride = (m_width*m_desc.bitsPerPixel+7)/8;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   460
	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   461
	m_data = RI_NEW_ARRAY(RIuint8, m_stride*m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   462
	memset(m_data, 0, m_stride*m_height);	//clear image
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   463
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   464
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   465
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   466
* \brief	Constructs an image that uses an external array for its data
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   467
*			storage.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   468
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   469
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   470
* \note		this is meant for internal use to make blitting easier
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   471
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   472
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   473
Image::Image(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   474
	m_desc(desc),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   475
	m_width(width),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   476
	m_height(height),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   477
	m_allowedQuality(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   478
	m_inUse(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   479
	m_stride(stride),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   480
	m_data(data),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   481
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   482
	m_ownsData(false),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   483
	m_parent(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   484
    m_storageOffsetX(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   485
    m_storageOffsetY(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   486
	m_mipmapsValid(false),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   487
	m_mipmaps()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   488
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   489
	RI_ASSERT(Color::isValidDescriptor(m_desc));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   490
	RI_ASSERT(width > 0 && height > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   491
	RI_ASSERT(data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   492
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   493
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   494
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   495
* \brief	Construcs a child image.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   496
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   497
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   498
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   499
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   500
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   501
Image::Image(Image* parent, int x, int y, int width, int height) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   502
	m_desc(Color::formatToDescriptor(VG_sRGBA_8888)),	//dummy initialization, will be overwritten below (can't read from parent->m_desc before knowing the pointer is valid)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   503
	m_width(width),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   504
	m_height(height),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   505
	m_allowedQuality(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   506
	m_inUse(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   507
	m_stride(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   508
	m_data(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   509
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   510
	m_ownsData(false),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   511
	m_parent(parent),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   512
    m_storageOffsetX(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   513
    m_storageOffsetY(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   514
	m_mipmapsValid(false),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   515
	m_mipmaps()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   516
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   517
	RI_ASSERT(parent);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   518
	RI_ASSERT(x >= 0 && y >= 0 && width > 0 && height > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   519
	RI_ASSERT(RI_INT_ADDSATURATE(x,width) <= parent->m_width && RI_INT_ADDSATURATE(y,height) <= parent->m_height);	//child image must be contained in parent
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   520
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   521
	m_desc = parent->m_desc;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   522
	RI_ASSERT(Color::isValidDescriptor(m_desc));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   523
	m_allowedQuality = parent->m_allowedQuality;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   524
	m_stride = parent->m_stride;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   525
	m_data = parent->m_data;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   526
    m_storageOffsetX = parent->m_storageOffsetX + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   527
    m_storageOffsetY = parent->m_storageOffsetY + y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   528
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   529
	//increase the reference and use count of the parent
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   530
	addInUse();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   531
	parent->addInUse();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   532
	parent->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   533
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   534
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   535
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   536
* \brief	Image destructor.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   537
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   538
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   539
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   540
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   541
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   542
Image::~Image()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   543
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   544
	RI_ASSERT(m_referenceCount == 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   545
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   546
	if(m_parent)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   547
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   548
		//decrease the reference and use count of the parent
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   549
		removeInUse();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   550
		m_parent->removeInUse();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   551
		if(!m_parent->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   552
			RI_DELETE(m_parent);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   553
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   554
	RI_ASSERT(m_inUse == 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   555
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   556
	for(int i=0;i<m_mipmaps.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   557
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   558
		if(!m_mipmaps[i]->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   559
			RI_DELETE(m_mipmaps[i]);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   560
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   561
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   562
			RI_ASSERT(0);	//there can't be any other references to the mipmap levels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   563
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   564
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   565
	m_mipmaps.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   566
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   567
	if(m_ownsData)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   568
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   569
		RI_ASSERT(!m_parent);		//can't have parent if owns the data
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   570
		RI_DELETE_ARRAY(m_data);	//delete image data if we own it
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   571
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   572
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   573
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   574
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   575
* \brief	Returns true if the two images share pixels.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   576
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   577
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   578
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   579
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   580
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   581
bool Image::overlaps(const Image* src) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   582
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   583
	RI_ASSERT(src);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   584
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   585
	if(m_data != src->m_data)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   586
		return false;	//images don't share data
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   587
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   588
	//check if the image storage regions overlap
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   589
	Rectangle r(m_storageOffsetX, m_storageOffsetY, m_width, m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   590
	r.intersect(Rectangle(src->m_storageOffsetX, src->m_storageOffsetY, src->m_width, src->m_height));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   591
	if(!r.width || !r.height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   592
		return false;	//intersection is empty, images don't overlap	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   593
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   594
	return true;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   595
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   596
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   597
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   598
* \brief	Clears a rectangular portion of an image with the given clear color.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   599
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   600
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   601
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   602
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   603
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   604
void Image::clear(const Color& clearColor, int x, int y, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   605
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   606
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   607
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   608
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   609
	//intersect clear region with image bounds
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   610
	Rectangle r(0,0,m_width,m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   611
	r.intersect(Rectangle(x,y,w,h));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   612
	if(!r.width || !r.height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   613
		return;		//intersection is empty or one of the rectangles is invalid
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   614
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   615
	Color col = clearColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   616
	col.clamp();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   617
	col.convert(m_desc.internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   618
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   619
	for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   620
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   621
		for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   622
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   623
			writePixel(i, j, col);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   624
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   625
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   626
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   627
	m_mipmapsValid = false;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   628
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   629
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   630
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   631
* \brief	Blits a source region to destination. Source and destination
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   632
*			can overlap.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   633
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   634
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   635
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   636
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   637
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   638
static RIfloat ditherChannel(RIfloat c, int bits, RIfloat m)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   639
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   640
	RIfloat fc = c * (RIfloat)((1<<bits)-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   641
	RIfloat ic = (RIfloat)floor(fc);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   642
	if(fc - ic > m) ic += 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   643
	return RI_MIN(ic / (RIfloat)((1<<bits)-1), 1.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   644
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   645
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   646
static void computeBlitRegion(int& sx, int& sy, int& dx, int& dy, int& w, int& h, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   647
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   648
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   649
	sx = RI_INT_MIN(RI_INT_MAX(sx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   650
	sy = RI_INT_MIN(RI_INT_MAX(sy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   651
	dx = RI_INT_MIN(RI_INT_MAX(dx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   652
	dy = RI_INT_MIN(RI_INT_MAX(dy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   653
	w = RI_INT_MIN(w, (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   654
	h = RI_INT_MIN(h, (int)(RI_INT32_MAX>>2));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   655
	int srcsx = sx, srcex = sx + w, dstsx = dx, dstex = dx + w;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   656
	if(srcsx < 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   657
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   658
		dstsx -= srcsx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   659
		srcsx = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   660
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   661
	if(srcex > srcWidth)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   662
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   663
		dstex -= srcex - srcWidth;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   664
		srcex = srcWidth;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   665
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   666
	if(dstsx < 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   667
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   668
		srcsx -= dstsx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   669
		dstsx = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   670
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   671
	if(dstex > dstWidth)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   672
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   673
		srcex -= dstex - dstWidth;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   674
		dstex = dstWidth;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   675
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   676
	RI_ASSERT(srcsx >= 0 && dstsx >= 0 && srcex <= srcWidth && dstex <= dstWidth);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   677
	w = srcex - srcsx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   678
	RI_ASSERT(w == dstex - dstsx);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   679
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   680
	int srcsy = sy, srcey = sy + h, dstsy = dy, dstey = dy + h;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   681
	if(srcsy < 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   682
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   683
		dstsy -= srcsy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   684
		srcsy = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   685
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   686
	if(srcey > srcHeight)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   687
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   688
		dstey -= srcey - srcHeight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   689
		srcey = srcHeight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   690
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   691
	if(dstsy < 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   692
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   693
		srcsy -= dstsy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   694
		dstsy = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   695
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   696
	if(dstey > dstHeight)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   697
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   698
		srcey -= dstey - dstHeight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   699
		dstey = dstHeight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   700
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   701
	RI_ASSERT(srcsy >= 0 && dstsy >= 0 && srcey <= srcHeight && dstey <= dstHeight);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   702
	h = srcey - srcsy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   703
	RI_ASSERT(h == dstey - dstsy);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   704
	sx = srcsx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   705
	sy = srcsy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   706
	dx = dstsx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   707
	dy = dstsy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   708
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   709
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   710
void Image::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, bool dither)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   711
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   712
	//img=>img: vgCopyImage
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   713
	//img=>user: vgGetImageSubData
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   714
	//user=>img: vgImageSubData
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   715
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   716
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   717
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   718
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   719
	computeBlitRegion(sx, sy, dx, dy, w, h, src.m_width, src.m_height, m_width, m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   720
	if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   721
		return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   722
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   723
	Array<Color> tmp;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   724
	tmp.resize(w*h);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   725
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   726
	//copy source region to tmp
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   727
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   728
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   729
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   730
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   731
			Color c = src.readPixel(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   732
			c.convert(m_desc.internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   733
			tmp[j*w+i] = c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   734
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   735
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   736
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   737
	int rbits = m_desc.redBits, gbits = m_desc.greenBits, bbits = m_desc.blueBits, abits = m_desc.alphaBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   738
	if(m_desc.isLuminance())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   739
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   740
		rbits = gbits = bbits = m_desc.luminanceBits;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   741
		abits = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   742
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   743
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   744
	//write tmp to destination region
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   745
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   746
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   747
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   748
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   749
			Color col = tmp[j*w+i];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   750
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   751
			if(dither)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   752
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   753
				static const int matrix[16] = {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   754
					0,  8,  2,  10,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   755
					12, 4,  14, 6,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   756
					3,  11, 1,  9,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   757
					15, 7,  13, 5};
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   758
				int x = i & 3;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   759
				int y = j & 3;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   760
				RIfloat m = matrix[y*4+x] / 16.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   761
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   762
				if(rbits) col.r = ditherChannel(col.r, rbits, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   763
				if(gbits) col.g = ditherChannel(col.g, gbits, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   764
				if(bbits) col.b = ditherChannel(col.b, bbits, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   765
				if(abits) col.a = ditherChannel(col.a, abits, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   766
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   767
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   768
			writePixel(dx + i, dy + j, col);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   769
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   770
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   771
	m_mipmapsValid = false;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   772
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   773
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   774
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   775
* \brief	Converts from multisampled format to display format.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   776
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   777
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   778
* \note
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   779
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   780
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   781
void Image::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   782
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   783
	//fb=>img: vgGetPixels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   784
	//fb=>user: vgReadPixels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   785
	RI_ASSERT(!src->isInUse(this));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   786
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   787
	computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), m_width, m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   788
	if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   789
		return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   790
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   791
	for(int y=0;y<h;y++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   792
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   793
		for(int x=0;x<w;x++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   794
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   795
			Color r = src->FSAAResolve(sx + x, sy + y);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   796
			r.convert(getDescriptor().internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   797
			writePixel(dx + x, dy + y, r);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   798
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   799
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   800
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   801
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   802
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   803
* \brief	Returns the color at pixel (x,y).
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   804
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   805
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   806
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   807
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   808
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   809
Color Image::readPixel(int x, int y) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   810
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   811
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   812
	RI_ASSERT(x >= 0 && x < m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   813
	RI_ASSERT(y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   814
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   815
    x += m_storageOffsetX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   816
    y += m_storageOffsetY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   817
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   818
	unsigned int p = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   819
	RIuint8* scanline = m_data + y * m_stride;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   820
	switch(m_desc.bitsPerPixel)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   821
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   822
	case 32:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   823
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   824
		RIuint32* s = (((RIuint32*)scanline) + x);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   825
		p = (unsigned int)*s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   826
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   827
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   828
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   829
	case 16:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   830
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   831
		RIuint16* s = ((RIuint16*)scanline) + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   832
		p = (unsigned int)*s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   833
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   834
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   835
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   836
    case 8:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   837
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   838
		RIuint8* s = ((RIuint8*)scanline) + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   839
		p = (unsigned int)*s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   840
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   841
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   842
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   843
    case 4:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   844
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   845
		RIuint8* s = ((RIuint8*)scanline) + (x>>1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   846
		p = (unsigned int)(*s >> ((x&1)<<2)) & 0xf;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   847
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   848
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   849
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   850
    case 2:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   851
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   852
		RIuint8* s = ((RIuint8*)scanline) + (x>>2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   853
		p = (unsigned int)(*s >> ((x&3)<<1)) & 0x3;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   854
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   855
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   856
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   857
    default:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   858
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   859
		RI_ASSERT(m_desc.bitsPerPixel == 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   860
		RIuint8* s = ((RIuint8*)scanline) + (x>>3);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   861
		p = (unsigned int)(*s >> (x&7)) & 0x1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   862
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   863
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   864
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   865
	Color c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   866
	c.unpack(p, m_desc);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   867
	return c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   868
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   869
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   870
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   871
* \brief	Writes the color to pixel (x,y). Internal color formats must
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   872
*			match.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   873
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   874
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   875
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   876
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   877
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   878
void Image::writePixel(int x, int y, const Color& c)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   879
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   880
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   881
	RI_ASSERT(x >= 0 && x < m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   882
	RI_ASSERT(y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   883
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   884
	RI_ASSERT(c.getInternalFormat() == m_desc.internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   885
    x += m_storageOffsetX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   886
    y += m_storageOffsetY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   887
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   888
	unsigned int p = c.pack(m_desc);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   889
	RIuint8* scanline = m_data + y * m_stride;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   890
	switch(m_desc.bitsPerPixel)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   891
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   892
	case 32:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   893
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   894
		RIuint32* s = ((RIuint32*)scanline) + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   895
		*s = (RIuint32)p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   896
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   897
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   898
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   899
	case 16:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   900
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   901
		RIuint16* s = ((RIuint16*)scanline) + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   902
		*s = (RIuint16)p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   903
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   904
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   905
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   906
	case 8:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   907
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   908
		RIuint8* s = ((RIuint8*)scanline) + x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   909
		*s = (RIuint8)p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   910
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   911
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   912
    case 4:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   913
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   914
		RIuint8* s = ((RIuint8*)scanline) + (x>>1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   915
        *s = (RIuint8)((p << ((x&1)<<2)) | ((unsigned int)*s & ~(0xf << ((x&1)<<2))));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   916
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   917
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   918
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   919
    case 2:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   920
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   921
		RIuint8* s = ((RIuint8*)scanline) + (x>>2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   922
        *s = (RIuint8)((p << ((x&3)<<1)) | ((unsigned int)*s & ~(0x3 << ((x&3)<<1))));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   923
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   924
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   925
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   926
    default:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   927
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   928
		RI_ASSERT(m_desc.bitsPerPixel == 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   929
		RIuint8* s = ((RIuint8*)scanline) + (x>>3);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   930
        *s = (RIuint8)((p << (x&7)) | ((unsigned int)*s & ~(0x1 << (x&7))));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   931
		break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   932
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   933
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   934
	m_mipmapsValid = false;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   935
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   936
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   937
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   938
* \brief	Writes a filtered color to destination surface
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   939
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   940
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   941
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   942
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   943
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   944
void Image::writeFilteredPixel(int i, int j, const Color& color, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   945
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   946
	//section 3.4.4: before color space conversion, premultiplied colors are
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   947
	//clamped to alpha, and the color is converted to nonpremultiplied format
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   948
	//section 11.2: how to deal with channel mask
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   949
	//step 1
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   950
	Color f = color;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   951
	f.clamp();			//vgColorMatrix and vgLookups can produce colors that exceed alpha or [0,1] range
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   952
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   953
	//step 2: color space conversion
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   954
	f.convert((Color::InternalFormat)(m_desc.internalFormat & (Color::NONLINEAR | Color::LUMINANCE)));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   955
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   956
	//step 3: read the destination color and convert it to nonpremultiplied
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   957
	Color d = readPixel(i,j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   958
	d.unpremultiply();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   959
	RI_ASSERT(d.getInternalFormat() == f.getInternalFormat());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   960
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   961
	//step 4: replace the destination channels specified by the channelMask (channelmask is ignored for luminance formats)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   962
    if(!m_desc.isLuminance())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   963
    {   //rgba format => use channelmask
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   964
        if(channelMask & VG_RED)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   965
            d.r = f.r;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   966
        if(channelMask & VG_GREEN)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   967
            d.g = f.g;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   968
        if(channelMask & VG_BLUE)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   969
            d.b = f.b;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   970
        if(channelMask & VG_ALPHA)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   971
            d.a = f.a;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   972
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   973
    else d = f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   974
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   975
	//step 5: if destination is premultiplied, convert to premultiplied format
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   976
	if(m_desc.isPremultiplied())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   977
		d.premultiply();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   978
	//write the color to destination
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   979
	writePixel(i,j,d);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   980
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   981
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   982
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   983
* \brief	Reads the pixel (x,y) and converts it into an alpha mask value.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   984
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   985
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   986
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   987
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   988
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   989
RIfloat Image::readMaskPixel(int x, int y) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   990
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   991
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   992
	RI_ASSERT(x >= 0 && x < m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   993
	RI_ASSERT(y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   994
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   995
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   996
	Color c = readPixel(x,y);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   997
	if(m_desc.isLuminance())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   998
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
   999
		return c.r;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1000
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1001
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1002
	{	//rgba
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1003
		if(m_desc.alphaBits)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1004
			return c.a;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1005
		return c.r;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1006
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1007
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1008
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1009
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1010
* \brief	Writes the alpha mask to pixel (x,y).
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1011
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1012
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1013
* \note		Overwrites color.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1014
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1015
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1016
void Image::writeMaskPixel(int x, int y, RIfloat m)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1017
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1018
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1019
	RI_ASSERT(x >= 0 && x < m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1020
	RI_ASSERT(y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1021
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1022
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1023
    //if luminance or no alpha, red channel will be used, otherwise alpha channel will be used
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1024
    writePixel(x, y, Color(m,m,m,m,m_desc.internalFormat));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1025
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1026
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1027
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1028
* \brief	Reads a texel (u,v) at the given mipmap level. Tiling modes and
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1029
*			color space conversion are applied. Outputs color in premultiplied
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1030
*			format.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1031
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1032
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1033
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1034
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1035
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1036
Color Image::readTexel(int u, int v, int level, VGTilingMode tilingMode, const Color& tileFillColor) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1037
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1038
	const Image* image = this;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1039
	if( level > 0 )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1040
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1041
		RI_ASSERT(level <= m_mipmaps.size());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1042
		image = m_mipmaps[level-1];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1043
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1044
	RI_ASSERT(image);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1045
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1046
	Color p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1047
	if(tilingMode == VG_TILE_FILL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1048
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1049
		if(u < 0 || v < 0 || u >= image->m_width || v >= image->m_height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1050
			p = tileFillColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1051
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1052
			p = image->readPixel(u, v);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1053
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1054
	else if(tilingMode == VG_TILE_PAD)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1055
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1056
		u = RI_INT_MIN(RI_INT_MAX(u,0),image->m_width-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1057
		v = RI_INT_MIN(RI_INT_MAX(v,0),image->m_height-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1058
		p = image->readPixel(u, v);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1059
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1060
	else if(tilingMode == VG_TILE_REPEAT)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1061
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1062
		u = RI_INT_MOD(u, image->m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1063
		v = RI_INT_MOD(v, image->m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1064
		p = image->readPixel(u, v);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1065
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1066
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1067
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1068
		RI_ASSERT(tilingMode == VG_TILE_REFLECT);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1069
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1070
		u = RI_INT_MOD(u, image->m_width*2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1071
		v = RI_INT_MOD(v, image->m_height*2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1072
		if( u >= image->m_width ) u = image->m_width*2-1 - u;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1073
		if( v >= image->m_height ) v = image->m_height*2-1 - v;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1074
		p = image->readPixel(u, v);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1075
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1076
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1077
	p.premultiply();    //interpolate in premultiplied format
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1078
	return p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1079
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1080
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1081
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1082
* \brief	Maps point (x,y) to an image and returns a filtered,
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1083
*			premultiplied color value.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1084
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1085
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1086
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1087
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1088
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1089
Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGImageQuality quality, VGTilingMode tilingMode, const Color& tileFillColor)	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1090
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1091
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1092
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1093
	VGbitfield aq = getAllowedQuality();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1094
	aq &= (VGbitfield)quality;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1095
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1096
	Vector3 uvw(x,y,1.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1097
	uvw = surfaceToImage * uvw;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1098
	RIfloat oow = 1.0f / uvw.z;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1099
	uvw *= oow;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1100
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1101
	if(aq & VG_IMAGE_QUALITY_BETTER)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1102
	{	//EWA on mipmaps
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1103
		makeMipMaps();	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1104
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1105
		Color::InternalFormat procFormat = (Color::InternalFormat)(m_desc.internalFormat | Color::PREMULTIPLIED);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1106
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1107
		RIfloat m_pixelFilterRadius = 1.25f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1108
		RIfloat m_resamplingFilterRadius = 1.25f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1109
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1110
		RIfloat Ux = (surfaceToImage[0][0] - uvw.x * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1111
		RIfloat Vx = (surfaceToImage[1][0] - uvw.y * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1112
		RIfloat Uy = (surfaceToImage[0][1] - uvw.x * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1113
		RIfloat Vy = (surfaceToImage[1][1] - uvw.y * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1114
		RIfloat U0 = uvw.x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1115
		RIfloat V0 = uvw.y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1116
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1117
		//calculate mip level
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1118
		int level = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1119
		RIfloat axis1sq = Ux*Ux + Vx*Vx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1120
		RIfloat axis2sq = Uy*Uy + Vy*Vy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1121
		RIfloat minorAxissq = RI_MIN(axis1sq,axis2sq);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1122
		while(minorAxissq > 9.0f && level < m_mipmaps.size())	//half the minor axis must be at least three texels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1123
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1124
			level++;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1125
			minorAxissq *= 0.25f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1126
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1127
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1128
		RIfloat sx = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1129
		RIfloat sy = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1130
		if(level > 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1131
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1132
			sx = (RIfloat)m_mipmaps[level-1]->m_width / (RIfloat)m_width;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1133
			sy = (RIfloat)m_mipmaps[level-1]->m_height / (RIfloat)m_height;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1134
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1135
		Ux *= sx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1136
		Vx *= sx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1137
		U0 *= sx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1138
		Uy *= sy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1139
		Vy *= sy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1140
		V0 *= sy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1141
		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1142
		//clamp filter size so that filtering doesn't take excessive amount of time (clamping results in aliasing)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1143
		RIfloat lim = 100.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1144
		axis1sq = Ux*Ux + Vx*Vx;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1145
		axis2sq = Uy*Uy + Vy*Vy;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1146
		if( axis1sq > lim*lim )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1147
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1148
			RIfloat s = lim / (RIfloat)sqrt(axis1sq);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1149
			Ux *= s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1150
			Vx *= s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1151
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1152
		if( axis2sq > lim*lim )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1153
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1154
			RIfloat s = lim / (RIfloat)sqrt(axis2sq);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1155
			Uy *= s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1156
			Vy *= s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1157
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1158
		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1159
		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1160
		//form elliptic filter by combining texel and pixel filters
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1161
		RIfloat A = Vx*Vx + Vy*Vy + 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1162
		RIfloat B = -2.0f*(Ux*Vx + Uy*Vy);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1163
		RIfloat C = Ux*Ux + Uy*Uy + 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1164
		//scale by the user-defined size of the kernel
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1165
		A *= m_resamplingFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1166
		B *= m_resamplingFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1167
		C *= m_resamplingFilterRadius;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1168
		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1169
		//calculate bounding box in texture space
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1170
		RIfloat usize = (RIfloat)sqrt(C);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1171
		RIfloat vsize = (RIfloat)sqrt(A);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1172
		int u1 = (int)floor(U0 - usize + 0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1173
		int u2 = (int)floor(U0 + usize + 0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1174
		int v1 = (int)floor(V0 - vsize + 0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1175
		int v2 = (int)floor(V0 + vsize + 0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1176
		if( u1 == u2 || v1 == v2 )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1177
			return Color(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1178
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1179
		//scale the filter so that Q = 1 at the cutoff radius
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1180
		RIfloat F = A*C - 0.25f * B*B;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1181
		if( F <= 0.0f )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1182
			return Color(0,0,0,0,procFormat);	//invalid filter shape due to numerical inaccuracies => return black
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1183
		RIfloat ooF = 1.0f / F;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1184
		A *= ooF;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1185
		B *= ooF;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1186
		C *= ooF;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1187
		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1188
		//evaluate filter by using forward differences to calculate Q = A*U^2 + B*U*V + C*V^2
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1189
		Color color(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1190
		RIfloat sumweight = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1191
		RIfloat DDQ = 2.0f * A;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1192
		RIfloat U = (RIfloat)u1 - U0 + 0.5f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1193
		for(int v=v1;v<v2;v++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1194
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1195
			RIfloat V = (RIfloat)v - V0 + 0.5f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1196
			RIfloat DQ = A*(2.0f*U+1.0f) + B*V;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1197
			RIfloat Q = (C*V+B*U)*V + A*U*U;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1198
			for(int u=u1;u<u2;u++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1199
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1200
				if( Q >= 0.0f && Q < 1.0f )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1201
				{	//Q = r^2, fit gaussian to the range [0,1]
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1202
					RIfloat weight = (RIfloat)exp(-0.5f * 10.0f * Q);	//gaussian at radius 10 equals 0.0067
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1203
					color += weight * readTexel(u, v, level, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1204
					sumweight += weight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1205
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1206
				Q += DQ;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1207
				DQ += DDQ;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1208
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1209
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1210
		if( sumweight == 0.0f )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1211
			return Color(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1212
		RI_ASSERT(sumweight > 0.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1213
		sumweight = 1.0f / sumweight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1214
		return color * sumweight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1215
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1216
	else if(aq & VG_IMAGE_QUALITY_FASTER)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1217
	{	//bilinear
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1218
		uvw.x -= 0.5f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1219
		uvw.y -= 0.5f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1220
		int u = (int)floor(uvw.x);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1221
		int v = (int)floor(uvw.y);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1222
		Color c00 = readTexel(u,v, 0, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1223
		Color c10 = readTexel(u+1,v, 0, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1224
		Color c01 = readTexel(u,v+1, 0, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1225
		Color c11 = readTexel(u+1,v+1, 0, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1226
		RIfloat fu = uvw.x - (RIfloat)u;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1227
		RIfloat fv = uvw.y - (RIfloat)v;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1228
		Color c0 = c00 * (1.0f - fu) + c10 * fu;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1229
		Color c1 = c01 * (1.0f - fu) + c11 * fu;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1230
		return c0 * (1.0f - fv) + c1 * fv;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1231
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1232
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1233
	{	//point sampling
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1234
		return readTexel((int)floor(uvw.x), (int)floor(uvw.y), 0, tilingMode, tileFillColor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1235
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1236
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1237
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1238
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1239
* \brief	Generates mip maps for an image.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1240
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1241
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1242
* \note		Downsampling is done in the input color space. We use a box
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1243
*			filter for downsampling.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1244
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1245
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1246
void Image::makeMipMaps()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1247
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1248
	RI_ASSERT(m_data);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1249
	RI_ASSERT(m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1250
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1251
	if(m_mipmapsValid)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1252
		return;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1253
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1254
	//delete existing mipmaps
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1255
	for(int i=0;i<m_mipmaps.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1256
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1257
		if(!m_mipmaps[i]->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1258
			RI_DELETE(m_mipmaps[i]);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1259
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1260
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1261
			RI_ASSERT(0);	//there can't be any other references to the mipmap levels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1262
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1263
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1264
	m_mipmaps.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1265
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1266
	try
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1267
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1268
		Color::InternalFormat procFormat = m_desc.internalFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1269
		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);	//premultiplied
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1270
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1271
		//generate mipmaps until width and height are one
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1272
		Image* prev = this;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1273
		while( prev->m_width > 1 || prev->m_height > 1 )
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1274
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1275
			int nextw = (int)ceil(prev->m_width*0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1276
			int nexth = (int)ceil(prev->m_height*0.5f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1277
			RI_ASSERT(nextw >= 1 && nexth >= 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1278
			RI_ASSERT(nextw < prev->m_width || nexth < prev->m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1279
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1280
			m_mipmaps.resize(m_mipmaps.size()+1);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1281
			m_mipmaps[m_mipmaps.size()-1] = NULL;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1282
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1283
			Image* next = RI_NEW(Image, (m_desc, nextw, nexth, m_allowedQuality));	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1284
			next->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1285
			for(int j=0;j<next->m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1286
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1287
				for(int i=0;i<next->m_width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1288
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1289
					RIfloat u0 = (RIfloat)i / (RIfloat)next->m_width;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1290
					RIfloat u1 = (RIfloat)(i+1) / (RIfloat)next->m_width;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1291
					RIfloat v0 = (RIfloat)j / (RIfloat)next->m_height;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1292
					RIfloat v1 = (RIfloat)(j+1) / (RIfloat)next->m_height;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1293
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1294
					u0 *= prev->m_width;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1295
					u1 *= prev->m_width;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1296
					v0 *= prev->m_height;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1297
					v1 *= prev->m_height;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1298
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1299
					int su = (int)floor(u0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1300
					int eu = (int)ceil(u1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1301
					int sv = (int)floor(v0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1302
					int ev = (int)ceil(v1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1303
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1304
					Color c(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1305
					int samples = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1306
					for(int y=sv;y<ev;y++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1307
					{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1308
						for(int x=su;x<eu;x++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1309
						{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1310
							Color p = prev->readPixel(x, y);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1311
							p.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1312
							c += p;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1313
							samples++;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1314
						}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1315
					}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1316
					c *= (1.0f/samples);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1317
					c.convert(m_desc.internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1318
					next->writePixel(i,j,c);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1319
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1320
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1321
			m_mipmaps[m_mipmaps.size()-1] = next;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1322
			prev = next;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1323
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1324
		RI_ASSERT(prev->m_width == 1 && prev->m_height == 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1325
		m_mipmapsValid = true;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1326
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1327
	catch(std::bad_alloc)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1328
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1329
		//delete existing mipmaps
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1330
		for(int i=0;i<m_mipmaps.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1331
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1332
			if(m_mipmaps[i])
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1333
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1334
				if(!m_mipmaps[i]->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1335
					RI_DELETE(m_mipmaps[i]);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1336
				else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1337
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1338
					RI_ASSERT(0);	//there can't be any other references to the mipmap levels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1339
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1340
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1341
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1342
		m_mipmaps.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1343
		m_mipmapsValid = false;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1344
		throw;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1345
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1346
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1347
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1348
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1349
* \brief	Applies color matrix filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1350
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1351
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1352
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1353
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1354
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1355
void Image::colorMatrix(const Image& src, const RIfloat* matrix, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1356
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1357
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1358
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1359
	RI_ASSERT(matrix);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1360
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1361
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1362
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1363
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1364
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1365
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1366
	Color::InternalFormat srcFormat = src.m_desc.internalFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1367
	Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE);	//process in RGB, not luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1368
	if(filterFormatLinear)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1369
		procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1370
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1371
		procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1372
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1373
	if(filterFormatPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1374
		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1375
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1376
		procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1377
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1378
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1379
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1380
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1381
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1382
			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1383
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1384
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1385
			Color d(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1386
			d.r = matrix[0+4*0] * s.r + matrix[0+4*1] * s.g + matrix[0+4*2] * s.b + matrix[0+4*3] * s.a + matrix[0+4*4];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1387
			d.g = matrix[1+4*0] * s.r + matrix[1+4*1] * s.g + matrix[1+4*2] * s.b + matrix[1+4*3] * s.a + matrix[1+4*4];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1388
			d.b = matrix[2+4*0] * s.r + matrix[2+4*1] * s.g + matrix[2+4*2] * s.b + matrix[2+4*3] * s.a + matrix[2+4*4];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1389
			d.a = matrix[3+4*0] * s.r + matrix[3+4*1] * s.g + matrix[3+4*2] * s.b + matrix[3+4*3] * s.a + matrix[3+4*4];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1390
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1391
			writeFilteredPixel(i, j, d, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1392
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1393
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1394
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1395
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1396
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1397
* \brief	Reads a pixel from image with tiling mode applied.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1398
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1399
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1400
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1401
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1402
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1403
static Color readTiledPixel(int x, int y, int w, int h, VGTilingMode tilingMode, const Array<Color>& image, const Color& edge)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1404
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1405
	Color s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1406
	if(x < 0 || x >= w || y < 0 || y >= h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1407
	{	//apply tiling mode
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1408
		switch(tilingMode)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1409
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1410
		case VG_TILE_FILL:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1411
			s = edge;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1412
			break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1413
		case VG_TILE_PAD:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1414
			x = RI_INT_MIN(RI_INT_MAX(x, 0), w-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1415
			y = RI_INT_MIN(RI_INT_MAX(y, 0), h-1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1416
			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1417
			s = image[y*w+x];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1418
			break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1419
		case VG_TILE_REPEAT:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1420
			x = RI_INT_MOD(x, w);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1421
			y = RI_INT_MOD(y, h);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1422
			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1423
			s = image[y*w+x];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1424
			break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1425
		default:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1426
			RI_ASSERT(tilingMode == VG_TILE_REFLECT);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1427
			x = RI_INT_MOD(x, w*2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1428
			y = RI_INT_MOD(y, h*2);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1429
			if(x >= w) x = w*2-1-x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1430
			if(y >= h) y = h*2-1-y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1431
			RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1432
			s = image[y*w+x];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1433
			break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1434
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1435
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1436
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1437
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1438
		RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1439
		s = image[y*w+x];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1440
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1441
	return s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1442
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1443
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1444
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1445
* \brief	Returns processing format for filtering.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1446
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1447
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1448
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1449
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1450
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1451
static Color::InternalFormat getProcessingFormat(Color::InternalFormat srcFormat, bool filterFormatLinear, bool filterFormatPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1452
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1453
	Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE);	//process in RGB, not luminance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1454
	if(filterFormatLinear)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1455
		procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1456
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1457
		procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1458
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1459
	if(filterFormatPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1460
		procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1461
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1462
		procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1463
	return procFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1464
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1465
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1466
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1467
* \brief	Applies convolution filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1468
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1469
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1470
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1471
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1472
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1473
void Image::convolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernel, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1474
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1475
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1476
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1477
	RI_ASSERT(kernel && kernelWidth > 0 && kernelHeight > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1478
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1479
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1480
	//the area to be written is an intersection of source and destination image areas.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1481
	//lower-left corners of the images are aligned.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1482
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1483
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1484
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1485
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1486
	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1487
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1488
	Color edge = edgeFillColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1489
	edge.clamp();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1490
	edge.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1491
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1492
	Array<Color> tmp;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1493
	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1494
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1495
	//copy source region to tmp and do conversion
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1496
	for(int j=0;j<src.m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1497
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1498
		for(int i=0;i<src.m_width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1499
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1500
			Color s = src.readPixel(i, j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1501
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1502
			tmp[j*src.m_width+i] = s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1503
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1504
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1505
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1506
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1507
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1508
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1509
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1510
			Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1511
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1512
			for(int kj=0;kj<kernelHeight;kj++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1513
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1514
				for(int ki=0;ki<kernelWidth;ki++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1515
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1516
					int x = i+ki-shiftX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1517
					int y = j+kj-shiftY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1518
					Color s = readTiledPixel(x, y, src.m_width, src.m_height, tilingMode, tmp, edge);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1519
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1520
					int kx = kernelWidth-ki-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1521
					int ky = kernelHeight-kj-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1522
					RI_ASSERT(kx >= 0 && kx < kernelWidth && ky >= 0 && ky < kernelHeight);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1523
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1524
					sum += (RIfloat)kernel[kx*kernelHeight+ky] * s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1525
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1526
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1527
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1528
			sum *= scale;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1529
			sum.r += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1530
			sum.g += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1531
			sum.b += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1532
			sum.a += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1533
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1534
			writeFilteredPixel(i, j, sum, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1535
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1536
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1537
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1538
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1539
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1540
* \brief	Applies separable convolution filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1541
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1542
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1543
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1544
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1545
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1546
void Image::separableConvolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernelX, const RIint16* kernelY, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1547
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1548
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1549
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1550
	RI_ASSERT(kernelX && kernelY && kernelWidth > 0 && kernelHeight > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1551
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1552
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1553
	//the area to be written is an intersection of source and destination image areas.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1554
	//lower-left corners of the images are aligned.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1555
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1556
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1557
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1558
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1559
	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1560
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1561
	Color edge = edgeFillColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1562
	edge.clamp();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1563
	edge.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1564
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1565
	Array<Color> tmp;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1566
	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1567
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1568
	//copy source region to tmp and do conversion
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1569
	for(int j=0;j<src.m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1570
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1571
		for(int i=0;i<src.m_width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1572
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1573
			Color s = src.readPixel(i, j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1574
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1575
			tmp[j*src.m_width+i] = s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1576
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1577
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1578
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1579
	Array<Color> tmp2;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1580
	tmp2.resize(w*src.m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1581
	for(int j=0;j<src.m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1582
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1583
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1584
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1585
			Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1586
			for(int ki=0;ki<kernelWidth;ki++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1587
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1588
				int x = i+ki-shiftX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1589
				Color s = readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1590
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1591
				int kx = kernelWidth-ki-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1592
				RI_ASSERT(kx >= 0 && kx < kernelWidth);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1593
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1594
				sum += (RIfloat)kernelX[kx] * s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1595
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1596
			tmp2[j*w+i] = sum;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1597
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1598
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1599
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1600
	if(tilingMode == VG_TILE_FILL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1601
	{	//convolve the edge color
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1602
		Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1603
		for(int ki=0;ki<kernelWidth;ki++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1604
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1605
			sum += (RIfloat)kernelX[ki] * edge;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1606
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1607
		edge = sum;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1608
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1609
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1610
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1611
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1612
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1613
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1614
			Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1615
			for(int kj=0;kj<kernelHeight;kj++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1616
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1617
				int y = j+kj-shiftY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1618
				Color s = readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1619
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1620
				int ky = kernelHeight-kj-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1621
				RI_ASSERT(ky >= 0 && ky < kernelHeight);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1622
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1623
				sum += (RIfloat)kernelY[ky] * s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1624
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1625
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1626
			sum *= scale;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1627
			sum.r += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1628
			sum.g += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1629
			sum.b += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1630
			sum.a += bias;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1631
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1632
			writeFilteredPixel(i, j, sum, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1633
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1634
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1635
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1636
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1637
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1638
* \brief	Applies Gaussian blur filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1639
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1640
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1641
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1642
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1643
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1644
void Image::gaussianBlur(const Image& src, RIfloat stdDeviationX, RIfloat stdDeviationY, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1645
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1646
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1647
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1648
	RI_ASSERT(stdDeviationX > 0.0f && stdDeviationY > 0.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1649
	RI_ASSERT(stdDeviationX <= RI_MAX_GAUSSIAN_STD_DEVIATION && stdDeviationY <= RI_MAX_GAUSSIAN_STD_DEVIATION);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1650
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1651
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1652
	//the area to be written is an intersection of source and destination image areas.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1653
	//lower-left corners of the images are aligned.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1654
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1655
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1656
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1657
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1658
	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1659
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1660
	Color edge = edgeFillColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1661
	edge.clamp();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1662
	edge.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1663
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1664
	Array<Color> tmp;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1665
	tmp.resize(src.m_width*src.m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1666
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1667
	//copy source region to tmp and do conversion
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1668
	for(int j=0;j<src.m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1669
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1670
		for(int i=0;i<src.m_width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1671
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1672
			Color s = src.readPixel(i, j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1673
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1674
			tmp[j*src.m_width+i] = s;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1675
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1676
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1677
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1678
	RIfloat expScaleX = -1.0f / (2.0f*stdDeviationX*stdDeviationX);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1679
	RIfloat expScaleY = -1.0f / (2.0f*stdDeviationY*stdDeviationY);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1680
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1681
	int kernelWidth = (int)(stdDeviationX * 4.0f + 1.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1682
	int kernelHeight = (int)(stdDeviationY * 4.0f + 1.0f);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1683
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1684
	//make a separable kernel
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1685
	Array<RIfloat> kernelX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1686
	kernelX.resize(kernelWidth*2+1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1687
	int shiftX = kernelWidth;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1688
	RIfloat scaleX = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1689
	for(int i=0;i<kernelX.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1690
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1691
		int x = i-shiftX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1692
		kernelX[i] = (RIfloat)exp((RIfloat)x*(RIfloat)x * expScaleX);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1693
		scaleX += kernelX[i];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1694
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1695
	scaleX = 1.0f / scaleX;	//NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1696
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1697
	Array<RIfloat> kernelY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1698
	kernelY.resize(kernelHeight*2+1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1699
	int shiftY = kernelHeight;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1700
	RIfloat scaleY = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1701
	for(int i=0;i<kernelY.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1702
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1703
		int y = i-shiftY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1704
		kernelY[i] = (RIfloat)exp((RIfloat)y*(RIfloat)y * expScaleY);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1705
		scaleY += kernelY[i];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1706
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1707
	scaleY = 1.0f / scaleY;	//NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1708
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1709
	Array<Color> tmp2;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1710
	tmp2.resize(w*src.m_height);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1711
	//horizontal pass
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1712
	for(int j=0;j<src.m_height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1713
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1714
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1715
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1716
			Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1717
			for(int ki=0;ki<kernelX.size();ki++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1718
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1719
				int x = i+ki-shiftX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1720
				sum += kernelX[ki] * readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1721
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1722
			tmp2[j*w+i] = sum * scaleX;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1723
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1724
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1725
	//vertical pass
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1726
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1727
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1728
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1729
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1730
			Color sum(0,0,0,0,procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1731
			for(int kj=0;kj<kernelY.size();kj++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1732
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1733
				int y = j+kj-shiftY;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1734
				sum += kernelY[kj] * readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1735
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1736
			writeFilteredPixel(i, j, sum * scaleY, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1737
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1738
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1739
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1740
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1741
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1742
* \brief	Returns lookup table format for lookup filters.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1743
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1744
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1745
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1746
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1747
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1748
static Color::InternalFormat getLUTFormat(bool outputLinear, bool outputPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1749
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1750
	Color::InternalFormat lutFormat = Color::lRGBA;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1751
	if(outputLinear && outputPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1752
		lutFormat = Color::lRGBA_PRE;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1753
	else if(!outputLinear && !outputPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1754
		lutFormat = Color::sRGBA;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1755
	else if(!outputLinear && outputPremultiplied)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1756
		lutFormat = Color::sRGBA_PRE;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1757
	return lutFormat;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1758
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1759
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1760
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1761
* \brief	Applies multi-channel lookup table filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1762
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1763
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1764
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1765
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1766
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1767
void Image::lookup(const Image& src, const RIuint8 * redLUT, const RIuint8 * greenLUT, const RIuint8 * blueLUT, const RIuint8 * alphaLUT, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1768
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1769
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1770
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1771
	RI_ASSERT(redLUT && greenLUT && blueLUT && alphaLUT);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1772
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1773
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1774
	//the area to be written is an intersection of source and destination image areas.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1775
	//lower-left corners of the images are aligned.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1776
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1777
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1778
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1779
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1780
	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1781
	Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1782
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1783
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1784
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1785
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1786
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1787
			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1788
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1789
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1790
			Color d(0,0,0,0,lutFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1791
			d.r = intToColor(  redLUT[colorToInt(s.r, 255)], 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1792
			d.g = intToColor(greenLUT[colorToInt(s.g, 255)], 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1793
			d.b = intToColor( blueLUT[colorToInt(s.b, 255)], 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1794
			d.a = intToColor(alphaLUT[colorToInt(s.a, 255)], 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1795
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1796
			writeFilteredPixel(i, j, d, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1797
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1798
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1799
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1800
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1801
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1802
* \brief	Applies single channel lookup table filter.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1803
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1804
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1805
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1806
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1807
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1808
void Image::lookupSingle(const Image& src, const RIuint32 * lookupTable, VGImageChannel sourceChannel, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1809
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1810
	RI_ASSERT(src.m_data);	//source exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1811
	RI_ASSERT(m_data);	//destination exists
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1812
	RI_ASSERT(lookupTable);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1813
	RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1814
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1815
	//the area to be written is an intersection of source and destination image areas.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1816
	//lower-left corners of the images are aligned.
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1817
	int w = RI_INT_MIN(m_width, src.m_width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1818
	int h = RI_INT_MIN(m_height, src.m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1819
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1820
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1821
	if(src.m_desc.isLuminance())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1822
		sourceChannel = VG_RED;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1823
	else if(src.m_desc.redBits + src.m_desc.greenBits + src.m_desc.blueBits == 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1824
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1825
		RI_ASSERT(src.m_desc.alphaBits);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1826
		sourceChannel = VG_ALPHA;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1827
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1828
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1829
	Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1830
	Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1831
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1832
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1833
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1834
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1835
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1836
			Color s = src.readPixel(i,j);	//convert to RGBA [0,1]
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1837
			s.convert(procFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1838
			int e;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1839
			switch(sourceChannel)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1840
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1841
			case VG_RED:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1842
				e = colorToInt(s.r, 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1843
				break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1844
			case VG_GREEN:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1845
				e = colorToInt(s.g, 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1846
				break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1847
			case VG_BLUE:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1848
				e = colorToInt(s.b, 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1849
				break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1850
			default:
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1851
				RI_ASSERT(sourceChannel == VG_ALPHA);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1852
				e = colorToInt(s.a, 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1853
				break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1854
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1855
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1856
			RIuint32 l = ((const RIuint32*)lookupTable)[e];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1857
			Color d(0,0,0,0,lutFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1858
			d.r = intToColor((l>>24), 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1859
			d.g = intToColor((l>>16), 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1860
			d.b = intToColor((l>> 8), 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1861
			d.a = intToColor((l    ), 255);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1862
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1863
			writeFilteredPixel(i, j, d, channelMask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1864
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1865
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1866
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1867
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1868
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1869
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1870
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1871
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1872
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1873
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1874
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1875
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1876
Surface::Surface(const Color::Descriptor& desc, int width, int height, int numSamples) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1877
	m_width(width),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1878
	m_height(height),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1879
	m_numSamples(numSamples),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1880
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1881
	m_image(NULL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1882
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1883
	RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1884
	m_image = RI_NEW(Image, (desc, width*numSamples, height, 0));	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1885
	m_image->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1886
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1887
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1888
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1889
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1890
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1891
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1892
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1893
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1894
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1895
Surface::Surface(Image* image) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1896
	m_width(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1897
	m_height(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1898
	m_numSamples(1),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1899
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1900
	m_image(image)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1901
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1902
	RI_ASSERT(image);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1903
	m_width = image->getWidth();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1904
	m_height = image->getHeight();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1905
	m_image->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1906
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1907
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1908
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1909
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1910
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1911
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1912
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1913
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1914
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1915
Surface::Surface(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1916
	m_width(width),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1917
	m_height(height),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1918
	m_numSamples(1),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1919
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1920
	m_image(NULL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1921
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1922
	RI_ASSERT(width > 0 && height > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1923
	m_image = RI_NEW(Image, (desc, width, height, stride, data));	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1924
	m_image->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1925
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1926
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1927
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1928
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1929
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1930
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1931
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1932
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1933
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1934
Surface::~Surface()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1935
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1936
	RI_ASSERT(m_referenceCount == 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1937
	if(!m_image->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1938
		RI_DELETE(m_image);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1939
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1940
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1941
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1942
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1943
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1944
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1945
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1946
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1947
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1948
void Surface::clear(const Color& clearColor, int x, int y, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1949
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1950
	Rectangle rect;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1951
	rect.x = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1952
	rect.y = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1953
	rect.width = getWidth();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1954
	rect.height = getHeight();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1955
	Array<Rectangle> scissors;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1956
	scissors.push_back(rect);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1957
	clear(clearColor, x, y, w, h, scissors);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1958
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1959
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1960
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1961
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1962
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1963
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1964
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1965
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1966
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1967
void Surface::clear(const Color& clearColor, int x, int y, int w, int h, const Array<Rectangle>& scissors)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1968
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1969
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1970
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1971
	//intersect clear region with image bounds
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1972
	Rectangle r(0,0,getWidth(),getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1973
	r.intersect(Rectangle(x,y,w,h));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1974
	if(!r.width || !r.height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1975
		return;		//intersection is empty or one of the rectangles is invalid
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1976
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1977
	Array<ScissorEdge> scissorEdges;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1978
	for(int i=0;i<scissors.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1979
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1980
		if(scissors[i].width > 0 && scissors[i].height > 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1981
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1982
			ScissorEdge e;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1983
			e.miny = scissors[i].y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1984
			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1985
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1986
			e.x = scissors[i].x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1987
			e.direction = 1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1988
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1989
			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1990
			e.direction = -1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1991
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1992
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1993
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1994
	if(!scissorEdges.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1995
		return;	//there are no scissor rectangles => nothing is visible
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1996
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1997
	//sort scissor edges by edge x
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1998
    scissorEdges.sort();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  1999
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2000
	//clear the image
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2001
	Color col = clearColor;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2002
	col.clamp();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2003
	col.convert(m_image->getDescriptor().internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2004
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2005
	Array<ScissorEdge> scissorAet;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2006
	for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2007
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2008
		//gather scissor edges intersecting this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2009
		scissorAet.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2010
		for(int e=0;e<scissorEdges.size();e++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2011
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2012
			const ScissorEdge& se = scissorEdges[e];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2013
			if(j >= se.miny && j < se.maxy)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2014
				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2015
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2016
		if(!scissorAet.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2017
			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2018
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2019
		//clear a scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2020
		int scissorWinding = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2021
		int scissorIndex = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2022
		for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2023
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2024
			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= i)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2025
				scissorWinding += scissorAet[scissorIndex++].direction;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2026
			RI_ASSERT(scissorWinding >= 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2027
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2028
			if(scissorWinding)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2029
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2030
                for(int s=0;s<m_numSamples;s++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2031
                    writeSample(i, j, s, col);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2032
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2033
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2034
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2035
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2036
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2037
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2038
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2039
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2040
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2041
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2042
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2043
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2044
void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2045
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2046
	Rectangle rect;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2047
	rect.x = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2048
	rect.y = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2049
	rect.width = getWidth();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2050
	rect.height = getHeight();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2051
	Array<Rectangle> scissors;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2052
	scissors.push_back(rect);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2053
	blit(src, sx, sy, dx, dy, w, h, scissors);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2054
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2055
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2056
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2057
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2058
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2059
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2060
* \note		no overlap is possible. Single sample to single or multisample (replicate)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2061
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2062
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2063
void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2064
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2065
	//img=>fb: vgSetPixels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2066
	//user=>fb: vgWritePixels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2067
	computeBlitRegion(sx, sy, dx, dy, w, h, src.getWidth(), src.getHeight(), getWidth(), getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2068
	if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2069
		return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2070
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2071
	Array<ScissorEdge> scissorEdges;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2072
	for(int i=0;i<scissors.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2073
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2074
		if(scissors[i].width > 0 && scissors[i].height > 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2075
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2076
			ScissorEdge e;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2077
			e.miny = scissors[i].y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2078
			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2079
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2080
			e.x = scissors[i].x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2081
			e.direction = 1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2082
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2083
			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2084
			e.direction = -1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2085
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2086
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2087
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2088
	if(!scissorEdges.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2089
		return;	//there are no scissor rectangles => nothing is visible
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2090
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2091
	//sort scissor edges by edge x
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2092
    scissorEdges.sort();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2093
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2094
	Array<ScissorEdge> scissorAet;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2095
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2096
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2097
		//gather scissor edges intersecting this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2098
		scissorAet.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2099
		for(int e=0;e<scissorEdges.size();e++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2100
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2101
			const ScissorEdge& se = scissorEdges[e];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2102
			if(dy + j >= se.miny && dy + j < se.maxy)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2103
				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2104
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2105
		if(!scissorAet.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2106
			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2107
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2108
		//blit a scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2109
		int scissorWinding = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2110
		int scissorIndex = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2111
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2112
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2113
			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2114
				scissorWinding += scissorAet[scissorIndex++].direction;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2115
			RI_ASSERT(scissorWinding >= 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2116
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2117
			if(scissorWinding)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2118
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2119
				Color c = src.readPixel(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2120
				c.convert(getDescriptor().internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2121
                for(int s=0;s<m_numSamples;s++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2122
                    writeSample(dx + i, dy + j, s, c);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2123
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2124
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2125
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2126
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2127
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2128
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2129
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2130
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2131
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2132
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2133
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2134
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2135
void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2136
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2137
	Rectangle rect;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2138
	rect.x = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2139
	rect.y = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2140
	rect.width = getWidth();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2141
	rect.height = getHeight();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2142
	Array<Rectangle> scissors;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2143
	scissors.push_back(rect);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2144
	blit(src, sx, sy, dx, dy, w, h, scissors);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2145
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2146
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2147
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2148
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2149
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2150
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2151
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2152
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2153
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2154
void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2155
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2156
    RI_ASSERT(m_numSamples == src->m_numSamples);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2157
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2158
	//fb=>fb: vgCopyPixels
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2159
	computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2160
	if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2161
		return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2162
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2163
	Array<ScissorEdge> scissorEdges;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2164
	for(int i=0;i<scissors.size();i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2165
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2166
		if(scissors[i].width > 0 && scissors[i].height > 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2167
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2168
			ScissorEdge e;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2169
			e.miny = scissors[i].y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2170
			e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2171
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2172
			e.x = scissors[i].x;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2173
			e.direction = 1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2174
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2175
			e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2176
			e.direction = -1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2177
			scissorEdges.push_back(e);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2178
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2179
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2180
	if(!scissorEdges.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2181
		return;	//there are no scissor rectangles => nothing is visible
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2182
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2183
	//sort scissor edges by edge x
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2184
    scissorEdges.sort();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2185
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2186
	Array<Color> tmp;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2187
	tmp.resize(w*m_numSamples*h);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2188
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2189
	//copy source region to tmp
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2190
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2191
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2192
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2193
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2194
			int numSamples = m_numSamples;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2195
			for(int s=0;s<numSamples;s++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2196
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2197
				Color c = src->m_image->readPixel((sx + i)*m_numSamples+s, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2198
				c.convert(m_image->getDescriptor().internalFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2199
				tmp[(j*w+i)*m_numSamples+s] = c;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2200
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2201
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2202
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2203
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2204
	Array<ScissorEdge> scissorAet;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2205
	for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2206
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2207
		//gather scissor edges intersecting this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2208
		scissorAet.clear();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2209
		for(int e=0;e<scissorEdges.size();e++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2210
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2211
			const ScissorEdge& se = scissorEdges[e];
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2212
			if(dy + j >= se.miny && dy + j < se.maxy)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2213
				scissorAet.push_back(scissorEdges[e]);	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2214
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2215
		if(!scissorAet.size())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2216
			continue;	//scissoring is on, but there are no scissor rectangles on this scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2217
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2218
		//blit a scanline
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2219
		int scissorWinding = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2220
		int scissorIndex = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2221
		for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2222
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2223
			while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2224
				scissorWinding += scissorAet[scissorIndex++].direction;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2225
			RI_ASSERT(scissorWinding >= 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2226
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2227
			if(scissorWinding)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2228
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2229
				int numSamples = m_numSamples;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2230
				for(int s=0;s<numSamples;s++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2231
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2232
					m_image->writePixel((dx + i)*m_numSamples+s, dy + j, tmp[(j*w+i)*m_numSamples+s]);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2233
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2234
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2235
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2236
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2237
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2238
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2239
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2240
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2241
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2242
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2243
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2244
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2245
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2246
void Surface::mask(const Image* src, VGMaskOperation operation, int x, int y, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2247
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2248
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2249
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2250
	if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2251
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2252
		//intersect clear region with image bounds
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2253
		Rectangle r(0,0,getWidth(),getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2254
		r.intersect(Rectangle(x,y,w,h));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2255
		if(!r.width || !r.height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2256
			return;		//intersection is empty or one of the rectangles is invalid
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2257
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2258
		if(m_numSamples == 1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2259
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2260
			RIfloat m = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2261
			if(operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2262
				m = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2263
			for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2264
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2265
				for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2266
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2267
					writeMaskCoverage(i, j, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2268
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2269
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2270
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2271
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2272
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2273
			unsigned int m = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2274
			if(operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2275
				m = (1<<m_numSamples)-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2276
			for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2277
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2278
				for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2279
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2280
					writeMaskMSAA(i, j, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2281
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2282
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2283
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2284
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2285
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2286
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2287
		RI_ASSERT(src);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2288
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2289
		int sx = 0, sy = 0, dx = x, dy = y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2290
		computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2291
		if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2292
			return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2293
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2294
		if(m_numSamples == 1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2295
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2296
			for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2297
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2298
				for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2299
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2300
					RIfloat amask = src->readMaskPixel(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2301
					if(operation == VG_SET_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2302
						writeMaskCoverage(dx + i, dy + j, amask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2303
					else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2304
					{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2305
						RIfloat aprev = readMaskCoverage(dx + i, dy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2306
						RIfloat anew = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2307
						switch(operation)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2308
						{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2309
						case VG_UNION_MASK:		anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2310
						case VG_INTERSECT_MASK:	anew = amask * aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2311
						default:				anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2312
						}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2313
						writeMaskCoverage(dx + i, dy + j, anew);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2314
					}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2315
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2316
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2317
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2318
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2319
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2320
			for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2321
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2322
				for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2323
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2324
					RIfloat fmask = src->readMaskPixel(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2325
					//TODO implement dithering?
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2326
					unsigned int amask = fmask > 0.5f ? (1<<m_numSamples)-1 : 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2327
					if(operation == VG_SET_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2328
						writeMaskMSAA(dx + i, dy + j, amask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2329
					else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2330
					{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2331
						unsigned int aprev = readMaskMSAA(dx + i, dy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2332
						unsigned int anew = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2333
						switch(operation)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2334
						{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2335
						case VG_UNION_MASK:		anew = amask | aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2336
						case VG_INTERSECT_MASK:	anew = amask & aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2337
						default:				anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2338
						}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2339
						writeMaskMSAA(dx + i, dy + j, anew);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2340
					}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2341
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2342
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2343
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2344
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2345
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2346
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2347
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2348
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2349
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2350
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2351
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2352
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2353
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2354
void Surface::mask(const Surface* src, VGMaskOperation operation, int x, int y, int w, int h)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2355
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2356
	RI_ASSERT(w > 0 && h > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2357
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2358
	if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2359
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2360
		//intersect clear region with image bounds
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2361
		Rectangle r(0,0,getWidth(),getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2362
		r.intersect(Rectangle(x,y,w,h));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2363
		if(!r.width || !r.height)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2364
			return;		//intersection is empty or one of the rectangles is invalid
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2365
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2366
		if(m_numSamples == 1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2367
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2368
			RIfloat m = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2369
			if(operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2370
				m = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2371
			for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2372
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2373
				for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2374
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2375
					writeMaskCoverage(i, j, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2376
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2377
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2378
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2379
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2380
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2381
			unsigned int m = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2382
			if(operation == VG_FILL_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2383
				m = (1<<m_numSamples)-1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2384
			for(int j=r.y;j<r.y + r.height;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2385
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2386
				for(int i=r.x;i<r.x + r.width;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2387
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2388
					writeMaskMSAA(i, j, m);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2389
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2390
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2391
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2392
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2393
	else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2394
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2395
		RI_ASSERT(src);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2396
        RI_ASSERT(m_numSamples == src->m_numSamples);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2397
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2398
		int sx = 0, sy = 0, dx = x, dy = y;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2399
		computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2400
		if(w <= 0 || h <= 0)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2401
			return;	//zero area
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2402
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2403
		if(m_numSamples == 1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2404
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2405
			for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2406
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2407
				for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2408
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2409
					RIfloat amask = src->readMaskCoverage(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2410
					if(operation == VG_SET_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2411
						writeMaskCoverage(dx + i, dy + j, amask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2412
					else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2413
					{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2414
						RIfloat aprev = readMaskCoverage(dx + i, dy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2415
						RIfloat anew = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2416
						switch(operation)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2417
						{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2418
						case VG_UNION_MASK:		anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2419
						case VG_INTERSECT_MASK:	anew = amask * aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2420
						default:				anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2421
						}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2422
						writeMaskCoverage(dx + i, dy + j, anew);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2423
					}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2424
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2425
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2426
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2427
		else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2428
		{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2429
			for(int j=0;j<h;j++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2430
			{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2431
				for(int i=0;i<w;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2432
				{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2433
					unsigned int amask = src->readMaskMSAA(sx + i, sy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2434
					if(operation == VG_SET_MASK)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2435
						writeMaskMSAA(dx + i, dy + j, amask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2436
					else
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2437
					{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2438
						unsigned int aprev = readMaskMSAA(dx + i, dy + j);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2439
						unsigned int anew = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2440
						switch(operation)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2441
						{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2442
						case VG_UNION_MASK:		anew = amask | aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2443
						case VG_INTERSECT_MASK:	anew = amask & aprev; break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2444
						default:				anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2445
						}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2446
						writeMaskMSAA(dx + i, dy + j, anew);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2447
					}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2448
				}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2449
			}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2450
		}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2451
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2452
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2453
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2454
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2455
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2456
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2457
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2458
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2459
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2460
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2461
RIfloat Surface::readMaskCoverage(int x, int y) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2462
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2463
	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2464
    RI_ASSERT(m_numSamples == 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2465
	return m_image->readMaskPixel(x, y);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2466
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2467
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2468
void Surface::writeMaskCoverage(int x, int y, RIfloat m)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2469
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2470
	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2471
    RI_ASSERT(m_numSamples == 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2472
    m_image->writeMaskPixel(x, y, m);    //TODO support other than alpha formats but don't write to color channels?
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2473
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2474
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2475
unsigned int Surface::readMaskMSAA(int x, int y) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2476
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2477
	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2478
    RI_ASSERT(m_numSamples > 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2479
    unsigned int m = 0;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2480
    for(int i=0;i<m_numSamples;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2481
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2482
        if(m_image->readMaskPixel(x*m_numSamples+i, y) > 0.5f)   //TODO is this the right formula for converting alpha to bit mask? does it matter?
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2483
            m |= 1<<i;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2484
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2485
    return m;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2486
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2487
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2488
void Surface::writeMaskMSAA(int x, int y, unsigned int m)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2489
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2490
	RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2491
    RI_ASSERT(m_numSamples > 1);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2492
    for(int i=0;i<m_numSamples;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2493
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2494
        RIfloat a = 0.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2495
        if(m & (1<<i))
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2496
            a = 1.0f;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2497
        m_image->writeMaskPixel(x*m_numSamples+i, y, a);    //TODO support other than alpha formats but don't write to color channels?
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2498
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2499
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2500
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2501
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2502
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2503
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2504
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2505
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2506
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2507
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2508
Color Surface::FSAAResolve(int x, int y) const
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2509
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2510
	if(m_numSamples == 1)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2511
		return readSample(x, y, 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2512
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2513
	Color::InternalFormat aaFormat = getDescriptor().isLuminance() ? Color::lLA_PRE : Color::lRGBA_PRE;	//antialias in linear color space
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2514
	Color r(0.0f, 0.0f, 0.0f, 0.0f, aaFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2515
	for(int i=0;i<m_numSamples;i++)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2516
	{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2517
		Color d = readSample(x, y, i);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2518
		d.convert(aaFormat);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2519
		r += d;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2520
	}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2521
	r *= 1.0f/m_numSamples;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2522
	return r;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2523
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2524
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2525
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2526
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2527
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2528
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2529
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2530
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2531
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2532
Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int numSamples, int maskBits) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2533
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2534
	m_color(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2535
	m_mask(NULL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2536
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2537
	RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2538
	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2539
    m_color = RI_NEW(Surface, (desc, width, height, numSamples));	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2540
	m_color->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2541
    if(maskBits)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2542
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2543
        VGImageFormat mf = VG_A_1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2544
        if(maskBits == 4)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2545
            mf = VG_A_4;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2546
        else if(maskBits == 8)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2547
            mf = VG_A_8;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2548
        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, numSamples));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2549
        m_mask->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2550
        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2551
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2552
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2553
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2554
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2555
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2556
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2557
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2558
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2559
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2560
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2561
Drawable::Drawable(Image* image, int maskBits) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2562
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2563
	m_color(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2564
	m_mask(NULL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2565
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2566
	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2567
	RI_ASSERT(image);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2568
    m_color = RI_NEW(Surface, (image));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2569
	m_color->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2570
    if(maskBits)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2571
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2572
        VGImageFormat mf = VG_A_1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2573
        if(maskBits == 4)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2574
            mf = VG_A_4;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2575
        else if(maskBits == 8)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2576
            mf = VG_A_8;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2577
        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), image->getWidth(), image->getHeight(), 1));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2578
        m_mask->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2579
        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, image->getWidth(), image->getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2580
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2581
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2582
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2583
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2584
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2585
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2586
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2587
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2588
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2589
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2590
Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data, int maskBits) :
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2591
	m_referenceCount(0),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2592
	m_color(NULL),
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2593
	m_mask(NULL)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2594
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2595
	RI_ASSERT(width > 0 && height > 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2596
	RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2597
	m_color = RI_NEW(Surface, (desc, width, height, stride, data));	//throws bad_alloc
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2598
	m_color->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2599
    if(maskBits)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2600
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2601
        VGImageFormat mf = VG_A_1;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2602
        if(maskBits == 4)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2603
            mf = VG_A_4;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2604
        else if(maskBits == 8)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2605
            mf = VG_A_8;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2606
        m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, 1));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2607
        m_mask->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2608
        m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2609
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2610
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2611
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2612
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2613
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2614
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2615
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2616
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2617
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2618
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2619
Drawable::~Drawable()
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2620
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2621
	RI_ASSERT(m_referenceCount == 0);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2622
	if(!m_color->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2623
		RI_DELETE(m_color);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2624
    if(m_mask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2625
        if(!m_mask->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2626
            RI_DELETE(m_mask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2627
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2628
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2629
/*-------------------------------------------------------------------*//*!
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2630
* \brief	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2631
* \param	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2632
* \return	
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2633
* \note		
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2634
*//*-------------------------------------------------------------------*/
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2635
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2636
void Drawable::resize(int newWidth, int newHeight)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2637
{
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2638
	Surface* oldcolor = m_color;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2639
	Surface* oldmask = m_mask;
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2640
	int oldWidth = m_color->getWidth();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2641
	int oldHeight = m_color->getHeight();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2642
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2643
	//TODO check that image is not a proxy
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2644
	m_color = RI_NEW(Surface, (m_color->getDescriptor(), newWidth, newHeight, m_color->getNumSamples()));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2645
	m_color->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2646
    if(m_mask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2647
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2648
        m_mask = RI_NEW(Surface, (m_mask->getDescriptor(), newWidth, newHeight, m_mask->getNumSamples()));
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2649
        m_mask->addReference();
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2650
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2651
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2652
	int wmin = RI_INT_MIN(newWidth,oldWidth);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2653
	int hmin = RI_INT_MIN(newHeight,oldHeight);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2654
	m_color->clear(Color(0.0f, 0.0f, 0.0f, 0.0f, getDescriptor().internalFormat), 0, 0, m_color->getWidth(), m_color->getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2655
    m_color->blit(oldcolor, 0, 0, 0, 0, wmin, hmin);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2656
    if(m_mask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2657
    {
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2658
        m_mask->clear(Color(1.0f, 1.0f, 1.0f, 1.0f, getDescriptor().internalFormat), 0, 0, m_mask->getWidth(), m_mask->getHeight());
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2659
        m_mask->blit(oldmask, 0, 0, 0, 0, wmin, hmin);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2660
    }
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2661
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2662
	if(!oldcolor->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2663
		RI_DELETE(oldcolor);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2664
    if(oldmask)
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2665
        if(!oldmask->removeReference())
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2666
            RI_DELETE(oldmask);
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2667
}
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2668
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2669
//==============================================================================================
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2670
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2671
}	//namespace OpenVGRI
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2672
2bf8a359aa2f Create EGL 1.4 implementation by merging eglrefimpl and EGL from sfopenvg
Jose Thachil<jose.thachil@cell-telecom.com>
parents:
diff changeset
  2673
//==============================================================================================