OLD | NEW |
---|---|
1 #include "DMSrcSink.h" | 1 #include "DMSrcSink.h" |
2 #include "SamplePipeControllers.h" | 2 #include "SamplePipeControllers.h" |
3 #include "SkCommonFlags.h" | 3 #include "SkCommonFlags.h" |
4 #include "SkCodec.h" | 4 #include "SkCodec.h" |
5 #include "SkDocument.h" | 5 #include "SkDocument.h" |
6 #include "SkError.h" | 6 #include "SkError.h" |
7 #include "SkMultiPictureDraw.h" | 7 #include "SkMultiPictureDraw.h" |
8 #include "SkNullCanvas.h" | 8 #include "SkNullCanvas.h" |
9 #include "SkOSFile.h" | 9 #include "SkOSFile.h" |
10 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // FIXME: Currently we cannot draw unpremultiplied sources. | 63 // FIXME: Currently we cannot draw unpremultiplied sources. |
64 info = info.makeAlphaType(kPremul_SkAlphaType); | 64 info = info.makeAlphaType(kPremul_SkAlphaType); |
65 } | 65 } |
66 if (!bitmap.tryAllocPixels(info)) { | 66 if (!bitmap.tryAllocPixels(info)) { |
67 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | 67 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), |
68 info.width(), info.height()); | 68 info.width(), info.height()); |
69 } | 69 } |
70 SkAutoLockPixels alp(bitmap); | 70 SkAutoLockPixels alp(bitmap); |
71 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(), | 71 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(), |
72 bitmap.rowB ytes()); | 72 bitmap.rowB ytes()); |
73 if (result != SkImageGenerator::kSuccess) { | 73 switch (result) { |
74 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | 74 case SkImageGenerator::kSuccess: |
75 // We consider incomplete to be valid, since we should still dec ode what is | |
76 // available. | |
77 case SkImageGenerator::kIncompleteInput: | |
78 break; | |
79 case SkImageGenerator::kInvalidConversion: | |
80 return Error::Nonfatal("Incompatible colortype conversion"); | |
81 default: | |
82 // Everything else is considered a failure. | |
83 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | |
75 } | 84 } |
76 } else { | 85 } else { |
77 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, | 86 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, |
78 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { | 87 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { |
79 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 88 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
80 } | 89 } |
90 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { | |
91 // Do not draw a bitmap with alpha to a destination without alph a. | |
92 return Error::Nonfatal("Skipping drawing non-opaque image to opa que dst."); | |
mtklein
2015/03/05 17:07:36
we're going to add "skipped: " to the front of thi
scroggo
2015/03/05 19:34:24
Done.
| |
93 } | |
81 } | 94 } |
82 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. | 95 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. |
83 canvas->drawBitmap(bitmap, 0,0); | 96 canvas->drawBitmap(bitmap, 0,0); |
84 return ""; | 97 return ""; |
85 } | 98 } |
86 // Decode subsets. This is a little involved. | 99 // Decode subsets. This is a little involved. |
87 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 100 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
88 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; | 101 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; |
89 if (!decoder) { | 102 if (!decoder) { |
90 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); | 103 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); |
(...skipping 12 matching lines...) Expand all Loading... | |
103 const int subsetWidth = w / fDivisor, | 116 const int subsetWidth = w / fDivisor, |
104 subsetHeight = h / fDivisor; | 117 subsetHeight = h / fDivisor; |
105 for (int y = 0; y < h; y += subsetHeight) { | 118 for (int y = 0; y < h; y += subsetHeight) { |
106 for (int x = 0; x < w; x += subsetWidth) { | 119 for (int x = 0; x < w; x += subsetWidth) { |
107 SkBitmap subset; | 120 SkBitmap subset; |
108 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight); | 121 SkIRect rect = SkIRect::MakeXYWH(x, y, subsetWidth, subsetHeight); |
109 if (!decoder->decodeSubset(&subset, rect, dstColorType)) { | 122 if (!decoder->decodeSubset(&subset, rect, dstColorType)) { |
110 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d). ", | 123 return SkStringPrintf("Could not decode subset (%d, %d, %d, %d). ", |
111 x, y, x+subsetWidth, y+subsetHeight); | 124 x, y, x+subsetWidth, y+subsetHeight); |
112 } | 125 } |
126 if (kRGB_565_SkColorType == dstColorType && !subset.isOpaque()) { | |
127 // Do not draw a bitmap with alpha to a destination without alph a. | |
128 // This is not an error, but there is nothing interesting to sho w. | |
129 | |
130 // This should only happen on the first iteration through the lo op. | |
131 SkASSERT(0 == x && 0 == y); | |
132 | |
133 return Error::Nonfatal("Skipping drawing non-opaque image to opa que dst."); | |
134 } | |
113 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y)); | 135 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y)); |
114 } | 136 } |
115 } | 137 } |
116 return ""; | 138 return ""; |
117 } | 139 } |
118 | 140 |
119 SkISize ImageSrc::size() const { | 141 SkISize ImageSrc::size() const { |
120 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 142 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
121 SkBitmap bitmap; | 143 SkBitmap bitmap; |
122 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(), | 144 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(), |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 surfaces.unrefAll(); | 533 surfaces.unrefAll(); |
512 return ""; | 534 return ""; |
513 } | 535 } |
514 SkISize size() const SK_OVERRIDE { return fSize; } | 536 SkISize size() const SK_OVERRIDE { return fSize; } |
515 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. | 537 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. |
516 } proxy(fW, fH, pic, src.size()); | 538 } proxy(fW, fH, pic, src.size()); |
517 return fSink->draw(proxy, bitmap, stream, log); | 539 return fSink->draw(proxy, bitmap, stream, log); |
518 } | 540 } |
519 | 541 |
520 } // namespace DM | 542 } // namespace DM |
OLD | NEW |