| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 343 |
| 344 if (rect.x() < 0 | 344 if (rect.x() < 0 |
| 345 || rect.y() < 0 | 345 || rect.y() < 0 |
| 346 || rect.maxX() > m_surface->size().width() | 346 || rect.maxX() > m_surface->size().width() |
| 347 || rect.maxY() > m_surface->size().height()) | 347 || rect.maxY() > m_surface->size().height()) |
| 348 result->zeroFill(); | 348 result->zeroFill(); |
| 349 | 349 |
| 350 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 350 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 351 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); | 351 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); |
| 352 | 352 |
| 353 m_surface->willReadback(); | 353 m_surface->willAccessPixels(); |
| 354 context()->readPixels(info, result->data(), 4 * rect.width(), rect.x(), rect
.y()); | 354 context()->readPixels(info, result->data(), 4 * rect.width(), rect.x(), rect
.y()); |
| 355 return result.release(); | 355 return result.release(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c
onst IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) | 358 void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c
onst IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) |
| 359 { | 359 { |
| 360 if (!isSurfaceValid()) | 360 if (!isSurfaceValid()) |
| 361 return; | 361 return; |
| 362 | 362 |
| 363 ASSERT(sourceRect.width() > 0); | 363 ASSERT(sourceRect.width() > 0); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 375 ASSERT(destY >= 0); | 375 ASSERT(destY >= 0); |
| 376 ASSERT(destY < m_surface->size().height()); | 376 ASSERT(destY < m_surface->size().height()); |
| 377 ASSERT(originY >= 0); | 377 ASSERT(originY >= 0); |
| 378 ASSERT(originY < sourceRect.maxY()); | 378 ASSERT(originY < sourceRect.maxY()); |
| 379 | 379 |
| 380 const size_t srcBytesPerRow = 4 * sourceSize.width(); | 380 const size_t srcBytesPerRow = 4 * sourceSize.width(); |
| 381 const void* srcAddr = source->data() + originY * srcBytesPerRow + originX *
4; | 381 const void* srcAddr = source->data() + originY * srcBytesPerRow + originX *
4; |
| 382 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 382 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 383 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); | 383 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); |
| 384 | 384 |
| 385 m_surface->willAccessPixels(); |
| 386 |
| 385 context()->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); | 387 context()->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
| 386 } | 388 } |
| 387 | 389 |
| 388 template <typename T> | 390 template <typename T> |
| 389 static bool encodeImage(T& source, const String& mimeType, const double* quality
, Vector<char>* output) | 391 static bool encodeImage(T& source, const String& mimeType, const double* quality
, Vector<char>* output) |
| 390 { | 392 { |
| 391 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char>
*>(output); | 393 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char>
*>(output); |
| 392 | 394 |
| 393 if (mimeType == "image/jpeg") { | 395 if (mimeType == "image/jpeg") { |
| 394 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; | 396 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 434 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 433 return "data:,"; | 435 return "data:,"; |
| 434 | 436 |
| 435 Vector<char> base64Data; | 437 Vector<char> base64Data; |
| 436 base64Encode(encodedImage, base64Data); | 438 base64Encode(encodedImage, base64Data); |
| 437 | 439 |
| 438 return "data:" + mimeType + ";base64," + base64Data; | 440 return "data:" + mimeType + ";base64," + base64Data; |
| 439 } | 441 } |
| 440 | 442 |
| 441 } // namespace blink | 443 } // namespace blink |
| OLD | NEW |