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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 return false; | 406 return false; |
407 } else { | 407 } else { |
408 if (!PNGImageEncoder::encode(source, encodedImage)) | 408 if (!PNGImageEncoder::encode(source, encodedImage)) |
409 return false; | 409 return false; |
410 ASSERT(mimeType == "image/png"); | 410 ASSERT(mimeType == "image/png"); |
411 } | 411 } |
412 | 412 |
413 return true; | 413 return true; |
414 } | 414 } |
415 | 415 |
416 static String EncodedImageToDataURL(const Vector<char>& encodedImage, const Stri ng& mimeType) | |
417 { | |
418 String base64Data = base64Encode(encodedImage); | |
419 return "data:" + mimeType + ";base64," + base64Data; | |
420 } | |
421 | |
416 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con st | 422 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con st |
417 { | 423 { |
418 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 424 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
419 | 425 |
420 Vector<char> encodedImage; | 426 Vector<char> encodedImage; |
421 if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality , &encodedImage)) | 427 if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality , &encodedImage)) |
422 return "data:,"; | 428 return "data:,"; |
423 Vector<char> base64Data; | 429 return EncodedImageToDataURL(encodedImage, mimeType); |
Noel Gordon
2014/09/11 01:03:23
/curious would writing this as
return "data:"
Daniel Bratell
2014/09/11 11:22:31
It would work the same. I put it in a separate met
| |
424 base64Encode(encodedImage, base64Data); | |
425 | |
426 return "data:" + mimeType + ";base64," + base64Data; | |
427 } | 430 } |
428 | 431 |
429 String ImageDataToDataURL(const ImageDataBuffer& imageData, const String& mimeTy pe, const double* quality) | 432 String ImageDataToDataURL(const ImageDataBuffer& imageData, const String& mimeTy pe, const double* quality) |
430 { | 433 { |
431 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 434 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
432 | 435 |
433 Vector<char> encodedImage; | 436 Vector<char> encodedImage; |
434 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 437 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
435 return "data:,"; | 438 return "data:,"; |
436 | 439 return EncodedImageToDataURL(encodedImage, mimeType); |
437 Vector<char> base64Data; | |
438 base64Encode(encodedImage, base64Data); | |
439 | |
440 return "data:" + mimeType + ";base64," + base64Data; | |
441 } | 440 } |
442 | 441 |
443 } // namespace blink | 442 } // namespace blink |
OLD | NEW |