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

Unified Diff: dm/DMWriteTask.cpp

Issue 802793002: Add image decoding mode to DM. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: transparent, build fixes Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DMImageTask.cpp ('k') | gyp/dm.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMWriteTask.cpp
diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp
index fbb3c77d9e6c84b9352ec2f80a0e9d0f3496e373..aee43a80b87c5fbf403abb82feae4b42b43a752b 100644
--- a/dm/DMWriteTask.cpp
+++ b/dm/DMWriteTask.cpp
@@ -60,8 +60,9 @@ WriteTask::WriteTask(const Task& parent,
}
void WriteTask::makeDirOrFail(SkString dir) {
- if (!sk_mkdir(dir.c_str())) {
- this->fail();
+ // This can be a little racy, so if it fails check to see if someone else succeeded.
+ if (!sk_mkdir(dir.c_str()) && !sk_isdir(dir.c_str())) {
+ this->fail("Can't make directory.");
}
}
@@ -92,6 +93,19 @@ static SkString get_md5(SkStreamAsset* stream) {
return get_md5_string(&hasher);
}
+static bool encode_png(const SkBitmap& src, SkFILEWStream* file) {
+ SkBitmap bm;
+ // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
+ if (src.info().colorType() == kAlpha_8_SkColorType) {
+ if (!src.copyTo(&bm, kN32_SkColorType)) {
+ return false;
+ }
+ } else {
+ bm = src;
+ }
+ return SkImageEncoder::EncodeStream(file, bm, SkImageEncoder::kPNG_Type, 100);
+}
+
void WriteTask::draw() {
SkString md5;
{
@@ -153,7 +167,7 @@ void WriteTask::draw() {
}
bool ok = fData ? write_asset(fData, &file)
- : SkImageEncoder::EncodeStream(&file, fBitmap, SkImageEncoder::kPNG_Type, 100);
+ : encode_png(fBitmap, &file);
if (!ok) {
return this->fail("Can't write to file.");
}
« no previous file with comments | « dm/DMImageTask.cpp ('k') | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698