blob: 31fdcf96042eaf6c701e000e14307be0f5c92391 [file] [log] [blame]
reed@android.comb08eb2b2009-01-06 20:16:26 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2009 The Android Open Source Project
reed@android.comb08eb2b2009-01-06 20:16:26 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.comb08eb2b2009-01-06 20:16:26 +00006 */
7
reed@android.comb08eb2b2009-01-06 20:16:26 +00008#include "SkImageEncoder.h"
9#include "SkBitmap.h"
10#include "SkStream.h"
11#include "SkTemplates.h"
12
13SkImageEncoder::~SkImageEncoder() {}
14
15bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm,
16 int quality) {
17 quality = SkMin32(100, SkMax32(0, quality));
18 return this->onEncode(stream, bm, quality);
19}
20
21bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm,
22 int quality) {
23 quality = SkMin32(100, SkMax32(0, quality));
24 SkFILEWStream stream(file);
25 return this->onEncode(&stream, bm, quality);
26}
27
reed@google.com4b0757b2013-05-20 16:33:41 +000028SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) {
29 SkDynamicMemoryWStream stream;
30 quality = SkMin32(100, SkMax32(0, quality));
31 if (this->onEncode(&stream, bm, quality)) {
32 return stream.copyToData();
33 }
34 return NULL;
35}
36
reed@android.comb08eb2b2009-01-06 20:16:26 +000037bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t,
38 int quality) {
39 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
40 return enc.get() && enc.get()->encodeFile(file, bm, quality);
41}
42
43bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t,
reed@google.com4b0757b2013-05-20 16:33:41 +000044 int quality) {
reed@android.comb08eb2b2009-01-06 20:16:26 +000045 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
46 return enc.get() && enc.get()->encodeStream(stream, bm, quality);
47}
reed@google.com4b0757b2013-05-20 16:33:41 +000048
49SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) {
50 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
51 return enc.get() ? enc.get()->encodeData(bm, quality) : NULL;
52}