| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/image/image_util.h" | 5 #include "ui/gfx/image/image_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
| 10 | 11 |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "ui/gfx/codec/jpeg_codec.h" | 14 #include "ui/gfx/codec/jpeg_codec.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Returns whether column |x| of |bitmap| has any "visible pixels", where | 20 // Returns whether column |x| of |bitmap| has any "visible pixels", where |
| 21 // "visible" is defined as having an opactiy greater than an arbitrary small | 21 // "visible" is defined as having an opactiy greater than an arbitrary small |
| 22 // value. | 22 // value. |
| 23 bool ColumnHasVisiblePixels(const SkBitmap& bitmap, int x) { | 23 bool ColumnHasVisiblePixels(const SkBitmap& bitmap, int x) { |
| 24 const SkAlpha kMinimumVisibleOpacity = 12; | 24 const SkAlpha kMinimumVisibleOpacity = 12; |
| 25 for (int y = 0; y < bitmap.height(); ++y) { | 25 for (int y = 0; y < bitmap.height(); ++y) { |
| 26 if (SkColorGetA(bitmap.getColor(x, y)) > kMinimumVisibleOpacity) | 26 if (SkColorGetA(bitmap.getColor(x, y)) > kMinimumVisibleOpacity) |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 namespace gfx { | 34 namespace gfx { |
| 35 | 35 |
| 36 // The iOS implementations of the JPEG functions are in image_util_ios.mm. | 36 // The iOS implementations of the JPEG functions are in image_util_ios.mm. |
| 37 #if !defined(OS_IOS) | 37 #if !defined(OS_IOS) |
| 38 Image ImageFrom1xJPEGEncodedData(const unsigned char* input, | 38 Image ImageFrom1xJPEGEncodedData(const unsigned char* input, |
| 39 size_t input_size) { | 39 size_t input_size) { |
| 40 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); | 40 std::unique_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); |
| 41 if (bitmap.get()) | 41 if (bitmap.get()) |
| 42 return Image::CreateFrom1xBitmap(*bitmap); | 42 return Image::CreateFrom1xBitmap(*bitmap); |
| 43 | 43 |
| 44 return Image(); | 44 return Image(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool JPEG1xEncodedDataFromImage(const Image& image, int quality, | 47 bool JPEG1xEncodedDataFromImage(const Image& image, int quality, |
| 48 std::vector<unsigned char>* dst) { | 48 std::vector<unsigned char>* dst) { |
| 49 const gfx::ImageSkiaRep& image_skia_rep = | 49 const gfx::ImageSkiaRep& image_skia_rep = |
| 50 image.AsImageSkia().GetRepresentation(1.0f); | 50 image.AsImageSkia().GetRepresentation(1.0f); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Since we already know column *left is non-transparent, we can avoid | 95 // Since we already know column *left is non-transparent, we can avoid |
| 96 // rechecking that column; hence the '>' here. | 96 // rechecking that column; hence the '>' here. |
| 97 for (x = bitmap.width() - 1; x > *left; --x) { | 97 for (x = bitmap.width() - 1; x > *left; --x) { |
| 98 if (ColumnHasVisiblePixels(bitmap, x)) | 98 if (ColumnHasVisiblePixels(bitmap, x)) |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 *right = bitmap.width() - 1 - x; | 101 *right = bitmap.width() - 1 - x; |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace gfx | 104 } // namespace gfx |
| OLD | NEW |