static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, SkColorType ct) { SkColorTable* ctable = nullptr; if (kIndex_8_SkColorType == ct) { ctable = init_ctable(); } srcOpaque->allocPixels(SkImageInfo::Make(W, H, ct, kOpaque_SkAlphaType), nullptr, ctable); srcPremul->allocPixels(SkImageInfo::Make(W, H, ct, kPremul_SkAlphaType), nullptr, ctable); SkSafeUnref(ctable); init_src(*srcOpaque); init_src(*srcPremul); }
static void setup_src_bitmaps(SkBitmap* srcOpaque, SkBitmap* srcPremul, SkBitmap::Config config) { SkColorTable* ctOpaque = NULL; SkColorTable* ctPremul = NULL; srcOpaque->setConfig(config, W, H, 0, kOpaque_SkAlphaType); srcPremul->setConfig(config, W, H, 0, kPremul_SkAlphaType); if (SkBitmap::kIndex8_Config == config) { ctOpaque = init_ctable(kOpaque_SkAlphaType); ctPremul = init_ctable(kPremul_SkAlphaType); } srcOpaque->allocPixels(ctOpaque); srcPremul->allocPixels(ctPremul); SkSafeUnref(ctOpaque); SkSafeUnref(ctPremul); init_src(*srcOpaque); init_src(*srcPremul); }
avx512f_test (void) { float a[NUM]; float r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = floorf (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != floorf (a[i])) abort(); }
TEST (void) { float a[NUM]; float r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = ceilf (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != ceilf (a[i])) abort(); }
sse4_1_test (void) { double a[NUM]; double r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = ceil (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != ceil (a[i])) abort(); }
avx512f_test (void) { double a[NUM]; int r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = (int) floor (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != (int) floor (a[i])) abort(); }
TEST (void) { double a[NUM]; float r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = (float) a[i]; /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != (float) a[i]) abort(); }
TEST (void) { double a[NUM]; double r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = floor (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != floor (a[i])) abort(); }
TEST (void) { float a[NUM]; int r[NUM]; int i; init_src (a); for (i = 0; i < NUM; i++) r[i] = (int) __builtin_floorf (a[i]); /* check results: */ for (i = 0; i < NUM; i++) if (r[i] != (int) __builtin_floorf (a[i])) abort(); }
static void TestBitmapCopy(skiatest::Reporter* reporter) { static const Pair gPairs[] = { { SkBitmap::kNo_Config, "00000000" }, { SkBitmap::kA1_Config, "01000000" }, { SkBitmap::kA8_Config, "00101110" }, { SkBitmap::kIndex8_Config, "00111110" }, { SkBitmap::kRGB_565_Config, "00101110" }, { SkBitmap::kARGB_4444_Config, "00101110" }, { SkBitmap::kARGB_8888_Config, "00101110" }, // TODO: create valid RLE bitmap to test with // { SkBitmap::kRLE_Index8_Config, "00101111" } }; const int W = 20; const int H = 33; for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) { SkBitmap src, dst; SkColorTable* ct = NULL; src.setConfig(gPairs[i].fConfig, W, H); if (SkBitmap::kIndex8_Config == src.config() || SkBitmap::kRLE_Index8_Config == src.config()) { ct = init_ctable(); } src.allocPixels(ct); ct->safeRef(); init_src(src); bool success = src.copyTo(&dst, gPairs[j].fConfig); bool expected = gPairs[i].fValid[j] != '0'; if (success != expected) { SkString str; str.printf("SkBitmap::copyTo from %s to %s. expected %s returned %s", gConfigName[i], gConfigName[j], boolStr(expected), boolStr(success)); reporter->reportFailed(str); } bool canSucceed = src.canCopyTo(gPairs[j].fConfig); if (success != canSucceed) { SkString str; str.printf("SkBitmap::copyTo from %s to %s. returned %s canCopyTo %s", gConfigName[i], gConfigName[j], boolStr(success), boolStr(canSucceed)); reporter->reportFailed(str); } if (success) { REPORTER_ASSERT(reporter, src.width() == dst.width()); REPORTER_ASSERT(reporter, src.height() == dst.height()); REPORTER_ASSERT(reporter, dst.config() == gPairs[j].fConfig); test_isOpaque(reporter, src, dst.config()); if (src.config() == dst.config()) { SkAutoLockPixels srcLock(src); SkAutoLockPixels dstLock(dst); REPORTER_ASSERT(reporter, src.readyToDraw()); REPORTER_ASSERT(reporter, dst.readyToDraw()); const char* srcP = (const char*)src.getAddr(0, 0); const char* dstP = (const char*)dst.getAddr(0, 0); REPORTER_ASSERT(reporter, srcP != dstP); REPORTER_ASSERT(reporter, !memcmp(srcP, dstP, src.getSize())); } // test extractSubset { SkBitmap subset; SkIRect r; r.set(1, 1, 2, 2); if (src.extractSubset(&subset, r)) { REPORTER_ASSERT(reporter, subset.width() == 1); REPORTER_ASSERT(reporter, subset.height() == 1); SkBitmap copy; REPORTER_ASSERT(reporter, subset.copyTo(©, subset.config())); REPORTER_ASSERT(reporter, copy.width() == 1); REPORTER_ASSERT(reporter, copy.height() == 1); REPORTER_ASSERT(reporter, copy.rowBytes() <= 4); SkAutoLockPixels alp0(subset); SkAutoLockPixels alp1(copy); // they should both have, or both not-have, a colortable bool hasCT = subset.getColorTable() != NULL; REPORTER_ASSERT(reporter, (copy.getColorTable() != NULL) == hasCT); } } } else { // dst should be unchanged from its initial state REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config); REPORTER_ASSERT(reporter, dst.width() == 0); REPORTER_ASSERT(reporter, dst.height() == 0); } } } }