All of the CodecSubset benches fail when the color type is
kIndex8. We need to pass a color table to allocPixels()
when we want to decode to kIndex8 or it will throw a failure.
BUG=skia:
Review URL: https://codereview.chromium.org/
1213983003
}
}
+/*
+ * If we plan to decode to kIndex8, we must create a color table and pass it to the
+ * bitmap when we allocate pixels. Otherwise, we simply allocate pixels using the
+ * decode info.
+ */
+static inline void alloc_pixels(SkBitmap* bitmap, const SkImageInfo& info, SkPMColor* colors,
+ int colorCount) {
+ if (kIndex_8_SkColorType == info.colorType()) {
+ SkAutoTUnref<SkColorTable> colorTable(SkNEW_ARGS(SkColorTable, (colors, colorCount)));
+ bitmap->allocPixels(info, NULL, colorTable);
+ } else {
+ bitmap->allocPixels(info);
+ }
+}
+
#endif // SubsetBenchPriv_DEFINED
info, NULL, colors, &colorCount);
SkBitmap bitmap;
- bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight));
+ SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
scanlineDecoder->skipScanlines(fOffsetTop);
uint32_t bpp = info.bytesPerPixel();
SkBitmap bitmap;
// Note that we use the same bitmap for all of the subsets.
// It might be larger than necessary for the end subsets.
- bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight));
+ SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
for (int x = 0; x < info.width(); x += fSubsetWidth) {
for (int y = 0; y < info.height(); y += fSubsetHeight) {
// Note that if we subsetted and scaled in a single step, we could use the
// same bitmap - as is often done in actual use cases.
SkBitmap bitmap;
- bitmap.allocPixels(info.makeWH(subsetWidth, subsetHeight));
+ SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
+ alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
uint32_t bpp = info.bytesPerPixel();
scanlineDecoder->skipScanlines(subsetStartY);