| 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 #include <memory> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 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 std::unique_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 // The MacOS implementation of this function is in image_utils_mac.mm. | 47 bool JPEG1xEncodedDataFromImage(const Image& image, int quality, |
| 48 #if !defined(OS_MACOSX) | |
| 49 bool JPEG1xEncodedDataFromImage(const Image& image, | |
| 50 int quality, | |
| 51 std::vector<unsigned char>* dst) { | 48 std::vector<unsigned char>* dst) { |
| 52 return JPEG1xEncodedDataFromSkiaRepresentation(image, quality, dst); | |
| 53 } | |
| 54 #endif // !defined(OS_MACOSX) | |
| 55 | |
| 56 bool JPEG1xEncodedDataFromSkiaRepresentation(const Image& image, | |
| 57 int quality, | |
| 58 std::vector<unsigned char>* dst) { | |
| 59 const gfx::ImageSkiaRep& image_skia_rep = | 49 const gfx::ImageSkiaRep& image_skia_rep = |
| 60 image.AsImageSkia().GetRepresentation(1.0f); | 50 image.AsImageSkia().GetRepresentation(1.0f); |
| 61 if (image_skia_rep.scale() != 1.0f) | 51 if (image_skia_rep.scale() != 1.0f) |
| 62 return false; | 52 return false; |
| 63 | 53 |
| 64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); | 54 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); |
| 65 SkAutoLockPixels bitmap_lock(bitmap); | 55 SkAutoLockPixels bitmap_lock(bitmap); |
| 66 | 56 |
| 67 if (!bitmap.readyToDraw()) | 57 if (!bitmap.readyToDraw()) |
| 68 return false; | 58 return false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // 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 |
| 106 // rechecking that column; hence the '>' here. | 96 // rechecking that column; hence the '>' here. |
| 107 for (x = bitmap.width() - 1; x > *left; --x) { | 97 for (x = bitmap.width() - 1; x > *left; --x) { |
| 108 if (ColumnHasVisiblePixels(bitmap, x)) | 98 if (ColumnHasVisiblePixels(bitmap, x)) |
| 109 break; | 99 break; |
| 110 } | 100 } |
| 111 *right = bitmap.width() - 1 - x; | 101 *right = bitmap.width() - 1 - x; |
| 112 } | 102 } |
| 113 | 103 |
| 114 } // namespace gfx | 104 } // namespace gfx |
| OLD | NEW |