Changeset 54616 in webkit
- Timestamp:
- Feb 10, 2010 1:05:55 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r54615 r54616 1 2010-02-10 Adam Roben <aroben@apple.com> 2 3 Optimize ImageBuffer::toDataURL's CG implementation 4 5 There was some unused code that could have been removed in r31830 when 6 this function was changed not to flip the CG image anymore. 7 8 Fixes <http://webkit.org/b/34808> ImageBuffer::toDataURL allocates 9 unnecessary memory under CoreGraphics 10 11 Reviewed by Sam Weinig. 12 13 * platform/graphics/cg/ImageBufferCG.cpp: 14 (WebCore::ImageBuffer::toDataURL): Don't allocate an unused CGImageRef 15 and buffer, and switch to the new overload of base64Encode that 16 doesn't require us to copy all the image data into a Vector first. 17 18 * platform/text/Base64.cpp: 19 (WebCore::base64Encode): 20 * platform/text/Base64.h: 21 Added an overload that takes a raw data pointer and length, just like 22 we have for base64Decode. The overload that takes a Vector as input 23 just calls through to the new overload. 24 1 25 2010-02-10 Dan Bernstein <mitz@apple.com> 2 26 -
trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r47585 r54616 281 281 return "data:,"; 282 282 283 size_t width = CGImageGetWidth(image.get()); 284 size_t height = CGImageGetHeight(image.get()); 285 286 OwnArrayPtr<uint32_t> imageData(new uint32_t[width * height]); 287 if (!imageData) 283 RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); 284 if (!data) 288 285 return "data:,"; 289 290 RetainPtr<CGImage Ref> transformedImage(AdoptCF, CGBitmapContextCreateImage(context()->platformContext()));291 if (! transformedImage)286 287 RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), utiFromMIMEType(mimeType).get(), 1, 0)); 288 if (!destination) 292 289 return "data:,"; 293 290 294 RetainPtr<CFMutableDataRef> transformedImageData(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); 295 if (!transformedImageData) 296 return "data:,"; 297 298 RetainPtr<CGImageDestinationRef> imageDestination(AdoptCF, CGImageDestinationCreateWithData(transformedImageData.get(), 299 utiFromMIMEType(mimeType).get(), 1, 0)); 300 if (!imageDestination) 301 return "data:,"; 302 303 CGImageDestinationAddImage(imageDestination.get(), transformedImage.get(), 0); 304 CGImageDestinationFinalize(imageDestination.get()); 305 306 Vector<char> in; 307 in.append(CFDataGetBytePtr(transformedImageData.get()), CFDataGetLength(transformedImageData.get())); 291 CGImageDestinationAddImage(destination.get(), image.get(), 0); 292 CGImageDestinationFinalize(destination.get()); 308 293 309 294 Vector<char> out; 310 base64Encode( in, out);295 base64Encode(reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())), CFDataGetLength(data.get()), out); 311 296 out.append('\0'); 312 297 -
trunk/WebCore/platform/text/Base64.cpp
r42002 r54616 63 63 void base64Encode(const Vector<char>& in, Vector<char>& out, bool insertLFs) 64 64 { 65 base64Encode(in.data(), in.size(), out, insertLFs); 66 } 67 68 void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insertLFs) 69 { 65 70 out.clear(); 66 if ( in.isEmpty())71 if (!len) 67 72 return; 68 73 … … 71 76 // Rather than being perfectly precise, this is a bit conservative. 72 77 const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2; 73 if ( in.size()> maxInputBufferSize)78 if (len > maxInputBufferSize) 74 79 return; 75 80 76 81 unsigned sidx = 0; 77 82 unsigned didx = 0; 78 const char* data = in.data();79 const unsigned len = in.size();80 83 81 84 unsigned out_len = ((len + 2) / 3) * 4; -
trunk/WebCore/platform/text/Base64.h
r28234 r54616 32 32 33 33 void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false); 34 void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false); 34 35 35 36 // this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob
Note: See TracChangeset
for help on using the changeset viewer.