}
/// Converts a 8888 bitmap to LAB color space and puts it into the output
-static void bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
- SkASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config);
+static bool bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
+ SkBitmap bm8888;
+ if (bitmap->config() != SkBitmap::kARGB_8888_Config) {
+ if (!bitmap->copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
+ return false;
+ }
+ bitmap = &bm8888;
+ }
int width = bitmap->width();
int height = bitmap->height();
}
}
bitmap->unlockPixels();
+ return true;
}
// From Barten SPIE 1989
maxLevels++;
}
+ // We'll be creating new arrays with maxLevels - 2, and ImageL3D requires maxLevels > 0,
+ // so just return failure if we're less than 3.
+ if (maxLevels <= 2) {
+ return 0.0;
+ }
+
const float fov = SK_ScalarPI / 180.0f * 45.0f;
float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f);
float pixelsPerDegree = width / (2.0f * tanf(fov * 0.5f) * 180.0f / SK_ScalarPI);
ImageLAB baselineLAB(baseline->width(), baseline->height());
ImageLAB testLAB(baseline->width(), baseline->height());
- bitmap_to_cielab(baseline, &baselineLAB);
- bitmap_to_cielab(test, &testLAB);
+ if (!bitmap_to_cielab(baseline, &baselineLAB) || !bitmap_to_cielab(test, &testLAB)) {
+ return diffID;
+ }
diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi);