| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 canvas->drawBitmap(bitmap, 0, 0); | 177 canvas->drawBitmap(bitmap, 0, 0); |
| 178 break; | 178 break; |
| 179 } | 179 } |
| 180 case kScanline_Subset_Mode: { | 180 case kScanline_Subset_Mode: { |
| 181 //this mode decodes the image in divisor*divisor subsets, using a sc
anline decoder | 181 //this mode decodes the image in divisor*divisor subsets, using a sc
anline decoder |
| 182 const int divisor = 2; | 182 const int divisor = 2; |
| 183 const int w = decodeInfo.width(); | 183 const int w = decodeInfo.width(); |
| 184 const int h = decodeInfo.height(); | 184 const int h = decodeInfo.height(); |
| 185 if (w*h == 1) { | |
| 186 return Error::Nonfatal("Subset decoding not supported."); | |
| 187 } | |
| 188 if (divisor > w || divisor > h) { | 185 if (divisor > w || divisor > h) { |
| 189 return SkStringPrintf("divisor %d is too big for %s with dimensi
ons (%d x %d)", | 186 return Error::Nonfatal(SkStringPrintf("Cannot decode subset: div
isor %d is too big" |
| 190 divisor, fPath.c_str(), w, h); | 187 "for %s with dimensions (%d x %d)", divisor, fPath.c_str
(), w, h)); |
| 191 } | 188 } |
| 192 const int subsetWidth = w/divisor; | 189 const int subsetWidth = w/divisor; |
| 193 const int subsetHeight = h/divisor; | 190 const int subsetHeight = h/divisor; |
| 194 // One of our subsets will be larger to contain any pixels that do n
ot divide evenly. | 191 // One of our subsets will be larger to contain any pixels that do n
ot divide evenly. |
| 195 const int extraX = w % divisor; | 192 const int extraX = w % divisor; |
| 196 const int extraY = h % divisor; | 193 const int extraY = h % divisor; |
| 197 /* | 194 /* |
| 198 * if w or h are not evenly divided by divisor need to adjust width a
nd height of end | 195 * if w or h are not evenly divided by divisor need to adjust width a
nd height of end |
| 199 * subsets to cover entire image. | 196 * subsets to cover entire image. |
| 200 * Add extraX and extraY to largestSubsetBm's width and height to adj
ust width | 197 * Add extraX and extraY to largestSubsetBm's width and height to adj
ust width |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 return ""; | 397 return ""; |
| 401 } | 398 } |
| 402 // Decode subsets. This is a little involved. | 399 // Decode subsets. This is a little involved. |
| 403 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 400 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| 404 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; | 401 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; |
| 405 if (!decoder) { | 402 if (!decoder) { |
| 406 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); | 403 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); |
| 407 } | 404 } |
| 408 stream->rewind(); | 405 stream->rewind(); |
| 409 int w,h; | 406 int w,h; |
| 410 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) { | 407 if (!decoder->buildTileIndex(stream.detach(), &w, &h)) { |
| 411 return Error::Nonfatal("Subset decoding not supported."); | 408 return Error::Nonfatal("Subset decoding not supported."); |
| 412 } | 409 } |
| 413 | 410 |
| 414 // Divide the image into subsets that cover the entire image. | 411 // Divide the image into subsets that cover the entire image. |
| 415 if (fDivisor > w || fDivisor > h) { | 412 if (fDivisor > w || fDivisor > h) { |
| 416 return SkStringPrintf("divisor %d is too big for %s with dimensions (%d
x %d)", | 413 return Error::Nonfatal(SkStringPrintf("Cannot decode subset: divisor %d
is too big" |
| 417 fDivisor, fPath.c_str(), w, h); | 414 "for %s with dimensions (%d x %d)", fDivisor, fPath.c_str(), w,
h)); |
| 418 } | 415 } |
| 419 const int subsetWidth = w / fDivisor, | 416 const int subsetWidth = w / fDivisor, |
| 420 subsetHeight = h / fDivisor; | 417 subsetHeight = h / fDivisor; |
| 421 for (int y = 0; y < h; y += subsetHeight) { | 418 for (int y = 0; y < h; y += subsetHeight) { |
| 422 for (int x = 0; x < w; x += subsetWidth) { | 419 for (int x = 0; x < w; x += subsetWidth) { |
| 423 SkBitmap subset; | 420 SkBitmap subset; |
| 424 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight); | 421 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight); |
| 425 if (!decoder->decodeSubset(&subset, rect, dstColorType)) { | 422 if (!decoder->decodeSubset(&subset, rect, dstColorType)) { |
| 426 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).
", | 423 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d).
", |
| 427 x, y, x+subsetWidth, y+subsetHeight); | 424 x, y, x+subsetWidth, y+subsetHeight); |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 skr.visit<void>(i, drawsAsSingletonPictures); | 967 skr.visit<void>(i, drawsAsSingletonPictures); |
| 971 } | 968 } |
| 972 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 969 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 973 | 970 |
| 974 canvas->drawPicture(macroPic); | 971 canvas->drawPicture(macroPic); |
| 975 return ""; | 972 return ""; |
| 976 }); | 973 }); |
| 977 } | 974 } |
| 978 | 975 |
| 979 } // namespace DM | 976 } // namespace DM |
| OLD | NEW |