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

Side by Side Diff: src/core/SkPixmap.cpp

Issue 1153893003: move readPixels from bitmap -> pixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/core/SkConfig8888.h ('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 2015 Google Inc. 2 * Copyright 2015 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 "SkConfig8888.h"
8 #include "SkPixmap.h" 9 #include "SkPixmap.h"
9 10
10 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) { 11 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) {
11 SkASSERT(pm.addr() != NULL); 12 SkASSERT(pm.addr() != NULL);
12 13
13 this->unlock(); 14 this->unlock();
14 fPixmap = pm; 15 fPixmap = pm;
15 fUnlockProc = unlock; 16 fUnlockProc = unlock;
16 fUnlockContext = ctx; 17 fUnlockContext = ctx;
17 fIsLocked = true; 18 fIsLocked = true;
18 } 19 }
20
21 //////////////////////////////////////////////////////////////////////////////// /////////////////
22
23 bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB,
24 int x, int y) const {
25 if (kUnknown_SkColorType == requestedDstInfo.colorType()) {
26 return false;
27 }
28 if (NULL == dstPixels || dstRB < requestedDstInfo.minRowBytes()) {
29 return false;
30 }
31 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) {
32 return false;
33 }
34
35 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs tInfo.height());
36 if (!srcR.intersect(0, 0, this->width(), this->height())) {
37 return false;
38 }
39
40 // the intersect may have shrunk info's logical size
41 const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.heigh t());
42
43 // if x or y are negative, then we have to adjust pixels
44 if (x > 0) {
45 x = 0;
46 }
47 if (y > 0) {
48 y = 0;
49 }
50 // here x,y are either 0 or negative
51 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel());
52
53 const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.hei ght());
54 const void* srcPixels = this->addr(srcR.x(), srcR.y());
55 return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB,
56 srcInfo, srcPixels, this->rowBytes(), this->c table());
57 }
OLDNEW
« no previous file with comments | « src/core/SkConfig8888.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698