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

Side by Side Diff: src/image/SkImage.cpp

Issue 1501303002: SkPixelSerializer: support indexed pixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-07 (Monday) 15:24:44 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/core/SkWriteBuffer.cpp ('k') | no next file » | 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 2012 Google Inc. 2 * Copyright 2012 Google Inc.
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return nullptr; 178 return nullptr;
179 } 179 }
180 180
181 namespace { 181 namespace {
182 182
183 class DefaultSerializer : public SkPixelSerializer { 183 class DefaultSerializer : public SkPixelSerializer {
184 protected: 184 protected:
185 bool onUseEncodedData(const void *data, size_t len) override { 185 bool onUseEncodedData(const void *data, size_t len) override {
186 return true; 186 return true;
187 } 187 }
188 188 SkData* onEncode(const SkPixmap& pixmap) override {
189 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t r owBytes) override { 189 SkBitmap bm;
190 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder ::kPNG_Type, 100); 190 if (!bm.installPixels(pixmap.info(),
191 const_cast<void*>(pixmap.addr()),
192 pixmap.rowBytes(),
193 pixmap.ctable(),
194 nullptr, nullptr)) {
195 return nullptr;
196 }
197 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
191 } 198 }
192 }; 199 };
193 200
194 } // anonymous namespace 201 } // anonymous namespace
195 202
196 SkData* SkImage::encode(SkPixelSerializer* serializer) const { 203 SkData* SkImage::encode(SkPixelSerializer* serializer) const {
197 DefaultSerializer defaultSerializer; 204 DefaultSerializer defaultSerializer;
198 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer; 205 SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultS erializer;
199 206
200 SkAutoTUnref<SkData> encoded(this->refEncoded()); 207 SkAutoTUnref<SkData> encoded(this->refEncoded());
201 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) { 208 if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded- >size())) {
202 return encoded.detach(); 209 return encoded.detach();
203 } 210 }
204 211
205 SkBitmap bm; 212 SkBitmap bm;
206 SkAutoPixmapUnlock apu; 213 SkAutoPixmapUnlock apu;
207 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { 214 if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) {
208 const SkPixmap& pmap = apu.pixmap(); 215 return effectiveSerializer->encode(apu.pixmap());
209 return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap. rowBytes());
210 } 216 }
211 217
212 return nullptr; 218 return nullptr;
213 } 219 }
214 220
215 SkData* SkImage::refEncoded() const { 221 SkData* SkImage::refEncoded() const {
216 return as_IB(this)->onRefEncoded(); 222 return as_IB(this)->onRefEncoded();
217 } 223 }
218 224
219 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 225 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 423
418 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 424 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
419 return nullptr; 425 return nullptr;
420 } 426 }
421 427
422 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 428 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
423 return nullptr; 429 return nullptr;
424 } 430 }
425 431
426 #endif 432 #endif
OLDNEW
« no previous file with comments | « src/core/SkWriteBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698