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

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

Issue 1511183002: Revert of default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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"
12 #include "SkStream.h" 10 #include "SkStream.h"
13 #include "SkTemplates.h" 11 #include "SkTemplates.h"
14 12
15 SkImageEncoder::~SkImageEncoder() {} 13 SkImageEncoder::~SkImageEncoder() {}
16 14
17 bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm, 15 bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm,
18 int quality) { 16 int quality) {
19 quality = SkMin32(100, SkMax32(0, quality)); 17 quality = SkMin32(100, SkMax32(0, quality));
20 return this->onEncode(stream, bm, quality); 18 return this->onEncode(stream, bm, quality);
21 } 19 }
(...skipping 30 matching lines...) Expand all
52 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); 50 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
53 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; 51 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr;
54 } 52 }
55 53
56 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,
57 Type t, int quality) { 55 Type t, int quality) {
58 SkBitmap bm; 56 SkBitmap bm;
59 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) { 57 if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
60 return nullptr; 58 return nullptr;
61 } 59 }
62 bm.setImmutable(); 60 SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
63 return SkImageEncoder::EncodeData(bm, t, quality); 61 return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr;
64 } 62 }
65
66 SkData* SkImageEncoder::EncodeData(const SkPixmap& pixmap,
67 Type t, int quality) {
68 SkBitmap bm;
69 if (!bm.installPixels(pixmap.info(),
70 const_cast<void*>(pixmap.addr()),
71 pixmap.rowBytes(),
72 pixmap.ctable(), nullptr, nullptr)) {
73 return nullptr;
74 }
75 bm.setImmutable();
76 return SkImageEncoder::EncodeData(bm, t, quality);
77 }
78
79 namespace {
80 class ImageEncoderPixelSerializer final : public SkPixelSerializer {
81 protected:
82 bool onUseEncodedData(const void*, size_t) override { return true; }
83 SkData* onEncode(const SkPixmap& pmap) override {
84 return SkImageEncoder::EncodeData(pmap, SkImageEncoder::kPNG_Type, 100);
85 }
86 };
87 } // namespace
88
89 SkPixelSerializer* SkImageEncoder::CreatePixelSerializer() {
90 return new ImageEncoderPixelSerializer;
91 }
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