Chromium Code Reviews| Index: ui/gfx/image/image_util.cc |
| diff --git a/ui/gfx/image/image_util.cc b/ui/gfx/image/image_util.cc |
| index 59d631d171df572b7912e4119a2df1966b74798f..7f8ac1c85dad5a151867ae95668a81f282f0d94b 100644 |
| --- a/ui/gfx/image/image_util.cc |
| +++ b/ui/gfx/image/image_util.cc |
| @@ -24,7 +24,7 @@ Image ImageFrom1xJPEGEncodedData(const unsigned char* input, |
| } |
| bool JPEG1xEncodedDataFromImage(const Image& image, int quality, |
| - std::vector<unsigned char>* dst) { |
| + std::vector<unsigned char>* dst) { |
| const gfx::ImageSkiaRep& image_skia_rep = |
| image.AsImageSkia().GetRepresentation(1.0f); |
| if (image_skia_rep.scale() != 1.0f) |
| @@ -45,4 +45,57 @@ bool JPEG1xEncodedDataFromImage(const Image& image, int quality, |
| } |
| #endif // !defined(OS_IOS) |
| +bool VisibleMargins(const ImageSkia& image, int* leading, int* trailing) { |
| + *leading = 0; |
| + *trailing = std::max(1, image.width()) - 1; |
| + if (!image.HasRepresentation(1.0)) |
| + return false; |
| + |
| + const ImageSkiaRep& rep = image.GetRepresentation(1.0); |
| + if (rep.is_null()) |
| + return false; |
| + |
| + const SkBitmap& bitmap = rep.sk_bitmap(); |
| + if (bitmap.isNull() || bitmap.width() == 0) |
| + return false; |
| + |
| + if (bitmap.isOpaque()) |
| + return true; |
| + |
| + SkAutoLockPixels l(bitmap); |
| + int innerMin = bitmap.width(); |
|
Robert Sesek
2014/01/30 20:41:38
naming: Use under_scores, not camelCase. Here and
Greg Billock
2014/01/30 23:39:19
Done.
|
| + for (int x = 0; x < bitmap.width(); ++x) { |
| + for (int y = 0; y < bitmap.height(); ++y) { |
| + if (SkColorGetA(bitmap.getColor(x, y)) > 12) { |
| + innerMin = x; |
| + break; |
| + } |
| + } |
| + if (innerMin < bitmap.width()) |
| + break; |
| + } |
| + |
| + int innerMax = -1; |
| + for (int x = bitmap.width() - 1; x > innerMin; --x) { |
| + for (int y = 0; y < bitmap.height(); ++y) { |
| + if (SkColorGetA(bitmap.getColor(x, y)) > 12) { |
| + innerMax = x; |
| + break; |
| + } |
| + } |
| + if (innerMax > -1) |
| + break; |
| + } |
| + |
| + if (innerMin == bitmap.width()) { |
| + *leading = bitmap.width()/2; |
| + *trailing = bitmap.width()/2 + 1; |
| + return true; |
| + } |
| + |
| + *leading = innerMin; |
| + *trailing = innerMax; |
| + return true; |
| } |
| + |
| +} // namespace gfx |