Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index f555b9fcbdba78f485e47b9baf4be67d2fa1d83c..6d4c3892d422e07c1cfced1db4739e9e16dee7be 100644 |
--- a/dm/DMSrcSink.cpp |
+++ b/dm/DMSrcSink.cpp |
@@ -64,6 +64,121 @@ void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
+BRDSrc::BRDSrc(Path path, SkBitmapRegionDecoder::Strategy strategy, Mode mode, SkColorType dstColorType, uint32_t sampleSize) |
scroggo
2015/08/13 16:53:06
nit: too many chars
msarett
2015/08/13 18:10:22
Done.
|
+ : fPath(path) |
+ , fStrategy(strategy) |
+ , fMode(mode) |
+ , fColorType(dstColorType) |
+ , fSampleSize(sampleSize) |
+{} |
+ |
+bool BRDSrc::veto(SinkFlags flags) const { |
+ // It is interesting to test different dstColorTypes instead of different sinks |
scroggo
2015/08/13 16:53:06
Huh?
msarett
2015/08/13 18:10:22
I changed this comment.
The original comment was
|
+ return flags.type != SinkFlags::kRaster |
+ || flags.approach != SinkFlags::kDirect; |
+} |
+ |
+Error BRDSrc::draw(SkCanvas* canvas) const { |
+ if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
+ return Error::Nonfatal("Testing to multiple backends is uninteresting."); |
+ } |
+ |
+ switch (fMode) { |
+ case kNormal_Mode: { |
+ SkAutoTDelete<SkBitmapRegionDecoder> brd( |
+ SkBitmapRegionDecoder::CreateBitmapRegionDecoder( |
+ SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName(fPath.c_str()))), |
+ fStrategy)); |
+ if (NULL == brd.get()) { |
+ return "Error: Could not CreateBRD.\n"; |
scroggo
2015/08/13 16:53:06
nit: I don't think "Error: " is necessary here. I
msarett
2015/08/13 18:10:22
Done.
|
+ } |
+ SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), |
+ brd->height(), fSampleSize, fColorType)); |
+ if (NULL == bitmap.get() || fColorType != bitmap->colorType()) { |
+ return Error::Nonfatal("Cannot convert to color type.\n"); |
+ } |
+ canvas->drawBitmap(*bitmap, 0, 0); |
+ return ""; |
+ } |
+ case kSubset_Mode: { |
+ SkAutoTDelete<SkBitmapRegionDecoder> brd( |
scroggo
2015/08/13 16:53:06
It looks like these two are the same? Why not crea
msarett
2015/08/13 18:10:22
Done.
|
+ SkBitmapRegionDecoder::CreateBitmapRegionDecoder( |
+ SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName(fPath.c_str()))), |
+ fStrategy)); |
+ if (NULL == brd.get()) { |
+ return "Error: Could not CreateBRD.\n"; |
+ } |
+ |
+ // Use a border to test what happens when we ask for subsets that extend outside the image |
msarett
2015/08/13 15:16:34
This leads to outputs that are a bit strange for 5
scroggo
2015/08/13 16:53:06
Wait, so if the subset is bigger than 5 pixels, th
msarett
2015/08/13 18:10:22
So I think my comment was completely wrong.
We ar
scroggo
2015/08/28 13:49:43
+1
msarett
2015/08/28 18:45:50
I've fixed this. I had an off by one error that w
|
+ uint32_t scaledBorder = 5; |
+ uint32_t unscaledBorder = 5 * fSampleSize; |
+ uint32_t divisor = 2; |
+ uint32_t width = brd->width(); |
+ uint32_t height = brd->height(); |
+ for (uint32_t x = 0; x < divisor; x++) { |
+ for (uint32_t y = 0; y < divisor; y++) { |
+ // Calculate the subset dimensions |
+ uint32_t subsetWidth = width / divisor; |
+ uint32_t subsetHeight = height / divisor; |
+ int left = x * subsetWidth; |
+ int top = y * subsetHeight; |
+ |
+ // Increase the size of the last subset in each row or column, when the |
+ // divisor does not divide evenly into the image dimensions |
+ subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0; |
+ subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0; |
+ |
+ // Increase the size of the subset in order to have a border on each side |
+ int decodeLeft = left - unscaledBorder; |
+ int decodeTop = top - unscaledBorder; |
+ uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; |
+ uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; |
+ |
+ SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, |
+ decodeTop, decodeWidth, decodeHeight, fSampleSize, fColorType)); |
+ if (NULL == bitmap.get() || fColorType != bitmap->colorType()) { |
+ return Error::Nonfatal("Cannot convert to color type.\n"); |
+ } |
+ canvas->drawBitmapRect(*bitmap, |
+ SkRect::MakeXYWH(scaledBorder, scaledBorder, |
+ subsetWidth / fSampleSize, subsetHeight / fSampleSize), |
+ SkRect::MakeXYWH(left / fSampleSize, top / fSampleSize, |
+ subsetWidth / fSampleSize, subsetHeight / fSampleSize), |
+ NULL); |
+ } |
+ } |
+ return ""; |
+ } |
+ default: |
+ SkASSERT(false); |
+ return "Error: Should not be reached.\n"; |
+ } |
+} |
+ |
+SkISize BRDSrc::size() const { |
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
+ if (NULL != codec) { |
scroggo
2015/08/13 16:53:06
nit: checking !condition seems odd to me, if there
msarett
2015/08/13 18:10:22
Done.
|
+ return SkISize::Make(codec->getInfo().width() / fSampleSize, |
+ codec->getInfo().height() / fSampleSize); |
+ } else { |
scroggo
2015/08/13 16:53:06
This else is unnecessary, since the earlier condit
msarett
2015/08/13 18:10:23
Done.
|
+ return SkISize::Make(0, 0); |
+ } |
+} |
+ |
+Name BRDSrc::name() const { |
+ // We will try to replicate the names used by CodecSrc so that images can |
scroggo
2015/08/13 16:53:06
Try to? Do we ever fail?
msarett
2015/08/13 18:10:22
Nope :)
|
+ // be compared in Gold. |
+ if (1.0f == fSampleSize) { |
+ return SkOSPath::Basename(fPath.c_str()); |
+ } else { |
+ float scale = 1.0f / fSampleSize; |
+ return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), scale); |
+ } |
+} |
+ |
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
+ |
CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
: fPath(path) |
, fMode(mode) |
@@ -448,8 +563,7 @@ SkISize CodecSrc::size() const { |
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
if (NULL != codec) { |
- SkISize size = codec->getScaledDimensions(fScale); |
- return size; |
+ return codec->getScaledDimensions(fScale); |
} else { |
return SkISize::Make(0, 0); |
} |