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

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: Changed fix to temporary light creation 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 data.lightSource->updatePaintingData(paintingData, lightX, lightY, static_ca st<float>(data.pixels->item(offset + cAlphaChannelOffset)) * data.surfaceScale);
191 191
192 float lightStrength; 192 float lightStrength;
193 if (!normal2DVector.x() && !normal2DVector.y()) { 193 if (!normal2DVector.x() && !normal2DVector.y()) {
194 // Normal vector is (0, 0, 1). This is a quite frequent case. 194 // Normal vector is (0, 0, 1). This is a quite frequent case.
195 if (m_lightingType == FELighting::DiffuseLighting) { 195 if (m_lightingType == FELighting::DiffuseLighting) {
196 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength; 196 lightStrength = m_diffuseConstant * paintingData.lightVector.z() / p aintingData.lightVectorLength;
197 } else { 197 } else {
198 FloatPoint3D halfwayVector = paintingData.lightVector; 198 FloatPoint3D halfwayVector = paintingData.lightVector;
199 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h); 199 halfwayVector.setZ(halfwayVector.z() + paintingData.lightVectorLengt h);
200 float halfwayVectorLength = halfwayVector.length(); 200 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) 295 inline void FELighting::platformApply(LightingData& data, LightSource::PaintingD ata& paintingData)
296 { 296 {
297 // The selection here eventually should happen dynamically on some platforms . 297 // The selection here eventually should happen dynamically on some platforms .
298 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC) 298 #if CPU(ARM_NEON) && CPU(ARM_TRADITIONAL) && COMPILER(GCC)
299 platformApplyNeon(data, paintingData); 299 platformApplyNeon(data, paintingData);
300 #else 300 #else
301 platformApplyGeneric(data, paintingData); 301 platformApplyGeneric(data, paintingData);
302 #endif 302 #endif
303 } 303 }
304 304
305 void FELighting::getTransform(FloatPoint3D* scale, FloatSize* offset) const
306 {
307 FloatRect initialEffectRect = effectBoundaries();
308 FloatRect absoluteEffectRect = filter()->mapLocalRectToAbsoluteRect(initialE ffectRect);
309 FloatPoint absoluteLocation(absolutePaintRect().location());
310 FloatSize positionOffset(absoluteLocation - absoluteEffectRect.location());
311 offset->setWidth(positionOffset.width());
312 offset->setHeight(positionOffset.height());
313 scale->setX(initialEffectRect.width() > 0.0f && initialEffectRect.width() > 0.0f ? absoluteEffectRect.width() / initialEffectRect.width() : 1.0f);
314 scale->setY(initialEffectRect.height() > 0.0f && initialEffectRect.height() > 0.0f ? absoluteEffectRect.height() / initialEffectRect.height() : 1.0f);
315 // X and Y scale should be the same, but, if not, do a best effort by averag ing the 2 for Z scale
316 scale->setZ(0.5f * (scale->x() + scale->y()));
317 }
318
305 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height) 319 bool FELighting::drawLighting(Uint8ClampedArray* pixels, int width, int height)
306 { 320 {
307 LightSource::PaintingData paintingData; 321 LightSource::PaintingData paintingData;
308 LightingData data; 322 LightingData data;
309 323
310 if (!m_lightSource) 324 if (!m_lightSource)
311 return false; 325 return false;
312 326
313 // FIXME: do something if width or height (or both) is 1 pixel. 327 // 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. 328 // The W3 spec does not define this case. Now the filter just returns.
315 if (width <= 2 || height <= 2) 329 if (width <= 2 || height <= 2)
316 return false; 330 return false;
317 331
318 data.pixels = pixels; 332 data.pixels = pixels;
319 data.surfaceScale = m_surfaceScale / 255.0f; 333 data.surfaceScale = m_surfaceScale / 255.0f;
320 data.widthMultipliedByPixelSize = width * cPixelSize; 334 data.widthMultipliedByPixelSize = width * cPixelSize;
321 data.widthDecreasedByOne = width - 1; 335 data.widthDecreasedByOne = width - 1;
322 data.heightDecreasedByOne = height - 1; 336 data.heightDecreasedByOne = height - 1;
337 FloatPoint3D worldScale;
338 FloatSize originOffset;
339 getTransform(&worldScale, &originOffset);
340 RefPtr<LightSource> lightSource = m_lightSource->create(worldScale, originOf fset);
341 data.lightSource = lightSource.get();
323 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor); 342 Color lightColor = adaptColorToOperatingColorSpace(m_lightingColor);
324 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue()); 343 paintingData.colorVector = FloatPoint3D(lightColor.red(), lightColor.green() , lightColor.blue());
325 m_lightSource->initPaintingData(paintingData); 344 data.lightSource->initPaintingData(paintingData);
326 345
327 // Top/Left corner. 346 // Top/Left corner.
328 IntPoint normalVector; 347 IntPoint normalVector;
329 int offset = 0; 348 int offset = 0;
330 data.topLeft(offset, normalVector); 349 data.topLeft(offset, normalVector);
331 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector); 350 setPixel(offset, data, paintingData, 0, 0, cFactor2div3, cFactor2div3, norma lVector);
332 351
333 // Top/Right pixel. 352 // Top/Right pixel.
334 offset = data.widthMultipliedByPixelSize - cPixelSize; 353 offset = data.widthMultipliedByPixelSize - cPixelSize;
335 data.topRight(offset, normalVector); 354 data.topRight(offset, normalVector);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 GraphicsContext* dstContext = resultImage->context(); 505 GraphicsContext* dstContext = resultImage->context();
487 506
488 SkPaint paint; 507 SkPaint paint;
489 RefPtr<SkImageFilter> filter = createImageFilter(0); 508 RefPtr<SkImageFilter> filter = createImageFilter(0);
490 paint.setImageFilter(filter.get()); 509 paint.setImageFilter(filter.get());
491 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint); 510 dstContext->drawBitmap(nativeImage->bitmap(), drawingRegion.location().x(), drawingRegion.location().y(), &paint);
492 return true; 511 return true;
493 } 512 }
494 513
495 } // namespace WebCore 514 } // 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