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" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 12 #include "SkScanlineDecoder.h" |
| 13 #include "SkStream.h" |
12 #include "SkSVGCanvas.h" | 14 #include "SkSVGCanvas.h" |
13 #include "SkStream.h" | |
14 #include "SkXMLWriter.h" | 15 #include "SkXMLWriter.h" |
15 | 16 |
16 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); | 17 DEFINE_bool(codec, true, "Use SkCodec instead of SkImageDecoder"); |
17 | 18 |
18 namespace DM { | 19 namespace DM { |
19 | 20 |
20 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 21 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
21 | 22 |
22 Error GMSrc::draw(SkCanvas* canvas) const { | 23 Error GMSrc::draw(SkCanvas* canvas) const { |
23 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 24 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
24 canvas->concat(gm->getInitialTransform()); | 25 canvas->concat(gm->getInitialTransform()); |
25 gm->draw(canvas); | 26 gm->draw(canvas); |
26 return ""; | 27 return ""; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 info = info.makeColorType(dstColorType); | 62 info = info.makeColorType(dstColorType); |
62 if (info.alphaType() == kUnpremul_SkAlphaType) { | 63 if (info.alphaType() == kUnpremul_SkAlphaType) { |
63 // FIXME: Currently we cannot draw unpremultiplied sources. | 64 // FIXME: Currently we cannot draw unpremultiplied sources. |
64 info = info.makeAlphaType(kPremul_SkAlphaType); | 65 info = info.makeAlphaType(kPremul_SkAlphaType); |
65 } | 66 } |
66 if (!bitmap.tryAllocPixels(info)) { | 67 if (!bitmap.tryAllocPixels(info)) { |
67 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat
h.c_str(), | 68 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat
h.c_str(), |
68 info.width(), info.height()); | 69 info.width(), info.height()); |
69 } | 70 } |
70 SkAutoLockPixels alp(bitmap); | 71 SkAutoLockPixels alp(bitmap); |
71 const SkImageGenerator::Result result = codec->getPixels(info, bitma
p.getPixels(), | 72 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineD
ecoder(info)); |
72 bitmap.rowB
ytes()); | 73 if (NULL == scanlineDecoder) { |
73 switch (result) { | 74 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); |
74 case SkImageGenerator::kSuccess: | 75 } |
75 // We consider incomplete to be valid, since we should still dec
ode what is | 76 |
76 // available. | 77 for (int y = 0; y < info.height(); ++y) { |
77 case SkImageGenerator::kIncompleteInput: | 78 const SkImageGenerator::Result result = |
78 break; | 79 scanlineDecoder->getNextScanline(bitmap.getAddr(0, y)); |
79 case SkImageGenerator::kInvalidConversion: | 80 switch (result) { |
80 return Error::Nonfatal("Incompatible colortype conversion"); | 81 case SkImageGenerator::kSuccess: |
81 default: | 82 // We consider incomplete to be valid, since we should s
till decode what is |
82 // Everything else is considered a failure. | 83 // available. |
83 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 84 case SkImageGenerator::kIncompleteInput: |
| 85 break; |
| 86 default: |
| 87 // Everything else is considered a failure. |
| 88 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_
str()); |
| 89 } |
| 90 } |
| 91 |
| 92 const SkImageGenerator::Result result = scanlineDecoder->finish(); |
| 93 if (result != SkImageGenerator::kSuccess) { |
| 94 return SkStringPrintf("failed in finish!"); |
84 } | 95 } |
85 } else { | 96 } else { |
86 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(),
&bitmap, | 97 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(),
&bitmap, |
87 dstColorType, SkImageDecoder::kDec
odePixels_Mode)) { | 98 dstColorType, SkImageDecoder::kDec
odePixels_Mode)) { |
88 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 99 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
89 } | 100 } |
90 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { | 101 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { |
91 // Do not draw a bitmap with alpha to a destination without alph
a. | 102 // Do not draw a bitmap with alpha to a destination without alph
a. |
92 return Error::Nonfatal("Uninteresting to decode image with alpha
into 565."); | 103 return Error::Nonfatal("Uninteresting to decode image with alpha
into 565."); |
93 } | 104 } |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 surfaces.unrefAll(); | 544 surfaces.unrefAll(); |
534 return ""; | 545 return ""; |
535 } | 546 } |
536 SkISize size() const SK_OVERRIDE { return fSize; } | 547 SkISize size() const SK_OVERRIDE { return fSize; } |
537 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 548 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
538 } proxy(fW, fH, pic, src.size()); | 549 } proxy(fW, fH, pic, src.size()); |
539 return fSink->draw(proxy, bitmap, stream, log); | 550 return fSink->draw(proxy, bitmap, stream, log); |
540 } | 551 } |
541 | 552 |
542 } // namespace DM | 553 } // namespace DM |
OLD | NEW |