Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: src/core/SkImageInfo.cpp

Issue 793723002: add readPixels to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/image/SkImage.cpp » ('j') | tests/SurfaceTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698