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()] ; | |
183 SkAutoTDeleteArray<char> lineDeleter(line); | |
184 for (int subset = 0; subset < divisor*divisor; subset++) { | |
185 //reset scanline decoder for right half of image | |
186 if (0 == subset%divisor && 0 != subset) { | |
scroggo
2015/05/18 20:43:18
Alternatively, you could remove the second half of
| |
187 subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo , NULL, | |
188 colorPtr, colorCountPtr); | |
189 } | |
190 int x; | |
191 int y; | |
192 //set drawing position based on subset number | |
193 if(subset == 0) { | |
194 //first subset, draw to top left corner | |
195 x = 0; | |
196 y = 0; | |
197 } else if (0 == subset%divisor) { | |
198 //new column, reset y, increment x by subset width | |
199 x += subsetDecodeInfo.width(); | |
200 y = 0; | |
201 } else { | |
202 //new row, increment y by subset height | |
203 y += subsetDecodeInfo.height(); | |
204 } | |
205 for (int y = 0; y < subsetDecodeInfo.height(); ++y) { | |
206 const SkImageGenerator::Result subsetResult = | |
207 subsetScanlineDecoder->getScanlines(line, 1, 0); | |
208 //copy section of line based on x value | |
209 memcpy(subsetBm.getAddr(0, y), line + x*subsetDecodeInfo .bytesPerPixel(), | |
210 subsetDecodeInfo.width()*subsetDecodeInfo.bytesP erPixel()); | |
211 switch (subsetResult) { | |
212 case SkImageGenerator::kSuccess: | |
213 case SkImageGenerator::kIncompleteInput: | |
214 break; | |
215 default: | |
216 return SkStringPrintf("%s failed after %d scanlines with error" | |
217 "message %d", fPath.c_str(), y-1, (int) subs etResult); | |
218 } | |
219 } | |
220 canvas->drawBitmap(subsetBm, x, y); | |
221 } | |
163 break; | 222 break; |
164 } | 223 } |
165 } | 224 } |
166 canvas->drawBitmap(bitmap, 0, 0); | |
167 return ""; | 225 return ""; |
168 } | 226 } |
169 | 227 |
170 SkISize CodecSrc::size() const { | 228 SkISize CodecSrc::size() const { |
171 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 229 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
172 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 230 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
173 if (NULL != codec) { | 231 if (NULL != codec) { |
174 return codec->getInfo().dimensions(); | 232 return codec->getInfo().dimensions(); |
175 } else { | 233 } else { |
176 return SkISize::Make(0, 0); | 234 return SkISize::Make(0, 0); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 skr.visit<void>(i, drawsAsSingletonPictures); | 838 skr.visit<void>(i, drawsAsSingletonPictures); |
781 } | 839 } |
782 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 840 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
783 | 841 |
784 canvas->drawPicture(macroPic); | 842 canvas->drawPicture(macroPic); |
785 return ""; | 843 return ""; |
786 }); | 844 }); |
787 } | 845 } |
788 | 846 |
789 } // namespace DM | 847 } // namespace DM |
OLD | NEW |