OLD | NEW |
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 } |
OLD | NEW |