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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | 389 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
390 if (!JPEGImageEncoder::encode(source, compressionQuality, encodedImage)) | 390 if (!JPEGImageEncoder::encode(source, compressionQuality, encodedImage)) |
391 return false; | 391 return false; |
392 } else if (mimeType == "image/webp") { | 392 } else if (mimeType == "image/webp") { |
393 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; | 393 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
394 if (quality && *quality >= 0.0 && *quality <= 1.0) | 394 if (quality && *quality >= 0.0 && *quality <= 1.0) |
395 compressionQuality = static_cast<int>(*quality * 100 + 0.5); | 395 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
396 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) | 396 if (!WEBPImageEncoder::encode(source, compressionQuality, encodedImage)) |
397 return false; | 397 return false; |
398 } else { | 398 } else { |
399 if (!PNGImageEncoder::encode(source, encodedImage)) | 399 int compressionQuality = PNGImageEncoder::DefaultCompressionQuality; |
| 400 if (quality && *quality >= 0.0 && *quality <= 1.0) |
| 401 compressionQuality = static_cast<int>(*quality * 100 + 0.5); |
| 402 if (!PNGImageEncoder::encode(source, compressionQuality, encodedImage)) |
400 return false; | 403 return false; |
401 ASSERT(mimeType == "image/png"); | 404 ASSERT(mimeType == "image/png"); |
402 } | 405 } |
403 | 406 |
404 return true; | 407 return true; |
405 } | 408 } |
406 | 409 |
407 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
st | 410 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con
st |
408 { | 411 { |
409 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 412 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
410 | 413 |
411 Vector<char> encodedImage; | 414 Vector<char> encodedImage; |
412 if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality
, &encodedImage)) | 415 if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality
, &encodedImage)) |
413 return "data:,"; | 416 return "data:,"; |
| 417 |
414 Vector<char> base64Data; | 418 Vector<char> base64Data; |
415 base64Encode(encodedImage, base64Data); | 419 base64Encode(encodedImage, base64Data); |
416 | 420 |
417 return "data:" + mimeType + ";base64," + base64Data; | 421 return "data:" + mimeType + ";base64," + base64Data; |
418 } | 422 } |
419 | 423 |
420 String ImageDataToDataURL(const ImageDataBuffer& imageData, const String& mimeTy
pe, const double* quality) | 424 String ImageDataToDataURL(const ImageDataBuffer& imageData, const String& mimeTy
pe, const double* quality) |
421 { | 425 { |
422 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 426 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
423 | 427 |
424 Vector<char> encodedImage; | 428 Vector<char> encodedImage; |
425 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 429 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
426 return "data:,"; | 430 return "data:,"; |
427 | 431 |
428 Vector<char> base64Data; | 432 Vector<char> base64Data; |
429 base64Encode(encodedImage, base64Data); | 433 base64Encode(encodedImage, base64Data); |
430 | 434 |
431 return "data:" + mimeType + ";base64," + base64Data; | 435 return "data:" + mimeType + ";base64," + base64Data; |
432 } | 436 } |
433 | 437 |
434 } // namespace WebCore | 438 } // namespace WebCore |
OLD | NEW |