| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 ASSERT(originY >= 0); | 320 ASSERT(originY >= 0); |
| 321 ASSERT(originY < sourceRect.maxY()); | 321 ASSERT(originY < sourceRect.maxY()); |
| 322 | 322 |
| 323 const size_t srcBytesPerRow = 4 * sourceSize.width(); | 323 const size_t srcBytesPerRow = 4 * sourceSize.width(); |
| 324 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; | 324 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; |
| 325 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 325 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 326 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); | 326 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height()
, kRGBA_8888_SkColorType, alphaType); |
| 327 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); | 327 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
| 328 } | 328 } |
| 329 | 329 |
| 330 static bool encodeImage(const ImageDataBuffer& source, const String& mimeType, c
onst double* quality, Vector<char>* output) | 330 bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality,
Vector<char>* output) const |
| 331 { | 331 { |
| 332 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char>
*>(output); | 332 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char>
*>(output); |
| 333 | 333 |
| 334 if (mimeType == "image/jpeg") { | 334 if (mimeType == "image/jpeg") { |
| 335 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; | 335 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; |
| 336 if (quality && *quality >= 0.0 && *quality <= 1.0) | 336 if (quality && *quality >= 0.0 && *quality <= 1.0) |
| 337 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | 337 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
| 338 if (!JPEGImageEncoder::encode(source, compressionQuality, encodedImage)) | 338 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage)) |
| 339 return false; | 339 return false; |
| 340 } else if (mimeType == "image/webp") { | 340 } else if (mimeType == "image/webp") { |
| 341 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; | 341 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
| 342 if (quality && *quality >= 0.0 && *quality <= 1.0) | 342 if (quality && *quality >= 0.0 && *quality <= 1.0) |
| 343 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | 343 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
| 344 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) | 344 if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage)) |
| 345 return false; | 345 return false; |
| 346 } else { | 346 } else { |
| 347 if (!PNGImageEncoder::encode(source, encodedImage)) | 347 if (!PNGImageEncoder::encode(*this, encodedImage)) |
| 348 return false; | 348 return false; |
| 349 ASSERT(mimeType == "image/png"); | 349 ASSERT(mimeType == "image/png"); |
| 350 } | 350 } |
| 351 | 351 |
| 352 return true; | 352 return true; |
| 353 } | 353 } |
| 354 | 354 |
| 355 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality)
const | 355 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality)
const |
| 356 { | 356 { |
| 357 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 357 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 358 | 358 |
| 359 Vector<char> encodedImage; | 359 Vector<char> encodedImage; |
| 360 if (!encodeImage(*this, mimeType, quality, &encodedImage)) | 360 if (!encodeImage(mimeType, quality, &encodedImage)) |
| 361 return "data:,"; | 361 return "data:,"; |
| 362 | 362 |
| 363 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); | 363 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace blink | 366 } // namespace blink |
| OLD | NEW |