OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. 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 are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 template <Multiply multiplied> | 294 template <Multiply multiplied> |
295 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext*
context, const IntSize& size) | 295 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext*
context, const IntSize& size) |
296 { | 296 { |
297 float area = 4.0f * rect.width() * rect.height(); | 297 float area = 4.0f * rect.width() * rect.height(); |
298 if (area > static_cast<float>(std::numeric_limits<int>::max())) | 298 if (area > static_cast<float>(std::numeric_limits<int>::max())) |
299 return nullptr; | 299 return nullptr; |
300 | 300 |
301 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re
ct.width() * rect.height() * 4); | 301 RefPtr<Uint8ClampedArray> result = Uint8ClampedArray::createUninitialized(re
ct.width() * rect.height() * 4); |
302 | 302 |
303 unsigned char* data = result->data(); | |
304 | |
305 if (rect.x() < 0 | 303 if (rect.x() < 0 |
306 || rect.y() < 0 | 304 || rect.y() < 0 |
307 || rect.maxX() > size.width() | 305 || rect.maxX() > size.width() |
308 || rect.maxY() > size.height()) | 306 || rect.maxY() > size.height()) |
309 result->zeroFill(); | 307 result->zeroFill(); |
310 | 308 |
311 unsigned destBytesPerRow = 4 * rect.width(); | 309 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
312 SkBitmap destBitmap; | 310 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); |
313 destBitmap.installPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.heigh
t()), data, destBytesPerRow); | |
314 | 311 |
315 SkCanvas::Config8888 config8888; | 312 context->readPixels(info, result->data(), 4 * rect.width(), rect.x(), rect.y
()); |
316 if (multiplied == Premultiplied) | |
317 config8888 = SkCanvas::kRGBA_Premul_Config8888; | |
318 else | |
319 config8888 = SkCanvas::kRGBA_Unpremul_Config8888; | |
320 | |
321 context->readPixels(&destBitmap, rect.x(), rect.y(), config8888); | |
322 return result.release(); | 313 return result.release(); |
323 } | 314 } |
324 | 315 |
325 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec
t& rect) const | 316 PassRefPtr<Uint8ClampedArray> ImageBuffer::getUnmultipliedImageData(const IntRec
t& rect) const |
326 { | 317 { |
327 if (!isValid()) | 318 if (!isValid()) |
328 return Uint8ClampedArray::create(rect.width() * rect.height() * 4); | 319 return Uint8ClampedArray::create(rect.width() * rect.height() * 4); |
329 return getImageData<Unmultiplied>(rect, context(), m_surface->size()); | 320 return getImageData<Unmultiplied>(rect, context(), m_surface->size()); |
330 } | 321 } |
331 | 322 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 404 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
414 return "data:,"; | 405 return "data:,"; |
415 | 406 |
416 Vector<char> base64Data; | 407 Vector<char> base64Data; |
417 base64Encode(encodedImage, base64Data); | 408 base64Encode(encodedImage, base64Data); |
418 | 409 |
419 return "data:" + mimeType + ";base64," + base64Data; | 410 return "data:" + mimeType + ";base64," + base64Data; |
420 } | 411 } |
421 | 412 |
422 } // namespace WebCore | 413 } // namespace WebCore |
OLD | NEW |