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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 std::vector<unsigned char>* dst) { | 58 std::vector<unsigned char>* dst) { |
59 const gfx::ImageSkiaRep& image_skia_rep = | 59 const gfx::ImageSkiaRep& image_skia_rep = |
60 image.AsImageSkia().GetRepresentation(1.0f); | 60 image.AsImageSkia().GetRepresentation(1.0f); |
61 if (image_skia_rep.scale() != 1.0f) | 61 if (image_skia_rep.scale() != 1.0f) |
62 return false; | 62 return false; |
63 | 63 |
64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); | 64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); |
65 if (!bitmap.readyToDraw()) | 65 if (!bitmap.readyToDraw()) |
66 return false; | 66 return false; |
67 | 67 |
68 return gfx::JPEGCodec::Encode( | 68 return gfx::JPEGCodec::Encode(bitmap, quality, dst); |
69 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | |
70 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), | |
71 bitmap.height(), | |
72 static_cast<int>(bitmap.rowBytes()), quality, | |
73 dst); | |
74 } | 69 } |
75 #endif // !defined(OS_IOS) | 70 #endif // !defined(OS_IOS) |
76 | 71 |
77 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) { | 72 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) { |
78 *left = 0; | 73 *left = 0; |
79 *right = 0; | 74 *right = 0; |
80 if (!image.HasRepresentation(1.f)) | 75 if (!image.HasRepresentation(1.f)) |
81 return; | 76 return; |
82 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap(); | 77 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap(); |
83 if (bitmap.drawsNothing() || bitmap.isOpaque()) | 78 if (bitmap.drawsNothing() || bitmap.isOpaque()) |
(...skipping 18 matching lines...) Expand all Loading... |
102 // Since we already know column *left is non-transparent, we can avoid | 97 // Since we already know column *left is non-transparent, we can avoid |
103 // rechecking that column; hence the '>' here. | 98 // rechecking that column; hence the '>' here. |
104 for (x = bitmap.width() - 1; x > *left; --x) { | 99 for (x = bitmap.width() - 1; x > *left; --x) { |
105 if (ColumnHasVisiblePixels(bitmap, x)) | 100 if (ColumnHasVisiblePixels(bitmap, x)) |
106 break; | 101 break; |
107 } | 102 } |
108 *right = bitmap.width() - 1 - x; | 103 *right = bitmap.width() - 1 - x; |
109 } | 104 } |
110 | 105 |
111 } // namespace gfx | 106 } // namespace gfx |
OLD | NEW |