MCPcopy Create free account
hub / github.com/SOUI2/soui / cropBitmap

Method cropBitmap

third-part/skia/src/images/SkImageDecoder.cpp:191–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
192 int dstX, int dstY, int width, int height,
193 int srcX, int srcY) {
194 int w = width / sampleSize;
195 int h = height / sampleSize;
196 if (src->colorType() == kIndex_8_SkColorType) {
197 // kIndex8 does not allow drawing via an SkCanvas, as is done below.
198 // Instead, use extractSubset. Note that this shares the SkPixelRef and
199 // SkColorTable.
200 // FIXME: Since src is discarded in practice, this holds on to more
201 // pixels than is strictly necessary. Switch to a copy if memory
202 // savings are more important than speed here. This also means
203 // that the pixels in dst can not be reused (though there is no
204 // allocation, which was already done on src).
205 int x = (dstX - srcX) / sampleSize;
206 int y = (dstY - srcY) / sampleSize;
207 SkIRect subset = SkIRect::MakeXYWH(x, y, w, h);
208 return src->extractSubset(dst, subset);
209 }
210 // if the destination has no pixels then we must allocate them.
211 if (dst->isNull()) {
212 dst->setInfo(src->info().makeWH(w, h));
213
214 if (!this->allocPixelRef(dst, NULL)) {
215 SkDEBUGF(("failed to allocate pixels needed to crop the bitmap"));
216 return false;
217 }
218 }
219 // check to see if the destination is large enough to decode the desired
220 // region. If this assert fails we will just draw as much of the source
221 // into the destination that we can.
222 if (dst->width() < w || dst->height() < h) {
223 SkDEBUGF(("SkImageDecoder::cropBitmap does not have a large enough bitmap.\n"));
224 }
225
226 // Set the Src_Mode for the paint to prevent transparency issue in the
227 // dest in the event that the dest was being re-used.
228 SkPaint paint;
229 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
230
231 SkCanvas canvas(*dst);
232 canvas.drawSprite(*src, (srcX - dstX) / sampleSize,
233 (srcY - dstY) / sampleSize,
234 &paint);
235 return true;
236}
237
238///////////////////////////////////////////////////////////////////////////////
239

Callers 1

onDecodeSubsetMethod · 0.45

Calls 11

allocPixelRefMethod · 0.95
colorTypeMethod · 0.80
extractSubsetMethod · 0.80
isNullMethod · 0.80
setInfoMethod · 0.80
makeWHMethod · 0.80
infoMethod · 0.80
setXfermodeModeMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
drawSpriteMethod · 0.45

Tested by

no test coverage detected