aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-09-28 11:55:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-28 11:55:28 -0700
commitc56c6ef3ce6447f39894649d535acb1606595d31 (patch)
tree5db32eb16857bf1a016848ed2ead2505831cd120
parentc11c62f4a235677f3921bceed331db91ca98aaaf (diff)
SkImage::NewFromBitmap works with Index8
-rw-r--r--src/image/SkImage_Raster.cpp21
-rw-r--r--tests/ImageTest.cpp16
2 files changed, 29 insertions, 8 deletions
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 30ea7cc1a4..512e788a39 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -22,7 +22,7 @@
class SkImage_Raster : public SkImage_Base {
public:
- static bool ValidArgs(const Info& info, size_t rowBytes, SkColorTable* ctable,
+ static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable,
size_t* minSize) {
const int maxDimension = SK_MaxS32 >> 2;
@@ -44,8 +44,7 @@ public:
}
const bool needsCT = kIndex_8_SkColorType == info.colorType();
- const bool hasCT = nullptr != ctable;
- if (needsCT != hasCT) {
+ if (needsCT != hasColorTable) {
return false;
}
@@ -227,7 +226,7 @@ SkImage* SkImage_Raster::onNewSubset(const SkIRect& subset) const {
SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes,
SkColorTable* ctable) {
size_t size;
- if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable, &size) || !pixels) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable != nullptr, &size) || !pixels) {
return nullptr;
}
@@ -239,7 +238,7 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t rowBytes) {
size_t size;
- if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, &size) || !data) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) {
return nullptr;
}
@@ -255,7 +254,7 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro
SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, size_t rowBytes,
RasterReleaseProc proc, ReleaseContext ctx) {
size_t size;
- if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, &size) || !pixels) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !pixels) {
return nullptr;
}
@@ -267,7 +266,7 @@ SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz
SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
const SkIPoint& pixelRefOrigin, size_t rowBytes,
const SkSurfaceProps* props) {
- if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, nullptr)) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) {
return nullptr;
}
return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes, props);
@@ -277,7 +276,13 @@ SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr
ForceCopyMode forceCopy) {
SkASSERT(nullptr == bm.getTexture());
- if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), nullptr, nullptr)) {
+ bool hasColorTable = false;
+ if (kIndex_8_SkColorType == bm.colorType()) {
+ SkAutoLockPixels autoLockPixels(bm);
+ hasColorTable = bm.getColorTable() != nullptr;
+ }
+
+ if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), hasColorTable, nullptr)) {
return nullptr;
}
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 0b27af9780..7cdf5b4c05 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDevice.h"
@@ -345,3 +346,18 @@ DEF_GPUTEST(SkImage_Gpu2Cpu, reporter, factory) {
}
}
#endif
+
+// http://skbug.com/4390
+DEF_TEST(ImageFromIndex8Bitmap, r) {
+ SkPMColor pmColors[1] = {SkPreMultiplyColor(SK_ColorWHITE)};
+ SkBitmap bm;
+ SkAutoTUnref<SkColorTable> ctable(
+ new SkColorTable(pmColors, SK_ARRAY_COUNT(pmColors)));
+ SkImageInfo info =
+ SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType);
+ bm.allocPixels(info, nullptr, ctable);
+ SkAutoLockPixels autoLockPixels(bm);
+ *bm.getAddr8(0, 0) = 0;
+ SkAutoTUnref<SkImage> img(SkImage::NewFromBitmap(bm));
+ REPORTER_ASSERT(r, img.get() != nullptr);
+}