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" | |
5 #include "SkDocument.h" | 4 #include "SkDocument.h" |
6 #include "SkError.h" | 5 #include "SkError.h" |
7 #include "SkMultiPictureDraw.h" | 6 #include "SkMultiPictureDraw.h" |
8 #include "SkNullCanvas.h" | 7 #include "SkNullCanvas.h" |
9 #include "SkOSFile.h" | 8 #include "SkOSFile.h" |
10 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
11 #include "SkRandom.h" | 10 #include "SkRandom.h" |
12 #include "SkSVGCanvas.h" | 11 #include "SkSVGCanvas.h" |
13 #include "SkStream.h" | 12 #include "SkStream.h" |
14 #include "SkXMLWriter.h" | 13 #include "SkXMLWriter.h" |
15 | 14 |
16 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); | |
17 | |
18 namespace DM { | 15 namespace DM { |
19 | 16 |
20 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 17 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
21 | 18 |
22 Error GMSrc::draw(SkCanvas* canvas) const { | 19 Error GMSrc::draw(SkCanvas* canvas) const { |
23 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 20 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
24 canvas->concat(gm->getInitialTransform()); | 21 canvas->concat(gm->getInitialTransform()); |
25 gm->draw(canvas); | 22 gm->draw(canvas); |
26 return ""; | 23 return ""; |
27 } | 24 } |
(...skipping 14 matching lines...) Expand all Loading... |
42 | 39 |
43 Error ImageSrc::draw(SkCanvas* canvas) const { | 40 Error ImageSrc::draw(SkCanvas* canvas) const { |
44 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 41 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
45 if (!encoded) { | 42 if (!encoded) { |
46 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 43 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
47 } | 44 } |
48 const SkColorType dstColorType = canvas->imageInfo().colorType(); | 45 const SkColorType dstColorType = canvas->imageInfo().colorType(); |
49 if (fDivisor == 0) { | 46 if (fDivisor == 0) { |
50 // Decode the full image. | 47 // Decode the full image. |
51 SkBitmap bitmap; | 48 SkBitmap bitmap; |
52 if (FLAGS_codec) { | 49 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit
map, |
53 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 50 dstColorType, SkImageDecoder::kDecodeP
ixels_Mode)) { |
54 if (!codec) { | 51 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
55 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
56 } | |
57 SkImageInfo info; | |
58 if (!codec->getInfo(&info)) { | |
59 return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str()); | |
60 } | |
61 info = info.makeColorType(dstColorType); | |
62 if (info.alphaType() == kUnpremul_SkAlphaType) { | |
63 // FIXME: Currently we cannot draw unpremultiplied sources. | |
64 info = info.makeAlphaType(kPremul_SkAlphaType); | |
65 } | |
66 if (!bitmap.tryAllocPixels(info)) { | |
67 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat
h.c_str(), | |
68 info.width(), info.height()); | |
69 } | |
70 SkAutoLockPixels alp(bitmap); | |
71 const SkImageGenerator::Result result = codec->getPixels(info, bitma
p.getPixels(), | |
72 bitmap.rowB
ytes()); | |
73 if (result != SkImageGenerator::kSuccess) { | |
74 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | |
75 } | |
76 } else { | |
77 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(),
&bitmap, | |
78 dstColorType, SkImageDecoder::kDec
odePixels_Mode)) { | |
79 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
80 } | |
81 } | 52 } |
82 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. | 53 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. |
83 canvas->drawBitmap(bitmap, 0,0); | 54 canvas->drawBitmap(bitmap, 0,0); |
84 return ""; | 55 return ""; |
85 } | 56 } |
86 // Decode subsets. This is a little involved. | 57 // Decode subsets. This is a little involved. |
87 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 58 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
88 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; | 59 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; |
89 if (!decoder) { | 60 if (!decoder) { |
90 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); | 61 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 surfaces.unrefAll(); | 464 surfaces.unrefAll(); |
494 return ""; | 465 return ""; |
495 } | 466 } |
496 SkISize size() const SK_OVERRIDE { return fSize; } | 467 SkISize size() const SK_OVERRIDE { return fSize; } |
497 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
498 } proxy(fW, fH, pic, src.size()); | 469 } proxy(fW, fH, pic, src.size()); |
499 return fSink->draw(proxy, bitmap, stream, log); | 470 return fSink->draw(proxy, bitmap, stream, log); |
500 } | 471 } |
501 | 472 |
502 } // namespace DM | 473 } // namespace DM |
OLD | NEW |