Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: dm/DMSrcSink.cpp

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: Improved clarity of swizzler with regard to weird alpha Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/codec.gyp » ('j') | gyp/codec.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkMultiPictureDraw.h" 6 #include "SkMultiPictureDraw.h"
7 #include "SkNullCanvas.h" 7 #include "SkNullCanvas.h"
8 #include "SkOSFile.h" 8 #include "SkOSFile.h"
9 #include "SkPictureRecorder.h" 9 #include "SkPictureRecorder.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 27 matching lines...) Expand all
38 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 38 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
39 39
40 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {} 40 ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
41 41
42 Error ImageSrc::draw(SkCanvas* canvas) const { 42 Error ImageSrc::draw(SkCanvas* canvas) const {
43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
44 if (!encoded) { 44 if (!encoded) {
45 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 45 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
46 } 46 }
47 const SkColorType dstColorType = canvas->imageInfo().colorType(); 47 const SkColorType dstColorType = canvas->imageInfo().colorType();
48 SkString error;
48 if (fDivisor == 0) { 49 if (fDivisor == 0) {
49 // Decode the full image. 50 // Decode the full image.
50 SkBitmap bitmap; 51 SkBitmap bitmap;
51 if (FLAGS_codec) { 52 if (FLAGS_codec) {
52 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 53 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
53 if (!codec) { 54 if (!codec) {
54 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); 55 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
55 } 56 }
56 SkImageInfo info; 57 SkImageInfo info;
57 if (!codec->getInfo(&info)) { 58 if (!codec->getInfo(&info)) {
58 return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str()); 59 return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
59 } 60 }
60 info = info.makeColorType(dstColorType); 61 info = info.makeColorType(dstColorType);
61 if (info.alphaType() == kUnpremul_SkAlphaType) { 62 if (info.alphaType() == kUnpremul_SkAlphaType) {
62 // FIXME: Currently we cannot draw unpremultiplied sources. 63 // FIXME: Currently we cannot draw unpremultiplied sources.
63 info = info.makeAlphaType(kPremul_SkAlphaType); 64 info = info.makeAlphaType(kPremul_SkAlphaType);
64 } 65 }
65 bitmap.allocPixels(info); 66 bitmap.allocPixels(info);
66 SkAutoLockPixels alp(bitmap); 67 SkAutoLockPixels alp(bitmap);
67 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(), 68 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(),
68 bitmap.rowB ytes()); 69 bitmap.rowB ytes());
69 if (result != SkImageGenerator::kSuccess) { 70 if (result == SkImageGenerator::kIncompleteInput) {
scroggo 2015/03/04 17:10:29 I think this would read better as a switch stateme
msarett 2015/03/05 23:13:17 Doesn't feel to me like a switch statement is nece
71 error = SkStringPrintf("Warning incomplete getPixels %s.", fPath .c_str());
scroggo 2015/03/04 17:10:29 I'm not sure what the right behavior is here. Note
msarett 2015/03/05 23:13:17 The decision here is to accept kSuccess or kIncomp
72 } else if (result != SkImageGenerator::kSuccess) {
70 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); 73 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
74 } else {
75 error = "";
scroggo 2015/03/04 17:10:29 Maybe set error to "" initially?
71 } 76 }
72 } else { 77 } else {
73 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, 78 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
74 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { 79 dstColorType, SkImageDecoder::kDec odePixels_Mode)) {
75 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); 80 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
81 } else {
82 error = "";
76 } 83 }
77 } 84 }
78 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. 85 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it.
79 canvas->drawBitmap(bitmap, 0,0); 86 canvas->drawBitmap(bitmap, 0,0);
80 return ""; 87 return error;
81 } 88 }
82 // Decode subsets. This is a little involved. 89 // Decode subsets. This is a little involved.
83 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); 90 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
84 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; 91 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ;
85 if (!decoder) { 92 if (!decoder) {
86 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); 93 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() );
87 } 94 }
88 stream->rewind(); 95 stream->rewind();
89 int w,h; 96 int w,h;
90 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) { 97 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) {
(...skipping 16 matching lines...) Expand all
107 x, y, x+subsetWidth, y+subsetHeight); 114 x, y, x+subsetWidth, y+subsetHeight);
108 } 115 }
109 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y)); 116 canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y));
110 } 117 }
111 } 118 }
112 return ""; 119 return "";
113 } 120 }
114 121
115 SkISize ImageSrc::size() const { 122 SkISize ImageSrc::size() const {
116 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); 123 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
117 SkBitmap bitmap; 124 if (FLAGS_codec) {
118 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(), 125 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
119 encoded->size(), 126 if (!codec) {
120 &bitmap, 127 return SkISize::Make(0,0);
121 kUnknown_SkColorType, 128 }
122 SkImageDecoder::kDecodeBounds_ Mode)) { 129 SkImageInfo info;
123 return SkISize::Make(0,0); 130 if (!codec->getInfo(&info)) {
131 return SkISize::Make(0,0);
132 }
133 return info.dimensions();
134 } else {
135 SkBitmap bitmap;
136 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
137 encoded->size(),
138 &bitmap,
139 kUnknown_SkColorType,
140 SkImageDecoder::kDecodeBou nds_Mode)) {
141 return SkISize::Make(0,0);
142 }
143 return bitmap.dimensions();
124 } 144 }
125 return bitmap.dimensions();
126 } 145 }
127 146
128 Name ImageSrc::name() const { 147 Name ImageSrc::name() const {
129 return SkOSPath::Basename(fPath.c_str()); 148 return SkOSPath::Basename(fPath.c_str());
130 } 149 }
131 150
132 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 151 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
133 152
134 static const SkRect kSKPViewport = {0,0, 1000,1000}; 153 static const SkRect kSKPViewport = {0,0, 1000,1000};
135 154
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 surfaces.unrefAll(); 502 surfaces.unrefAll();
484 return ""; 503 return "";
485 } 504 }
486 SkISize size() const SK_OVERRIDE { return fSize; } 505 SkISize size() const SK_OVERRIDE { return fSize; }
487 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 506 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
488 } proxy(fW, fH, pic, src.size()); 507 } proxy(fW, fH, pic, src.size());
489 return fSink->draw(proxy, bitmap, stream, log); 508 return fSink->draw(proxy, bitmap, stream, log);
490 } 509 }
491 510
492 } // namespace DM 511 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | gyp/codec.gyp » ('j') | gyp/codec.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698