Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/images/SkImageEncoder.cpp

Issue 1507123002: default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-10 (Thursday) 13:15:57 EST Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkPixelSerializer.h"
11 #include "SkPixmap.h"
10 #include "SkStream.h" 12 #include "SkStream.h"
11 #include "SkTemplates.h" 13 #include "SkTemplates.h"
12 14
13 SkImageEncoder::~SkImageEncoder() {} 15 SkImageEncoder::~SkImageEncoder() {}
14 16
15 bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm, 17 bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm,
16 int quality) { 18 int quality) {
17 quality = SkMin32(100, SkMax32(0, quality)); 19 quality = SkMin32(100, SkMax32(0, quality));
18 return this->onEncode(stream, bm, quality); 20 return this->onEncode(stream, bm, quality);
19 } 21 }
(...skipping 30 matching lines...) Expand all
50 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); 52 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
51 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; 53 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr;
52 } 54 }
53 55
54 SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes, 56 SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes,
55 Type t, int quality) { 57 Type t, int quality) {
56 SkBitmap bm; 58 SkBitmap bm;
57 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) { 59 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
58 return nullptr; 60 return nullptr;
59 } 61 }
60 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); 62 bm.setImmutable();
61 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; 63 return SkImageEncoder::EncodeData(bm, t, quality);
62 } 64 }
65
66 SkData* SkImageEncoder::EncodeData(const SkPixmap& pixmap,
67 Type t, int quality) {
68 SkBitmap bm;
69 if (!bm.installPixels(pixmap)) {
70 return nullptr;
71 }
72 bm.setImmutable();
73 return SkImageEncoder::EncodeData(bm, t, quality);
74 }
75
76 namespace {
77 class ImageEncoderPixelSerializer final : public SkPixelSerializer {
78 protected:
79 bool onUseEncodedData(const void*, size_t) override { return true; }
80 SkData* onEncode(const SkPixmap& pmap) override {
81 return SkImageEncoder::EncodeData(pmap, SkImageEncoder::kPNG_Type, 100);
82 }
83 };
84 } // namespace
85
86 SkPixelSerializer* SkImageEncoder::CreatePixelSerializer() {
87 return new ImageEncoderPixelSerializer;
88 }
OLDNEW
« no previous file with comments | « src/image/SkImage.cpp ('k') | src/ports/SkImageDecoder_empty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698