OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 University of Szeged | 2 * Copyright (C) 2010 University of Szeged |
3 * Copyright (C) 2010 Zoltan Herczeg | 3 * Copyright (C) 2010 Zoltan Herczeg |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // FIXME: do something if width or height (or both) is 1 pixel. | 313 // FIXME: do something if width or height (or both) is 1 pixel. |
314 // The W3 spec does not define this case. Now the filter just returns. | 314 // The W3 spec does not define this case. Now the filter just returns. |
315 if (width <= 2 || height <= 2) | 315 if (width <= 2 || height <= 2) |
316 return false; | 316 return false; |
317 | 317 |
318 data.pixels = pixels; | 318 data.pixels = pixels; |
319 data.surfaceScale = m_surfaceScale / 255.0f; | 319 data.surfaceScale = m_surfaceScale / 255.0f; |
320 data.widthMultipliedByPixelSize = width * cPixelSize; | 320 data.widthMultipliedByPixelSize = width * cPixelSize; |
321 data.widthDecreasedByOne = width - 1; | 321 data.widthDecreasedByOne = width - 1; |
322 data.heightDecreasedByOne = height - 1; | 322 data.heightDecreasedByOne = height - 1; |
323 paintingData.colorVector = FloatPoint3D(m_lightingColor.red(), m_lightingCol
or.green(), m_lightingColor.blue()); | 323 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); |
| 324 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green()
, lightColor.blue()); |
324 m_lightSource->initPaintingData(paintingData); | 325 m_lightSource->initPaintingData(paintingData); |
325 | 326 |
326 // Top/Left corner. | 327 // Top/Left corner. |
327 IntPoint normalVector; | 328 IntPoint normalVector; |
328 int offset = 0; | 329 int offset = 0; |
329 data.topLeft(offset, normalVector); | 330 data.topLeft(offset, normalVector); |
330 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma
lVector); | 331 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma
lVector); |
331 | 332 |
332 // Top/Right pixel. | 333 // Top/Right pixel. |
333 offset = data.widthMultipliedByPixelSize - cPixelSize; | 334 offset = data.widthMultipliedByPixelSize - cPixelSize; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // output for various kernelUnitLengths, and I am not sure they are reliable
. | 415 // output for various kernelUnitLengths, and I am not sure they are reliable
. |
415 // Anyway, feConvolveMatrix should also use the implementation | 416 // Anyway, feConvolveMatrix should also use the implementation |
416 | 417 |
417 IntSize absolutePaintSize = absolutePaintRect().size(); | 418 IntSize absolutePaintSize = absolutePaintRect().size(); |
418 drawLighting(srcPixelArray, absolutePaintSize.width(), absolutePaintSize.hei
ght()); | 419 drawLighting(srcPixelArray, absolutePaintSize.width(), absolutePaintSize.hei
ght()); |
419 } | 420 } |
420 | 421 |
421 PassRefPtr<SkImageFilter> FELighting::createImageFilter(SkiaImageFilterBuilder*
builder) | 422 PassRefPtr<SkImageFilter> FELighting::createImageFilter(SkiaImageFilterBuilder*
builder) |
422 { | 423 { |
423 SkImageFilter::CropRect rect = getCropRect(builder ? builder->cropOffset() :
FloatSize()); | 424 SkImageFilter::CropRect rect = getCropRect(builder ? builder->cropOffset() :
FloatSize()); |
| 425 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); |
424 RefPtr<SkImageFilter> input(builder ? builder->build(inputEffect(0), operati
ngColorSpace()) : 0); | 426 RefPtr<SkImageFilter> input(builder ? builder->build(inputEffect(0), operati
ngColorSpace()) : 0); |
425 switch (m_lightSource->type()) { | 427 switch (m_lightSource->type()) { |
426 case LS_DISTANT: { | 428 case LS_DISTANT: { |
427 DistantLightSource* distantLightSource = static_cast<DistantLightSource*
>(m_lightSource.get()); | 429 DistantLightSource* distantLightSource = static_cast<DistantLightSource*
>(m_lightSource.get()); |
428 float azimuthRad = deg2rad(distantLightSource->azimuth()); | 430 float azimuthRad = deg2rad(distantLightSource->azimuth()); |
429 float elevationRad = deg2rad(distantLightSource->elevation()); | 431 float elevationRad = deg2rad(distantLightSource->elevation()); |
430 SkPoint3 direction(cosf(azimuthRad) * cosf(elevationRad), | 432 SkPoint3 direction(cosf(azimuthRad) * cosf(elevationRad), |
431 sinf(azimuthRad) * cosf(elevationRad), | 433 sinf(azimuthRad) * cosf(elevationRad), |
432 sinf(elevationRad)); | 434 sinf(elevationRad)); |
433 if (m_specularConstant > 0) | 435 if (m_specularConstant > 0) |
434 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire
ction, m_lightingColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExpo
nent, input.get(), &rect)); | 436 return adoptRef(SkLightingImageFilter::CreateDistantLitSpecular(dire
ction, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); |
435 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction
, m_lightingColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect))
; | 437 return adoptRef(SkLightingImageFilter::CreateDistantLitDiffuse(direction
, lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
436 } | 438 } |
437 case LS_POINT: { | 439 case LS_POINT: { |
438 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li
ghtSource.get()); | 440 PointLightSource* pointLightSource = static_cast<PointLightSource*>(m_li
ghtSource.get()); |
439 FloatPoint3D position = pointLightSource->position(); | 441 FloatPoint3D position = pointLightSource->position(); |
440 SkPoint3 skPosition(position.x(), position.y(), position.z()); | 442 SkPoint3 skPosition(position.x(), position.y(), position.z()); |
441 if (m_specularConstant > 0) | 443 if (m_specularConstant > 0) |
442 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi
tion, m_lightingColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExpon
ent, input.get(), &rect)); | 444 return adoptRef(SkLightingImageFilter::CreatePointLitSpecular(skPosi
tion, lightColor.rgb(), m_surfaceScale, m_specularConstant, m_specularExponent,
input.get(), &rect)); |
443 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition,
m_lightingColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); | 445 return adoptRef(SkLightingImageFilter::CreatePointLitDiffuse(skPosition,
lightColor.rgb(), m_surfaceScale, m_diffuseConstant, input.get(), &rect)); |
444 } | 446 } |
445 case LS_SPOT: { | 447 case LS_SPOT: { |
446 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light
Source.get()); | 448 SpotLightSource* spotLightSource = static_cast<SpotLightSource*>(m_light
Source.get()); |
447 SkPoint3 location(spotLightSource->position().x(), spotLightSource->posi
tion().y(), spotLightSource->position().z()); | 449 SkPoint3 location(spotLightSource->position().x(), spotLightSource->posi
tion().y(), spotLightSource->position().z()); |
448 SkPoint3 target(spotLightSource->direction().x(), spotLightSource->direc
tion().y(), spotLightSource->direction().z()); | 450 SkPoint3 target(spotLightSource->direction().x(), spotLightSource->direc
tion().y(), spotLightSource->direction().z()); |
449 float specularExponent = spotLightSource->specularExponent(); | 451 float specularExponent = spotLightSource->specularExponent(); |
450 float limitingConeAngle = spotLightSource->limitingConeAngle(); | 452 float limitingConeAngle = spotLightSource->limitingConeAngle(); |
451 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle <
-90) | 453 if (!limitingConeAngle || limitingConeAngle > 90 || limitingConeAngle <
-90) |
452 limitingConeAngle = 90; | 454 limitingConeAngle = 90; |
453 if (m_specularConstant > 0) | 455 if (m_specularConstant > 0) |
454 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio
n, target, specularExponent, limitingConeAngle, m_lightingColor.rgb(), m_surface
Scale, m_specularConstant, m_specularExponent, input.get(), &rect)); | 456 return adoptRef(SkLightingImageFilter::CreateSpotLitSpecular(locatio
n, target, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale
, m_specularConstant, m_specularExponent, input.get(), &rect)); |
455 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta
rget, specularExponent, limitingConeAngle, m_lightingColor.rgb(), m_surfaceScale
, m_diffuseConstant, input.get(), &rect)); | 457 return adoptRef(SkLightingImageFilter::CreateSpotLitDiffuse(location, ta
rget, specularExponent, limitingConeAngle, lightColor.rgb(), m_surfaceScale, m_d
iffuseConstant, input.get(), &rect)); |
456 } | 458 } |
457 default: | 459 default: |
458 ASSERT_NOT_REACHED(); | 460 ASSERT_NOT_REACHED(); |
459 return 0; | 461 return 0; |
460 } | 462 } |
461 } | 463 } |
462 | 464 |
463 bool FELighting::applySkia() | 465 bool FELighting::applySkia() |
464 { | 466 { |
465 // For now, only use the skia implementation for accelerated rendering. | 467 // For now, only use the skia implementation for accelerated rendering. |
(...skipping 18 matching lines...) Expand all Loading... |
484 GraphicsContext* dstContext = resultImage->context(); | 486 GraphicsContext* dstContext = resultImage->context(); |
485 | 487 |
486 SkPaint paint; | 488 SkPaint paint; |
487 RefPtr<SkImageFilter> filter = createImageFilter(0); | 489 RefPtr<SkImageFilter> filter = createImageFilter(0); |
488 paint.setImageFilter(filter.get()); | 490 paint.setImageFilter(filter.get()); |
489 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(),
drawingRegion.location().y(), &paint); | 491 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(),
drawingRegion.location().y(), &paint); |
490 return true; | 492 return true; |
491 } | 493 } |
492 | 494 |
493 } // namespace WebCore | 495 } // namespace WebCore |
OLD | NEW |