OLD | NEW |
1 #include "DMImageTask.h" | 1 #include "DMImageTask.h" |
2 #include "DMUtil.h" | 2 #include "DMUtil.h" |
3 #include "DMWriteTask.h" | 3 #include "DMWriteTask.h" |
4 #include "SkImageDecoder.h" | 4 #include "SkImageDecoder.h" |
5 #include "SkRandom.h" | 5 #include "SkRandom.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 namespace DM { | 9 namespace DM { |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 if (fSubsets == 0) { | 31 if (fSubsets == 0) { |
32 // Decoding the whole image is considerably simpler than decoding subset
s! | 32 // Decoding the whole image is considerably simpler than decoding subset
s! |
33 SkBitmap bitmap; | 33 SkBitmap bitmap; |
34 if (!SkImageDecoder::DecodeMemory(fEncoded->data(), fEncoded->size(), &b
itmap)) { | 34 if (!SkImageDecoder::DecodeMemory(fEncoded->data(), fEncoded->size(), &b
itmap)) { |
35 return this->fail("Can't DecodeMemory"); | 35 return this->fail("Can't DecodeMemory"); |
36 } | 36 } |
37 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", bitmap))); | 37 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", bitmap))); |
38 return; | 38 return; |
39 } | 39 } |
40 | 40 |
41 SkMemoryStream stream(fEncoded->data(), fEncoded->size()); | 41 SkAutoTDelete<SkMemoryStream> stream(SkNEW_ARGS(SkMemoryStream, |
42 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); | 42 (fEncoded->data(), fEncoded-
>size()))); |
| 43 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); |
43 if (!decoder) { | 44 if (!decoder) { |
44 return this->fail("Can't find good decoder."); | 45 return this->fail("Can't find good decoder."); |
45 } | 46 } |
46 | 47 |
47 int w,h; | 48 int w,h; |
48 if (!decoder->buildTileIndex(&stream, &w, &h) || w*h == 1) { | 49 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) { |
49 return; // Subset decoding is not always supported. | 50 return; // Subset decoding is not always supported. |
50 } | 51 } |
51 | 52 |
52 SkBitmap composite; | 53 SkBitmap composite; |
53 composite.allocN32Pixels(w,h); // We're lazy here and just always use nativ
e 8888. | 54 composite.allocN32Pixels(w,h); // We're lazy here and just always use nativ
e 8888. |
54 composite.eraseColor(SK_ColorTRANSPARENT); | 55 composite.eraseColor(SK_ColorTRANSPARENT); |
55 SkCanvas canvas(composite); | 56 SkCanvas canvas(composite); |
56 | 57 |
57 SkRandom rand; | 58 SkRandom rand; |
58 for (int i = 0; i < fSubsets; i++) { | 59 for (int i = 0; i < fSubsets; i++) { |
(...skipping 10 matching lines...) Expand all Loading... |
69 if (!decoder->decodeSubset(&subset, rect, kN32_SkColorType)) { | 70 if (!decoder->decodeSubset(&subset, rect, kN32_SkColorType)) { |
70 return this->fail("Could not decode subset."); | 71 return this->fail("Could not decode subset."); |
71 } | 72 } |
72 canvas.drawBitmap(subset, SkIntToScalar(rect.fLeft), SkIntToScalar(rect.
fTop)); | 73 canvas.drawBitmap(subset, SkIntToScalar(rect.fLeft), SkIntToScalar(rect.
fTop)); |
73 } | 74 } |
74 canvas.flush(); | 75 canvas.flush(); |
75 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", composite))); | 76 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "image", composite))); |
76 } | 77 } |
77 | 78 |
78 } // namespace DM | 79 } // namespace DM |
OLD | NEW |