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
3 // found in the LICENSE file.
5 #include "ui/gfx/image/image_util.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/gfx/codec/jpeg_codec.h"
10 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/image/image_skia.h"
15 // The iOS implementations of the JPEG functions are in image_util_ios.mm.
17 Image
ImageFrom1xJPEGEncodedData(const unsigned char* input
,
19 scoped_ptr
<SkBitmap
> bitmap(gfx::JPEGCodec::Decode(input
, input_size
));
21 return Image::CreateFrom1xBitmap(*bitmap
);
26 bool JPEG1xEncodedDataFromImage(const Image
& image
, int quality
,
27 std::vector
<unsigned char>* dst
) {
28 const gfx::ImageSkiaRep
& image_skia_rep
=
29 image
.AsImageSkia().GetRepresentation(ui::SCALE_FACTOR_100P
);
30 if (image_skia_rep
.scale_factor() != ui::SCALE_FACTOR_100P
)
33 const SkBitmap
& bitmap
= image_skia_rep
.sk_bitmap();
34 SkAutoLockPixels
bitmap_lock(bitmap
);
36 if (!bitmap
.readyToDraw())
39 return gfx::JPEGCodec::Encode(
40 reinterpret_cast<unsigned char*>(bitmap
.getAddr32(0, 0)),
41 gfx::JPEGCodec::FORMAT_SkBitmap
, bitmap
.width(),
43 static_cast<int>(bitmap
.rowBytes()), quality
,
46 #endif // !defined(OS_IOS)