| 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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/gfx/codec/jpeg_codec.h" | 9 #include "ui/gfx/codec/jpeg_codec.h" |
| 10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| 11 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 // The iOS implementations of the JPEG functions are in image_util_ios.mm. | 15 // The iOS implementations of the JPEG functions are in image_util_ios.mm. |
| 16 #if !defined(OS_IOS) | 16 #if !defined(OS_IOS) |
| 17 Image ImageFrom1xJPEGEncodedData(const unsigned char* input, | 17 Image ImageFrom1xJPEGEncodedData(const unsigned char* input, |
| 18 size_t input_size) { | 18 size_t input_size) { |
| 19 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); | 19 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(input, input_size)); |
| 20 if (bitmap.get()) | 20 if (bitmap.get()) |
| 21 return Image::CreateFrom1xBitmap(*bitmap); | 21 return Image::CreateFrom1xBitmap(*bitmap); |
| 22 | 22 |
| 23 return Image(); | 23 return Image(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool JPEG1xEncodedDataFromImage(const Image& image, int quality, | 26 bool JPEG1xEncodedDataFromImage(const Image& image, int quality, |
| 27 std::vector<unsigned char>* dst) { | 27 std::vector<unsigned char>* dst) { |
| 28 const gfx::ImageSkiaRep& image_skia_rep = | 28 const gfx::ImageSkiaRep& image_skia_rep = |
| 29 image.AsImageSkia().GetRepresentation(ui::SCALE_FACTOR_100P); | 29 image.AsImageSkia().GetRepresentation(1.0f); |
| 30 if (image_skia_rep.scale_factor() != ui::SCALE_FACTOR_100P) | 30 if (image_skia_rep.scale() != 1.0f) |
| 31 return false; | 31 return false; |
| 32 | 32 |
| 33 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); | 33 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); |
| 34 SkAutoLockPixels bitmap_lock(bitmap); | 34 SkAutoLockPixels bitmap_lock(bitmap); |
| 35 | 35 |
| 36 if (!bitmap.readyToDraw()) | 36 if (!bitmap.readyToDraw()) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 return gfx::JPEGCodec::Encode( | 39 return gfx::JPEGCodec::Encode( |
| 40 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 40 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 41 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), | 41 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), |
| 42 bitmap.height(), | 42 bitmap.height(), |
| 43 static_cast<int>(bitmap.rowBytes()), quality, | 43 static_cast<int>(bitmap.rowBytes()), quality, |
| 44 dst); | 44 dst); |
| 45 } | 45 } |
| 46 #endif // !defined(OS_IOS) | 46 #endif // !defined(OS_IOS) |
| 47 | 47 |
| 48 } | 48 } |
| OLD | NEW |