OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkImageInfo.h" | 8 #include "SkImageInfo.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 alphaType = kOpaque_SkAlphaType; | 69 alphaType = kOpaque_SkAlphaType; |
70 break; | 70 break; |
71 default: | 71 default: |
72 return false; | 72 return false; |
73 } | 73 } |
74 if (canonical) { | 74 if (canonical) { |
75 *canonical = alphaType; | 75 *canonical = alphaType; |
76 } | 76 } |
77 return true; | 77 return true; |
78 } | 78 } |
| 79 |
| 80 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 81 |
| 82 #include "SkReadPixelsRec.h" |
| 83 |
| 84 bool SkReadPixelsRec::trim(int srcWidth, int srcHeight) { |
| 85 switch (fInfo.colorType()) { |
| 86 case kUnknown_SkColorType: |
| 87 case kIndex_8_SkColorType: |
| 88 return false; |
| 89 default: |
| 90 break; |
| 91 } |
| 92 if (NULL == fPixels || fRowBytes < fInfo.minRowBytes()) { |
| 93 return false; |
| 94 } |
| 95 if (0 == fInfo.width() || 0 == fInfo.height()) { |
| 96 return false; |
| 97 } |
| 98 |
| 99 int x = fX; |
| 100 int y = fY; |
| 101 SkIRect srcR = SkIRect::MakeXYWH(x, y, fInfo.width(), fInfo.height()); |
| 102 if (!srcR.intersect(0, 0, srcWidth, srcHeight)) { |
| 103 return false; |
| 104 } |
| 105 |
| 106 // if x or y are negative, then we have to adjust pixels |
| 107 if (x > 0) { |
| 108 x = 0; |
| 109 } |
| 110 if (y > 0) { |
| 111 y = 0; |
| 112 } |
| 113 // here x,y are either 0 or negative |
| 114 fPixels = ((char*)fPixels - y * fRowBytes - x * fInfo.bytesPerPixel()); |
| 115 // the intersect may have shrunk info's logical size |
| 116 fInfo = fInfo.makeWH(srcR.width(), srcR.height()); |
| 117 fX = srcR.x(); |
| 118 fY = srcR.y(); |
| 119 |
| 120 return true; |
| 121 } |
| 122 |
OLD | NEW |