OLD | NEW |
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 "SkImagePriv.h" | 10 #include "SkImagePriv.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (NULL == rowBytes) { | 48 if (NULL == rowBytes) { |
49 rowBytes = &rowBytesStorage; | 49 rowBytes = &rowBytesStorage; |
50 } | 50 } |
51 return as_IB(this)->onPeekPixels(info, rowBytes); | 51 return as_IB(this)->onPeekPixels(info, rowBytes); |
52 } | 52 } |
53 | 53 |
54 bool SkImage::readPixels(SkBitmap* bitmap, const SkIRect* subset) const { | 54 bool SkImage::readPixels(SkBitmap* bitmap, const SkIRect* subset) const { |
55 if (NULL == bitmap) { | 55 if (NULL == bitmap) { |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); | 59 SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); |
60 | 60 |
61 // trim against the bitmap, if its already been allocated | 61 // trim against the bitmap, if its already been allocated |
62 if (bitmap->pixelRef()) { | 62 if (bitmap->pixelRef()) { |
63 bounds.fRight = SkMin32(bounds.fRight, bitmap->width()); | 63 bounds.fRight = SkMin32(bounds.fRight, bitmap->width()); |
64 bounds.fBottom = SkMin32(bounds.fBottom, bitmap->height()); | 64 bounds.fBottom = SkMin32(bounds.fBottom, bitmap->height()); |
65 if (bounds.isEmpty()) { | 65 if (bounds.isEmpty()) { |
66 return false; | 66 return false; |
67 } | 67 } |
68 } | 68 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if (!tmp.allocPixels(info)) { | 119 if (!tmp.allocPixels(info)) { |
120 return false; | 120 return false; |
121 } | 121 } |
122 *bitmap = tmp; | 122 *bitmap = tmp; |
123 } | 123 } |
124 | 124 |
125 SkRect srcR, dstR; | 125 SkRect srcR, dstR; |
126 srcR.set(subset); | 126 srcR.set(subset); |
127 dstR = srcR; | 127 dstR = srcR; |
128 dstR.offset(-dstR.left(), -dstR.top()); | 128 dstR.offset(-dstR.left(), -dstR.top()); |
129 | 129 |
130 SkCanvas canvas(*bitmap); | 130 SkCanvas canvas(*bitmap); |
131 | 131 |
132 SkPaint paint; | 132 SkPaint paint; |
133 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 133 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
134 canvas.drawRect(dstR, paint); | 134 canvas.drawRect(dstR, paint); |
135 | 135 |
136 const_cast<SkImage_Base*>(this)->onDrawRectToRect(&canvas, &srcR, dstR, NULL
); | 136 const_cast<SkImage_Base*>(this)->onDrawRectToRect(&canvas, &srcR, dstR, NULL
); |
137 return true; | 137 return true; |
138 } | 138 } |
| 139 |
OLD | NEW |