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

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

Issue 834633006: add ImageGenerator::NewFromData to porting layer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add helper for SkInstallDiscardablePixelRef(SkData*, ...) Created 5 years, 11 months 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
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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImageGenerator.h"
10 #include "SkImagePriv.h" 11 #include "SkImagePriv.h"
11 #include "SkImage_Base.h" 12 #include "SkImage_Base.h"
12 #include "SkReadPixelsRec.h" 13 #include "SkReadPixelsRec.h"
13 #include "SkString.h" 14 #include "SkString.h"
14 #include "SkSurface.h" 15 #include "SkSurface.h"
15 16
16 uint32_t SkImage::NextUniqueID() { 17 uint32_t SkImage::NextUniqueID() {
17 static int32_t gUniqueID; 18 static int32_t gUniqueID;
18 19
19 // never return 0; 20 // never return 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 66 }
66 67
67 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 68 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
68 SkBitmap bm; 69 SkBitmap bm;
69 if (as_IB(this)->getROPixels(&bm)) { 70 if (as_IB(this)->getROPixels(&bm)) {
70 return SkImageEncoder::EncodeData(bm, type, quality); 71 return SkImageEncoder::EncodeData(bm, type, quality);
71 } 72 }
72 return NULL; 73 return NULL;
73 } 74 }
74 75
76 SkImage* SkImage::NewFromData(SkData* data) {
77 if (NULL == data) {
78 return NULL;
79 }
80 SkImageGenerator* generator = SkImageGenerator::NewFromData(data);
81 return generator ? SkImage::NewFromGenerator(generator) : NULL;
82 }
83
75 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const { 84 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const {
76 if (NULL == props) { 85 if (NULL == props) {
77 props = &as_IB(this)->props(); 86 props = &as_IB(this)->props();
78 } 87 }
79 return as_IB(this)->onNewSurface(info, *props); 88 return as_IB(this)->onNewSurface(info, *props);
80 } 89 }
81 90
82 const char* SkImage::toString(SkString* str) const { 91 const char* SkImage::toString(SkString* str) const {
83 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), 92 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
84 this->isOpaque() ? "opaque" : ""); 93 this->isOpaque() ? "opaque" : "");
(...skipping 25 matching lines...) Expand all
110 SkBitmap bm; 119 SkBitmap bm;
111 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 120 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
112 SkCanvas canvas(bm); 121 SkCanvas canvas(bm);
113 122
114 SkPaint paint; 123 SkPaint paint;
115 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 124 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
116 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 125 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
117 126
118 return true; 127 return true;
119 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698