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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // We consider incomplete to be valid, since we should still decode what is | 134 // We consider incomplete to be valid, since we should still decode what is |
135 // available. | 135 // available. |
136 case SkImageGenerator::kIncompleteInput: | 136 case SkImageGenerator::kIncompleteInput: |
137 break; | 137 break; |
138 case SkImageGenerator::kInvalidConversion: | 138 case SkImageGenerator::kInvalidConversion: |
139 return Error::Nonfatal("Incompatible colortype conversion"); | 139 return Error::Nonfatal("Incompatible colortype conversion"); |
140 default: | 140 default: |
141 // Everything else is considered a failure. | 141 // Everything else is considered a failure. |
142 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | 142 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); |
143 } | 143 } |
144 canvas->drawBitmap(bitmap, 0, 0); | |
144 break; | 145 break; |
145 case kScanline_Mode: { | 146 case kScanline_Mode: { |
146 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL, | 147 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL, |
147 colorPtr, colorCountPtr); | 148 colorPtr, colorCountPtr); |
148 if (NULL == scanlineDecoder) { | 149 if (NULL == scanlineDecoder) { |
149 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | 150 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); |
150 } | 151 } |
151 for (int y = 0; y < decodeInfo.height(); ++y) { | 152 for (int y = 0; y < decodeInfo.height(); ++y) { |
152 const SkImageGenerator::Result result = scanlineDecoder->getScan lines( | 153 const SkImageGenerator::Result result = scanlineDecoder->getScan lines( |
153 bitmap.getAddr(0, y), 1, 0); | 154 bitmap.getAddr(0, y), 1, 0); |
154 switch (result) { | 155 switch (result) { |
155 case SkImageGenerator::kSuccess: | 156 case SkImageGenerator::kSuccess: |
156 case SkImageGenerator::kIncompleteInput: | 157 case SkImageGenerator::kIncompleteInput: |
157 break; | 158 break; |
158 default: | 159 default: |
159 return SkStringPrintf("%s failed after %d scanlines with error message %d", | 160 return SkStringPrintf("%s failed after %d scanlines with error message %d", |
160 fPath.c_str(), y-1, (int) result); | 161 fPath.c_str(), y-1, (int) result); |
161 } | 162 } |
162 } | 163 } |
164 canvas->drawBitmap(bitmap, 0, 0); | |
165 break; | |
166 } | |
167 case kSubset_Mode: { | |
168 //this mode decodes the image in divisor*divisor subsets, using a sc anline decoder | |
169 const int divisor = 2; | |
170 SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlineDecoder (decodeInfo, NULL, | |
171 colorPtr, colorCountPtr); | |
172 if (NULL == subsetScanlineDecoder) { | |
173 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | |
174 } | |
175 SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(decodeInfo.width()/ divisor, | |
176 decodeInfo.height()/divisor); | |
177 SkBitmap subsetBm; | |
178 if (!subsetBm.tryAllocPixels(subsetDecodeInfo, NULL, colorTable.get( ))) { | |
179 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | |
180 subsetDecodeInfo.width(), subsetDecodeInfo.height()); | |
181 } | |
182 char* line = new char[decodeInfo.width()*decodeInfo.bytesPerPixel()] ; | |
msarett
2015/05/19 14:01:13
nit: Let's check with Leon, but I think the prefer
scroggo
2015/05/19 15:21:41
The short answer is yes.
A little background: we
emmaleer
2015/05/21 17:51:13
Acknowledged.
| |
183 SkAutoTDeleteArray<char> lineDeleter(line); | |
184 const int subsetWidth = subsetDecodeInfo.width(); | |
185 const int subsetHeight = subsetDecodeInfo.height(); | |
186 const int w = subsetWidth*divisor; | |
scroggo
2015/05/18 23:02:17
I think it would be better to use decodeInfo.width
msarett
2015/05/19 14:01:13
I think this is the tricky part of this test. If
scroggo
2015/05/19 15:21:41
Indeed. We need to investigate how exactly BitmapR
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
| |
187 const int h = subsetHeight*divisor; | |
188 if (divisor > w || divisor > h) { | |
189 return SkStringPrintf("divisor %d is too big for %s with dimensi ons (%d x %d)", | |
190 divisor, fPath.c_str(), w, h); | |
191 } | |
192 for (int x = 0; x < w; x += subsetWidth) { | |
193 for (int y = 0; y < h; y += subsetHeight) { | |
194 for (int subsetY = 0; subsetY < subsetHeight; ++subsetY) { | |
msarett
2015/05/19 14:01:13
My preference is to use a different scanline decod
scroggo
2015/05/19 15:21:41
Good questions. I think it's reasonable to use a n
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
| |
195 const SkImageGenerator::Result subsetResult = | |
196 subsetScanlineDecoder->getScanlines(line, 1, 0); | |
msarett
2015/05/19 14:01:13
I'm a little confused about how this works. It lo
scroggo
2015/05/19 15:21:41
I missed this at first, too - at the end of the y
emmaleer
2015/05/21 17:51:13
On 2015/05/19 15:21:41, scroggo wrote:
> On 2015/0
| |
197 //copy section of line based on x value | |
198 memcpy(subsetBm.getAddr(0, subsetY), | |
199 line + x*subsetDecodeInfo.bytesPerPixel(), | |
200 subsetDecodeInfo.width()*subsetDecodeInfo.bytesP erPixel()); | |
201 switch (subsetResult) { | |
202 case SkImageGenerator::kSuccess: | |
203 case SkImageGenerator::kIncompleteInput: | |
204 break; | |
205 default: | |
206 return SkStringPrintf("%s failed after %d scanli nes with error" | |
207 "message %d", fPath.c_str(), y-1, (int) subsetResult); | |
208 } | |
209 } | |
210 canvas->drawBitmap(subsetBm, x, y); | |
211 } | |
212 subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo, NU LL, | |
213 colorPtr, colorCountPtr); | |
214 if (NULL == subsetScanlineDecoder) { | |
215 return SkStringPrintf("Error scanline decoder is NULL"); | |
scroggo
2015/05/18 23:02:17
No need for SkStringPrintf. You're returning an Er
| |
216 } | |
217 } | |
163 break; | 218 break; |
164 } | 219 } |
165 } | 220 } |
166 canvas->drawBitmap(bitmap, 0, 0); | |
167 return ""; | 221 return ""; |
168 } | 222 } |
169 | 223 |
170 SkISize CodecSrc::size() const { | 224 SkISize CodecSrc::size() const { |
171 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 225 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
172 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 226 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
173 if (NULL != codec) { | 227 if (NULL != codec) { |
174 return codec->getInfo().dimensions(); | 228 return codec->getInfo().dimensions(); |
175 } else { | 229 } else { |
176 return SkISize::Make(0, 0); | 230 return SkISize::Make(0, 0); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 skr.visit<void>(i, drawsAsSingletonPictures); | 834 skr.visit<void>(i, drawsAsSingletonPictures); |
781 } | 835 } |
782 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 836 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
783 | 837 |
784 canvas->drawPicture(macroPic); | 838 canvas->drawPicture(macroPic); |
785 return ""; | 839 return ""; |
786 }); | 840 }); |
787 } | 841 } |
788 | 842 |
789 } // namespace DM | 843 } // namespace DM |
OLD | NEW |