* Changing crash report limitation logic to have more control over extreme cases.
[chromium-blink-merge.git] / components / suggestions / image_encoder.cc
blob5e92b653a58e6a613e8785b2e6dc973cba7e1104
1 // Copyright 2014 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 "components/suggestions/image_encoder.h"
7 #include "ui/gfx/codec/jpeg_codec.h"
8 #include "ui/gfx/image/image_skia.h"
10 namespace suggestions {
12 SkBitmap* DecodeJPEGToSkBitmap(const void* encoded_data, size_t size) {
13 return gfx::JPEGCodec::Decode(static_cast<const unsigned char*>(encoded_data),
14 size);
17 bool EncodeSkBitmapToJPEG(const SkBitmap& bitmap,
18 std::vector<unsigned char>* dest) {
19 SkAutoLockPixels bitmap_lock(bitmap);
20 if (!bitmap.readyToDraw() || bitmap.isNull()) {
21 return false;
23 return gfx::JPEGCodec::Encode(
24 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
25 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(),
26 bitmap.rowBytes(), 100, dest);
29 } // namespace suggestions