Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: Source/platform/image-encoders/skia/WEBPImageEncoder.cpp

Issue 1234083003: Canvas.toDataURL to use SkBitmap::readPixels to avoid uninitialized memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed asan error in webp encoder Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/graphics/ImageBuffer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011, Google Inc. All rights reserved. 2 * Copyright (c) 2011, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 static bool rgbPictureImport(const unsigned char* pixels, bool premultiplied, We bPImporter importRGBX, WebPImporter importRGB, WebPPicture* picture) 49 static bool rgbPictureImport(const unsigned char* pixels, bool premultiplied, We bPImporter importRGBX, WebPImporter importRGB, WebPPicture* picture)
50 { 50 {
51 if (premultiplied) 51 if (premultiplied)
52 return importRGBX(picture, pixels, picture->width * 4); 52 return importRGBX(picture, pixels, picture->width * 4);
53 53
54 // Write the RGB pixels to an rgb data buffer, alpha premultiplied, then imp ort the rgb data. 54 // Write the RGB pixels to an rgb data buffer, alpha premultiplied, then imp ort the rgb data.
55 55
56 Vector<unsigned char> rgb; 56 Vector<unsigned char> rgb;
57 size_t pixelCount = picture->height * picture->width; 57 size_t pixelCount = picture->height * picture->width;
58 rgb.reserveInitialCapacity(pixelCount * 3); 58 rgb.reserveInitialCapacity(pixelCount * 3);
59 rgb.resize(pixelCount * 3);
Stephen White 2015/07/20 15:33:10 As discussed, could be cleaner to just put the siz
59 60
60 for (unsigned char* data = rgb.data(); pixelCount-- > 0; pixels += 4) { 61 for (unsigned char* data = rgb.data(); pixelCount-- > 0; pixels += 4) {
61 unsigned char alpha = pixels[3]; 62 unsigned char alpha = pixels[3];
62 if (alpha != 255) { 63 if (alpha != 255) {
63 *data++ = SkMulDiv255Round(pixels[0], alpha); 64 *data++ = SkMulDiv255Round(pixels[0], alpha);
64 *data++ = SkMulDiv255Round(pixels[1], alpha); 65 *data++ = SkMulDiv255Round(pixels[1], alpha);
65 *data++ = SkMulDiv255Round(pixels[2], alpha); 66 *data++ = SkMulDiv255Round(pixels[2], alpha);
66 } else { 67 } else {
67 *data++ = pixels[0]; 68 *data++ = pixels[0];
68 *data++ = pixels[1]; 69 *data++ = pixels[1];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) 137 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output)
137 { 138 {
138 if (!imageData.pixels()) 139 if (!imageData.pixels())
139 return false; 140 return false;
140 141
141 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output); 142 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output);
142 } 143 }
143 144
144 } // namespace blink 145 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698