author | Matt Plumtree <matt.plumtree@nokia.com> |
Mon, 01 Nov 2010 18:10:32 +0000 | |
branch | bug235_bringup_0 |
changeset 69 | 3f914c77c2e9 |
parent 53 | c2ef9095503a |
permissions | -rw-r--r-- |
24 | 1 |
/*------------------------------------------------------------------------ |
2 |
* |
|
3 |
* OpenVG 1.1 Reference Implementation |
|
4 |
* ----------------------------------- |
|
5 |
* |
|
6 |
* Copyright (c) 2007 The Khronos Group Inc. |
|
7 |
* Portions copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
8 |
* |
|
9 |
* Permission is hereby granted, free of charge, to any person obtaining a |
|
10 |
* copy of this software and /or associated documentation files |
|
11 |
* (the "Materials "), to deal in the Materials without restriction, |
|
12 |
* including without limitation the rights to use, copy, modify, merge, |
|
13 |
* publish, distribute, sublicense, and/or sell copies of the Materials, |
|
14 |
* and to permit persons to whom the Materials are furnished to do so, |
|
15 |
* subject to the following conditions: |
|
16 |
* |
|
17 |
* The above copyright notice and this permission notice shall be included |
|
18 |
* in all copies or substantial portions of the Materials. |
|
19 |
* |
|
20 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
21 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
22 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
23 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
24 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
25 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
26 |
* THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
27 |
* |
|
28 |
*//** |
|
29 |
* \file |
|
30 |
* \brief Implementation of Paint and pixel pipe functionality. |
|
31 |
* \note |
|
32 |
*//*-------------------------------------------------------------------*/ |
|
33 |
||
34 |
#ifndef __RIPIXELPIPE_H |
|
35 |
# include "riPixelPipe.h" |
|
36 |
#endif |
|
37 |
#ifndef __RIRASTERIZER_H |
|
38 |
# include "riRasterizer.h" |
|
39 |
#endif |
|
40 |
#ifndef __SFDYNAMICPIXELPIPE_H |
|
41 |
# include "sfDynamicPixelPipe.h" |
|
42 |
#endif |
|
69
3f914c77c2e9
Host OpenVG building using GCC, without LLVM integration.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
53
diff
changeset
|
43 |
#if defined(RI_COMPILE_LLVM_BYTECODE) |
24 | 44 |
#ifndef __SFCOMPILER_H |
45 |
# include "sfCompiler.h" |
|
46 |
#endif |
|
69
3f914c77c2e9
Host OpenVG building using GCC, without LLVM integration.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
53
diff
changeset
|
47 |
#endif |
24 | 48 |
|
49 |
//============================================================================================== |
|
50 |
||
51 |
namespace OpenVGRI |
|
52 |
{ |
|
53 |
||
54 |
/*-------------------------------------------------------------------*//*! |
|
55 |
* \brief Paint constructor. |
|
56 |
* \param |
|
57 |
* \return |
|
58 |
* \note |
|
59 |
*//*-------------------------------------------------------------------*/ |
|
60 |
||
61 |
Paint::Paint() : |
|
62 |
m_paintType(VG_PAINT_TYPE_COLOR), |
|
63 |
m_paintColor(0,0,0,1,Color::sRGBA_PRE), |
|
64 |
m_inputPaintColor(0,0,0,1,Color::sRGBA), |
|
65 |
m_colorRampSpreadMode(VG_COLOR_RAMP_SPREAD_PAD), |
|
66 |
m_colorRampStops(), |
|
67 |
m_inputColorRampStops(), |
|
68 |
m_colorRampPremultiplied(VG_TRUE), |
|
69 |
m_inputLinearGradientPoint0(0,0), |
|
70 |
m_inputLinearGradientPoint1(1,0), |
|
71 |
m_inputRadialGradientCenter(0,0), |
|
72 |
m_inputRadialGradientFocalPoint(0,0), |
|
73 |
m_inputRadialGradientRadius(1.0f), |
|
74 |
m_linearGradientPoint0(0,0), |
|
75 |
m_linearGradientPoint1(1,0), |
|
76 |
m_radialGradientCenter(0,0), |
|
77 |
m_radialGradientFocalPoint(0,0), |
|
78 |
m_radialGradientRadius(1.0f), |
|
79 |
m_patternTilingMode(VG_TILE_FILL), |
|
80 |
m_pattern(NULL), |
|
81 |
m_referenceCount(0), |
|
82 |
m_lutFormat((VGImageFormat)-1), |
|
83 |
m_gradientStopsChanged(true) |
|
84 |
{ |
|
85 |
Paint::GradientStop gs; |
|
86 |
gs.offset = 0.0f; |
|
87 |
gs.color.set(0,0,0,1,Color::sRGBA); |
|
88 |
m_colorRampStops.push_back(gs); //throws bad_alloc |
|
89 |
gs.offset = 1.0f; |
|
90 |
gs.color.set(1,1,1,1,Color::sRGBA); |
|
91 |
m_colorRampStops.push_back(gs); //throws bad_alloc |
|
92 |
} |
|
93 |
||
94 |
/*-------------------------------------------------------------------*//*! |
|
95 |
* \brief Paint destructor. |
|
96 |
* \param |
|
97 |
* \return |
|
98 |
* \note |
|
99 |
*//*-------------------------------------------------------------------*/ |
|
100 |
||
101 |
Paint::~Paint() |
|
102 |
{ |
|
103 |
RI_ASSERT(m_referenceCount == 0); |
|
104 |
if(m_pattern) |
|
105 |
{ |
|
106 |
m_pattern->removeInUse(); |
|
107 |
if(!m_pattern->removeReference()) |
|
108 |
RI_DELETE(m_pattern); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
static Color readStopColor(const Array<Paint::GradientStop>& colorRampStops, int i, VGboolean colorRampPremultiplied) |
|
113 |
{ |
|
114 |
RI_ASSERT(i >= 0 && i < colorRampStops.size()); |
|
115 |
Color c = colorRampStops[i].color; |
|
116 |
RI_ASSERT(c.getInternalFormat() == Color::sRGBA); |
|
117 |
if(colorRampPremultiplied) |
|
118 |
c.premultiply(); |
|
119 |
return c; |
|
120 |
} |
|
121 |
||
122 |
void Paint::setGradientStops(Array<GradientStop>& inputStops, Array<GradientStop>& stops) |
|
123 |
{ |
|
124 |
m_colorRampStops.swap(stops); |
|
125 |
m_inputColorRampStops.swap(inputStops); |
|
126 |
m_gradientStopsChanged = true; |
|
127 |
} |
|
128 |
||
129 |
void Paint::setLinearGradient(const Vector2& p0, const Vector2& p1) |
|
130 |
{ |
|
131 |
m_linearGradientPoint0 = p0; |
|
132 |
m_linearGradientPoint1 = p1; |
|
133 |
} |
|
134 |
||
135 |
void Paint::setRadialGradient(const Vector2& c, const Vector2& f, VGfloat r) |
|
136 |
{ |
|
137 |
m_radialGradientCenter = c; |
|
138 |
m_radialGradientFocalPoint = f; |
|
139 |
m_radialGradientRadius = r; |
|
140 |
} |
|
141 |
||
142 |
bool Paint::linearDegenerate() const |
|
143 |
{ |
|
144 |
return m_linearGradientPoint0 == m_linearGradientPoint1 ? true : false; |
|
145 |
} |
|
146 |
||
147 |
bool Paint::radialDegenerate() const |
|
148 |
{ |
|
149 |
return m_radialGradientRadius == 0.0f ? true : false; |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* \brief Returns either the VG_PAINT_COLOR, or evaluated gradient value when the |
|
154 |
* gradient is degenerate. |
|
155 |
*/ |
|
156 |
Color Paint::getSolidColor() const |
|
157 |
{ |
|
158 |
if (m_paintType == VG_PAINT_TYPE_PATTERN) |
|
159 |
{ |
|
160 |
RI_ASSERT(m_pattern == NULL); |
|
161 |
return m_paintColor; |
|
162 |
} |
|
163 |
||
164 |
if (m_paintType == VG_PAINT_TYPE_COLOR) |
|
165 |
return m_paintColor; |
|
166 |
||
167 |
RI_ASSERT(linearDegenerate() || radialDegenerate()); |
|
168 |
||
169 |
// Determine the color at the end of the gradient |
|
170 |
RIfloat gs, ge; |
|
171 |
if (m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_PAD) |
|
172 |
{ |
|
173 |
gs = 1.0f - 1/256.0f; |
|
174 |
ge = 1.0f; |
|
175 |
} else if (m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT) |
|
176 |
{ |
|
177 |
gs = 0.0f; |
|
178 |
ge = 1/256.0f; |
|
179 |
} else |
|
180 |
{ |
|
181 |
gs = 1.0f - 1/256.0f; |
|
182 |
ge = 1.0f; |
|
183 |
} |
|
184 |
Color c = integrateColorRamp(gs, ge); |
|
185 |
return c * 256.0f; |
|
186 |
} |
|
187 |
||
188 |
/*-------------------------------------------------------------------*//*! |
|
189 |
* \brief Returns the average color within an offset range in the color ramp. |
|
190 |
* \param |
|
191 |
* \return |
|
192 |
* \note |
|
193 |
*//*-------------------------------------------------------------------*/ |
|
194 |
||
195 |
Color Paint::integrateColorRamp(RIfloat gmin, RIfloat gmax) const |
|
196 |
{ |
|
197 |
RI_ASSERT(gmin <= gmax); |
|
198 |
RI_ASSERT(gmin >= 0.0f && gmin <= 1.0f); |
|
199 |
RI_ASSERT(gmax >= 0.0f && gmax <= 1.0f); |
|
200 |
RI_ASSERT(m_colorRampStops.size() >= 2); //there are at least two stops |
|
201 |
||
202 |
Color currC(0,0,0,0,m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA); |
|
203 |
||
204 |
if(gmin == 1.0f || gmax == 0.0f) |
|
205 |
return currC; |
|
206 |
||
207 |
int i = 0; |
|
208 |
||
209 |
for(; i < m_colorRampStops.size()-1; i++) |
|
210 |
{ |
|
211 |
if(gmin >= m_colorRampStops[i].offset && gmin < m_colorRampStops[i+1].offset) |
|
212 |
{ |
|
213 |
RIfloat s = m_colorRampStops[i].offset; |
|
214 |
RIfloat e = m_colorRampStops[i+1].offset; |
|
215 |
RI_ASSERT(s < e); |
|
216 |
RIfloat g = (gmin - s) / (e - s); |
|
217 |
||
218 |
Color sc = readStopColor(m_colorRampStops, i, m_colorRampPremultiplied); |
|
219 |
Color ec = readStopColor(m_colorRampStops, i+1, m_colorRampPremultiplied); |
|
220 |
Color rc = (1.0f-g) * sc + g * ec; |
|
221 |
||
222 |
//subtract the average color from the start of the stop to gmin |
|
223 |
Color dc = 0.5f*(gmin - s)*(sc + rc); |
|
224 |
currC -= dc; |
|
225 |
break; |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
for(;i < m_colorRampStops.size()-1; i++) |
|
230 |
{ |
|
231 |
RIfloat s = m_colorRampStops[i].offset; |
|
232 |
RIfloat e = m_colorRampStops[i+1].offset; |
|
233 |
RI_ASSERT(s <= e); |
|
234 |
||
235 |
Color sc = readStopColor(m_colorRampStops, i, m_colorRampPremultiplied); |
|
236 |
Color ec = readStopColor(m_colorRampStops, i+1, m_colorRampPremultiplied); |
|
237 |
||
238 |
//average of the stop |
|
239 |
Color dc = 0.5f*(e-s)*(sc + ec); |
|
240 |
currC += dc; |
|
241 |
||
242 |
if(gmax >= m_colorRampStops[i].offset && gmax < m_colorRampStops[i+1].offset) |
|
243 |
{ |
|
244 |
RIfloat g = (gmax - s) / (e - s); |
|
245 |
Color rc = (1.0f-g) * sc + g * ec; |
|
246 |
||
247 |
//subtract the average color from gmax to the end of the stop |
|
248 |
dc = 0.5f*(e - gmax)*(rc + ec); |
|
249 |
currC -= dc; |
|
250 |
break; |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
return currC; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* \brief Generates gradient color-ramp lookup values. |
|
259 |
* |
|
260 |
* \param targetFormat Destination or image format to associate LUT with. |
|
261 |
* \patam drawImage true if paint is evaluated along drawImage. |
|
262 |
* |
|
263 |
* \note Must be called prior to rendering, and after the destination |
|
264 |
* format is known. The destination format is either destination |
|
265 |
* surface format, or the image format in case of image rendering |
|
266 |
* operation. |
|
267 |
*/ |
|
268 |
void Paint::generateLUT(PixelPipe& pipe, VGImageFormat preferredFormat) |
|
269 |
{ |
|
270 |
const RIfloat gstep = 1.0f / (GRADIENT_LUT_COUNT); |
|
271 |
const RIfloat rcp = (RIfloat)(GRADIENT_LUT_COUNT); |
|
272 |
RIfloat gsx; |
|
273 |
gsx = 0.0f; |
|
274 |
||
275 |
if (!pipe.colorTransformChanged() && !m_gradientStopsChanged && (preferredFormat == m_lutFormat)) |
|
276 |
return; // Already in correct format |
|
277 |
||
278 |
const bool inputPremultiplied = m_colorRampPremultiplied == VG_TRUE ? true : false; |
|
279 |
||
280 |
// Colortransform premultiplies color. |
|
281 |
const Color::Descriptor srcDesc = Color::formatToDescriptorConst( |
|
282 |
inputPremultiplied || pipe.hasColorTransform() ? VG_sRGBA_8888_PRE : VG_sRGBA_8888); |
|
283 |
||
284 |
const Color::Descriptor dstDesc = Color::formatToDescriptorConst(preferredFormat); |
|
285 |
||
286 |
// Create a pre-calculated LUT. |
|
287 |
for (int i = 0; i < GRADIENT_LUT_COUNT; i++) |
|
288 |
{ |
|
289 |
// \todo Open up the integrator and/or use also integers. |
|
290 |
Color c = integrateColorRamp(gsx, gsx + gstep); |
|
291 |
c *= rcp; |
|
292 |
||
293 |
// \todo Changing the mode must be tracked somehow! |
|
294 |
if (pipe.getImageMode() != VG_DRAW_IMAGE_MULTIPLY) |
|
295 |
pipe.colorTransform(c); |
|
296 |
||
297 |
IntegerColor ic = IntegerColor(c); |
|
298 |
ic.convertToFrom(dstDesc, srcDesc, false); |
|
299 |
m_gradientLUT[i] = ic; |
|
300 |
||
301 |
gsx += gstep; |
|
302 |
} |
|
303 |
||
304 |
m_gradientStopsChanged = false; |
|
305 |
m_lutFormat = Color::descriptorToVGImageFormat(dstDesc); |
|
306 |
pipe.setColorTransformChanged(false); |
|
307 |
||
308 |
RI_ASSERT(m_lutFormat == preferredFormat); |
|
309 |
} |
|
310 |
||
311 |
/*-------------------------------------------------------------------*//*! |
|
312 |
* \brief PixelPipe constructor. |
|
313 |
* \param |
|
314 |
* \return |
|
315 |
* \note |
|
316 |
*//*-------------------------------------------------------------------*/ |
|
317 |
||
318 |
PixelPipe::PixelPipe() : |
|
319 |
m_drawable(NULL), |
|
320 |
m_image(NULL), |
|
321 |
m_paint(NULL), |
|
322 |
m_defaultPaint(), |
|
323 |
m_blendMode(VG_BLEND_SRC_OVER), |
|
324 |
m_imageMode(VG_DRAW_IMAGE_NORMAL), |
|
325 |
m_imageQuality(VG_IMAGE_QUALITY_FASTER), |
|
326 |
m_tileFillColor(0,0,0,0,Color::sRGBA), |
|
327 |
m_colorTransform(false), |
|
328 |
m_colorTransformValues(), |
|
329 |
m_iColorTransformValues(), |
|
330 |
m_surfaceToPaintMatrix(), |
|
331 |
m_surfaceToImageMatrix(), |
|
332 |
m_paintToSurfaceMatrix(), |
|
333 |
m_maskOperation(VG_SET_MASK), |
|
334 |
m_renderToMask(false), |
|
335 |
m_colorTransformChanged(true) |
|
336 |
{ |
|
337 |
for(int i=0;i<8;i++) |
|
338 |
{ |
|
339 |
m_colorTransformValues[i] = (i < 4) ? 1.0f : 0.0f; |
|
340 |
m_iColorTransformValues[i] = (i < 4) ? (COLOR_TRANSFORM_ONE) : 0; |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
||
345 |
/*-------------------------------------------------------------------*//*! |
|
346 |
* \brief PixelPipe destructor. |
|
347 |
* \param |
|
348 |
* \return |
|
349 |
* \note |
|
350 |
*//*-------------------------------------------------------------------*/ |
|
351 |
||
352 |
PixelPipe::~PixelPipe() |
|
353 |
{ |
|
354 |
} |
|
355 |
||
356 |
/*-------------------------------------------------------------------*//*! |
|
357 |
* \brief Sets the rendering surface. |
|
358 |
* \param |
|
359 |
* \return |
|
360 |
* \note |
|
361 |
*//*-------------------------------------------------------------------*/ |
|
362 |
||
363 |
void PixelPipe::setDrawable(Drawable* drawable) |
|
364 |
{ |
|
365 |
RI_ASSERT(drawable); |
|
366 |
m_drawable = drawable; |
|
367 |
} |
|
368 |
||
369 |
/*-------------------------------------------------------------------*//*! |
|
370 |
* \brief Sets the blend mode. |
|
371 |
* \param |
|
372 |
* \return |
|
373 |
* \note |
|
374 |
*//*-------------------------------------------------------------------*/ |
|
375 |
||
376 |
void PixelPipe::setBlendMode(VGBlendMode blendMode) |
|
377 |
{ |
|
378 |
RI_ASSERT(blendMode >= VG_BLEND_SRC && blendMode <= VG_BLEND_ADDITIVE); |
|
379 |
m_blendMode = blendMode; |
|
380 |
} |
|
381 |
||
382 |
/*-------------------------------------------------------------------*//*! |
|
383 |
* \brief Sets the mask image. NULL disables masking. |
|
384 |
* \param |
|
385 |
* \return |
|
386 |
* \note |
|
387 |
*//*-------------------------------------------------------------------*/ |
|
388 |
||
389 |
void PixelPipe::setMask(bool masking) |
|
390 |
{ |
|
391 |
m_masking = masking; |
|
392 |
} |
|
393 |
||
394 |
/*-------------------------------------------------------------------*//*! |
|
395 |
* \brief Sets the image to be drawn. NULL disables image drawing. |
|
396 |
* \param |
|
397 |
* \return |
|
398 |
* \note |
|
399 |
*//*-------------------------------------------------------------------*/ |
|
400 |
||
401 |
void PixelPipe::setImage(Image* image, VGImageMode imageMode) |
|
402 |
{ |
|
403 |
RI_ASSERT(imageMode == VG_DRAW_IMAGE_NORMAL || imageMode == VG_DRAW_IMAGE_MULTIPLY || imageMode == VG_DRAW_IMAGE_STENCIL); |
|
404 |
m_image = image; |
|
405 |
m_imageMode = imageMode; |
|
406 |
} |
|
407 |
||
408 |
/*-------------------------------------------------------------------*//*! |
|
409 |
* \brief Sets the surface-to-paint matrix. |
|
410 |
* \param |
|
411 |
* \return |
|
412 |
* \note |
|
413 |
*//*-------------------------------------------------------------------*/ |
|
414 |
||
415 |
void PixelPipe::setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix) |
|
416 |
{ |
|
417 |
m_surfaceToPaintMatrix = surfaceToPaintMatrix; |
|
418 |
} |
|
419 |
||
420 |
/*-------------------------------------------------------------------*//*! |
|
421 |
* \brief Sets the surface-to-image matrix. |
|
422 |
* \param |
|
423 |
* \return |
|
424 |
* \note |
|
425 |
*//*-------------------------------------------------------------------*/ |
|
426 |
||
427 |
void PixelPipe::setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix) |
|
428 |
{ |
|
429 |
m_surfaceToImageMatrix = surfaceToImageMatrix; |
|
430 |
} |
|
431 |
||
432 |
/*-------------------------------------------------------------------*//*! |
|
433 |
* \brief Sets image quality. |
|
434 |
* \param |
|
435 |
* \return |
|
436 |
* \note |
|
437 |
*//*-------------------------------------------------------------------*/ |
|
438 |
||
439 |
void PixelPipe::setImageQuality(VGImageQuality imageQuality) |
|
440 |
{ |
|
441 |
RI_ASSERT(imageQuality == VG_IMAGE_QUALITY_NONANTIALIASED || imageQuality == VG_IMAGE_QUALITY_FASTER || imageQuality == VG_IMAGE_QUALITY_BETTER); |
|
442 |
m_imageQuality = imageQuality; |
|
443 |
} |
|
444 |
||
445 |
/*-------------------------------------------------------------------*//*! |
|
446 |
* \brief Sets fill color for VG_TILE_FILL tiling mode (pattern only). |
|
447 |
* \param |
|
448 |
* \return |
|
449 |
* \note |
|
450 |
*//*-------------------------------------------------------------------*/ |
|
451 |
||
452 |
void PixelPipe::setTileFillColor(const Color& c) |
|
453 |
{ |
|
454 |
m_tileFillColor = c; |
|
455 |
m_tileFillColor.clamp(); |
|
456 |
} |
|
457 |
||
458 |
/*-------------------------------------------------------------------*//*! |
|
459 |
* \brief Sets paint. |
|
460 |
* \param |
|
461 |
* \return |
|
462 |
* \note |
|
463 |
*//*-------------------------------------------------------------------*/ |
|
464 |
||
465 |
void PixelPipe::setPaint(Paint* paint) |
|
466 |
{ |
|
467 |
// \temp Only call this right before filling a polygon. |
|
468 |
m_paint = paint; |
|
469 |
||
470 |
if(!m_paint) |
|
471 |
m_paint = &m_defaultPaint; |
|
472 |
||
473 |
if(m_paint->m_pattern) |
|
474 |
m_tileFillColor.convert(m_paint->m_pattern->getDescriptor().internalFormat); |
|
475 |
||
476 |
} |
|
477 |
||
478 |
/*-------------------------------------------------------------------*//*! |
|
479 |
* \brief Color transform. |
|
480 |
* \param |
|
481 |
* \return |
|
482 |
* \note |
|
483 |
*//*-------------------------------------------------------------------*/ |
|
484 |
||
485 |
void PixelPipe::setColorTransform(bool enable, RIfloat values[8]) |
|
486 |
{ |
|
487 |
m_colorTransform = enable; |
|
488 |
for(int i=0;i<4;i++) |
|
489 |
{ |
|
490 |
m_colorTransformValues[i] = RI_CLAMP(values[i], -127.0f, 127.0f); |
|
491 |
m_colorTransformValues[i+4] = RI_CLAMP(values[i+4], -1.0f, 1.0f); |
|
492 |
m_iColorTransformValues[i] = RI_ROUND_TO_INT(m_colorTransformValues[i]*(RIfloat)COLOR_TRANSFORM_ONE); |
|
493 |
m_iColorTransformValues[i+4] = RI_ROUND_TO_INT(m_colorTransformValues[i+4]*255.0f); |
|
494 |
} |
|
495 |
m_colorTransformChanged = true; |
|
496 |
} |
|
497 |
||
498 |
const Image* PixelPipe::getRenderTargetImage() const |
|
499 |
{ |
|
500 |
if (m_renderToMask) |
|
501 |
return m_drawable->getMaskBuffer()->getImage(); |
|
502 |
||
503 |
return m_drawable->getColorBuffer()->getImage(); |
|
504 |
} |
|
505 |
||
506 |
/** |
|
507 |
* \brief Determine an appropriate VGImageFormat to use for lookup tables. |
|
508 |
* \todo Should return descriptor instead? |
|
509 |
*/ |
|
510 |
VGImageFormat PixelPipe::getPreferredLUTFormat() const |
|
511 |
{ |
|
512 |
const Image* target = getRenderTargetImage(); |
|
513 |
const Color::Descriptor& targetDesc = target->getDescriptor(); |
|
514 |
||
515 |
if (m_renderToMask) |
|
516 |
{ |
|
517 |
RI_ASSERT(!m_image); |
|
518 |
if (targetDesc.isNonlinear()) |
|
519 |
return VG_sRGBA_8888_PRE; |
|
520 |
else |
|
521 |
return VG_lRGBA_8888_PRE; |
|
522 |
} |
|
523 |
||
524 |
if (m_image && m_imageMode == VG_DRAW_IMAGE_MULTIPLY) |
|
525 |
return VG_sRGBA_8888_PRE; // ? |
|
526 |
||
527 |
// Prefer premultiplied formats |
|
528 |
// \note Can also generate non-premultiplied if no sampling/other operation and destination |
|
529 |
// is in linear format. |
|
530 |
// \note Do not use VGImageFormat, because using (s/l)LA88 is possible with |
|
531 |
// luminance destination formats. |
|
532 |
if (targetDesc.isNonlinear()) |
|
533 |
return VG_sRGBA_8888_PRE; |
|
534 |
else |
|
535 |
return VG_lRGBA_8888_PRE; |
|
536 |
} |
|
537 |
||
538 |
void PixelPipe::prepareSolidFill() |
|
539 |
{ |
|
540 |
if (!(m_drawable && m_paint)) |
|
541 |
return; |
|
542 |
||
543 |
Color c = m_paint->getSolidColor(); |
|
544 |
//Color c = m_paint->m_paintColor; |
|
545 |
||
546 |
if (!m_image || m_imageMode != VG_DRAW_IMAGE_MULTIPLY) |
|
547 |
colorTransform(c); // Output will be premultiplied |
|
548 |
// Generate internal color |
|
549 |
Color::Descriptor blendDesc = getRenderTargetImage()->getDescriptor(); |
|
550 |
||
551 |
// MULTIPLY uses the color as-is. |
|
552 |
if (m_imageMode != VG_DRAW_IMAGE_MULTIPLY) c.convert(blendDesc.internalFormat); |
|
553 |
||
554 |
IntegerColor ic = IntegerColor(c); |
|
555 |
blendDesc.internalFormat = (Color::InternalFormat)(blendDesc.internalFormat | (Color::PREMULTIPLIED)); |
|
556 |
||
557 |
if (m_imageMode != VG_DRAW_IMAGE_MULTIPLY) c.convert(blendDesc.internalFormat); |
|
558 |
||
559 |
IntegerColor blendColor = IntegerColor(c); |
|
560 |
||
561 |
if (m_imageMode == VG_DRAW_IMAGE_STENCIL) |
|
562 |
blendColor.asFixedPoint(c); // Enhance the precision a bit |
|
563 |
||
564 |
// \todo No need to pack the color if solid fill is not possible |
|
565 |
if (!m_renderToMask) |
|
566 |
ic.truncateColor(getRenderTargetImage()->getDescriptor()); |
|
567 |
else |
|
568 |
ic.truncateMask(getRenderTargetImage()->getDescriptor()); |
|
569 |
||
570 |
RIuint32 p = ic.getPackedColor(getRenderTargetImage()->getDescriptor()); |
|
571 |
||
572 |
m_spanUniforms.solidColor = blendColor; // This must be premultiplied |
|
573 |
m_spanUniforms.packedSolidColor = p; // This must be exactly the dst color |
|
574 |
} |
|
575 |
||
576 |
void PixelPipe::prepareCoverageFill() |
|
577 |
{ |
|
578 |
IntegerColor ic = IntegerColor(255, 255, 255, 255); |
|
579 |
RIuint32 p = ic.getPackedColor(m_drawable->getMaskBuffer()->getDescriptor()); |
|
580 |
||
581 |
m_spanUniforms.solidColor = ic; |
|
582 |
m_spanUniforms.packedSolidColor = p; |
|
583 |
} |
|
584 |
||
585 |
void PixelPipe::prepareLinearGradient() |
|
586 |
{ |
|
587 |
const Matrix3x3& s2p = m_surfaceToPaintMatrix; |
|
588 |
||
589 |
Vector2 zero(0,0); |
|
590 |
Vector2 p0 = m_paint->m_linearGradientPoint0; |
|
591 |
Vector2 p1 = m_paint->m_linearGradientPoint1; |
|
592 |
Vector2 delta = p1 - p0; |
|
593 |
||
594 |
zero = affineTransform(s2p, zero); |
|
595 |
||
596 |
RIfloat d = (delta.x * delta.x) + (delta.y * delta.y); |
|
597 |
RIfloat gdx = (s2p[0][0] * delta.x + s2p[1][0] * delta.y) / d; |
|
598 |
RIfloat gdy = (s2p[0][1] * delta.x + s2p[1][1] * delta.y) / d; |
|
599 |
RIfloat cx = (zero.x-p0.x) * (delta.x); |
|
600 |
RIfloat cy = (zero.y-p0.y) * (delta.y); |
|
601 |
RIfloat c = (cx + cy) / d; |
|
602 |
||
603 |
m_spanUniforms.dgdx = RI_FLOAT_TO_FX(gdx, PixelPipe::GRADIENT_BITS); |
|
604 |
m_spanUniforms.dgdy = RI_FLOAT_TO_FX(gdy, PixelPipe::GRADIENT_BITS); |
|
605 |
m_spanUniforms.lgc = RI_FLOAT_TO_FX(c + 0.5*(gdx + gdy), PixelPipe::GRADIENT_BITS); |
|
606 |
||
607 |
m_spanUniforms.gradientLookup = m_paint->getGradientLUT(); |
|
608 |
} |
|
609 |
||
610 |
void PixelPipe::prepareRadialGradient() |
|
611 |
{ |
|
612 |
const Matrix3x3& s2p = m_surfaceToPaintMatrix; |
|
613 |
||
614 |
Vector2 c = m_paint->m_radialGradientCenter; |
|
615 |
Vector2 f = m_paint->m_radialGradientFocalPoint; |
|
616 |
RGScalar r = m_paint->m_radialGradientRadius; |
|
617 |
||
618 |
Vector2 zero(0,0); |
|
619 |
Vector2 pzero = affineTransform(s2p, zero); |
|
620 |
||
621 |
Vector2 fp = f - c; |
|
622 |
||
623 |
RGScalar q = fp.length(); |
|
624 |
||
625 |
if (q > r) |
|
626 |
{ |
|
627 |
const RIfloat scale = 0.99f; |
|
628 |
fp.normalize(); |
|
629 |
fp *= r * scale; |
|
630 |
f = fp + c; |
|
631 |
} |
|
632 |
||
633 |
RGScalar r1sqr = RI_SQR(r); |
|
634 |
RGScalar d = r1sqr - dot(fp, fp); |
|
635 |
||
636 |
m_spanUniforms.rdxdx = s2p[0][0]; |
|
637 |
m_spanUniforms.rdxdy = s2p[0][1]; |
|
638 |
m_spanUniforms.rdydx = s2p[1][0]; |
|
639 |
m_spanUniforms.rdydy = s2p[1][1]; |
|
640 |
||
641 |
m_spanUniforms.rsqrp = r1sqr / RI_SQR(d); |
|
642 |
m_spanUniforms.rfxp = fp.x / d; |
|
643 |
m_spanUniforms.rfyp = fp.y / d; |
|
644 |
m_spanUniforms.rx0 = pzero.x - f.x + 0.5f*(m_spanUniforms.rdxdx + m_spanUniforms.rdxdy); |
|
645 |
m_spanUniforms.ry0 = pzero.y - f.y + 0.5f*(m_spanUniforms.rdydy + m_spanUniforms.rdydx); |
|
646 |
||
647 |
m_spanUniforms.gradientLookup = m_paint->getGradientLUT(); |
|
648 |
} |
|
649 |
||
650 |
void PixelPipe::preparePattern() |
|
651 |
{ |
|
652 |
// Patterns only support affine transforms |
|
653 |
const Matrix3x3& s2p = m_surfaceToPaintMatrix; |
|
654 |
const RIfloat patternWidth = (RIfloat)m_paint->m_pattern->getWidth(); |
|
655 |
const RIfloat patternHeight = (RIfloat)m_paint->m_pattern->getHeight(); |
|
656 |
const Vector2 zero(0, 0); |
|
657 |
Vector2 pzero = affineTransform(s2p, zero); |
|
658 |
||
659 |
m_spanUniforms.paint_x0 = RI_ROUND_TO_INT((pzero.x/patternWidth)*(1<<GRADIENT_BITS)); |
|
660 |
m_spanUniforms.paint_y0 = RI_ROUND_TO_INT((pzero.y/patternHeight)*(1<<GRADIENT_BITS)); |
|
661 |
m_spanUniforms.paint_dxdx = RI_ROUND_TO_INT((s2p[0][0]/patternWidth)*(1<<GRADIENT_BITS)); |
|
662 |
m_spanUniforms.paint_dxdy = RI_ROUND_TO_INT((s2p[0][1]/patternHeight)*(1<<GRADIENT_BITS)); |
|
663 |
m_spanUniforms.paint_dydx = RI_ROUND_TO_INT((s2p[1][0]/patternWidth)*(1<<GRADIENT_BITS)); |
|
664 |
m_spanUniforms.paint_dydy = RI_ROUND_TO_INT((s2p[1][1]/patternHeight)*(1<<GRADIENT_BITS)); |
|
665 |
||
666 |
m_spanUniforms.paint_x0 += (m_spanUniforms.paint_dxdx + m_spanUniforms.paint_dxdy) / 2; |
|
667 |
m_spanUniforms.paint_y0 += (m_spanUniforms.paint_dydy + m_spanUniforms.paint_dydx) / 2; |
|
668 |
||
669 |
m_spanUniforms.patternPtr = m_paint->m_pattern->getData(); |
|
670 |
m_spanUniforms.patternStride = m_paint->m_pattern->getStride(); |
|
671 |
m_spanUniforms.paint_width = m_paint->m_pattern->getWidth(); |
|
672 |
m_spanUniforms.paint_height = m_paint->m_pattern->getHeight(); |
|
673 |
||
674 |
m_signatureState.patternDesc = m_paint->m_pattern->getDescriptor(); |
|
675 |
||
676 |
m_spanUniforms.tileFillColor = IntegerColor(m_tileFillColor); |
|
677 |
// The tile fill-color must be shifted down to same bit-depth (see integer samplers) |
|
678 |
m_spanUniforms.tileFillColor.truncateColor(m_signatureState.patternDesc); |
|
679 |
||
680 |
} |
|
681 |
||
682 |
RI_INLINE static RIfloat floatEqu(RIfloat a, RIfloat b, RIfloat e) |
|
683 |
{ |
|
684 |
// \note This should be sufficient for our use-cases; |
|
685 |
return (RI_ABS(a - b) < e); |
|
686 |
} |
|
687 |
||
688 |
RI_INLINE static RIfloat distToInt(RIfloat f) |
|
689 |
{ |
|
690 |
const RIfloat intF = RI_ROUND_TO_INT(f); |
|
691 |
return RI_ABS(intF - f); |
|
692 |
} |
|
693 |
||
694 |
/** |
|
695 |
* \brief Check if transform is 90 degree rotation, or flip and nothing else. |
|
696 |
*/ |
|
697 |
RI_INLINE static bool orthoNormalCoAxialTransform(const Matrix3x3& t, bool aa) |
|
698 |
{ |
|
699 |
const RIfloat epsilonCoord = 1/255.0f; // 1/127.0f; |
|
700 |
const RIfloat epsilonGradient = epsilonCoord * epsilonCoord; // \todo Too strict? |
|
701 |
const RIfloat absPatterns[2][4] = { |
|
702 |
{1.0f, 0.0f, 0.0f, 1.0f}, |
|
703 |
{0.0f, 1.0f, 1.0f, 0.0f} }; |
|
704 |
||
705 |
if (!t.isAffine()) |
|
706 |
return false; |
|
707 |
||
708 |
// \todo This rule only applies if filtering is in use? |
|
709 |
if (aa) |
|
710 |
if (!floatEqu(distToInt(t[0][2]), 0.0f, epsilonCoord) || !floatEqu(distToInt(t[1][2]), 0.0f, epsilonCoord)) |
|
711 |
return false; |
|
712 |
||
713 |
Matrix3x3 u = t; |
|
714 |
||
715 |
for (int j = 0; j < 2; j++) |
|
716 |
for (int i = 0; i < 2; i++) |
|
717 |
u[j][i] = RI_ABS(u[j][i]); |
|
718 |
||
719 |
bool found; |
|
720 |
||
721 |
for (int m = 0; m < 2; m++) |
|
722 |
{ |
|
723 |
found = true; |
|
724 |
for (int j = 0; j < 2; j++) |
|
725 |
{ |
|
726 |
for (int i = 0; i < 2; i++) |
|
727 |
{ |
|
728 |
//if (u[j][i] != absPatterns[m][i+j*2]) |
|
729 |
if (!floatEqu(u[j][i], absPatterns[m][i+j*2], epsilonGradient)) |
|
730 |
{ |
|
731 |
found = false; |
|
732 |
break; |
|
733 |
} |
|
734 |
} |
|
735 |
if (!found) break; |
|
736 |
} |
|
737 |
if (found) break; |
|
738 |
} |
|
739 |
||
740 |
return found; |
|
741 |
} |
|
742 |
||
743 |
void PixelPipe::prepareImage(bool aa) |
|
744 |
{ |
|
745 |
if (!m_image) |
|
746 |
{ |
|
747 |
m_signatureState.imageGradientType = GRADIENT_TYPE_INTEGER; |
|
748 |
return; |
|
749 |
} |
|
750 |
||
751 |
RI_ASSERT(m_image); |
|
752 |
m_spanUniforms.imagePtr = m_image->getData(); |
|
753 |
m_spanUniforms.imageStride = m_image->getStride(); |
|
754 |
||
755 |
if (m_image->getParent() != NULL) |
|
756 |
{ |
|
757 |
// Adjust the pointer. |
|
758 |
int x, y; |
|
759 |
m_image->getStorageOffset(x, y); |
|
760 |
m_spanUniforms.imagePtr = Image::calculateAddress( |
|
761 |
m_spanUniforms.imagePtr, m_image->getDescriptor().bitsPerPixel, x, y, m_spanUniforms.imageStride); |
|
762 |
} |
|
763 |
||
764 |
// \todo This function writes to derived state also. |
|
765 |
// \todo Plenty of fast-paths possible! |
|
766 |
const Matrix3x3& s2i = m_surfaceToImageMatrix; |
|
767 |
||
768 |
Vector3 zero(0,0,1); |
|
769 |
Vector3 pzero; |
|
770 |
||
771 |
bool fastImage = orthoNormalCoAxialTransform(s2i, aa); |
|
772 |
||
773 |
pzero = s2i * zero; |
|
774 |
||
775 |
if (fastImage) |
|
776 |
{ |
|
777 |
RI_ASSERT(pzero.z == 1.0f); |
|
778 |
m_spanUniforms.image_idxdx = RI_ROUND_TO_INT(s2i[0][0]); |
|
779 |
m_spanUniforms.image_idxdy = RI_ROUND_TO_INT(s2i[0][1]); |
|
780 |
m_spanUniforms.image_idydx = RI_ROUND_TO_INT(s2i[1][0]); |
|
781 |
m_spanUniforms.image_idydy = RI_ROUND_TO_INT(s2i[1][1]); |
|
782 |
m_spanUniforms.image_ix0 = RI_FLOOR(pzero.x + 0.5f*(s2i[0][0]+s2i[0][1])); |
|
783 |
m_spanUniforms.image_iy0 = RI_FLOOR(pzero.y + 0.5f*(s2i[1][1]+s2i[1][0])); |
|
784 |
||
785 |
// Adjust sample-center when using (exactly) integer coordinates. |
|
786 |
||
787 |
#if 0 |
|
788 |
if (m_spanUniforms.image_idxdx < 0 || m_spanUniforms.image_idxdy < 0) |
|
789 |
m_spanUniforms.image_ix0--; |
|
790 |
||
791 |
if (m_spanUniforms.image_idydy < 0 || m_spanUniforms.image_idydx < 0) |
|
792 |
m_spanUniforms.image_iy0--; |
|
793 |
#endif |
|
794 |
||
795 |
m_signatureState.imageGradientType = GRADIENT_TYPE_INTEGER; |
|
796 |
} |
|
797 |
else if (s2i.isAffine()) |
|
798 |
{ |
|
799 |
RI_ASSERT(pzero.z == 1.0f); |
|
800 |
const RIfloat imageWidth = m_image->getWidth(); |
|
801 |
const RIfloat imageHeight = m_image->getHeight(); |
|
802 |
||
803 |
m_spanUniforms.image_idxdx = RI_ROUND_TO_INT((s2i[0][0]/imageWidth)*(1<<GRADIENT_BITS)); |
|
804 |
m_spanUniforms.image_idxdy = RI_ROUND_TO_INT((s2i[0][1]/imageHeight)*(1<<GRADIENT_BITS)); |
|
805 |
m_spanUniforms.image_idydx = RI_ROUND_TO_INT((s2i[1][0]/imageWidth)*(1<<GRADIENT_BITS)); |
|
806 |
m_spanUniforms.image_idydy = RI_ROUND_TO_INT((s2i[1][1]/imageHeight)*(1<<GRADIENT_BITS)); |
|
807 |
m_spanUniforms.image_ix0 = RI_ROUND_TO_INT((pzero.x/imageWidth)*(1<<GRADIENT_BITS)); |
|
808 |
m_spanUniforms.image_iy0 = RI_ROUND_TO_INT((pzero.y/imageHeight)*(1<<GRADIENT_BITS)); |
|
809 |
||
810 |
m_spanUniforms.image_ix0 += (m_spanUniforms.image_idxdx + m_spanUniforms.image_idxdy)/2; |
|
811 |
m_spanUniforms.image_iy0 += (m_spanUniforms.image_idydy + m_spanUniforms.image_idydx)/2; |
|
812 |
||
813 |
m_spanUniforms.image_iWidth = (RIint32)imageWidth; |
|
814 |
m_spanUniforms.image_iHeight = (RIint32)imageHeight; |
|
815 |
||
816 |
m_signatureState.imageGradientType = GRADIENT_TYPE_FIXED; |
|
817 |
} |
|
818 |
else |
|
819 |
{ |
|
820 |
// Use floats. |
|
821 |
m_spanUniforms.image_fx0 = pzero.x; |
|
822 |
m_spanUniforms.image_fy0 = pzero.y; |
|
823 |
m_spanUniforms.image_fw0 = pzero.z; |
|
824 |
m_spanUniforms.image_fdxdx = s2i[0][0]; |
|
825 |
m_spanUniforms.image_fdxdy = s2i[0][1]; |
|
826 |
m_spanUniforms.image_fdydx = s2i[1][0]; |
|
827 |
m_spanUniforms.image_fdydy = s2i[1][1]; |
|
828 |
m_spanUniforms.image_fdwdx = s2i[2][0]; |
|
829 |
m_spanUniforms.image_fdwdy = s2i[2][1]; |
|
830 |
||
831 |
m_spanUniforms.image_fx0 += 0.5f * (m_spanUniforms.image_fdxdx + m_spanUniforms.image_fdxdy); |
|
832 |
m_spanUniforms.image_fy0 += 0.5f * (m_spanUniforms.image_fdydy + m_spanUniforms.image_fdydx); |
|
833 |
m_spanUniforms.image_fw0 += 0.5f * (m_spanUniforms.image_fdwdx + m_spanUniforms.image_fdwdy); |
|
834 |
||
835 |
m_spanUniforms.image_fWidth = (RIfloat)m_image->getWidth(); |
|
836 |
m_spanUniforms.image_fHeight = (RIfloat)m_image->getHeight(); |
|
837 |
||
838 |
m_signatureState.imageGradientType = GRADIENT_TYPE_FLOAT; |
|
839 |
} |
|
840 |
||
841 |
m_signatureState.imageDesc = m_image->getDescriptor(); |
|
842 |
} |
|
843 |
||
844 |
static PixelPipe::TilingMode tilingModeOfImageTilingMode(VGTilingMode it) |
|
845 |
{ |
|
846 |
switch(it) |
|
847 |
{ |
|
848 |
case VG_TILE_PAD: |
|
849 |
return PixelPipe::TILING_MODE_PAD; |
|
850 |
case VG_TILE_REPEAT: |
|
851 |
return PixelPipe::TILING_MODE_REPEAT; |
|
852 |
case VG_TILE_REFLECT: |
|
853 |
return PixelPipe::TILING_MODE_REFLECT; |
|
854 |
default: |
|
855 |
RI_ASSERT(it == VG_TILE_FILL); |
|
856 |
return PixelPipe::TILING_MODE_FILL; |
|
857 |
} |
|
858 |
} |
|
859 |
||
860 |
static PixelPipe::TilingMode tilingModeOfSpreadMode(VGColorRampSpreadMode sm) |
|
861 |
{ |
|
862 |
switch(sm) |
|
863 |
{ |
|
864 |
case VG_COLOR_RAMP_SPREAD_PAD: |
|
865 |
return PixelPipe::TILING_MODE_PAD; |
|
866 |
case VG_COLOR_RAMP_SPREAD_REPEAT: |
|
867 |
return PixelPipe::TILING_MODE_REPEAT; |
|
868 |
default: |
|
869 |
RI_ASSERT(sm == VG_COLOR_RAMP_SPREAD_REFLECT); |
|
870 |
return PixelPipe::TILING_MODE_REFLECT; |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
static PixelPipe::TilingMode tilingModeOfPaint(const Paint* paint) |
|
875 |
{ |
|
876 |
switch(paint->m_paintType) |
|
877 |
{ |
|
878 |
case VG_PAINT_TYPE_COLOR: |
|
879 |
return PixelPipe::TILING_MODE_PAD; |
|
880 |
case VG_PAINT_TYPE_LINEAR_GRADIENT: |
|
881 |
case VG_PAINT_TYPE_RADIAL_GRADIENT: |
|
882 |
return tilingModeOfSpreadMode(paint->m_colorRampSpreadMode); |
|
883 |
default: |
|
884 |
RI_ASSERT(paint->m_paintType == VG_PAINT_TYPE_PATTERN); |
|
885 |
return tilingModeOfImageTilingMode(paint->m_patternTilingMode); |
|
886 |
} |
|
887 |
} |
|
888 |
||
889 |
void PixelPipe::prepareRenderToMask() |
|
890 |
{ |
|
891 |
RI_ASSERT(m_drawable->getMaskBuffer()); |
|
892 |
||
893 |
m_signatureState.dstDesc = m_drawable->getMaskBuffer()->getDescriptor(); |
|
894 |
//RI_ASSERT(m_signatureState.dstFormat >= 0 && m_signatureState.dstFormat <= VG_lABGR_8888_PRE); |
|
895 |
||
896 |
m_signatureState.maskOperation = m_maskOperation; |
|
897 |
} |
|
898 |
||
899 |
void PixelPipe::prepareSignatureState() |
|
900 |
{ |
|
901 |
m_signatureState.isRenderToMask = m_renderToMask; |
|
902 |
||
903 |
if (m_signatureState.isRenderToMask) |
|
904 |
{ |
|
905 |
prepareRenderToMask(); |
|
906 |
return; |
|
907 |
} |
|
908 |
||
909 |
m_signatureState.blendMode = getBlendMode(); |
|
910 |
||
911 |
m_signatureState.hasColorTransform = this->m_colorTransform; |
|
912 |
||
913 |
m_signatureState.paintType = getPaintType(); |
|
914 |
||
915 |
m_signatureState.paintTilingMode = tilingModeOfPaint(m_paint); |
|
916 |
// \todo Derive these from the quality settings somehow. |
|
917 |
// Linear and nearest should work atm. |
|
918 |
m_signatureState.paintSampler = SAMPLER_TYPE_NEAREST; |
|
919 |
m_signatureState.imageSampler = SAMPLER_TYPE_NEAREST; |
|
920 |
||
921 |
m_signatureState.hasMasking = isMasking() && (m_drawable->getMaskBuffer() != NULL); |
|
922 |
||
923 |
m_signatureState.hasImage = m_image ? true : false; |
|
924 |
m_signatureState.unsafeImageInput = !m_image ? false : m_image->isUnsafe(); |
|
925 |
m_signatureState.imageMode = m_imageMode; |
|
926 |
||
927 |
// Formats. Note that fields that are not filled in / used get set to a derived state in a |
|
928 |
// separate function! |
|
929 |
||
930 |
if (m_signatureState.paintType == (RIuint32)VG_PAINT_TYPE_COLOR) |
|
931 |
{ |
|
932 |
RI_ASSERT(m_paint); |
|
933 |
if (m_paint->getSolidColor().a == 1.0) |
|
934 |
m_signatureState.fillColorTransparent = false; |
|
935 |
else |
|
936 |
m_signatureState.fillColorTransparent = true; |
|
937 |
} |
|
938 |
||
939 |
m_signatureState.dstDesc = m_drawable->getColorBuffer()->getDescriptor(); |
|
940 |
||
941 |
// \todo Why isn't the imagedescriptor set here? |
|
942 |
if (m_signatureState.hasMasking) |
|
943 |
{ |
|
944 |
m_signatureState.maskDesc = m_drawable->getMaskBuffer()->getDescriptor(); |
|
945 |
} |
|
946 |
||
947 |
} |
|
948 |
||
949 |
/** |
|
950 |
* \brief Remove redundancy from the pixel-pipeline state so that less |
|
951 |
* pipelines are generated. |
|
952 |
*/ |
|
953 |
static void determineDerivedState(PixelPipe::SignatureState& derivedState, const PixelPipe::SignatureState& originalState) |
|
954 |
{ |
|
955 |
derivedState = originalState; |
|
956 |
||
957 |
if (derivedState.isRenderToMask) |
|
958 |
{ |
|
959 |
// Set a lot of defaults: |
|
960 |
derivedState.blendMode = VG_BLEND_SRC; |
|
961 |
derivedState.imageMode = VG_DRAW_IMAGE_NORMAL; |
|
962 |
derivedState.paintType = VG_PAINT_TYPE_COLOR; |
|
963 |
||
964 |
derivedState.hasImage = false; |
|
965 |
derivedState.hasMasking = false; |
|
966 |
derivedState.hasColorTransform = false; |
|
967 |
} |
|
968 |
||
969 |
if (derivedState.paintType == VG_PAINT_TYPE_COLOR) |
|
970 |
{ |
|
971 |
derivedState.paintTilingMode = PixelPipe::TILING_MODE_PAD; |
|
972 |
derivedState.paintSampler = PixelPipe::SAMPLER_TYPE_NEAREST; |
|
973 |
// \todo Opaque solid colors can benefit from simpler coverage-blending |
|
974 |
// becase SRC_OVER == SRC. This information has to be present in |
|
975 |
// the derivedState (and not just uniform). |
|
976 |
} |
|
977 |
||
978 |
if (!derivedState.hasImage) |
|
979 |
{ |
|
980 |
derivedState.imageMode = VG_DRAW_IMAGE_NORMAL; |
|
981 |
derivedState.imageSampler = PixelPipe::SAMPLER_TYPE_NEAREST; |
|
982 |
derivedState.imageGradientType = PixelPipe::GRADIENT_TYPE_INTEGER; |
|
983 |
derivedState.imageDesc = Color::Descriptor::getDummyDescriptor(); |
|
984 |
} else if (derivedState.imageMode == VG_DRAW_IMAGE_NORMAL) |
|
985 |
{ |
|
986 |
// If paint is not generated, use a common enum |
|
987 |
derivedState.paintType = VG_PAINT_TYPE_COLOR; |
|
988 |
} |
|
989 |
||
990 |
if (derivedState.paintType != VG_PAINT_TYPE_PATTERN) |
|
991 |
{ |
|
992 |
derivedState.patternDesc = Color::Descriptor::getDummyDescriptor(); |
|
993 |
} |
|
994 |
||
995 |
if (!derivedState.isRenderToMask) |
|
996 |
derivedState.maskOperation = VG_CLEAR_MASK; |
|
997 |
||
998 |
if (!derivedState.hasMasking) |
|
999 |
{ |
|
1000 |
derivedState.maskDesc = Color::Descriptor::getDummyDescriptor(); |
|
1001 |
} |
|
1002 |
} |
|
1003 |
||
1004 |
||
1005 |
/** |
|
1006 |
* \brief Determine per-scanconversion constant state. |
|
1007 |
* \todo NOTE! This also prepares the derived state at the moment. |
|
1008 |
*/ |
|
1009 |
void PixelPipe::prepareSpanUniforms(bool aa) |
|
1010 |
{ |
|
1011 |
prepareSignatureState(); |
|
1012 |
||
1013 |
if (m_signatureState.hasColorTransform) |
|
1014 |
m_spanUniforms.colorTransformValues = m_iColorTransformValues; |
|
1015 |
||
1016 |
RI_ASSERT(m_drawable->getColorBuffer()); |
|
1017 |
||
1018 |
const Image* dst; |
|
1019 |
||
1020 |
if (!m_signatureState.isRenderToMask) |
|
1021 |
dst = m_drawable->getColorBuffer()->getImage(); |
|
1022 |
else |
|
1023 |
dst = m_drawable->getMaskBuffer()->getImage(); |
|
1024 |
||
1025 |
m_spanUniforms.dstPtr = dst->getData(); |
|
1026 |
m_spanUniforms.dstStride = dst->getStride(); |
|
1027 |
||
1028 |
if (m_drawable->getMaskBuffer()) |
|
1029 |
{ |
|
1030 |
m_spanUniforms.maskPtr = m_drawable->getMaskBuffer()->m_image->getData(); |
|
1031 |
m_spanUniforms.maskStride = m_drawable->getMaskBuffer()->m_image->getStride(); |
|
1032 |
} |
|
1033 |
else |
|
1034 |
{ |
|
1035 |
m_spanUniforms.maskPtr = NULL; |
|
1036 |
m_spanUniforms.maskStride = 0; |
|
1037 |
} |
|
1038 |
||
1039 |
if (!m_renderToMask) |
|
1040 |
{ |
|
1041 |
VGImageFormat prefPaintFormat = getPreferredLUTFormat(); |
|
1042 |
||
1043 |
switch (getPaintType()) |
|
1044 |
{ |
|
1045 |
case VG_PAINT_TYPE_COLOR: |
|
1046 |
prepareSolidFill(); |
|
1047 |
break; |
|
1048 |
case VG_PAINT_TYPE_LINEAR_GRADIENT: |
|
1049 |
m_paint->generateLUT(*this, prefPaintFormat); |
|
1050 |
prepareLinearGradient(); |
|
1051 |
break; |
|
1052 |
case VG_PAINT_TYPE_RADIAL_GRADIENT: |
|
1053 |
m_paint->generateLUT(*this, prefPaintFormat); |
|
1054 |
prepareRadialGradient(); |
|
1055 |
break; |
|
1056 |
default: |
|
1057 |
RI_ASSERT(getPaintType() == VG_PAINT_TYPE_PATTERN); |
|
1058 |
preparePattern(); |
|
1059 |
break; |
|
1060 |
} |
|
1061 |
} |
|
1062 |
else |
|
1063 |
{ |
|
1064 |
prepareCoverageFill(); |
|
1065 |
} |
|
1066 |
||
1067 |
prepareImage(aa); |
|
1068 |
||
1069 |
// Must be done last: |
|
1070 |
determineDerivedState(m_derivedState, m_signatureState); |
|
1071 |
} |
|
1072 |
||
1073 |
||
1074 |
/*-------------------------------------------------------------------*//*! |
|
1075 |
* \brief Computes the linear gradient function at (x,y). |
|
1076 |
* \param |
|
1077 |
* \return |
|
1078 |
* \note |
|
1079 |
*//*-------------------------------------------------------------------*/ |
|
1080 |
void PixelPipe::linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const |
|
1081 |
{ |
|
1082 |
RI_ASSERT(m_paint); |
|
1083 |
Vector2 u = m_paint->m_linearGradientPoint1 - m_paint->m_linearGradientPoint0; |
|
1084 |
RIfloat usq = dot(u,u); |
|
1085 |
if( usq <= 0.0f ) |
|
1086 |
{ //points are equal, gradient is always 1.0f |
|
1087 |
g = 1.0f; |
|
1088 |
rho = 0.0f; |
|
1089 |
return; |
|
1090 |
} |
|
1091 |
RIfloat oou = 1.0f / usq; |
|
1092 |
||
1093 |
Vector2 p(x, y); |
|
1094 |
p = affineTransform(m_surfaceToPaintMatrix, p); |
|
1095 |
p -= m_paint->m_linearGradientPoint0; |
|
1096 |
RI_ASSERT(usq >= 0.0f); |
|
1097 |
g = dot(p, u) * oou; |
|
1098 |
RIfloat dgdx = oou * u.x * m_surfaceToPaintMatrix[0][0] + oou * u.y * m_surfaceToPaintMatrix[1][0]; |
|
1099 |
RIfloat dgdy = oou * u.x * m_surfaceToPaintMatrix[0][1] + oou * u.y * m_surfaceToPaintMatrix[1][1]; |
|
1100 |
rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy); |
|
1101 |
RI_ASSERT(rho >= 0.0f); |
|
1102 |
} |
|
1103 |
||
1104 |
/*-------------------------------------------------------------------*//*! |
|
1105 |
* \brief Computes the radial gradient function at (x,y). |
|
1106 |
* \param |
|
1107 |
* \return |
|
1108 |
* \note |
|
1109 |
*//*-------------------------------------------------------------------*/ |
|
1110 |
||
1111 |
void PixelPipe::radialGradient(RIfloat &g, RIfloat &rho, RIfloat x, RIfloat y) const |
|
1112 |
{ |
|
1113 |
RI_ASSERT(m_paint); |
|
1114 |
if( m_paint->m_radialGradientRadius <= 0.0f ) |
|
1115 |
{ |
|
1116 |
g = 1.0f; |
|
1117 |
rho = 0.0f; |
|
1118 |
return; |
|
1119 |
} |
|
1120 |
||
1121 |
RIfloat r = m_paint->m_radialGradientRadius; |
|
1122 |
Vector2 c = m_paint->m_radialGradientCenter; |
|
1123 |
Vector2 f = m_paint->m_radialGradientFocalPoint; |
|
1124 |
Vector2 gx(m_surfaceToPaintMatrix[0][0], m_surfaceToPaintMatrix[1][0]); |
|
1125 |
Vector2 gy(m_surfaceToPaintMatrix[0][1], m_surfaceToPaintMatrix[1][1]); |
|
1126 |
||
1127 |
Vector2 fp = f - c; |
|
1128 |
||
1129 |
//clamp the focal point inside the gradient circle |
|
1130 |
RIfloat fpLen = fp.length(); |
|
1131 |
if( fpLen > 0.999f * r ) |
|
1132 |
fp *= 0.999f * r / fpLen; |
|
1133 |
||
1134 |
RIfloat D = -1.0f / (dot(fp,fp) - r*r); |
|
1135 |
Vector2 p(x, y); |
|
1136 |
p = affineTransform(m_surfaceToPaintMatrix, p) - c; |
|
1137 |
Vector2 d = p - fp; |
|
1138 |
RIfloat s = (RIfloat)sqrt(r*r*dot(d,d) - RI_SQR(p.x*fp.y - p.y*fp.x)); |
|
1139 |
g = (dot(fp,d) + s) * D; |
|
1140 |
if(RI_ISNAN(g)) |
|
1141 |
g = 0.0f; |
|
1142 |
RIfloat dgdx = D*dot(fp,gx) + (r*r*dot(d,gx) - (gx.x*fp.y - gx.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s); |
|
1143 |
RIfloat dgdy = D*dot(fp,gy) + (r*r*dot(d,gy) - (gy.x*fp.y - gy.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s); |
|
1144 |
rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy); |
|
1145 |
if(RI_ISNAN(rho)) |
|
1146 |
rho = 0.0f; |
|
1147 |
RI_ASSERT(rho >= 0.0f); |
|
1148 |
} |
|
1149 |
||
1150 |
/*-------------------------------------------------------------------*//*! |
|
1151 |
* \brief Maps a gradient function value to a color. |
|
1152 |
* \param |
|
1153 |
* \return |
|
1154 |
* \note |
|
1155 |
*//*-------------------------------------------------------------------*/ |
|
1156 |
||
1157 |
Color PixelPipe::colorRamp(RIfloat gradient, RIfloat rho) const |
|
1158 |
{ |
|
1159 |
RI_ASSERT(m_paint); |
|
1160 |
RI_ASSERT(rho >= 0.0f); |
|
1161 |
||
1162 |
Color c(0,0,0,0,m_paint->m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA); |
|
1163 |
Color avg; |
|
1164 |
||
1165 |
if(rho == 0.0f) |
|
1166 |
{ //filter size is zero or gradient is degenerate |
|
1167 |
switch(m_paint->m_colorRampSpreadMode) |
|
1168 |
{ |
|
1169 |
case VG_COLOR_RAMP_SPREAD_PAD: |
|
1170 |
gradient = RI_CLAMP(gradient, 0.0f, 1.0f); |
|
1171 |
break; |
|
1172 |
case VG_COLOR_RAMP_SPREAD_REFLECT: |
|
1173 |
{ |
|
1174 |
RIfloat g = RI_MOD(gradient, 2.0f); |
|
1175 |
gradient = (g < 1.0f) ? g : 2.0f - g; |
|
1176 |
break; |
|
1177 |
} |
|
1178 |
default: |
|
1179 |
RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT); |
|
1180 |
gradient = gradient - (RIfloat)floor(gradient); |
|
1181 |
break; |
|
1182 |
} |
|
1183 |
RI_ASSERT(gradient >= 0.0f && gradient <= 1.0f); |
|
1184 |
||
1185 |
for(int i=0;i<m_paint->m_colorRampStops.size()-1;i++) |
|
1186 |
{ |
|
1187 |
if(gradient >= m_paint->m_colorRampStops[i].offset && gradient < m_paint->m_colorRampStops[i+1].offset) |
|
1188 |
{ |
|
1189 |
RIfloat s = m_paint->m_colorRampStops[i].offset; |
|
1190 |
RIfloat e = m_paint->m_colorRampStops[i+1].offset; |
|
1191 |
RI_ASSERT(s < e); |
|
1192 |
RIfloat g = RI_CLAMP((gradient - s) / (e - s), 0.0f, 1.0f); //clamp needed due to numerical inaccuracies |
|
1193 |
||
1194 |
Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied); |
|
1195 |
Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied); |
|
1196 |
return (1.0f-g) * sc + g * ec; //return interpolated value |
|
1197 |
} |
|
1198 |
} |
|
1199 |
return readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied); |
|
1200 |
} |
|
1201 |
||
1202 |
RIfloat gmin = gradient - rho*0.5f; //filter starting from the gradient point (if starts earlier, radial gradient center will be an average of the first and the last stop, which doesn't look good) |
|
1203 |
RIfloat gmax = gradient + rho*0.5f; |
|
1204 |
||
1205 |
switch(m_paint->m_colorRampSpreadMode) |
|
1206 |
{ |
|
1207 |
case VG_COLOR_RAMP_SPREAD_PAD: |
|
1208 |
{ |
|
1209 |
if(gmin < 0.0f) |
|
1210 |
c += (RI_MIN(gmax, 0.0f) - gmin) * readStopColor(m_paint->m_colorRampStops, 0, m_paint->m_colorRampPremultiplied); |
|
1211 |
if(gmax > 1.0f) |
|
1212 |
c += (gmax - RI_MAX(gmin, 1.0f)) * readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied); |
|
1213 |
gmin = RI_CLAMP(gmin, 0.0f, 1.0f); |
|
1214 |
gmax = RI_CLAMP(gmax, 0.0f, 1.0f); |
|
1215 |
c += m_paint->integrateColorRamp(gmin, gmax); |
|
1216 |
c *= 1.0f/rho; |
|
1217 |
c.clamp(); //clamp needed due to numerical inaccuracies |
|
1218 |
return c; |
|
1219 |
} |
|
1220 |
||
1221 |
case VG_COLOR_RAMP_SPREAD_REFLECT: |
|
1222 |
{ |
|
1223 |
avg = m_paint->integrateColorRamp(0.0f, 1.0f); |
|
1224 |
RIfloat gmini = (RIfloat)floor(gmin); |
|
1225 |
RIfloat gmaxi = (RIfloat)floor(gmax); |
|
1226 |
c = (gmaxi + 1.0f - gmini) * avg; //full ramps |
|
1227 |
||
1228 |
//subtract beginning |
|
1229 |
if(((int)gmini) & 1) |
|
1230 |
c -= m_paint->integrateColorRamp(RI_CLAMP(1.0f - (gmin - gmini), 0.0f, 1.0f), 1.0f); |
|
1231 |
else |
|
1232 |
c -= m_paint->integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f)); |
|
1233 |
||
1234 |
//subtract end |
|
1235 |
if(((int)gmaxi) & 1) |
|
1236 |
c -= m_paint->integrateColorRamp(0.0f, RI_CLAMP(1.0f - (gmax - gmaxi), 0.0f, 1.0f)); |
|
1237 |
else |
|
1238 |
c -= m_paint->integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f); |
|
1239 |
break; |
|
1240 |
} |
|
1241 |
||
1242 |
default: |
|
1243 |
{ |
|
1244 |
RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT); |
|
1245 |
avg = m_paint->integrateColorRamp(0.0f, 1.0f); |
|
1246 |
RIfloat gmini = (RIfloat)floor(gmin); |
|
1247 |
RIfloat gmaxi = (RIfloat)floor(gmax); |
|
1248 |
c = (gmaxi + 1.0f - gmini) * avg; //full ramps |
|
1249 |
c -= m_paint->integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f)); //subtract beginning |
|
1250 |
c -= m_paint->integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f); //subtract end |
|
1251 |
break; |
|
1252 |
} |
|
1253 |
} |
|
1254 |
||
1255 |
//divide color by the length of the range |
|
1256 |
c *= 1.0f / rho; |
|
1257 |
c.clamp(); //clamp needed due to numerical inaccuracies |
|
1258 |
||
1259 |
//hide aliasing by fading to the average color |
|
1260 |
const RIfloat fadeStart = 0.5f; |
|
1261 |
const RIfloat fadeMultiplier = 2.0f; //the larger, the earlier fade to average is done |
|
1262 |
||
1263 |
if(rho < fadeStart) |
|
1264 |
return c; |
|
1265 |
||
1266 |
RIfloat ratio = RI_MIN((rho - fadeStart) * fadeMultiplier, 1.0f); |
|
1267 |
return ratio * avg + (1.0f - ratio) * c; |
|
1268 |
} |
|
1269 |
||
1270 |
/*-------------------------------------------------------------------*//*! |
|
1271 |
* \brief Computes blend. |
|
1272 |
* \param |
|
1273 |
* \return |
|
1274 |
* \note premultiplied blending formulas |
|
1275 |
//src |
|
1276 |
a = asrc |
|
1277 |
r = rsrc |
|
1278 |
//src over |
|
1279 |
a = asrc + adst * (1-asrc) |
|
1280 |
r = rsrc + rdst * (1-asrc) |
|
1281 |
//dst over |
|
1282 |
a = asrc * (1-adst) + adst |
|
1283 |
r = rsrc * (1-adst) + adst |
|
1284 |
//src in |
|
1285 |
a = asrc * adst |
|
1286 |
r = rsrc * adst |
|
1287 |
//dst in |
|
1288 |
a = adst * asrc |
|
1289 |
r = rdst * asrc |
|
1290 |
//multiply |
|
1291 |
a = asrc + adst * (1-asrc) |
|
1292 |
r = rsrc * (1-adst) + rdst * (1-asrc) + rsrc * rdst |
|
1293 |
//screen |
|
1294 |
a = asrc + adst * (1-asrc) |
|
1295 |
r = rsrc + rdst - rsrc * rdst |
|
1296 |
//darken |
|
1297 |
a = asrc + adst * (1-asrc) |
|
1298 |
r = MIN(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst)) |
|
1299 |
//lighten |
|
1300 |
a = asrc + adst * (1-asrc) |
|
1301 |
r = MAX(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst)) |
|
1302 |
//additive |
|
1303 |
a = MIN(asrc+adst,1) |
|
1304 |
r = rsrc + rdst |
|
1305 |
*//*-------------------------------------------------------------------*/ |
|
1306 |
||
1307 |
||
1308 |
||
1309 |
Color PixelPipe::blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const |
|
1310 |
{ |
|
1311 |
//apply blending in the premultiplied format |
|
1312 |
Color r(0,0,0,0,d.getInternalFormat()); |
|
1313 |
RI_ASSERT(s.a >= 0.0f && s.a <= 1.0f); |
|
1314 |
RI_ASSERT(s.r >= 0.0f && s.r <= s.a && s.r <= ar); |
|
1315 |
RI_ASSERT(s.g >= 0.0f && s.g <= s.a && s.g <= ag); |
|
1316 |
RI_ASSERT(s.b >= 0.0f && s.b <= s.a && s.b <= ab); |
|
1317 |
RI_ASSERT(d.a >= 0.0f && d.a <= 1.0f); |
|
1318 |
RI_ASSERT(d.r >= 0.0f && d.r <= d.a); |
|
1319 |
RI_ASSERT(d.g >= 0.0f && d.g <= d.a); |
|
1320 |
RI_ASSERT(d.b >= 0.0f && d.b <= d.a); |
|
1321 |
switch(blendMode) |
|
1322 |
{ |
|
1323 |
case VG_BLEND_SRC: |
|
1324 |
r = s; |
|
1325 |
break; |
|
1326 |
||
1327 |
case VG_BLEND_SRC_OVER: |
|
1328 |
r.r = s.r + d.r * (1.0f - ar); |
|
1329 |
r.g = s.g + d.g * (1.0f - ag); |
|
1330 |
r.b = s.b + d.b * (1.0f - ab); |
|
1331 |
r.a = s.a + d.a * (1.0f - s.a); |
|
1332 |
break; |
|
1333 |
||
1334 |
case VG_BLEND_DST_OVER: |
|
1335 |
r.r = s.r * (1.0f - d.a) + d.r; |
|
1336 |
r.g = s.g * (1.0f - d.a) + d.g; |
|
1337 |
r.b = s.b * (1.0f - d.a) + d.b; |
|
1338 |
r.a = s.a * (1.0f - d.a) + d.a; |
|
1339 |
break; |
|
1340 |
||
1341 |
case VG_BLEND_SRC_IN: |
|
1342 |
r.r = s.r * d.a; |
|
1343 |
r.g = s.g * d.a; |
|
1344 |
r.b = s.b * d.a; |
|
1345 |
r.a = s.a * d.a; |
|
1346 |
break; |
|
1347 |
||
1348 |
case VG_BLEND_DST_IN: |
|
1349 |
r.r = d.r * ar; |
|
1350 |
r.g = d.g * ag; |
|
1351 |
r.b = d.b * ab; |
|
1352 |
r.a = d.a * s.a; |
|
1353 |
break; |
|
1354 |
||
1355 |
case VG_BLEND_MULTIPLY: |
|
1356 |
r.r = s.r * (1.0f - d.a + d.r) + d.r * (1.0f - ar); |
|
1357 |
r.g = s.g * (1.0f - d.a + d.g) + d.g * (1.0f - ag); |
|
1358 |
r.b = s.b * (1.0f - d.a + d.b) + d.b * (1.0f - ab); |
|
1359 |
r.a = s.a + d.a * (1.0f - s.a); |
|
1360 |
break; |
|
1361 |
||
1362 |
case VG_BLEND_SCREEN: |
|
1363 |
r.r = s.r + d.r * (1.0f - s.r); |
|
1364 |
r.g = s.g + d.g * (1.0f - s.g); |
|
1365 |
r.b = s.b + d.b * (1.0f - s.b); |
|
1366 |
r.a = s.a + d.a * (1.0f - s.a); |
|
1367 |
break; |
|
1368 |
||
1369 |
case VG_BLEND_DARKEN: |
|
1370 |
r.r = RI_MIN(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a)); |
|
1371 |
r.g = RI_MIN(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a)); |
|
1372 |
r.b = RI_MIN(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a)); |
|
1373 |
r.a = s.a + d.a * (1.0f - s.a); |
|
1374 |
break; |
|
1375 |
||
1376 |
case VG_BLEND_LIGHTEN: |
|
1377 |
r.r = RI_MAX(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a)); |
|
1378 |
r.g = RI_MAX(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a)); |
|
1379 |
r.b = RI_MAX(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a)); |
|
1380 |
//although the statement below is equivalent to r.a = s.a + d.a * (1.0f - s.a) |
|
1381 |
//in practice there can be a very slight difference because |
|
1382 |
//of the max operation in the blending formula that may cause color to exceed alpha. |
|
1383 |
//Because of this, we compute the result both ways and return the maximum. |
|
1384 |
r.a = RI_MAX(s.a + d.a * (1.0f - s.a), d.a + s.a * (1.0f - d.a)); |
|
1385 |
break; |
|
1386 |
||
1387 |
default: |
|
1388 |
RI_ASSERT(blendMode == VG_BLEND_ADDITIVE); |
|
1389 |
r.r = RI_MIN(s.r + d.r, 1.0f); |
|
1390 |
r.g = RI_MIN(s.g + d.g, 1.0f); |
|
1391 |
r.b = RI_MIN(s.b + d.b, 1.0f); |
|
1392 |
r.a = RI_MIN(s.a + d.a, 1.0f); |
|
1393 |
break; |
|
1394 |
} |
|
1395 |
return r; |
|
1396 |
} |
|
1397 |
||
1398 |
/*-------------------------------------------------------------------*//*! |
|
1399 |
* \brief Applies color transform. |
|
1400 |
* \param |
|
1401 |
* \return |
|
1402 |
* \note |
|
1403 |
*//*-------------------------------------------------------------------*/ |
|
1404 |
||
1405 |
void PixelPipe::colorTransform(Color& c) const |
|
1406 |
{ |
|
1407 |
if(m_colorTransform) |
|
1408 |
{ |
|
1409 |
c.unpremultiply(); |
|
1410 |
c.luminanceToRGB(); |
|
1411 |
c.r = c.r * m_colorTransformValues[0] + m_colorTransformValues[4]; |
|
1412 |
c.g = c.g * m_colorTransformValues[1] + m_colorTransformValues[5]; |
|
1413 |
c.b = c.b * m_colorTransformValues[2] + m_colorTransformValues[6]; |
|
1414 |
c.a = c.a * m_colorTransformValues[3] + m_colorTransformValues[7]; |
|
1415 |
c.clamp(); |
|
1416 |
c.premultiply(); |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
void PixelPipe::fillSpans(PPVariants& variants, const Span* spans, int nSpans) const |
|
1421 |
{ |
|
69
3f914c77c2e9
Host OpenVG building using GCC, without LLVM integration.
Matt Plumtree <matt.plumtree@nokia.com>
parents:
53
diff
changeset
|
1422 |
#if defined(RI_COMPILE_LLVM_BYTECODE) |
24 | 1423 |
PPCompiler& compiler = PPCompiler::getCompiler(); |
1424 |
||
1425 |
PPCompiler::PixelPipeHandle handle = compiler.compilePixelPipeline(m_derivedState); |
|
1426 |
if (handle) |
|
1427 |
{ |
|
1428 |
PixelPipeFunction func = compiler.getPixelPipePtr(handle); |
|
1429 |
RI_ASSERT(func); |
|
1430 |
func(m_spanUniforms, variants, spans, nSpans); |
|
1431 |
compiler.releasePixelPipeline(handle); |
|
1432 |
} else |
|
1433 |
#endif |
|
1434 |
{ |
|
1435 |
executePixelPipeline(m_derivedState, m_spanUniforms, variants, spans, nSpans); |
|
1436 |
} |
|
1437 |
} |
|
1438 |
||
1439 |
//======================================================================= |
|
1440 |
||
1441 |
} //namespace OpenVGRI |
|
1442 |