Chromium Code Reviews| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 static bool encodeImage(const ImageDataBuffer& source, const String& mimeType, c onst double* quality, Vector<char>* output) | 344 static bool encodeImage(const ImageDataBuffer& source, const String& mimeType, c onst double* quality, Vector<char>* output) |
| 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(source, compressionQuality, encodedImage)) |
| 353 return false; | 353 return false; |
| 354 } else if (mimeType == "image/webplossless") { | |
| 355 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; | |
| 356 if (quality && *quality >= 0.0 && *quality <= 1.0) | |
| 357 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | |
| 358 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage, WEBPImageEncoder::Lossless)) | |
| 359 return false; | |
| 354 } else if (mimeType == "image/webp") { | 360 } else if (mimeType == "image/webp") { |
| 355 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; | 361 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
| 356 if (quality && *quality >= 0.0 && *quality <= 1.0) | 362 if (quality && *quality >= 0.0 && *quality <= 1.0) |
| 357 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | 363 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
| 358 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) | 364 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) |
| 359 return false; | 365 return false; |
| 360 } else { | 366 } else { |
| 361 if (!PNGImageEncoder::encode(source, encodedImage)) | 367 if (!PNGImageEncoder::encode(source, encodedImage)) |
| 362 return false; | 368 return false; |
| 363 ASSERT(mimeType == "image/png"); | 369 ASSERT(mimeType == "image/png"); |
| 364 } | 370 } |
| 365 | 371 |
| 366 return true; | 372 return true; |
| 367 } | 373 } |
| 368 | 374 |
| 369 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality) const | 375 String ImageDataBuffer::toDataURL(const String& mimeType, const double* quality) const |
| 370 { | 376 { |
| 371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 377 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 372 | 378 |
| 373 Vector<char> encodedImage; | 379 Vector<char> encodedImage; |
| 374 if (!encodeImage(*this, mimeType, quality, &encodedImage)) | 380 if (!encodeImage(*this, mimeType, quality, &encodedImage)) |
| 375 return "data:,"; | 381 return "data:,"; |
| 376 | 382 |
| 377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); | 383 // webplossless is an encoder selector: map it to the actual mimeType "image /webp". |
| 384 | |
|
acterhd
2015/08/27 17:18:19
I'm used ternary operator for replace mimes.
| |
| 385 String encodedImageMimeType = mimeType; | |
| 386 if (mimeType == "image/webplossless") | |
| 387 encodedImageMimeType = String("image/webp"); | |
| 388 | |
| 389 return "data:" + encodedImageMimeType + ";base64," + base64Encode(encodedIma ge); | |
| 378 } | 390 } |
| 379 | 391 |
| 380 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |