Changeset 73173 in webkit
- Timestamp:
- Dec 2, 2010 11:42:52 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r73171 r73173 1 2010-12-02 Noel Gordon <noel.gordon@gmail.com> 2 3 Reviewed by David Levin. 4 5 [chromium] Add canvas.toDataURL("image/jpeg", quality) support 6 https://bugs.webkit.org/show_bug.cgi?id=49365 7 8 Chromium window/linux layout try results now match the default test result, so 9 remove this platform-specific test exception file. 10 11 * platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt: Removed. 12 1 13 2010-12-02 Sheriff Bot <webkit.review.bot@gmail.com> 2 14 -
trunk/WebCore/ChangeLog
r73171 r73173 1 2010-12-02 Noel Gordon <noel.gordon@gmail.com> 2 3 Reviewed by David Levin. 4 5 [chromium] Add canvas.toDataURL("image/jpeg", quality) support 6 https://bugs.webkit.org/show_bug.cgi?id=49365 7 8 Adds a libjpeg-based image encoder for Skia bitmaps. Default encoding quality 9 is 92 to match Mozilla, also Safari, though the actual value used by Safari is 10 undocumented, and it appears to pre-blur images prior to compression. 11 12 The preMultipliedBGRAtoRGB() routine restores the un-premultiplied RGB colors 13 where there is non-zero alpha. Again, this matches Firefox and Safari, but no 14 browser conforms to the HTML5 canvas standard here, I believe, considering the 15 result of canvas/philip/tests/toDataURL.jpeg.alpha.html; that test ignores the 16 alpha channel when extracting an "image/jpeg".toDataURL(). The correct answer 17 needs more investigation, bug http://webkit.org/b/40147. 18 19 Canvas toDataURL is covered by existing tests canvas/philip/tests/toDataURL.*, 20 and fast/canvas/*toDataURL* tests. 21 22 * WebCore.gypi: 23 * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: 24 (WebCore::V8HTMLCanvasElement::toDataURLCallback): don't set encoding quality 25 here, just pass the toDataURL parameters through to the canvas layer. 26 * platform/chromium/MIMETypeRegistryChromium.cpp: 27 (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding): implement 28 the supported mimeTypes for encoding in-place. 29 * platform/graphics/skia/ImageBufferSkia.cpp: 30 (WebCore::ImageBuffer::toDataURL): add jpeg encoding and quality support. 31 * platform/image-encoders/skia/JPEGImageEncoder.cpp: Added. 32 (WebCore::prepareOutput): 33 (WebCore::writeOutput): 34 (WebCore::finishOutput): 35 (WebCore::handleError): 36 (WebCore::preMultipliedBGRAtoRGB): FIXME: bug 40147. 37 (WebCore::JPEGImageEncoder::encode): 38 * platform/image-encoders/skia/JPEGImageEncoder.h: Added. 39 1 40 2010-12-02 Sheriff Bot <webkit.review.bot@gmail.com> 2 41 -
trunk/WebCore/WebCore.gypi
r73121 r73173 2938 2938 'platform/image-decoders/zlib/zlib.h', 2939 2939 'platform/image-decoders/zlib/zutil.h', 2940 'platform/image-encoders/skia/JPEGImageEncoder.cpp', 2941 'platform/image-encoders/skia/JPEGImageEncoder.h', 2940 2942 'platform/image-encoders/skia/PNGImageEncoder.cpp', 2941 2943 'platform/image-encoders/skia/PNGImageEncoder.h', -
trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
r60675 r73173 95 95 v8::Handle<v8::Value> V8HTMLCanvasElement::toDataURLCallback(const v8::Arguments& args) 96 96 { 97 double quality = 1.0;98 if (args.Length() > 1) {99 if (args[1]->IsNumber())100 quality = args[1]->NumberValue();101 if (!(0.0 <= quality && quality <= 1.0))102 quality = 1.0;103 }104 97 v8::Handle<v8::Object> holder = args.Holder(); 105 98 HTMLCanvasElement* canvas = V8HTMLCanvasElement::toNative(holder); 99 ExceptionCode ec = 0; 100 106 101 String type = toWebCoreString(args[0]); 107 ExceptionCode ec = 0; 108 String result = canvas->toDataURL(type, &quality, ec); 102 double quality; 103 double* qualityPtr = 0; 104 if (args.Length() > 1 && args[1]->IsNumber()) { 105 quality = args[1]->NumberValue(); 106 qualityPtr = &quality; 107 } 108 109 String result = canvas->toDataURL(type, qualityPtr, ec); 109 110 V8Proxy::setDOMException(ec); 110 111 return v8StringOrUndefined(result); -
trunk/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp
r56825 r73173 92 92 bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType) 93 93 { 94 // FIXME: Fill this out. See: http://trac.webkit.org/changeset/30888 95 return isSupportedImageMIMEType(mimeType); 94 return mimeType == "image/jpeg" || mimeType == "image/png"; 96 95 } 97 96 -
trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
r72374 r73173 41 41 #include "GraphicsContext.h" 42 42 #include "ImageData.h" 43 #include "JPEGImageEncoder.h" 44 #include "MIMETypeRegistry.h" 43 45 #include "PNGImageEncoder.h" 44 46 #include "PlatformContextSkia.h" … … 319 321 } 320 322 321 String ImageBuffer::toDataURL(const String&, const double*) const 322 { 323 // Encode the image into a vector. 324 Vector<unsigned char> pngEncodedData; 325 PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &pngEncodedData); 326 327 // Convert it into base64. 328 Vector<char> base64EncodedData; 329 base64Encode(*reinterpret_cast<Vector<char>*>(&pngEncodedData), base64EncodedData); 330 // Append with a \0 so that it's a valid string. 331 base64EncodedData.append('\0'); 332 333 // And the resulting string. 334 return makeString("data:image/png;base64,", base64EncodedData.data()); 323 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const 324 { 325 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 326 327 Vector<unsigned char> encodedImage; 328 if (mimeType == "image/jpeg") { 329 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; 330 if (quality && *quality >= 0.0 && *quality <= 1.0) 331 compressionQuality = static_cast<int>(*quality * 100 + 0.5); 332 if (!JPEGImageEncoder::encode(*context()->platformContext()->bitmap(), compressionQuality, &encodedImage)) 333 return "data:,"; 334 } else { 335 if (!PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &encodedImage)) 336 return "data:,"; 337 ASSERT(mimeType == "image/png"); 338 } 339 340 Vector<char> base64Data; 341 base64Encode(*reinterpret_cast<Vector<char>*>(&encodedImage), base64Data); 342 base64Data.append('\0'); 343 344 return makeString("data:", mimeType, ";base64,", base64Data.data()); 335 345 } 336 346
Note: See TracChangeset
for help on using the changeset viewer.