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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 this->reset(); | 51 this->reset(); |
52 return false; | 52 return false; |
53 } | 53 } |
54 | 54 |
55 bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { | 55 bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { |
56 SkIRect srcRect, r; | 56 SkIRect srcRect, r; |
57 srcRect.set(0, 0, this->width(), this->height()); | 57 srcRect.set(0, 0, this->width(), this->height()); |
58 if (!r.intersect(srcRect, subset)) { | 58 if (!r.intersect(srcRect, subset)) { |
59 return false; // r is empty (i.e. no intersection) | 59 return false; // r is empty (i.e. no intersection) |
60 } | 60 } |
61 | 61 |
62 // If the upper left of the rectangle was outside the bounds of this SkBitma
p, we should have | 62 // If the upper left of the rectangle was outside the bounds of this SkBitma
p, we should have |
63 // exited above. | 63 // exited above. |
64 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width(
))); | 64 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width(
))); |
65 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height(
))); | 65 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height(
))); |
66 | 66 |
67 const void* pixels = nullptr; | 67 const void* pixels = nullptr; |
68 if (fPixels) { | 68 if (fPixels) { |
69 const size_t bpp = fInfo.bytesPerPixel(); | 69 const size_t bpp = fInfo.bytesPerPixel(); |
70 pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp; | 70 pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp; |
71 } | 71 } |
72 result->reset(fInfo.makeWH(r.width(), r.height()), pixels, fRowBytes, fCTabl
e); | 72 result->reset(fInfo.makeWH(r.width(), r.height()), pixels, fRowBytes, fCTabl
e); |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
size_t dstRB, | 76 bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
size_t dstRB, |
77 int x, int y) const { | 77 int x, int y) const { |
78 if (kUnknown_SkColorType == requestedDstInfo.colorType()) { | 78 if (kUnknown_SkColorType == requestedDstInfo.colorType()) { |
79 return false; | 79 return false; |
80 } | 80 } |
81 if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { | 81 if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { |
82 return false; | 82 return false; |
83 } | 83 } |
84 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { | 84 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { |
85 return false; | 85 return false; |
86 } | 86 } |
87 | 87 |
88 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs
tInfo.height()); | 88 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs
tInfo.height()); |
89 if (!srcR.intersect(0, 0, this->width(), this->height())) { | 89 if (!srcR.intersect(0, 0, this->width(), this->height())) { |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
93 // the intersect may have shrunk info's logical size | 93 // the intersect may have shrunk info's logical size |
94 const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.heigh
t()); | 94 const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.heigh
t()); |
95 | 95 |
96 // if x or y are negative, then we have to adjust pixels | 96 // if x or y are negative, then we have to adjust pixels |
97 if (x > 0) { | 97 if (x > 0) { |
98 x = 0; | 98 x = 0; |
99 } | 99 } |
100 if (y > 0) { | 100 if (y > 0) { |
101 y = 0; | 101 y = 0; |
102 } | 102 } |
103 // here x,y are either 0 or negative | 103 // here x,y are either 0 or negative |
104 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); | 104 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); |
105 | 105 |
(...skipping 21 matching lines...) Expand all Loading... |
127 } | 127 } |
128 | 128 |
129 U8CPU a = SkColorGetA(color); | 129 U8CPU a = SkColorGetA(color); |
130 U8CPU r = SkColorGetR(color); | 130 U8CPU r = SkColorGetR(color); |
131 U8CPU g = SkColorGetG(color); | 131 U8CPU g = SkColorGetG(color); |
132 U8CPU b = SkColorGetB(color); | 132 U8CPU b = SkColorGetB(color); |
133 | 133 |
134 int height = area.height(); | 134 int height = area.height(); |
135 const int width = area.width(); | 135 const int width = area.width(); |
136 const int rowBytes = this->rowBytes(); | 136 const int rowBytes = this->rowBytes(); |
137 | 137 |
138 switch (this->colorType()) { | 138 switch (this->colorType()) { |
139 case kGray_8_SkColorType: { | 139 case kGray_8_SkColorType: { |
140 if (255 != a) { | 140 if (255 != a) { |
141 r = SkMulDiv255Round(r, a); | 141 r = SkMulDiv255Round(r, a); |
142 g = SkMulDiv255Round(g, a); | 142 g = SkMulDiv255Round(g, a); |
143 b = SkMulDiv255Round(b, a); | 143 b = SkMulDiv255Round(b, a); |
144 } | 144 } |
145 int gray = SkComputeLuminance(r, g, b); | 145 int gray = SkComputeLuminance(r, g, b); |
146 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); | 146 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); |
147 while (--height >= 0) { | 147 while (--height >= 0) { |
148 memset(p, gray, width); | 148 memset(p, gray, width); |
149 p += rowBytes; | 149 p += rowBytes; |
150 } | 150 } |
151 break; | 151 break; |
152 } | 152 } |
153 case kAlpha_8_SkColorType: { | 153 case kAlpha_8_SkColorType: { |
154 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); | 154 uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); |
155 while (--height >= 0) { | 155 while (--height >= 0) { |
156 memset(p, a, width); | 156 memset(p, a, width); |
157 p += rowBytes; | 157 p += rowBytes; |
158 } | 158 } |
159 break; | 159 break; |
160 } | 160 } |
161 case kARGB_4444_SkColorType: | 161 case kARGB_4444_SkColorType: |
162 case kRGB_565_SkColorType: { | 162 case kRGB_565_SkColorType: { |
163 uint16_t* p = this->writable_addr16(area.fLeft, area.fTop); | 163 uint16_t* p = this->writable_addr16(area.fLeft, area.fTop); |
164 uint16_t v; | 164 uint16_t v; |
165 | 165 |
166 // make rgb premultiplied | 166 // make rgb premultiplied |
167 if (255 != a) { | 167 if (255 != a) { |
168 r = SkMulDiv255Round(r, a); | 168 r = SkMulDiv255Round(r, a); |
169 g = SkMulDiv255Round(g, a); | 169 g = SkMulDiv255Round(g, a); |
170 b = SkMulDiv255Round(b, a); | 170 b = SkMulDiv255Round(b, a); |
171 } | 171 } |
172 | 172 |
173 if (kARGB_4444_SkColorType == this->colorType()) { | 173 if (kARGB_4444_SkColorType == this->colorType()) { |
174 v = pack_8888_to_4444(a, r, g, b); | 174 v = pack_8888_to_4444(a, r, g, b); |
175 } else { | 175 } else { |
176 v = SkPackRGB16(r >> (8 - SK_R16_BITS), | 176 v = SkPackRGB16(r >> (8 - SK_R16_BITS), |
177 g >> (8 - SK_G16_BITS), | 177 g >> (8 - SK_G16_BITS), |
178 b >> (8 - SK_B16_BITS)); | 178 b >> (8 - SK_B16_BITS)); |
179 } | 179 } |
180 while (--height >= 0) { | 180 while (--height >= 0) { |
181 sk_memset16(p, v, width); | 181 sk_memset16(p, v, width); |
182 p = (uint16_t*)((char*)p + rowBytes); | 182 p = (uint16_t*)((char*)p + rowBytes); |
183 } | 183 } |
184 break; | 184 break; |
185 } | 185 } |
186 case kBGRA_8888_SkColorType: | 186 case kBGRA_8888_SkColorType: |
187 case kRGBA_8888_SkColorType: { | 187 case kRGBA_8888_SkColorType: { |
188 uint32_t* p = this->writable_addr32(area.fLeft, area.fTop); | 188 uint32_t* p = this->writable_addr32(area.fLeft, area.fTop); |
189 | 189 |
190 if (255 != a && kPremul_SkAlphaType == this->alphaType()) { | 190 if (255 != a && kPremul_SkAlphaType == this->alphaType()) { |
191 r = SkMulDiv255Round(r, a); | 191 r = SkMulDiv255Round(r, a); |
192 g = SkMulDiv255Round(g, a); | 192 g = SkMulDiv255Round(g, a); |
193 b = SkMulDiv255Round(b, a); | 193 b = SkMulDiv255Round(b, a); |
194 } | 194 } |
195 uint32_t v = kRGBA_8888_SkColorType == this->colorType() | 195 uint32_t v = kRGBA_8888_SkColorType == this->colorType() |
196 ? SkPackARGB_as_RGBA(a, r, g, b) | 196 ? SkPackARGB_as_RGBA(a, r, g, b) |
197 : SkPackARGB_as_BGRA(a, r, g, b); | 197 : SkPackARGB_as_BGRA(a, r, g, b); |
198 | 198 |
199 while (--height >= 0) { | 199 while (--height >= 0) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 266 |
267 SkPaint paint; | 267 SkPaint paint; |
268 paint.setFilterQuality(quality); | 268 paint.setFilterQuality(quality); |
269 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 269 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
270 surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), ds
t.height()), | 270 surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), ds
t.height()), |
271 &paint); | 271 &paint); |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 275 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
276 | |
OLD | NEW |