case kPremul_SkAlphaType:
folder.append("_premul");
break;
+ case kUnpremul_SkAlphaType:
+ folder.append("_unpremul");
+ break;
default:
break;
}
SkTArray<SkAlphaType> alphaModes;
alphaModes.push_back(kPremul_SkAlphaType);
- // FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339
- // alphaModes.push_back(kUnpremul_SkAlphaType);
+ alphaModes.push_back(kUnpremul_SkAlphaType);
if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
alphaModes.push_back(kOpaque_SkAlphaType);
}
#include "SkMultiPictureDraw.h"
#include "SkNullCanvas.h"
#include "SkOSFile.h"
+#include "SkOpts.h"
#include "SkPictureData.h"
#include "SkPictureRecorder.h"
#include "SkRandom.h"
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
+// FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339.
+// This allows us to still test unpremultiplied decodes.
+void premultiply_if_necessary(SkBitmap& bitmap) {
+ if (kUnpremul_SkAlphaType != bitmap.alphaType()) {
+ return;
+ }
+
+ switch (bitmap.colorType()) {
+ case kN32_SkColorType:
+ for (int y = 0; y < bitmap.height(); y++) {
+ uint32_t* row = (uint32_t*) bitmap.getAddr(0, y);
+ SkOpts::RGBA_to_rgbA(row, row, bitmap.width());
+ }
+ break;
+ case kIndex_8_SkColorType: {
+ SkColorTable* colorTable = bitmap.getColorTable();
+ SkPMColor* colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
+ SkOpts::RGBA_to_rgbA(colorPtr, colorPtr, colorTable->count());
+ break;
+ }
+ default:
+ // No need to premultiply kGray or k565 outputs.
+ break;
+ }
+}
+
bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
CodecSrc::DstColorType dstColorType) {
switch (dstColorType) {
// Everything else is considered a failure.
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
+ premultiply_if_necessary(bitmap);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
}
}
+ premultiply_if_necessary(bitmap);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
codec->skipScanlines(linesToSkip);
}
}
+ premultiply_if_necessary(bitmap);
canvas->drawBitmap(bitmap, 0, 0);
break;
}
x, y, decodeInfo.width(), decodeInfo.height(),
fPath.c_str(), W, H, result);
}
+ premultiply_if_necessary(subsetBm);
canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToScalar(top));
// translate by the scaled height.
top += decodeInfo.height();
default:
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
+ premultiply_if_necessary(bitmap);
canvas->drawBitmap(bitmap, 0, 0);
return "";
}
SkRect rect = SkRect::MakeXYWH(0, 0, (SkScalar) finalScaledWidth,
(SkScalar) finalScaledHeight);
+ premultiply_if_necessary(bitmap);
canvas->drawBitmapRect(bitmap, rect, rect, nullptr);
return "";
}