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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 template <bool Premultiplied> inline bool importPictureBGRX(const unsigned char*
pixels, WebPPicture* picture) | 76 template <bool Premultiplied> inline bool importPictureBGRX(const unsigned char*
pixels, WebPPicture* picture) |
77 { | 77 { |
78 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportBGRX, &WebP
PictureImportBGR, picture); | 78 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportBGRX, &WebP
PictureImportBGR, picture); |
79 } | 79 } |
80 | 80 |
81 template <bool Premultiplied> inline bool importPictureRGBX(const unsigned char*
pixels, WebPPicture* picture) | 81 template <bool Premultiplied> inline bool importPictureRGBX(const unsigned char*
pixels, WebPPicture* picture) |
82 { | 82 { |
83 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportRGBX, &WebP
PictureImportRGB, picture); | 83 return rgbPictureImport(pixels, Premultiplied, &WebPPictureImportRGBX, &WebP
PictureImportRGB, picture); |
84 } | 84 } |
85 | 85 |
| 86 static bool platformPremultipliedImportPicture(const unsigned char* pixels, WebP
Picture* picture) |
| 87 { |
| 88 if (SK_B32_SHIFT) // Android |
| 89 return importPictureRGBX<true>(pixels, picture); |
| 90 |
| 91 return importPictureBGRX<true>(pixels, picture); |
| 92 } |
| 93 |
86 static bool encodePixels(IntSize imageSize, const unsigned char* pixels, bool pr
emultiplied, int quality, Vector<unsigned char>* output) | 94 static bool encodePixels(IntSize imageSize, const unsigned char* pixels, bool pr
emultiplied, int quality, Vector<unsigned char>* output) |
87 { | 95 { |
88 WebPConfig config; | 96 WebPConfig config; |
89 if (!WebPConfigInit(&config)) | 97 if (!WebPConfigInit(&config)) |
90 return false; | 98 return false; |
91 WebPPicture picture; | 99 WebPPicture picture; |
92 if (!WebPPictureInit(&picture)) | 100 if (!WebPPictureInit(&picture)) |
93 return false; | 101 return false; |
94 | 102 |
95 imageSize.clampNegativeToZero(); | 103 imageSize.clampNegativeToZero(); |
96 if (!imageSize.width() || imageSize.width() > WEBP_MAX_DIMENSION) | 104 if (!imageSize.width() || imageSize.width() > WEBP_MAX_DIMENSION) |
97 return false; | 105 return false; |
98 picture.width = imageSize.width(); | 106 picture.width = imageSize.width(); |
99 if (!imageSize.height() || imageSize.height() > WEBP_MAX_DIMENSION) | 107 if (!imageSize.height() || imageSize.height() > WEBP_MAX_DIMENSION) |
100 return false; | 108 return false; |
101 picture.height = imageSize.height(); | 109 picture.height = imageSize.height(); |
102 | 110 |
103 if (premultiplied && !importPictureBGRX<true>(pixels, &picture)) | 111 if (premultiplied && !platformPremultipliedImportPicture(pixels, &picture)) |
104 return false; | 112 return false; |
105 if (!premultiplied && !importPictureRGBX<false>(pixels, &picture)) | 113 if (!premultiplied && !importPictureRGBX<false>(pixels, &picture)) |
106 return false; | 114 return false; |
107 | 115 |
108 picture.custom_ptr = output; | 116 picture.custom_ptr = output; |
109 picture.writer = &writeOutput; | 117 picture.writer = &writeOutput; |
110 config.quality = quality; | 118 config.quality = quality; |
111 config.method = 3; | 119 config.method = 3; |
112 | 120 |
113 bool success = WebPEncode(&config, &picture); | 121 bool success = WebPEncode(&config, &picture); |
(...skipping 10 matching lines...) Expand all Loading... |
124 | 132 |
125 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un
signed char *>(bitmap.getPixels()), true, quality, output); | 133 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un
signed char *>(bitmap.getPixels()), true, quality, output); |
126 } | 134 } |
127 | 135 |
128 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec
tor<unsigned char>* output) | 136 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec
tor<unsigned char>* output) |
129 { | 137 { |
130 return encodePixels(imageData.size(), imageData.data(), false, quality, outp
ut); | 138 return encodePixels(imageData.size(), imageData.data(), false, quality, outp
ut); |
131 } | 139 } |
132 | 140 |
133 } // namespace blink | 141 } // namespace blink |
OLD | NEW |