reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2009 The Android Open Source Project |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame^] | 8 | #include "SkImageEncoderPriv.h" |
reed@android.com | b08eb2b | 2009-01-06 20:16:26 +0000 | [diff] [blame] | 9 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame^] | 10 | bool SkEncodeImage(SkWStream* dst, const SkPixmap& src, |
| 11 | SkEncodedImageFormat format, int quality) { |
reed | 53b9e2e | 2014-12-19 12:26:07 -0800 | [diff] [blame] | 12 | SkBitmap bm; |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame^] | 13 | if (!bm.installPixels(src)) { |
| 14 | return false; |
reed | 53b9e2e | 2014-12-19 12:26:07 -0800 | [diff] [blame] | 15 | } |
halcanary | f2848b6 | 2015-12-10 12:40:23 -0800 | [diff] [blame] | 16 | bm.setImmutable(); |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame^] | 17 | std::unique_ptr<SkImageEncoder> enc(SkImageEncoder::Create((SkImageEncoder::Type)format)); |
| 18 | return enc && enc->encodeStream(dst, bm, quality); |
reed | 53b9e2e | 2014-12-19 12:26:07 -0800 | [diff] [blame] | 19 | } |