Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 return 1; | 46 return 1; |
| 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 Vector<unsigned char> rgb; | |
| 57 size_t pixelCount = picture->height * picture->width; | 56 size_t pixelCount = picture->height * picture->width; |
| 58 rgb.reserveInitialCapacity(pixelCount * 3); | 57 Vector<unsigned char> rgb(pixelCount * 3); |
| 59 | 58 |
|
Noel Gordon
2015/07/21 00:48:36
Overall patch seems fine, but just to confirm, the
| |
| 60 for (unsigned char* data = rgb.data(); pixelCount-- > 0; pixels += 4) { | 59 for (unsigned char* data = rgb.data(); pixelCount-- > 0; pixels += 4) { |
| 61 unsigned char alpha = pixels[3]; | 60 unsigned char alpha = pixels[3]; |
| 62 if (alpha != 255) { | 61 if (alpha != 255) { |
| 63 *data++ = SkMulDiv255Round(pixels[0], alpha); | 62 *data++ = SkMulDiv255Round(pixels[0], alpha); |
| 64 *data++ = SkMulDiv255Round(pixels[1], alpha); | 63 *data++ = SkMulDiv255Round(pixels[1], alpha); |
| 65 *data++ = SkMulDiv255Round(pixels[2], alpha); | 64 *data++ = SkMulDiv255Round(pixels[2], alpha); |
| 66 } else { | 65 } else { |
| 67 *data++ = pixels[0]; | 66 *data++ = pixels[0]; |
| 68 *data++ = pixels[1]; | 67 *data++ = pixels[1]; |
| 69 *data++ = pixels[2]; | 68 *data++ = pixels[2]; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 134 |
| 136 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) | 135 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) |
| 137 { | 136 { |
| 138 if (!imageData.pixels()) | 137 if (!imageData.pixels()) |
| 139 return false; | 138 return false; |
| 140 | 139 |
| 141 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output); | 140 return encodePixels(IntSize(imageData.width(), imageData.height()), imageDat a.pixels(), false, quality, output); |
| 142 } | 141 } |
| 143 | 142 |
| 144 } // namespace blink | 143 } // namespace blink |
| OLD | NEW |