1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/core/SkPixmap.h"
9 
10 #include "include/core/SkBitmap.h"
11 #include "include/core/SkData.h"
12 #include "include/core/SkSurface.h"
13 #include "include/core/SkUnPreMultiply.h"
14 #include "include/private/SkColorData.h"
15 #include "include/private/SkHalf.h"
16 #include "include/private/SkImageInfoPriv.h"
17 #include "include/private/SkNx.h"
18 #include "include/private/SkTPin.h"
19 #include "include/private/SkTemplates.h"
20 #include "include/private/SkTo.h"
21 #include "src/core/SkConvertPixels.h"
22 #include "src/core/SkDraw.h"
23 #include "src/core/SkMask.h"
24 #include "src/core/SkMatrixProvider.h"
25 #include "src/core/SkPixmapPriv.h"
26 #include "src/core/SkRasterClip.h"
27 #include "src/core/SkUtils.h"
28 #include "src/image/SkReadPixelsRec.h"
29 #include "src/shaders/SkImageShader.h"
30 
31 #include <utility>
32 
33 /////////////////////////////////////////////////////////////////////////////////////////////////
34 
reset()35 void SkPixmap::reset() {
36     fPixels = nullptr;
37     fRowBytes = 0;
38     fInfo = SkImageInfo::MakeUnknown();
39 }
40 
reset(const SkImageInfo & info,const void * addr,size_t rowBytes)41 void SkPixmap::reset(const SkImageInfo& info, const void* addr, size_t rowBytes) {
42     if (addr) {
43         SkASSERT(info.validRowBytes(rowBytes));
44     }
45     fPixels = addr;
46     fRowBytes = rowBytes;
47     fInfo = info;
48 }
49 
reset(const SkMask & src)50 bool SkPixmap::reset(const SkMask& src) {
51     if (SkMask::kA8_Format == src.fFormat) {
52         this->reset(SkImageInfo::MakeA8(src.fBounds.width(), src.fBounds.height()),
53                     src.fImage, src.fRowBytes);
54         return true;
55     }
56     this->reset();
57     return false;
58 }
59 
setColorSpace(sk_sp<SkColorSpace> cs)60 void SkPixmap::setColorSpace(sk_sp<SkColorSpace> cs) {
61     fInfo = fInfo.makeColorSpace(std::move(cs));
62 }
63 
extractSubset(SkPixmap * result,const SkIRect & subset) const64 bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const {
65     SkIRect srcRect, r;
66     srcRect.setWH(this->width(), this->height());
67     if (!r.intersect(srcRect, subset)) {
68         return false;   // r is empty (i.e. no intersection)
69     }
70 
71     // If the upper left of the rectangle was outside the bounds of this SkBitmap, we should have
72     // exited above.
73     SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width()));
74     SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height()));
75 
76     const void* pixels = nullptr;
77     if (fPixels) {
78         const size_t bpp = fInfo.bytesPerPixel();
79         pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp;
80     }
81     result->reset(fInfo.makeDimensions(r.size()), pixels, fRowBytes);
82     return true;
83 }
84 
85 // This is the same as SkPixmap::addr(x,y), but this version gets inlined, while the public
86 // method does not. Perhaps we could bloat it so it can be inlined, but that would grow code-size
87 // everywhere, instead of just here (on behalf of getAlphaf()).
fast_getaddr(const SkPixmap & pm,int x,int y)88 static const void* fast_getaddr(const SkPixmap& pm, int x, int y) {
89     x <<= SkColorTypeShiftPerPixel(pm.colorType());
90     return static_cast<const char*>(pm.addr()) + y * pm.rowBytes() + x;
91 }
92 
getAlphaf(int x,int y) const93 float SkPixmap::getAlphaf(int x, int y) const {
94     SkASSERT(this->addr());
95     SkASSERT((unsigned)x < (unsigned)this->width());
96     SkASSERT((unsigned)y < (unsigned)this->height());
97 
98     float value = 0;
99     const void* srcPtr = fast_getaddr(*this, x, y);
100 
101     switch (this->colorType()) {
102         case kUnknown_SkColorType:
103             return 0;
104         case kGray_8_SkColorType:
105         case kR8G8_unorm_SkColorType:
106         case kR16G16_unorm_SkColorType:
107         case kR16G16_float_SkColorType:
108         case kRGB_565_SkColorType:
109         case kRGB_888x_SkColorType:
110         case kRGB_101010x_SkColorType:
111         case kBGR_101010x_SkColorType:
112             return 1;
113         case kAlpha_8_SkColorType:
114             value = static_cast<const uint8_t*>(srcPtr)[0] * (1.0f/255);
115             break;
116         case kA16_unorm_SkColorType:
117             value = static_cast<const uint16_t*>(srcPtr)[0] * (1.0f/65535);
118             break;
119         case kA16_float_SkColorType: {
120             SkHalf half = static_cast<const SkHalf*>(srcPtr)[0];
121             value = SkHalfToFloat(half);
122             break;
123         }
124         case kARGB_4444_SkColorType: {
125             uint16_t u16 = static_cast<const uint16_t*>(srcPtr)[0];
126             value = SkGetPackedA4444(u16) * (1.0f/15);
127             break;
128         }
129         case kRGBA_8888_SkColorType:
130         case kBGRA_8888_SkColorType:
131             value = static_cast<const uint8_t*>(srcPtr)[3] * (1.0f/255);
132             break;
133         case kRGBA_1010102_SkColorType:
134         case kBGRA_1010102_SkColorType: {
135             uint32_t u32 = static_cast<const uint32_t*>(srcPtr)[0];
136             value = (u32 >> 30) * (1.0f/3);
137             break;
138         }
139         case kR16G16B16A16_unorm_SkColorType: {
140             uint64_t u64 = static_cast<const uint64_t*>(srcPtr)[0];
141             value = (u64 >> 48) * (1.0f/65535);
142             break;
143         }
144         case kRGBA_F16Norm_SkColorType:
145         case kRGBA_F16_SkColorType: {
146             uint64_t px;
147             memcpy(&px, srcPtr, sizeof(px));
148             value = SkHalfToFloat_finite_ftz(px)[3];
149             break;
150         }
151         case kRGBA_F32_SkColorType:
152             value = static_cast<const float*>(srcPtr)[3];
153             break;
154     }
155     return value;
156 }
157 
readPixels(const SkImageInfo & dstInfo,void * dstPixels,size_t dstRB,int x,int y) const158 bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
159                           int x, int y) const {
160     if (!SkImageInfoValidConversion(dstInfo, fInfo)) {
161         return false;
162     }
163 
164     SkReadPixelsRec rec(dstInfo, dstPixels, dstRB, x, y);
165     if (!rec.trim(fInfo.width(), fInfo.height())) {
166         return false;
167     }
168 
169     const void* srcPixels = this->addr(rec.fX, rec.fY);
170     const SkImageInfo srcInfo = fInfo.makeDimensions(rec.fInfo.dimensions());
171     return SkConvertPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, srcInfo, srcPixels,
172                            this->rowBytes());
173 }
174 
erase(SkColor color,const SkIRect & subset) const175 bool SkPixmap::erase(SkColor color, const SkIRect& subset) const {
176     return this->erase(SkColor4f::FromColor(color), &subset);
177 }
178 
erase(const SkColor4f & color,SkColorSpace * cs,const SkIRect * subset) const179 bool SkPixmap::erase(const SkColor4f& color, SkColorSpace* cs, const SkIRect* subset) const {
180     SkPaint paint;
181     paint.setBlendMode(SkBlendMode::kSrc);
182     paint.setColor4f(color, cs);
183 
184     SkIRect clip = this->bounds();
185     if (subset && !clip.intersect(*subset)) {
186         return false;
187     }
188     SkRasterClip rc{clip};
189 
190     SkDraw draw;
191     SkSimpleMatrixProvider matrixProvider(SkMatrix::I());
192     draw.fDst            = *this;
193     draw.fMatrixProvider = &matrixProvider;
194     draw.fRC             = &rc;
195 
196     draw.drawPaint(paint);
197     return true;
198 }
199 
scalePixels(const SkPixmap & actualDst,const SkSamplingOptions & sampling) const200 bool SkPixmap::scalePixels(const SkPixmap& actualDst, const SkSamplingOptions& sampling) const {
201     // We may need to tweak how we interpret these just a little below, so we make copies.
202     SkPixmap src = *this,
203              dst = actualDst;
204 
205     // Can't do anthing with empty src or dst
206     if (src.width() <= 0 || src.height() <= 0 ||
207         dst.width() <= 0 || dst.height() <= 0) {
208         return false;
209     }
210 
211     // no scaling involved?
212     if (src.width() == dst.width() && src.height() == dst.height()) {
213         return src.readPixels(dst);
214     }
215 
216     // If src and dst are both unpremul, we'll fake the source out to appear as if premul,
217     // and mark the destination as opaque.  This odd combination allows us to scale unpremul
218     // pixels without ever premultiplying them (perhaps losing information in the color channels).
219     // This is an idiosyncratic feature of scalePixels(), and is tested by scalepixels_unpremul GM.
220     bool clampAsIfUnpremul = false;
221     if (src.alphaType() == kUnpremul_SkAlphaType &&
222         dst.alphaType() == kUnpremul_SkAlphaType) {
223         src.reset(src.info().makeAlphaType(kPremul_SkAlphaType), src.addr(), src.rowBytes());
224         dst.reset(dst.info().makeAlphaType(kOpaque_SkAlphaType), dst.addr(), dst.rowBytes());
225 
226         // We'll need to tell the image shader to clamp to [0,1] instead of the
227         // usual [0,a] when using a bicubic scaling (kHigh_SkFilterQuality).
228         clampAsIfUnpremul = true;
229     }
230 
231     SkBitmap bitmap;
232     if (!bitmap.installPixels(src)) {
233         return false;
234     }
235     bitmap.setImmutable();        // Don't copy when we create an image.
236 
237     SkMatrix scale = SkMatrix::RectToRect(SkRect::Make(src.bounds()), SkRect::Make(dst.bounds()));
238 
239     sk_sp<SkShader> shader = SkImageShader::Make(bitmap.asImage(),
240                                                  SkTileMode::kClamp,
241                                                  SkTileMode::kClamp,
242                                                  sampling,
243                                                  &scale,
244                                                  clampAsIfUnpremul);
245 
246     sk_sp<SkSurface> surface = SkSurface::MakeRasterDirect(dst.info(),
247                                                            dst.writable_addr(),
248                                                            dst.rowBytes());
249     if (!shader || !surface) {
250         return false;
251     }
252 
253     SkPaint paint;
254     paint.setBlendMode(SkBlendMode::kSrc);
255     paint.setShader(std::move(shader));
256     surface->getCanvas()->drawPaint(paint);
257     return true;
258 }
259 
260 //////////////////////////////////////////////////////////////////////////////////////////////////
261 
getColor(int x,int y) const262 SkColor SkPixmap::getColor(int x, int y) const {
263     SkASSERT(this->addr());
264     SkASSERT((unsigned)x < (unsigned)this->width());
265     SkASSERT((unsigned)y < (unsigned)this->height());
266 
267     const bool needsUnpremul = (kPremul_SkAlphaType == fInfo.alphaType());
268     auto toColor = [needsUnpremul](uint32_t maybePremulColor) {
269         return needsUnpremul ? SkUnPreMultiply::PMColorToColor(maybePremulColor)
270                              : SkSwizzle_BGRA_to_PMColor(maybePremulColor);
271     };
272 
273     switch (this->colorType()) {
274         case kGray_8_SkColorType: {
275             uint8_t value = *this->addr8(x, y);
276             return SkColorSetRGB(value, value, value);
277         }
278         case kAlpha_8_SkColorType: {
279             return SkColorSetA(0, *this->addr8(x, y));
280         }
281         case kA16_unorm_SkColorType: {
282             uint16_t value = *this->addr16(x, y);
283             return SkColorSetA(0, value * (255 / 65535.0f));
284         }
285         case kA16_float_SkColorType: {
286             SkHalf value = *this->addr16(x, y);
287             return SkColorSetA(0, 255 * SkHalfToFloat(value));
288         }
289         case kRGB_565_SkColorType: {
290             return SkPixel16ToColor(*this->addr16(x, y));
291         }
292         case kARGB_4444_SkColorType: {
293             uint16_t value = *this->addr16(x, y);
294             SkPMColor c = SkPixel4444ToPixel32(value);
295             return toColor(c);
296         }
297         case kR8G8_unorm_SkColorType: {
298             uint16_t value = *this->addr16(x, y);
299             return (uint32_t)( ((value >>  0) & 0xff) ) << 16
300                  | (uint32_t)( ((value >>  8) & 0xff) ) <<  8
301                  | 0xff000000;
302         }
303         case kR16G16_unorm_SkColorType: {
304             uint32_t value = *this->addr32(x, y);
305             return (uint32_t)( ((value >>  0) & 0xffff) * (255/65535.0f) ) << 16
306                  | (uint32_t)( ((value >> 16) & 0xffff) * (255/65535.0f) ) <<  8
307                  | 0xff000000;
308         }
309         case kR16G16_float_SkColorType: {
310             uint32_t value = *this->addr32(x, y);
311             uint32_t r = 255 * SkHalfToFloat((value >>  0) & 0xffff);
312             uint32_t g = 255 * SkHalfToFloat((value >> 16) & 0xffff);
313             return (r << 16) | (g << 8) | 0xff000000;
314         }
315         case kRGB_888x_SkColorType: {
316             uint32_t value = *this->addr32(x, y);
317             return SkSwizzle_RB(value | 0xff000000);
318         }
319         case kBGRA_8888_SkColorType: {
320             uint32_t value = *this->addr32(x, y);
321             SkPMColor c = SkSwizzle_BGRA_to_PMColor(value);
322             return toColor(c);
323         }
324         case kRGBA_8888_SkColorType: {
325             uint32_t value = *this->addr32(x, y);
326             SkPMColor c = SkSwizzle_RGBA_to_PMColor(value);
327             return toColor(c);
328         }
329         case kRGB_101010x_SkColorType: {
330             uint32_t value = *this->addr32(x, y);
331             // Convert 10-bit rgb to 8-bit bgr, and mask in 0xff alpha at the top.
332             return (uint32_t)( ((value >>  0) & 0x3ff) * (255/1023.0f) ) << 16
333                  | (uint32_t)( ((value >> 10) & 0x3ff) * (255/1023.0f) ) <<  8
334                  | (uint32_t)( ((value >> 20) & 0x3ff) * (255/1023.0f) ) <<  0
335                  | 0xff000000;
336         }
337         case kBGR_101010x_SkColorType: {
338             uint32_t value = *this->addr32(x, y);
339             // Convert 10-bit bgr to 8-bit bgr, and mask in 0xff alpha at the top.
340             return (uint32_t)( ((value >>  0) & 0x3ff) * (255/1023.0f) ) <<  0
341                  | (uint32_t)( ((value >> 10) & 0x3ff) * (255/1023.0f) ) <<  8
342                  | (uint32_t)( ((value >> 20) & 0x3ff) * (255/1023.0f) ) << 16
343                  | 0xff000000;
344         }
345         case kRGBA_1010102_SkColorType:
346         case kBGRA_1010102_SkColorType: {
347             uint32_t value = *this->addr32(x, y);
348 
349             float r = ((value >>  0) & 0x3ff) * (1/1023.0f),
350                   g = ((value >> 10) & 0x3ff) * (1/1023.0f),
351                   b = ((value >> 20) & 0x3ff) * (1/1023.0f),
352                   a = ((value >> 30) & 0x3  ) * (1/   3.0f);
353             if (this->colorType() == kBGRA_1010102_SkColorType) {
354                 std::swap(r,b);
355             }
356             if (a != 0 && needsUnpremul) {
357                 r = SkTPin(r/a, 0.0f, 1.0f);
358                 g = SkTPin(g/a, 0.0f, 1.0f);
359                 b = SkTPin(b/a, 0.0f, 1.0f);
360             }
361             return (uint32_t)( r * 255.0f ) << 16
362                  | (uint32_t)( g * 255.0f ) <<  8
363                  | (uint32_t)( b * 255.0f ) <<  0
364                  | (uint32_t)( a * 255.0f ) << 24;
365         }
366         case kR16G16B16A16_unorm_SkColorType: {
367             uint64_t value = *this->addr64(x, y);
368 
369             float r = ((value      ) & 0xffff) * (1/65535.0f),
370                   g = ((value >> 16) & 0xffff) * (1/65535.0f),
371                   b = ((value >> 32) & 0xffff) * (1/65535.0f),
372                   a = ((value >> 48) & 0xffff) * (1/65535.0f);
373             if (a != 0 && needsUnpremul) {
374                 r *= (1.0f/a);
375                 g *= (1.0f/a);
376                 b *= (1.0f/a);
377             }
378             return (uint32_t)( r * 255.0f ) << 16
379                  | (uint32_t)( g * 255.0f ) <<  8
380                  | (uint32_t)( b * 255.0f ) <<  0
381                  | (uint32_t)( a * 255.0f ) << 24;
382         }
383         case kRGBA_F16Norm_SkColorType:
384         case kRGBA_F16_SkColorType: {
385             const uint64_t* addr =
386                 (const uint64_t*)fPixels + y * (fRowBytes >> 3) + x;
387             Sk4f p4 = SkHalfToFloat_finite_ftz(*addr);
388             if (p4[3] && needsUnpremul) {
389                 float inva = 1 / p4[3];
390                 p4 = p4 * Sk4f(inva, inva, inva, 1);
391             }
392             SkColor c;
393             SkNx_cast<uint8_t>(p4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
394             // p4 is RGBA, but we want BGRA, so we need to swap next
395             return SkSwizzle_RB(c);
396         }
397         case kRGBA_F32_SkColorType: {
398             const float* rgba =
399                 (const float*)fPixels + 4*y*(fRowBytes >> 4) + 4*x;
400             Sk4f p4 = Sk4f::Load(rgba);
401             // From here on, just like F16:
402             if (p4[3] && needsUnpremul) {
403                 float inva = 1 / p4[3];
404                 p4 = p4 * Sk4f(inva, inva, inva, 1);
405             }
406             SkColor c;
407             SkNx_cast<uint8_t>(p4 * Sk4f(255) + Sk4f(0.5f)).store(&c);
408             // p4 is RGBA, but we want BGRA, so we need to swap next
409             return SkSwizzle_RB(c);
410         }
411         case kUnknown_SkColorType:
412             break;
413     }
414     SkDEBUGFAIL("");
415     return SkColorSetARGB(0, 0, 0, 0);
416 }
417 
computeIsOpaque() const418 bool SkPixmap::computeIsOpaque() const {
419     const int height = this->height();
420     const int width = this->width();
421 
422     switch (this->colorType()) {
423         case kAlpha_8_SkColorType: {
424             unsigned a = 0xFF;
425             for (int y = 0; y < height; ++y) {
426                 const uint8_t* row = this->addr8(0, y);
427                 for (int x = 0; x < width; ++x) {
428                     a &= row[x];
429                 }
430                 if (0xFF != a) {
431                     return false;
432                 }
433             }
434             return true;
435         }
436         case kA16_unorm_SkColorType: {
437             unsigned a = 0xFFFF;
438             for (int y = 0; y < height; ++y) {
439                 const uint16_t* row = this->addr16(0, y);
440                 for (int x = 0; x < width; ++x) {
441                     a &= row[x];
442                 }
443                 if (0xFFFF != a) {
444                     return false;
445                 }
446             }
447             return true;
448         }
449         case kA16_float_SkColorType: {
450             for (int y = 0; y < height; ++y) {
451                 const SkHalf* row = this->addr16(0, y);
452                 for (int x = 0; x < width; ++x) {
453                     if (row[x] < SK_Half1) {
454                         return false;
455                     }
456                 }
457             }
458             return true;
459         }
460         case kRGB_565_SkColorType:
461         case kGray_8_SkColorType:
462         case kR8G8_unorm_SkColorType:
463         case kR16G16_unorm_SkColorType:
464         case kR16G16_float_SkColorType:
465         case kRGB_888x_SkColorType:
466         case kRGB_101010x_SkColorType:
467         case kBGR_101010x_SkColorType:
468             return true;
469             break;
470         case kARGB_4444_SkColorType: {
471             unsigned c = 0xFFFF;
472             for (int y = 0; y < height; ++y) {
473                 const SkPMColor16* row = this->addr16(0, y);
474                 for (int x = 0; x < width; ++x) {
475                     c &= row[x];
476                 }
477                 if (0xF != SkGetPackedA4444(c)) {
478                     return false;
479                 }
480             }
481             return true;
482         }
483         case kBGRA_8888_SkColorType:
484         case kRGBA_8888_SkColorType: {
485             SkPMColor c = (SkPMColor)~0;
486             for (int y = 0; y < height; ++y) {
487                 const SkPMColor* row = this->addr32(0, y);
488                 for (int x = 0; x < width; ++x) {
489                     c &= row[x];
490                 }
491                 if (0xFF != SkGetPackedA32(c)) {
492                     return false;
493                 }
494             }
495             return true;
496         }
497         case kRGBA_F16Norm_SkColorType:
498         case kRGBA_F16_SkColorType: {
499             const SkHalf* row = (const SkHalf*)this->addr();
500             for (int y = 0; y < height; ++y) {
501                 for (int x = 0; x < width; ++x) {
502                     if (row[4 * x + 3] < SK_Half1) {
503                         return false;
504                     }
505                 }
506                 row += this->rowBytes() >> 1;
507             }
508             return true;
509         }
510         case kRGBA_F32_SkColorType: {
511             const float* row = (const float*)this->addr();
512             for (int y = 0; y < height; ++y) {
513                 for (int x = 0; x < width; ++x) {
514                     if (row[4 * x + 3] < 1.0f) {
515                         return false;
516                     }
517                 }
518                 row += this->rowBytes() >> 2;
519             }
520             return true;
521         }
522         case kRGBA_1010102_SkColorType:
523         case kBGRA_1010102_SkColorType: {
524             uint32_t c = ~0;
525             for (int y = 0; y < height; ++y) {
526                 const uint32_t* row = this->addr32(0, y);
527                 for (int x = 0; x < width; ++x) {
528                     c &= row[x];
529                 }
530                 if (0b11 != c >> 30) {
531                     return false;
532                 }
533             }
534             return true;
535         }
536         case kR16G16B16A16_unorm_SkColorType: {
537             uint16_t acc = 0xFFFF;
538             for (int y = 0; y < height; ++y) {
539                 const uint64_t* row = this->addr64(0, y);
540                 for (int x = 0; x < width; ++x) {
541                     acc &= (row[x] >> 48);
542                 }
543                 if (0xFFFF != acc) {
544                     return false;
545                 }
546             }
547             return true;
548         }
549         case kUnknown_SkColorType:
550             SkDEBUGFAIL("");
551             break;
552     }
553     return false;
554 }
555 
556 //////////////////////////////////////////////////////////////////////////////////////////////////
557 
draw_orientation(const SkPixmap & dst,const SkPixmap & src,SkEncodedOrigin origin)558 static bool draw_orientation(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin) {
559     auto surf = SkSurface::MakeRasterDirect(dst.info(), dst.writable_addr(), dst.rowBytes());
560     if (!surf) {
561         return false;
562     }
563 
564     SkBitmap bm;
565     bm.installPixels(src);
566 
567     SkMatrix m = SkEncodedOriginToMatrix(origin, dst.width(), dst.height());
568 
569     SkPaint p;
570     p.setBlendMode(SkBlendMode::kSrc);
571     surf->getCanvas()->concat(m);
572     surf->getCanvas()->drawImage(SkImage::MakeFromBitmap(bm), 0, 0, SkSamplingOptions(), &p);
573     return true;
574 }
575 
Orient(const SkPixmap & dst,const SkPixmap & src,SkEncodedOrigin origin)576 bool SkPixmapPriv::Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin) {
577     if (src.colorType() != dst.colorType()) {
578         return false;
579     }
580     // note: we just ignore alphaType and colorSpace for this transformation
581 
582     int w = src.width();
583     int h = src.height();
584     if (SkEncodedOriginSwapsWidthHeight(origin)) {
585         using std::swap;
586         swap(w, h);
587     }
588     if (dst.width() != w || dst.height() != h) {
589         return false;
590     }
591     if (w == 0 || h == 0) {
592         return true;
593     }
594 
595     // check for aliasing to self
596     if (src.addr() == dst.addr()) {
597         return kTopLeft_SkEncodedOrigin == origin;
598     }
599     return draw_orientation(dst, src, origin);
600 }
601 
SwapWidthHeight(const SkImageInfo & info)602 SkImageInfo SkPixmapPriv::SwapWidthHeight(const SkImageInfo& info) {
603     return info.makeWH(info.height(), info.width());
604 }
605 
606