OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009 Google, Inc. | 3 * Copyright (C) 2008, 2009 Google, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 | 164 |
165 void ImageFrame::zeroFillFrameRect(const IntRect& rect) { | 165 void ImageFrame::zeroFillFrameRect(const IntRect& rect) { |
166 if (rect.isEmpty()) | 166 if (rect.isEmpty()) |
167 return; | 167 return; |
168 | 168 |
169 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 169 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
170 setHasAlpha(true); | 170 setHasAlpha(true); |
171 } | 171 } |
172 | 172 |
| 173 static uint8_t blendChannel(uint8_t src, |
| 174 uint8_t srcA, |
| 175 uint8_t dst, |
| 176 uint8_t dstA, |
| 177 unsigned scale) { |
| 178 unsigned blendUnscaled = src * srcA + dst * dstA; |
| 179 DCHECK(blendUnscaled < (1ULL << 32) / scale); |
| 180 return (blendUnscaled * scale) >> 24; |
| 181 } |
| 182 |
| 183 static uint32_t blendSrcOverDstNonPremultiplied(uint32_t src, uint32_t dst) { |
| 184 uint8_t srcA = SkGetPackedA32(src); |
| 185 if (srcA == 0) |
| 186 return dst; |
| 187 |
| 188 uint8_t dstA = SkGetPackedA32(dst); |
| 189 uint8_t dstFactorA = (dstA * SkAlpha255To256(255 - srcA)) >> 8; |
| 190 DCHECK(srcA + dstFactorA < (1U << 8)); |
| 191 uint8_t blendA = srcA + dstFactorA; |
| 192 unsigned scale = (1UL << 24) / blendA; |
| 193 |
| 194 uint8_t blendR = blendChannel(SkGetPackedR32(src), srcA, SkGetPackedR32(dst), |
| 195 dstFactorA, scale); |
| 196 uint8_t blendG = blendChannel(SkGetPackedG32(src), srcA, SkGetPackedG32(dst), |
| 197 dstFactorA, scale); |
| 198 uint8_t blendB = blendChannel(SkGetPackedB32(src), srcA, SkGetPackedB32(dst), |
| 199 dstFactorA, scale); |
| 200 |
| 201 return SkPackARGB32NoCheck(blendA, blendR, blendG, blendB); |
| 202 } |
| 203 |
| 204 void ImageFrame::blendRGBARaw(PixelData* dest, |
| 205 unsigned r, |
| 206 unsigned g, |
| 207 unsigned b, |
| 208 unsigned a) { |
| 209 *dest = blendSrcOverDstNonPremultiplied(SkPackARGB32NoCheck(a, r, g, b), *dest
); |
| 210 } |
| 211 |
| 212 void ImageFrame::blendSrcOverDstRaw(PixelData* src, PixelData dst) { |
| 213 *src = blendSrcOverDstNonPremultiplied(*src, dst); |
| 214 } |
| 215 |
173 SkAlphaType ImageFrame::computeAlphaType() const { | 216 SkAlphaType ImageFrame::computeAlphaType() const { |
174 // If the frame is not fully loaded, there will be transparent pixels, | 217 // If the frame is not fully loaded, there will be transparent pixels, |
175 // so we can't tell skia we're opaque, even for image types that logically | 218 // so we can't tell skia we're opaque, even for image types that logically |
176 // always are (e.g. jpeg). | 219 // always are (e.g. jpeg). |
177 if (!m_hasAlpha && m_status == FrameComplete) | 220 if (!m_hasAlpha && m_status == FrameComplete) |
178 return kOpaque_SkAlphaType; | 221 return kOpaque_SkAlphaType; |
179 | 222 |
180 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 223 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
181 } | 224 } |
182 | 225 |
183 } // namespace blink | 226 } // namespace blink |
OLD | NEW |