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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return false; | 93 return false; |
| 94 | 94 |
| 95 imageSize.clampNegativeToZero(); | 95 imageSize.clampNegativeToZero(); |
| 96 if (!imageSize.width() || imageSize.width() > WEBP_MAX_DIMENSION) | 96 if (!imageSize.width() || imageSize.width() > WEBP_MAX_DIMENSION) |
| 97 return false; | 97 return false; |
| 98 picture.width = imageSize.width(); | 98 picture.width = imageSize.width(); |
| 99 if (!imageSize.height() || imageSize.height() > WEBP_MAX_DIMENSION) | 99 if (!imageSize.height() || imageSize.height() > WEBP_MAX_DIMENSION) |
| 100 return false; | 100 return false; |
| 101 picture.height = imageSize.height(); | 101 picture.height = imageSize.height(); |
| 102 | 102 |
| 103 #if SK_B32_SHIFT // Little-endian RGBA pixels. (Android) | |
| 104 if (premultiplied && !importPictureRGBX<true>(pixels, &picture)) | |
| 105 return false; | |
| 106 #else | |
| 103 if (premultiplied && !importPictureBGRX<true>(pixels, &picture)) | 107 if (premultiplied && !importPictureBGRX<true>(pixels, &picture)) |
| 104 return false; | 108 return false; |
| 109 #endif | |
| 105 if (!premultiplied && !importPictureRGBX<false>(pixels, &picture)) | 110 if (!premultiplied && !importPictureRGBX<false>(pixels, &picture)) |
|
skal
2014/10/11 13:53:53
the logic is hard to follow as written. Would be b
| |
| 106 return false; | 111 return false; |
| 107 | 112 |
| 108 picture.custom_ptr = output; | 113 picture.custom_ptr = output; |
| 109 picture.writer = &writeOutput; | 114 picture.writer = &writeOutput; |
| 110 config.quality = quality; | 115 config.quality = quality; |
| 111 config.method = 3; | 116 config.method = 3; |
| 112 | 117 |
| 113 bool success = WebPEncode(&config, &picture); | 118 bool success = WebPEncode(&config, &picture); |
| 114 WebPPictureFree(&picture); | 119 WebPPictureFree(&picture); |
| 115 return success; | 120 return success; |
| 116 } | 121 } |
| 117 | 122 |
| 118 bool WEBPImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign ed char>* output) | 123 bool WEBPImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector<unsign ed char>* output) |
| 119 { | 124 { |
| 120 SkAutoLockPixels bitmapLock(bitmap); | 125 SkAutoLockPixels bitmapLock(bitmap); |
| 121 | 126 |
| 122 if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels()) | 127 if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels()) |
| 123 return false; // Only support 32 bit/pixel skia bitmaps. | 128 return false; // Only support 32 bit/pixel skia bitmaps. |
| 124 | 129 |
| 125 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un signed char *>(bitmap.getPixels()), true, quality, output); | 130 return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast<un signed char *>(bitmap.getPixels()), true, quality, output); |
| 126 } | 131 } |
| 127 | 132 |
| 128 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) | 133 bool WEBPImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vec tor<unsigned char>* output) |
| 129 { | 134 { |
| 130 return encodePixels(imageData.size(), imageData.data(), false, quality, outp ut); | 135 return encodePixels(imageData.size(), imageData.data(), false, quality, outp ut); |
| 131 } | 136 } |
| 132 | 137 |
| 133 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |