Chromium Code Reviews| 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 kScanline_Subset_Mode: { | |
| 168 //this mode decodes the image in divisor*divisor subsets, using a sc anline decoder | |
| 169 const int divisor = 2; | |
| 170 const int w = decodeInfo.width(); | |
| 171 const int h = decodeInfo.height(); | |
| 172 const int subsetWidth = decodeInfo.width()/divisor; | |
|
scroggo
2015/05/21 19:32:35
nit: From here on you could use w and h instead of
| |
| 173 const int subsetHeight = decodeInfo.height()/divisor; | |
| 174 SkImageInfo subsetDecodeInfo = | |
|
scroggo
2015/05/21 19:32:36
I think these names might be a little misleading.
emmaleeroach
2015/05/21 22:17:24
Acknowledged.
| |
| 175 decodeInfo.makeWH(subsetWidth + decodeInfo.width()%divisor, | |
|
scroggo
2015/05/21 19:32:36
Please add a comment that explains why we're addin
| |
| 176 subsetHeight + decodeInfo.height()%divisor); | |
| 177 SkBitmap subsetBm; | |
| 178 if (!subsetBm.tryAllocPixels(subsetDecodeInfo, NULL, colorTable.get( ))) { | |
|
scroggo
2015/05/21 19:32:35
I don't think you need this. This will set subsetB
emmaleeroach
2015/05/21 22:17:24
Acknowledged.
| |
| 179 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | |
| 180 subsetDecodeInfo.width(), subsetDecodeInfo.height()); | |
| 181 } | |
| 182 SkBitmap largestSubsetBm; | |
| 183 if (!largestSubsetBm.tryAllocPixels(subsetDecodeInfo, NULL, colorTab le.get())) { | |
| 184 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | |
| 185 subsetDecodeInfo.width(), subsetDecodeInfo.height()); | |
| 186 } | |
| 187 char* line = SkNEW_ARRAY(char, decodeInfo.width()*decodeInfo.bytesPe rPixel()); | |
|
scroggo
2015/05/21 19:32:35
FYI: You could instead use decodeInfo.minRowBytes(
| |
| 188 SkAutoTDeleteArray<char> lineDeleter(line); | |
| 189 SkIRect bounds = SkIRect::MakeWH(subsetWidth, subsetHeight); | |
| 190 //used if image w and h are not evenly divided by divisor | |
| 191 int extrax = 0; | |
|
scroggo
2015/05/21 19:32:36
nit: extraX (camelCase)
| |
| 192 int extray = 0; | |
| 193 if (divisor > w || divisor > h) { | |
|
scroggo
2015/05/21 19:32:35
This probably belongs closer to the beginning, rig
| |
| 194 return SkStringPrintf("divisor %d is too big for %s with dimensi ons (%d x %d)", | |
| 195 divisor, fPath.c_str(), w, h); | |
| 196 } | |
| 197 for (int x = 0; x < subsetWidth*divisor; x += subsetWidth) { | |
| 198 //consider extrax for rightmost subset | |
| 199 if (x + 2*subsetWidth > w) { | |
| 200 extrax = w - subsetWidth*divisor; | |
| 201 } | |
| 202 for (int y = 0; y < subsetHeight*divisor; y += subsetHeight) { | |
| 203 //consider extray for bottom subset | |
| 204 if (y + 2*subsetHeight > h) { | |
| 205 extray = h - subsetHeight*divisor; | |
| 206 } | |
| 207 //create scanline decoder for each subset | |
| 208 SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlin eDecoder(decodeInfo, | |
| 209 NULL, colorPtr, colorCountPtr); | |
| 210 if (NULL == subsetScanlineDecoder) { | |
| 211 return Error::Nonfatal("Cannot use scanline decoder for all images"); | |
|
scroggo
2015/05/21 19:32:36
This is good for the first time through the loop,
emmaleeroach
2015/05/21 22:17:24
Acknowledged.
| |
| 212 } | |
| 213 //skip to first line of subset | |
| 214 const SkImageGenerator::Result skipResult = | |
| 215 subsetScanlineDecoder->skipScanlines(y); | |
| 216 switch (skipResult) { | |
| 217 case SkImageGenerator::kSuccess: | |
| 218 case SkImageGenerator::kIncompleteInput: | |
| 219 break; | |
| 220 default: | |
| 221 return SkStringPrintf("%s failed after skipping %d s canlines with" | |
|
scroggo
2015/05/21 19:32:36
Maybe rephrase this: y-1 is not the number of scan
emmaleeroach
2015/05/21 22:17:24
Acknowledged.
| |
| 222 "error message %d", fPath.c_str(), y-1, (int ) skipResult); | |
| 223 } | |
| 224 //set size of subsetBm | |
| 225 bounds.setXYWH(0, 0, subsetWidth + extrax, subsetHeight + ex tray); | |
|
scroggo
2015/05/21 19:32:35
This is always the size of subsetBm, right? Can yo
emmaleeroach
2015/05/21 22:17:24
On 2015/05/21 19:32:35, scroggo wrote:
> This is a
| |
| 226 largestSubsetBm.extractSubset(&subsetBm, bounds); | |
|
scroggo
2015/05/21 19:32:36
Try to declare variables just before they're used.
emmaleeroach
2015/05/21 22:17:24
Acknowledged.
| |
| 227 SkAutoLockPixels autlockSubsetBm(subsetBm, true); | |
| 228 for (int subsetY = 0; subsetY < subsetHeight + extray; ++sub setY) { | |
| 229 const SkImageGenerator::Result subsetResult = | |
| 230 subsetScanlineDecoder->getScanlines(line, 1, 0); | |
| 231 //copy section of line based on x value | |
| 232 memcpy(subsetBm.getAddr(0, subsetY), | |
| 233 line + x*subsetDecodeInfo.bytesPerPixel(), | |
| 234 (subsetWidth + extrax)*subsetDecodeInfo.bytesPer Pixel()); | |
|
scroggo
2015/05/21 19:32:36
I wonder if it would be cleaner to define new vari
emmaleeroach
2015/05/21 22:17:24
On 2015/05/21 19:32:36, scroggo wrote:
> I wonder
| |
| 235 switch (subsetResult) { | |
| 236 case SkImageGenerator::kSuccess: | |
| 237 case SkImageGenerator::kIncompleteInput: | |
| 238 break; | |
| 239 default: | |
| 240 return SkStringPrintf("%s failed after %d scanli nes with error" | |
| 241 "message %d", fPath.c_str(), y-1, (int) subsetResult); | |
| 242 } | |
| 243 } | |
| 244 canvas->drawBitmap(subsetBm, x, y); | |
| 245 } | |
| 246 extray = 0; | |
| 247 } | |
| 163 break; | 248 break; |
| 164 } | 249 } |
| 165 } | 250 } |
| 166 canvas->drawBitmap(bitmap, 0, 0); | |
| 167 return ""; | 251 return ""; |
| 168 } | 252 } |
| 169 | 253 |
| 170 SkISize CodecSrc::size() const { | 254 SkISize CodecSrc::size() const { |
| 171 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 255 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 172 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 256 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 173 if (NULL != codec) { | 257 if (NULL != codec) { |
| 174 return codec->getInfo().dimensions(); | 258 return codec->getInfo().dimensions(); |
| 175 } else { | 259 } else { |
| 176 return SkISize::Make(0, 0); | 260 return SkISize::Make(0, 0); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 skr.visit<void>(i, drawsAsSingletonPictures); | 864 skr.visit<void>(i, drawsAsSingletonPictures); |
| 781 } | 865 } |
| 782 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 866 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 783 | 867 |
| 784 canvas->drawPicture(macroPic); | 868 canvas->drawPicture(macroPic); |
| 785 return ""; | 869 return ""; |
| 786 }); | 870 }); |
| 787 } | 871 } |
| 788 | 872 |
| 789 } // namespace DM | 873 } // namespace DM |
| OLD | NEW |