OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
4 * | 4 * |
5 * Portions are Copyright (C) 2001 mozilla.org | 5 * Portions are Copyright (C) 2001 mozilla.org |
6 * | 6 * |
7 * Other contributors: | 7 * Other contributors: |
8 * Stuart Parmenter <stuart@mozilla.com> | 8 * Stuart Parmenter <stuart@mozilla.com> |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 360 |
361 if (png_bytep interlaceBuffer = m_reader->interlaceBuffer()) { | 361 if (png_bytep interlaceBuffer = m_reader->interlaceBuffer()) { |
362 unsigned colorChannels = hasAlpha ? 4 : 3; | 362 unsigned colorChannels = hasAlpha ? 4 : 3; |
363 row = interlaceBuffer + (rowIndex * colorChannels * size().width()); | 363 row = interlaceBuffer + (rowIndex * colorChannels * size().width()); |
364 png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer); | 364 png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer); |
365 } | 365 } |
366 | 366 |
367 // Write the decoded row pixels to the frame buffer. The repetitive | 367 // Write the decoded row pixels to the frame buffer. The repetitive |
368 // form of the row write loops is for speed. | 368 // form of the row write loops is for speed. |
369 ImageFrame::PixelData* const dstRow = buffer.getAddr(frameRect.x(), y); | 369 ImageFrame::PixelData* const dstRow = buffer.getAddr(frameRect.x(), y); |
370 int width = frameRect.width(); | 370 const int width = frameRect.width(); |
371 | 371 |
372 png_bytep srcPtr = row; | 372 png_bytep srcPtr = row; |
373 if (hasAlpha) { | 373 if (hasAlpha) { |
374 // Here we apply the color space transformation to the dst space. | 374 // Here we apply the color space transformation to the dst space. |
375 // It does not really make sense to transform to a gamma-encoded | 375 // It does not really make sense to transform to a gamma-encoded |
376 // space and then immediately after, perform a linear premultiply. | 376 // space and then immediately after, perform a linear premultiply. |
377 // Ideally we would pass kPremul_SkAlphaType to xform->apply(), | 377 // Ideally we would pass kPremul_SkAlphaType to xform->apply(), |
378 // instructing SkColorSpaceXform to perform the linear premultiply | 378 // instructing SkColorSpaceXform to perform the linear premultiply |
379 // while the pixels are a linear space. | 379 // while the pixels are a linear space. |
380 // We cannot do this because when we apply the gamma encoding after | 380 // We cannot do this because when we apply the gamma encoding after |
381 // the premultiply, we will very likely end up with valid pixels | 381 // the premultiply, we will very likely end up with valid pixels |
382 // where R, G, and/or B are greater than A. The legacy drawing | 382 // where R, G, and/or B are greater than A. The legacy drawing |
383 // pipeline does not know how to handle this. | 383 // pipeline does not know how to handle this. |
384 if (SkColorSpaceXform* xform = colorTransform()) { | 384 if (SkColorSpaceXform* xform = colorTransform()) { |
385 SkColorSpaceXform::ColorFormat colorFormat = | 385 SkColorSpaceXform::ColorFormat colorFormat = |
386 SkColorSpaceXform::kRGBA_8888_ColorFormat; | 386 SkColorSpaceXform::kRGBA_8888_ColorFormat; |
387 xform->apply(colorFormat, dstRow, colorFormat, srcPtr, size().width(), | 387 xform->apply(colorFormat, dstRow, colorFormat, srcPtr, width, |
388 kUnpremul_SkAlphaType); | 388 kUnpremul_SkAlphaType); |
389 srcPtr = png_bytep(dstRow); | 389 srcPtr = png_bytep(dstRow); |
390 } | 390 } |
391 | 391 |
392 unsigned alphaMask = 255; | 392 unsigned alphaMask = 255; |
393 if (m_frameBufferCache[m_currentFrame].getAlphaBlendSource() == | 393 if (m_frameBufferCache[m_currentFrame].getAlphaBlendSource() == |
394 ImageFrame::BlendAtopBgcolor) { | 394 ImageFrame::BlendAtopBgcolor) { |
395 if (buffer.premultiplyAlpha()) { | 395 if (buffer.premultiplyAlpha()) { |
396 for (auto *dstPixel = dstRow; dstPixel < dstRow + width; | 396 for (auto *dstPixel = dstRow; dstPixel < dstRow + width; |
397 dstPixel++, srcPtr += 4) { | 397 dstPixel++, srcPtr += 4) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 for (auto *dstPixel = dstRow; dstPixel < dstRow + width; | 436 for (auto *dstPixel = dstRow; dstPixel < dstRow + width; |
437 srcPtr += 3, ++dstPixel) { | 437 srcPtr += 3, ++dstPixel) { |
438 buffer.setRGBARaw(dstPixel, srcPtr[0], srcPtr[1], srcPtr[2], 255); | 438 buffer.setRGBARaw(dstPixel, srcPtr[0], srcPtr[1], srcPtr[2], 255); |
439 } | 439 } |
440 | 440 |
441 // We'll apply the color space xform to opaque pixels after they have been | 441 // We'll apply the color space xform to opaque pixels after they have been |
442 // written to the ImageFrame, purely because SkColorSpaceXform supports | 442 // written to the ImageFrame, purely because SkColorSpaceXform supports |
443 // RGBA (and not RGB). | 443 // RGBA (and not RGB). |
444 if (SkColorSpaceXform* xform = colorTransform()) { | 444 if (SkColorSpaceXform* xform = colorTransform()) { |
445 xform->apply(xformColorFormat(), dstRow, xformColorFormat(), dstRow, | 445 xform->apply(xformColorFormat(), dstRow, xformColorFormat(), dstRow, |
446 size().width(), kOpaque_SkAlphaType); | 446 width, kOpaque_SkAlphaType); |
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 buffer.setPixelsChanged(true); | 450 buffer.setPixelsChanged(true); |
451 } | 451 } |
452 | 452 |
453 void PNGImageDecoder::frameComplete() { | 453 void PNGImageDecoder::frameComplete() { |
454 if (m_currentFrame >= m_frameBufferCache.size()) | 454 if (m_currentFrame >= m_frameBufferCache.size()) |
455 return; | 455 return; |
456 | 456 |
(...skipping 27 matching lines...) Expand all Loading... |
484 return m_reader->frameIsReceivedAtIndex(index); | 484 return m_reader->frameIsReceivedAtIndex(index); |
485 } | 485 } |
486 | 486 |
487 float PNGImageDecoder::frameDurationAtIndex(size_t index) const { | 487 float PNGImageDecoder::frameDurationAtIndex(size_t index) const { |
488 if (index < m_frameBufferCache.size()) | 488 if (index < m_frameBufferCache.size()) |
489 return m_frameBufferCache[index].duration(); | 489 return m_frameBufferCache[index].duration(); |
490 return 0; | 490 return 0; |
491 } | 491 } |
492 | 492 |
493 } // namespace blink | 493 } // namespace blink |
OLD | NEW |