Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 1257253004: [HTMLCanvasElement.toBlob] Default callback version without scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: A small change from thread safe bind to common bind based on Kinuko's review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 ASSERT(originY >= 0); 334 ASSERT(originY >= 0);
335 ASSERT(originY < sourceRect.maxY()); 335 ASSERT(originY < sourceRect.maxY());
336 336
337 const size_t srcBytesPerRow = 4 * sourceSize.width(); 337 const size_t srcBytesPerRow = 4 * sourceSize.width();
338 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; 338 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4;
339 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 339 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
340 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType); 340 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType);
341 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 341 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
342 } 342 }
343 343
344 static bool encodeImage(const ImageDataBuffer& source, const String& mimeType, c onst double* quality, Vector<char>* output) 344 bool ImageDataBuffer::encodeImage(const String& mimeType, const double* quality, Vector<char>* output) const
Noel Gordon 2015/08/28 08:53:47 This function was moved to ImageDataBuffer so toBl
xlai (Olivia) 2015/08/28 19:54:19 I believe that this ASSERT in toDataURL is redunda
345 { 345 {
346 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char> *>(output); 346 Vector<unsigned char>* encodedImage = reinterpret_cast<Vector<unsigned char> *>(output);
347 347
348 if (mimeType == "image/jpeg") { 348 if (mimeType == "image/jpeg") {
349 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; 349 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
350 if (quality && *quality >= 0.0 && *quality <= 1.0) 350 if (quality && *quality >= 0.0 && *quality <= 1.0)
351 compressionQuality = static_cast<int>(*quality * 100 + 0.5); 351 compressionQuality = static_cast<int>(*quality * 100 + 0.5);
352 if (!JPEGImageEncoder::encode(source, compressionQuality, encodedImage)) 352 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage))
353 return false; 353 return false;
354 } else if (mimeType == "image/webp") { 354 } else if (mimeType == "image/webp") {
355 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; 355 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality;
356 if (quality && *quality >= 0.0 && *quality <= 1.0) 356 if (quality && *quality >= 0.0 && *quality <= 1.0)
357 compressionQuality = static_cast<int>(*quality * 100 + 0.5); 357 compressionQuality = static_cast<int>(*quality * 100 + 0.5);
358 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) 358 if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage))
359 return false; 359 return false;
360 } else { 360 } else {
361 if (!PNGImageEncoder::encode(source, encodedImage)) 361 if (!PNGImageEncoder::encode(*this, encodedImage))
362 return false; 362 return false;
363 ASSERT(mimeType == "image/png"); 363 ASSERT(mimeType == "image/png");
364 } 364 }
365 365
366 return true; 366 return true;
367 } 367 }
368 368
369 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality) const 369 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality) const
370 { 370 {
371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
372 372
373 Vector<char> encodedImage; 373 Vector<char> encodedImage;
374 if (!encodeImage(*this, mimeType, quality, &encodedImage)) 374 if (!encodeImage(mimeType, quality, &encodedImage))
375 return "data:,"; 375 return "data:,";
376 376
377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); 377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage);
378 } 378 }
379 379
380 } // namespace blink 380 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698