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 "SkError.h" | 6 #include "SkError.h" |
6 #include "SkMultiPictureDraw.h" | 7 #include "SkMultiPictureDraw.h" |
7 #include "SkNullCanvas.h" | 8 #include "SkNullCanvas.h" |
8 #include "SkOSFile.h" | 9 #include "SkOSFile.h" |
9 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
10 #include "SkRandom.h" | 11 #include "SkRandom.h" |
11 #include "SkSVGCanvas.h" | 12 #include "SkSVGCanvas.h" |
12 #include "SkStream.h" | 13 #include "SkStream.h" |
13 #include "SkXMLWriter.h" | 14 #include "SkXMLWriter.h" |
14 | 15 |
| 16 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); |
| 17 |
15 namespace DM { | 18 namespace DM { |
16 | 19 |
17 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 20 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
18 | 21 |
19 Error GMSrc::draw(SkCanvas* canvas) const { | 22 Error GMSrc::draw(SkCanvas* canvas) const { |
20 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 23 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
21 canvas->concat(gm->getInitialTransform()); | 24 canvas->concat(gm->getInitialTransform()); |
22 gm->draw(canvas); | 25 gm->draw(canvas); |
23 return ""; | 26 return ""; |
24 } | 27 } |
(...skipping 14 matching lines...) Expand all Loading... |
39 | 42 |
40 Error ImageSrc::draw(SkCanvas* canvas) const { | 43 Error ImageSrc::draw(SkCanvas* canvas) const { |
41 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 44 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
42 if (!encoded) { | 45 if (!encoded) { |
43 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 46 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
44 } | 47 } |
45 const SkColorType dstColorType = canvas->imageInfo().colorType(); | 48 const SkColorType dstColorType = canvas->imageInfo().colorType(); |
46 if (fDivisor == 0) { | 49 if (fDivisor == 0) { |
47 // Decode the full image. | 50 // Decode the full image. |
48 SkBitmap bitmap; | 51 SkBitmap bitmap; |
49 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit
map, | 52 if (FLAGS_codec) { |
50 dstColorType, SkImageDecoder::kDecodeP
ixels_Mode)) { | 53 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
51 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 54 if (!codec) { |
| 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 } |
52 } | 81 } |
53 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. | 82 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. |
54 canvas->drawBitmap(bitmap, 0,0); | 83 canvas->drawBitmap(bitmap, 0,0); |
55 return ""; | 84 return ""; |
56 } | 85 } |
57 // Decode subsets. This is a little involved. | 86 // Decode subsets. This is a little involved. |
58 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 87 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
59 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; | 88 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; |
60 if (!decoder) { | 89 if (!decoder) { |
61 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); | 90 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... |
464 surfaces.unrefAll(); | 493 surfaces.unrefAll(); |
465 return ""; | 494 return ""; |
466 } | 495 } |
467 SkISize size() const SK_OVERRIDE { return fSize; } | 496 SkISize size() const SK_OVERRIDE { return fSize; } |
468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 497 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
469 } proxy(fW, fH, pic, src.size()); | 498 } proxy(fW, fH, pic, src.size()); |
470 return fSink->draw(proxy, bitmap, stream, log); | 499 return fSink->draw(proxy, bitmap, stream, log); |
471 } | 500 } |
472 | 501 |
473 } // namespace DM | 502 } // namespace DM |
OLD | NEW |