OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The Android Open Source Project | 2 * Copyright 2009 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkImageEncoder.h" | 8 #include "SkImageEncoder.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 SkFILEWStream stream(file); | 24 SkFILEWStream stream(file); |
25 return this->onEncode(&stream, bm, quality); | 25 return this->onEncode(&stream, bm, quality); |
26 } | 26 } |
27 | 27 |
28 SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) { | 28 SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) { |
29 SkDynamicMemoryWStream stream; | 29 SkDynamicMemoryWStream stream; |
30 quality = SkMin32(100, SkMax32(0, quality)); | 30 quality = SkMin32(100, SkMax32(0, quality)); |
31 if (this->onEncode(&stream, bm, quality)) { | 31 if (this->onEncode(&stream, bm, quality)) { |
32 return stream.copyToData(); | 32 return stream.copyToData(); |
33 } | 33 } |
34 return NULL; | 34 return nullptr; |
35 } | 35 } |
36 | 36 |
37 bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, | 37 bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, |
38 int quality) { | 38 int quality) { |
39 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); | 39 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
40 return enc.get() && enc.get()->encodeFile(file, bm, quality); | 40 return enc.get() && enc.get()->encodeFile(file, bm, quality); |
41 } | 41 } |
42 | 42 |
43 bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, | 43 bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, |
44 int quality) { | 44 int quality) { |
45 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); | 45 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
46 return enc.get() && enc.get()->encodeStream(stream, bm, quality); | 46 return enc.get() && enc.get()->encodeStream(stream, bm, quality); |
47 } | 47 } |
48 | 48 |
49 SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) { | 49 SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) { |
50 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); | 50 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
51 return enc.get() ? enc.get()->encodeData(bm, quality) : NULL; | 51 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; |
52 } | 52 } |
53 | 53 |
54 SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels,
size_t rowBytes, | 54 SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels,
size_t rowBytes, |
55 Type t, int quality) { | 55 Type t, int quality) { |
56 SkBitmap bm; | 56 SkBitmap bm; |
57 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) { | 57 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) { |
58 return NULL; | 58 return nullptr; |
59 } | 59 } |
60 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); | 60 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); |
61 return enc.get() ? enc.get()->encodeData(bm, quality) : NULL; | 61 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; |
62 } | 62 } |
OLD | NEW |