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 "SkDocument.h" | 5 #include "SkDocument.h" |
5 #include "SkMultiPictureDraw.h" | 6 #include "SkMultiPictureDraw.h" |
6 #include "SkNullCanvas.h" | 7 #include "SkNullCanvas.h" |
7 #include "SkOSFile.h" | 8 #include "SkOSFile.h" |
8 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
9 #include "SkRandom.h" | 10 #include "SkRandom.h" |
10 #include "SkSVGCanvas.h" | 11 #include "SkSVGCanvas.h" |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 #include "SkXMLWriter.h" | 13 #include "SkXMLWriter.h" |
13 | 14 |
15 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); | |
16 | |
14 namespace DM { | 17 namespace DM { |
15 | 18 |
16 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 19 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
17 | 20 |
18 Error GMSrc::draw(SkCanvas* canvas) const { | 21 Error GMSrc::draw(SkCanvas* canvas) const { |
19 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 22 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
20 canvas->concat(gm->getInitialTransform()); | 23 canvas->concat(gm->getInitialTransform()); |
21 gm->draw(canvas); | 24 gm->draw(canvas); |
22 return ""; | 25 return ""; |
23 } | 26 } |
(...skipping 14 matching lines...) Expand all Loading... | |
38 | 41 |
39 Error ImageSrc::draw(SkCanvas* canvas) const { | 42 Error ImageSrc::draw(SkCanvas* canvas) const { |
40 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
41 if (!encoded) { | 44 if (!encoded) { |
42 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 45 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
43 } | 46 } |
44 const SkColorType dstColorType = canvas->imageInfo().colorType(); | 47 const SkColorType dstColorType = canvas->imageInfo().colorType(); |
45 if (fDivisor == 0) { | 48 if (fDivisor == 0) { |
46 // Decode the full image. | 49 // Decode the full image. |
47 SkBitmap bitmap; | 50 SkBitmap bitmap; |
48 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, | 51 if (FLAGS_codec) { |
49 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { | 52 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
50 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 53 if (!codec) { |
54 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
55 } | |
56 SkImageInfo info; | |
57 if (!codec->getInfo(&info)) { | |
58 return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str()); | |
59 } | |
60 info = info.makeColorType(dstColorType); | |
61 if (info.alphaType() == kUnpremul_SkAlphaType) { | |
62 // FIXME: Currently we cannot draw unpremultiplied sources. | |
63 info = info.makeAlphaType(kPremul_SkAlphaType); | |
64 } | |
65 bitmap.allocPixels(info); | |
66 SkAutoLockPixels alp(bitmap); | |
djsollen
2015/02/25 16:02:19
aren't the pixels locked during allocPixels if you
scroggo
2015/02/25 18:00:54
Yes. In fact I initially left this line out, if yo
| |
67 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(), | |
68 bitmap.rowB ytes()); | |
69 if (result != SkImageGenerator::kSuccess) { | |
70 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | |
71 } | |
72 } else { | |
djsollen
2015/02/25 16:02:19
else if
scroggo
2015/02/25 18:00:54
In this case, I actually like the current code bet
| |
73 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, | |
74 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { | |
75 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
76 } | |
51 } | 77 } |
52 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. | 78 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. |
53 canvas->drawBitmap(bitmap, 0,0); | 79 canvas->drawBitmap(bitmap, 0,0); |
54 return ""; | 80 return ""; |
55 } | 81 } |
56 // Decode subsets. This is a little involved. | 82 // Decode subsets. This is a little involved. |
57 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 83 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
58 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; | 84 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; |
59 if (!decoder) { | 85 if (!decoder) { |
60 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); | 86 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 surfaces.unrefAll(); | 483 surfaces.unrefAll(); |
458 return ""; | 484 return ""; |
459 } | 485 } |
460 SkISize size() const SK_OVERRIDE { return fSize; } | 486 SkISize size() const SK_OVERRIDE { return fSize; } |
461 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. | 487 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. |
462 } proxy(fW, fH, pic, src.size()); | 488 } proxy(fW, fH, pic, src.size()); |
463 return fSink->draw(proxy, bitmap, stream, log); | 489 return fSink->draw(proxy, bitmap, stream, log); |
464 } | 490 } |
465 | 491 |
466 } // namespace DM | 492 } // namespace DM |
OLD | NEW |