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

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

Issue 1285533002: [WEBPImageEncoder] Use local buffer allocation instead of WTF::Vector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
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 size_t pixelCount = picture->height * picture->width; 56 size_t pixelCount = picture->height * picture->width;
57 Vector<unsigned char> rgb(pixelCount * 3);
58 57
59 for (unsigned char* data = rgb.data(); pixelCount-- > 0; pixels += 4) { 58 OwnPtr<unsigned char[]> rgb = adoptArrayPtr(new unsigned char[pixelCount * 3 ]);
59 if (!rgb.get())
60 return false;
61
62 for (unsigned char* data = rgb.get(); pixelCount-- > 0; pixels += 4) {
60 unsigned char alpha = pixels[3]; 63 unsigned char alpha = pixels[3];
61 if (alpha != 255) { 64 if (alpha != 255) {
62 *data++ = SkMulDiv255Round(pixels[0], alpha); 65 *data++ = SkMulDiv255Round(pixels[0], alpha);
63 *data++ = SkMulDiv255Round(pixels[1], alpha); 66 *data++ = SkMulDiv255Round(pixels[1], alpha);
64 *data++ = SkMulDiv255Round(pixels[2], alpha); 67 *data++ = SkMulDiv255Round(pixels[2], alpha);
65 } else { 68 } else {
66 *data++ = pixels[0]; 69 *data++ = pixels[0];
67 *data++ = pixels[1]; 70 *data++ = pixels[1];
68 *data++ = pixels[2]; 71 *data++ = pixels[2];
69 } 72 }
70 } 73 }
71 74
72 return importRGB(picture, rgb.data(), picture->width * 3); 75 return importRGB(picture, rgb.get(), picture->width * 3);
73 } 76 }
74 77
75 template <bool Premultiplied> inline bool importPictureBGRX(const unsigned char* pixels, WebPPicture* picture) 78 template <bool Premultiplied> inline bool importPictureBGRX(const unsigned char* pixels, WebPPicture* picture)
76 { 79 {
77 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportBGRX, &WebP PictureImportBGR, picture); 80 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportBGRX, &WebP PictureImportBGR, picture);
78 } 81 }
79 82
80 template <bool Premultiplied> inline bool importPictureRGBX(const unsigned char* pixels, WebPPicture* picture) 83 template <bool Premultiplied> inline bool importPictureRGBX(const unsigned char* pixels, WebPPicture* picture)
81 { 84 {
82 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportRGBX, &WebP PictureImportRGB, picture); 85 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportRGBX, &WebP PictureImportRGB, picture);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 137
135 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) 138 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output)
136 { 139 {
137 if (!imageData.pixels()) 140 if (!imageData.pixels())
138 return false; 141 return false;
139 142
140 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output); 143 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output);
141 } 144 }
142 145
143 } // namespace blink 146 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698