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;
}
const bool needsCT = kIndex_8_SkColorType == info.colorType();
- const bool hasCT = nullptr != ctable;
- if (needsCT != hasCT) {
+ if (needsCT != hasColorTable) {
return false;
}
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;
}
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;
}
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;
}
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);
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;
}
* found in the LICENSE file.
*/
+#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDevice.h"
}
}
#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);
+}