Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: Source/platform/graphics/filters/FELighting.cpp

Issue 181943003: Scaling and offset fix for FELighting (software and skia paths) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed related Layout Tests to avoid rebaselining Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 offset -= widthMultipliedByPixelSize; 180 offset -= widthMultipliedByPixelSize;
181 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChan nelOffset)); 181 int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChan nelOffset));
182 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); 182 int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset));
183 normalVector.setX(-topLeft + top - (left << 1) + (center << 1)); 183 normalVector.setX(-topLeft + top - (left << 1) + (center << 1));
184 normalVector.setY(-topLeft - (top << 1) + left + (center << 1)); 184 normalVector.setY(-topLeft - (top << 1) + left + (center << 1));
185 } 185 }
186 186
187 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSour ce::PaintingData& paintingData, 187 inline void FELighting::inlineSetPixel(int offset, LightingData& data, LightSour ce::PaintingData& paintingData,
188 int lightX, int lightY, float factorX, fl oat factorY, IntPoint& normal2DVector) 188 int lightX, int lightY, float factorX, fl oat factorY, IntPoint& normal2DVector)
189 { 189 {
190 m_lightSource->updatePaintingData(paintingData, lightX, lightY, static_cast< float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale); 190 float transformedLightX = (static_cast<float>(lightX) + data.originOffset.wi dth()) / data.worldScale.x();
Stephen White 2014/03/03 21:00:57 Nit: I don't think you need static_cast<float> her
sugoi1 2014/03/04 14:45:56 Done.
191 float transformedLightY = (static_cast<float>(lightY) + data.originOffset.he ight()) / data.worldScale.y();
192 m_lightSource->updatePaintingData(paintingData, transformedLightX, transform edLightY, static_cast<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale * data.worldScale.z());
191 193
192 float lightStrength; 194 float lightStrength;
193 if (!normal2DVector.x() && !normal2DVector.y()) { 195 if (!normal2DVector.x() && !normal2DVector.y()) {
194 // Normal vector is (0, 0, 1). This is a quite frequent case. 196 // Normal vector is (0, 0, 1). This is a quite frequent case.
195 if (m_lightingType == FELighting::DiffuseLighting) { 197 if (m_lightingType == FELighting::DiffuseLighting) {
196 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength; 198 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength;
197 } else { 199 } else {
198 FloatPoint3D halfwayVector = paintingData.lightVector; 200 FloatPoint3D halfwayVector = paintingData.lightVector;
199 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h); 201 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h);
200 float halfwayVectorLength = halfwayVector.length(); 202 float halfwayVectorLength = halfwayVector.length();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD ata& paintingData) 297 inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD ata& paintingData)
296 { 298 {
297 // The selection here eventually should happen dynamically on some platforms . 299 // The selection here eventually should happen dynamically on some platforms .
298 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC) 300 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC)
299 platformApplyNeon(data, paintingData); 301 platformApplyNeon(data, paintingData);
300 #else 302 #else
301 platformApplyGeneric(data, paintingData); 303 platformApplyGeneric(data, paintingData);
302 #endif 304 #endif
303 } 305 }
304 306
307 void FELighting::getTransform(FloatSize* offset, FloatPoint3D* scale) const
308 {
309 FloatRect initialEffectRect = effectBoundaries();
310 FloatRect absoluteEffectRect = filter()->mapLocalRectToAbsoluteRect(initialE ffectRect);
311 FloatPoint absoluteLocation(absolutePaintRect().location());
312 FloatSize positionOffset(absoluteLocation - absoluteEffectRect.location());
313 offset->setWidth(positionOffset.width());
314 offset->setHeight(positionOffset.height());
315 scale->setX(initialEffectRect.width() > 0.0f && initialEffectRect.width() > 0.0f ? absoluteEffectRect.width() / initialEffectRect.width() : 1.0f);
316 scale->setY(initialEffectRect.height() > 0.0f && initialEffectRect.height() > 0.0f ? absoluteEffectRect.height() / initialEffectRect.height() : 1.0f);
317 // X and Y scale should be the same, but, if not, do a best effort by averag ing the 2 for Z scale
318 scale->setZ(0.5f * (scale->x() + scale->y()));
319 }
320
305 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height) 321 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
306 { 322 {
307 LightSource::PaintingData paintingData; 323 LightSource::PaintingData paintingData;
308 LightingData data; 324 LightingData data;
309 325
310 if (!m_lightSource) 326 if (!m_lightSource)
311 return false; 327 return false;
312 328
313 // FIXME: do something if width or height (or both) is 1 pixel. 329 // 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. 330 // The W3 spec does not define this case. Now the filter just returns.
315 if (width <= 2 || height <= 2) 331 if (width <= 2 || height <= 2)
316 return false; 332 return false;
317 333
318 data.pixels = pixels; 334 data.pixels = pixels;
319 data.surfaceScale = m_surfaceScale / 255.0f; 335 data.surfaceScale = m_surfaceScale / 255.0f;
320 data.widthMultipliedByPixelSize = width * cPixelSize; 336 data.widthMultipliedByPixelSize = width * cPixelSize;
321 data.widthDecreasedByOne = width - 1; 337 data.widthDecreasedByOne = width - 1;
322 data.heightDecreasedByOne = height - 1; 338 data.heightDecreasedByOne = height - 1;
339 getTransform(&data.originOffset, &data.worldScale);
323 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); 340 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor);
324 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue()); 341 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue());
325 m_lightSource->initPaintingData(paintingData); 342 m_lightSource->initPaintingData(paintingData);
326 343
327 // Top/Left corner. 344 // Top/Left corner.
328 IntPoint normalVector; 345 IntPoint normalVector;
329 int offset = 0; 346 int offset = 0;
330 data.topLeft(offset, normalVector); 347 data.topLeft(offset, normalVector);
331 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector); 348 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector);
332 349
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 GraphicsContext* dstContext = resultImage->context(); 503 GraphicsContext* dstContext = resultImage->context();
487 504
488 SkPaint paint; 505 SkPaint paint;
489 RefPtr<SkImageFilter> filter = createImageFilter(0); 506 RefPtr<SkImageFilter> filter = createImageFilter(0);
490 paint.setImageFilter(filter.get()); 507 paint.setImageFilter(filter.get());
491 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint); 508 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint);
492 return true; 509 return true;
493 } 510 }
494 511
495 } // namespace WebCore 512 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/graphics/filters/FELighting.h ('k') | Source/platform/graphics/filters/LightSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698